task_type
stringclasses
4 values
problem
stringlengths
14
5.23k
solution
stringlengths
1
8.29k
problem_tokens
int64
9
1.02k
solution_tokens
int64
1
1.98k
coding
Solve the programming task below in a Python markdown code block. In this kata, your job is to return the two distinct highest values in a list. If there're less than 2 unique values, return as many of them, as possible. The result should also be ordered from highest to lowest. Examples: ``` [4, 10, 10, 9] => [10,...
{"functional": "_inputs = [[[]], [[15]], [[15, 20, 20, 17]]]\n_outputs = [[[]], [[15]], [[20, 17]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != l...
134
188
coding
Solve the programming task below in a Python markdown code block. Given an array of integers, calculate the ratios of its elements that are positive, negative, and zero. Print the decimal value of each fraction on a new line with $6$ places after the decimal. Note: This challenge introduces precision problems. The te...
{"inputs": ["6 \n-4 3 -9 0 4 1\n"], "outputs": ["0.500000\n0.333333\n0.166667\n"]}
556
54
coding
Solve the programming task below in a Python markdown code block. You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}] containing distinct positive integers. Let B be a [permutation] of A. Define the *value* of B to be \sum_{i=1}^N (B_{i} \bmod{B_{i+1}}) where B_{N+1} is treated to be B_{1}. Find the maximum *va...
{"inputs": ["2\n2\n5 13\n4\n11 5 14869010166 19007432007\n"], "outputs": ["8\n14869010184\n"]}
755
64
coding
Solve the programming task below in a Python markdown code block. Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the ...
{"inputs": ["1\nw\n", "1\nw\n", "1\nv\n", "1\nu\n", "1\nt\n", "1\ns\n", "2\nno\n", "2\ncb\n"], "outputs": ["w\n", "w\n", "v\n", "u\n", "t\n", "s\n", "no\n", "cb\n"]}
527
87
coding
Solve the programming task below in a Python markdown code block. Consider an N \times M binary matrix A, i.e. a grid consisting of N rows numbered 1 to N from top to bottom and M columns numbered 1 to M from left to right, whose cells take the value 0 or 1. Let (i, j) denote the cell on the i-th row and j-th column. ...
{"inputs": ["2\n3 3\n4 5"], "outputs": ["5\n10"]}
439
23
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Сhef has assembled a football team! Now he needs to choose a name for his team. There are $N$ words in English that Chef considers *funny*. These wor...
{"inputs": ["3\n2\nsuf mas\n3\ngood game guys\n4\nhell bell best test"], "outputs": ["2\n0\n2"]}
563
36
coding
Solve the programming task below in a Python markdown code block. The city of Gridland is represented as an $n\times m$ matrix where the rows are numbered from $1$ to $n$ and the columns are numbered from $1$ to $m$. Gridland has a network of train tracks that always run in straight horizontal lines along a row. In ot...
{"inputs": ["4 4 3\n2 2 3\n3 1 4\n4 4 4\n"], "outputs": ["9\n"]}
702
36
coding
Solve the programming task below in a Python markdown code block. Given a string, swap the case for each of the letters. e.g. CodEwArs --> cODeWaRS ### Examples ``` "" -> "" "CodeWars" -> "cODEwARS" "abc" -> "ABC" "ABC" -> "abc" "123235" -> "123235" ``` Also feel free to reuse...
{"functional": "_inputs = [['HelloWorld'], ['CodeWars'], ['ThIs iS A l0NG sENTence witH nUMbERs in IT 123 456'], [''], [' '], [' '], [' 1a1 '], ['H_E_l-l_0 WO|||Rld'], ['TeSt'], ['EeEEeeEEEeee']]\n_outputs = [['hELLOwORLD'], ['cODEwARS'], ['tHiS Is a L0ng SentENCE WITh NumBerS IN it 123 456'], [''], [' '], [' '], [' ...
123
311
coding
Solve the programming task below in a Python markdown code block. Takahashi has an empty string S and a variable x whose initial value is 0. Also, we have a string T consisting of `0` and `1`. Now, Takahashi will do the operation with the following two steps |T| times. * Insert a `0` or a `1` at any position of S of...
{"inputs": ["1001", "1000", "1010", "0010", "0001", "0000", "1110", "1011"], "outputs": ["5\n", "4\n", "6\n", "3\n", "2\n", "0\n", "6\n", "6\n"]}
281
86
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. In every contest there should be an easy problem about matrices. December Cook-Off is not an exception. Given a matrix A which consists of n rows and m columns, and contains integer num...
{"inputs": ["2 2\n1 2\n3 4", "2 2\n1 3\n3 4", "2 2\n1 3\n3 3", "2 2\n1 3\n3 1", "2 2\n1 3\n2 1", "2 2\n1 3\n4 1", "2 2\n1 6\n3 4", "2 2\n0 3\n3 4"], "outputs": ["24", "28\n", "24\n", "16\n", "12\n", "20\n", "40\n", "21\n"]}
453
149
coding
Solve the programming task below in a Python markdown code block. We have a matrix of integers with m rows and n columns. We want to calculate the total sum for the matrix: As you can see, the name "alternating sum" of the title is due to the sign of the terms that changes from one term to its contiguous one and ...
{"functional": "_inputs = [[[[1, 2, 3], [-3, -2, 1], [3, -1, 2]]]]\n_outputs = [[8]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return F...
232
180
coding
Solve the programming task below in a Python markdown code block. Given a string containing a list of integers separated by commas, write the function string_to_int_list(s) that takes said string and returns a new list containing all integers present in the string, preserving the order. For example, give the string "-...
{"functional": "_inputs = [['1,2,3,4,5'], ['21,12,23,34,45'], ['-1,-2,3,-4,-5'], ['1,2,3,,,4,,5,,,'], [',,,,,1,2,3,,,4,,5,,,'], [''], [',,,,,,,,']]\n_outputs = [[[1, 2, 3, 4, 5]], [[21, 12, 23, 34, 45]], [[-1, -2, 3, -4, -5]], [[1, 2, 3, 4, 5]], [[1, 2, 3, 4, 5]], [[]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):...
148
306
coding
Solve the programming task below in a Python markdown code block. You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7. -----Constraints----- - 1≤N≤10^3 -----Input----- The input is given from Standard Input in the following format: N -----Output----- Print the number of the pos...
{"inputs": ["8", "0", "2", "4", "9", "5", "7", "6"], "outputs": ["96\n", "1\n", "2\n", "8\n", "160\n", "16\n", "60\n", "30"]}
139
67
coding
Solve the programming task below in a Python markdown code block. There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has n characters. The characters are labeled from 1 to n. Every pair of two characters ca...
{"inputs": ["3 0\n", "1 0\n", "3 0\n", "100000 0\n", "100000 0\n", "9 2\n1 2 0\n2 3 0\n", "9 2\n1 2 0\n2 3 0\n", "9 2\n1 2 0\n2 3 1\n"], "outputs": ["4\n", "1\n", " 4\n", "303861760\n", " 303861760\n", "6...
631
157
coding
Solve the programming task below in a Python markdown code block. Given a $6\times6$ 2D Array, $\textbf{arr}$: 1 1 1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 An hourglass in $\mbox{A}$ is a subset of values with indices falling in this pattern in $\textbf{arr}$'s graphical representation: a...
{"inputs": ["1 1 1 0 0 0\n0 1 0 0 0 0\n1 1 1 0 0 0\n0 0 2 4 4 0\n0 0 0 2 0 0\n0 0 1 2 4 0\n"], "outputs": ["19\n"]}
727
85
coding
Solve the programming task below in a Python markdown code block. Following from the previous kata and taking into account how cool psionic powers are compare to the Vance spell system (really, the idea of slots to dumb down the game sucks, not to mention that D&D became a smash hit among geeks, so...), your task in th...
{"functional": "_inputs = [[1, 0], [1, 10], [1, 11], [0, 11], [1, 20], [21, 30]]\n_outputs = [[0], [0], [2], [0], [4], [448]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)...
594
212
coding
Solve the programming task below in a Python markdown code block. Mr. Krabs loves money. He enters a bank and sees that there are n rooms arranged in a row. The only rooms with doors are the two rooms on either corner. Initially, all the rooms are locked (including the corner ones). To enter a room, it must be unlocked...
{"inputs": ["7\n1 2 3 4 5 6 1\n3"], "outputs": ["12"]}
504
29
coding
Solve the programming task below in a Python markdown code block. N hotels are located on a straight line. The coordinate of the i-th hotel (1 \leq i \leq N) is x_i. Tak the traveler has the following two personal principles: - He never travels a distance of more than L in a single day. - He never sleeps in the open....
{"inputs": ["9\n1 6 6 24 7 15 19 29 31\n10\n3\n2 8\n8 3\n1 2\n5 5", "9\n1 3 6 6 15 15 19 29 31\n10\n2\n1 8\n7 3\n1 2\n8 5", "9\n1 3 6 13 15 18 19 29 31\n10\n2\n1 8\n7 3\n6 7\n8 5", "9\n1 3 6 13 23 18 19 29 31\n10\n2\n1 8\n7 5\n6 7\n8 5", "9\n1 3 6 13 23 18 19 29 31\n12\n2\n1 8\n1 3\n9 7\n8 7", "9\n1 3 6 13 23 18 19 29 ...
661
438
coding
Solve the programming task below in a Python markdown code block. ## Nova polynomial add This kata is from a series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714041e8807940ff3001140...
{"functional": "_inputs = [[[1], [1]], [[1, 2], [1]], [[1, 2, 3, 4], [4, 3, 2, 1]], [[], []], [[1, 2, 3, 4, 5, 6], []], [[], [1, 2, 3, 4, 5, 6]]]\n_outputs = [[[2]], [[2, 2]], [[5, 5, 5, 5]], [[]], [[1, 2, 3, 4, 5, 6]], [[1, 2, 3, 4, 5, 6]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or is...
297
290
coding
Solve the programming task below in a Python markdown code block. You are playing a new computer game in which you have to fight monsters. In a dungeon you are trying to clear, you met three monsters; the first of them has $a$ health points, the second has $b$ health points, and the third has $c$. To kill the monsters...
{"inputs": ["1\n3 1 5\n", "1\n1 2 6\n", "1\n4 4 1\n", "1\n7 1 1\n", "1\n1 1 7\n", "1\n4 1 4\n", "1\n9 2 7\n", "1\n1 3 5\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
557
118
coding
Solve the programming task below in a Python markdown code block. C: Divisor Game problem tsutaj is trying to play about a few games. In a divisor game, a natural number N of 2 or more is given first, and then the game progresses according to the following procedure. * Declare one integer from the divisors of N oth...
{"inputs": ["2", "8", "7", "4", "5", "3", "6", "9"], "outputs": ["1 1\n", "1 3\n", "1 1\n", "1 2\n", "1 1\n", "1 1\n", "2 3\n", "1 2\n"]}
398
78
coding
Solve the programming task below in a Python markdown code block. There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city? ----...
{"inputs": ["4 3\n1 2\n4 3\n1 4", "4 0\n1 2\n2 3\n1 4", "5 0\n1 2\n2 3\n1 4", "6 0\n0 3\n2 3\n1 4", "4 3\n1 2\n2 2\n1 4", "8 0\n1 2\n2 3\n1 4", "4 3\n1 2\n2 3\n1 4", "4 3\n1 2\n2 3\n1 4\n"], "outputs": ["2\n1\n1\n2\n", "0\n0\n0\n0\n", "0\n0\n0\n0\n0\n", "0\n0\n0\n0\n0\n0\n", "2\n3\n0\n1\n", "0\n0\n0\n0\n0\n0\n0\n0\n", ...
281
236
coding
Solve the programming task below in a Python markdown code block. Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m ho...
{"inputs": ["2", "8", "16", "1000010000000", "1000011000000", "1100011000000", "1110011000000", "1110011100000"], "outputs": ["0\n", "10", "22\n", "2716922731275\n", "3307289212967\n", "2999416055122\n", "3146654438234\n", "4080876601631\n"]}
180
184
coding
Solve the programming task below in a Python markdown code block. B: Twice as own problem You will be given Q queries. Since one positive integer N is given for each query, find the number of positive integers M that satisfy the following two conditions. * 2 Satisfy \ leq M \ leq N * Of the divisors of M, excluding ...
{"inputs": ["3\n73\n8\n9", "3\n7\n24\n1", "3\n7\n45\n2", "3\n7\n59\n2", "3\n7\n33\n1", "3\n7\n80\n2", "3\n7\n52\n2", "3\n7\n94\n1"], "outputs": ["25\n0\n0\n", "0\n5\n0\n", "0\n13\n0\n", "0\n18\n0\n", "0\n8\n0\n", "0\n29\n0\n", "0\n16\n0\n", "0\n34\n0\n"]}
305
156
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an undirected graph with n nodes, where each node is numbered between 0 and n - 1. You are given a 2D array graph, where graph[u] is an array of nodes that node u is adjacent to. More formally, for each v in ...
{"functional": "def check(candidate):\n assert candidate(graph = [[1,2,3],[0,2],[0,1,3],[0,2]]) == False\n assert candidate(graph = [[1,3],[0,2],[1,3],[0,2]]) == True\n\n\ncheck(Solution().isBipartite)"}
260
76
coding
Solve the programming task below in a Python markdown code block. Leo has developed a new programming language C+=. In C+=, integer variables can only be changed with a "+=" operation that adds the right-hand side value to the left-hand side variable. For example, performing "a += b" when a = $2$, b = $3$ changes the v...
{"inputs": ["2\n1 2 3\n5 4 100\n", "2\n1 2 3\n7 4 100\n", "2\n1 1 3\n5 4 100\n", "2\n1 1 3\n5 4 101\n", "2\n1 1 3\n5 4 111\n", "2\n1 2 3\n5 4 100\n", "16\n1 1 1\n3 4 7\n4 5 13\n456 123 7890123\n1 1 1000000000\n45 12 782595420\n1 1000000000 1000000000\n1 999999999 1000000000\n1 99999 676497416\n5 6 930234861\n8 9 881919...
364
836
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a sorted integer array nums and an integer n, add/patch elements to the array such that any number in the range [1, n] inclusive can be formed by the sum of some elements in the array. Return the minimum number ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3], n = 6) == 1\n assert candidate(nums = [1,5,10], n = 20) == 2\n assert candidate(nums = [1,2,2], n = 5) == 0\n\n\ncheck(Solution().minPatches)"}
105
83
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Gintoki has been very lazy recently and he hasn't made enough money to pay the rent this month. So the old landlady has given him a problem to solve instead, ...
{"inputs": ["3\n3\n4\n5"], "outputs": ["3\n6\n9"]}
704
22
coding
Solve the programming task below in a Python markdown code block. # Task Your task is to find the sum for the range `0 ... m` for all powers from `0 ... n. # Example For `m = 2, n = 3`, the result should be `20` `0^0+1^0+2^0 + 0^1+1^1+2^1 + 0^2+1^2+2^2 + 0^3+1^3+2^3 = 20` Note, that no output ever exceeds 2e9....
{"functional": "_inputs = [[2, 3], [3, 5], [10, 9], [1, 1], [0, 0], [300, 2], [567, 2], [37, 4], [36, 4]]\n_outputs = [[20], [434], [1762344782], [3], [1], [9090501], [61083856], [15335280], [13409059]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return mat...
220
276
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array arr which consists of only zeros and ones, divide the array into three non-empty parts such that all of these parts represent the same binary value. If it is possible, return any [i, j] with i +...
{"functional": "def check(candidate):\n assert candidate(arr = [1,0,1,0,1]) == [0,3]\n assert candidate(arr = [1,1,0,1,1]) == [-1,-1]\n assert candidate(arr = [1,1,0,0,1]) == [0,2]\n\n\ncheck(Solution().threeEqualParts)"}
254
89
coding
Solve the programming task below in a Python markdown code block. You are given a board of size $n \times n$, where $n$ is odd (not divisible by $2$). Initially, each cell of the board contains one figure. In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a s...
{"inputs": ["1\n2119\n", "1\n9693\n", "1\n2569\n", "1\n69791\n", "1\n69791\n", "1\n54111\n", "1\n39575\n", "1\n47045\n"], "outputs": ["3171549680\n", "303566175288\n", "5651594480\n", "113312287936960\n", "113312287936960\n", "52812341771840\n", "20660532731600\n", "34707166856360\n"]}
496
211
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers nums and a positive integer k, check whether it is possible to divide this array into sets of k consecutive numbers. Return true if it is possible. Otherwise, return false.   Please complete...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,3,4,4,5,6], k = 4) == True\n assert candidate(nums = [3,2,1,2,3,4,3,4,5,9,10,11], k = 3) == True\n assert candidate(nums = [3,3,2,2,1,1], k = 3) == True\n assert candidate(nums = [1,2,3,4], k = 3) == False\n\n\ncheck(Solution().isPossibl...
94
139
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums of length n where nums is a permutation of the numbers in the range [0, n - 1]. You should build a set s[k] = {nums[k], nums[nums[k]], nums[nums[nums[k]]], ... } subjected to the fo...
{"functional": "def check(candidate):\n assert candidate(nums = [5,4,0,3,1,6,2]) == 4\n assert candidate(nums = [0,1,2]) == 1\n\n\ncheck(Solution().arrayNesting)"}
185
60
coding
Solve the programming task below in a Python markdown code block. If you can't sleep, just count sheep!! ## Task: Given a non-negative integer, `3` for example, return a string with a murmur: `"1 sheep...2 sheep...3 sheep..."`. Input will always be valid, i.e. no negative integers. Also feel free to reuse/extend the ...
{"functional": "_inputs = [[3]]\n_outputs = [['1 sheep...2 sheep...3 sheep...']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False...
94
164
coding
Solve the programming task below in a Python markdown code block. Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten. -----Constraints----- - 1 \leq N < 10^{100} - 1 \leq K \leq 3 -----Input----- Input is given from Standard Input in the followin...
{"inputs": ["9\n1\n", "9\n2\n", "25\n1", "25\n4", "25\n5", "25\n3", "25\n9", "25\n7"], "outputs": ["9\n", "0\n", "11\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
173
87
coding
Solve the programming task below in a Python markdown code block. Little Johnny Bubbles enjoys spending hours in front of his computer playing video games. His favorite game is Bubble Strike, fast-paced bubble shooting online game for two players. Each game is set in one of the N maps, each having different terrain co...
{"inputs": ["7 1.0000\n", "3 0.0000\n", "3 1.0000\n", "3 1.0000\n", "3 0.0000\n", "3 0.5879\n", "4 0.0000\n", "8 0.0000\n"], "outputs": ["6\n", "0\n", "2\n", "2\n", "0\n", "2\n", "0\n", "0\n"]}
373
126
coding
Solve the programming task below in a Python markdown code block. Kevin is noticing his space run out! Write a function that removes the spaces from the values and returns an array showing the space decreasing. For example, running this function on the array ['i', 'have','no','space'] would produce ['i','ihave','ihaven...
{"functional": "_inputs = [[['kevin', 'has', 'no', 'space']], [['this', 'cheese', 'has', 'no', 'holes']]]\n_outputs = [[['kevin', 'kevinhas', 'kevinhasno', 'kevinhasnospace']], [['this', 'thischeese', 'thischeesehas', 'thischeesehasno', 'thischeesehasnoholes']]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isins...
97
232
coding
Solve the programming task below in a Python markdown code block. We have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively. We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time....
{"inputs": ["3\n0 2\n4 0\n0 0", "3\n0 0\n-2 0\n2 0", "3\n1 0\n-2 0\n2 0", "3\n1 0\n-2 0\n2 1", "3\n1 0\n-2 0\n0 1", "3\n1 0\n-2 0\n0 2", "3\n1 0\n-1 0\n0 1", "3\n1 4\n-1 1\n2 -1"], "outputs": ["3\n", "4\n", "7\n", "7\n", "4\n", "4\n", "4\n", "7\n"]}
349
165
coding
Solve the programming task below in a Python markdown code block. Task ====== Make a custom esolang interpreter for the language [InfiniTick](https://esolangs.org/wiki/InfiniTick). InfiniTick is a descendant of [Tick](https://esolangs.org/wiki/tick) but also very different. Unlike Tick, InfiniTick has 8 commands inste...
{"functional": "_inputs = [['\\\\h*&'], ['+-*&']]\n_outputs = [['\\x00'], ['\\x00']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return F...
466
169
coding
Solve the programming task below in a Python markdown code block. One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once. The appointed Judg...
{"inputs": ["3 1\n", "7 3\n", "4 1\n", "5 2\n", "5 2\n", "1 1\n", "2 1\n", "3 1\n"], "outputs": ["3\n1 2\n2 3\n3 1\n", "21\n1 2\n1 3\n1 4\n2 3\n2 4\n2 5\n3 4\n3 5\n3 6\n4 5\n4 6\n4 7\n5 6\n5 7\n5 1\n6 7\n6 1\n6 2\n7 1\n7 2\n7 3\n", "4\n1 2\n2 3\n3 4\n4 1\n", "10\n1 2\n1 3\n2 3\n2 4\n3 4\n3 5\n4 5\n4 1\n5 1\n5 2\n", "10...
406
293
coding
Solve the programming task below in a Python markdown code block. Vasya got really tired of these credits (from problem F) and now wants to earn the money himself! He decided to make a contest to gain a profit. Vasya has $n$ problems to choose from. They are numbered from $1$ to $n$. The difficulty of the $i$-th probl...
{"inputs": ["1 10\n1 13\n", "1 10\n1 13\n", "1 16\n1 13\n", "1 235\n15 210\n", "1 235\n15 210\n", "1 235\n23 210\n", "1 235\n23 340\n", "3 5\n1 8\n2 19\n3 11\n"], "outputs": ["0\n", " 0\n", "3\n", "25\n", " ...
519
161
coding
Solve the programming task below in a Python markdown code block. We have a string S of length N consisting of uppercase English letters. How many times does ABC occur in S as contiguous subsequences (see Sample Inputs and Outputs)? -----Constraints----- - 3 \leq N \leq 50 - S consists of uppercase English letters. ...
{"inputs": ["3\nABC\n", "3\nDEF\n", "10\nQCBABDCBAZ", "10\nZABCDB@BCQ", "10\nZABCCB@BDQ", "10\nZABCCB@CDQ", "10\nQDB@BCCBAZ", "10\nZABCCQ@BDB"], "outputs": ["1\n", "0\n", "0\n", "1\n", "1\n", "1\n", "0\n", "1\n"]}
157
120
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A distinct string is a string that is present only once in an array. Given an array of strings arr, and an integer k, return the kth distinct string present in arr. If there are fewer than k distinct strings, return a...
{"functional": "def check(candidate):\n assert candidate(arr = [\"d\",\"b\",\"c\",\"b\",\"c\",\"a\"], k = 2) == \"a\"\n assert candidate(arr = [\"aaa\",\"aa\",\"a\"], k = 1) == \"aaa\"\n assert candidate(arr = [\"a\",\"b\",\"a\"], k = 3) == \"\"\n\n\ncheck(Solution().kthDistinct)"}
122
97
coding
Solve the programming task below in a Python markdown code block. Salem gave you $n$ sticks with integer positive lengths $a_1, a_2, \ldots, a_n$. For every stick, you can change its length to any other positive integer length (that is, either shrink or stretch it). The cost of changing the stick's length from $a$ to ...
{"inputs": ["1\n5\n", "1\n1\n", "1\n5\n", "1\n1\n", "1\n8\n", "1\n14\n", "2\n1 2\n", "2\n1 3\n"], "outputs": ["4 0\n", "1 0\n", "4 0\n", "1 0\n", "7 0\n", "13 0\n", "1 0\n", "2 0\n"]}
478
108
coding
Solve the programming task below in a Python markdown code block. Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the l...
{"inputs": ["1\nqvwli hz\n", "1\nqvilw hz\n", "1\nqvilw gz\n", "1\nqvilw zg\n", "1\nqvhlw zg\n", "1\nqvhlw gz\n", "1\nqvhlv gz\n", "1\nrvhlv gz\n"], "outputs": ["1", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
259
111
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. Chef is busy preparing for the next lunchtime, so he has given you the following task. You are given an array a consisting of n positive integers. The goodness of the array a...
{"inputs": ["2\n5\n18 6 4 3 12\n5\n12 4 6 16 28 "], "outputs": ["6\n4"]}
690
44
coding
Solve the programming task below in a Python markdown code block. Sergey recently learned about country codes - two letter strings, denoting countries. For example, BY stands for Belarus and IN stands for India. Mesmerized by this new discovery, Sergey now looks for country codes everywhere! Sergey has recently found a...
{"inputs": ["2\nINBY\nBYBY"], "outputs": ["3\n2"]}
292
20
coding
Solve the programming task below in a Python markdown code block. You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i. An edge whose removal disconnects the graph is called a brid...
{"inputs": ["3 2\n1 2\n1 3\n2 3", "3 0\n2 2\n1 3\n3 3", "6 1\n2 1\n1 1\n1 3", "3 2\n2 2\n1 3\n2 3", "3 2\n2 1\n1 3\n2 3", "3 2\n2 2\n1 3\n3 3", "3 2\n1 2\n1 3\n2 1", "3 2\n2 2\n1 3\n1 3"], "outputs": ["2\n", "0\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
369
174
coding
Solve the programming task below in a Python markdown code block. You have decided to give an allowance to your child depending on the outcome of the game that he will play now. The game is played as follows: - There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "oper...
{"inputs": ["9 9 8", "1 8 2", "6 6 5", "0 9 8", "1 1 2", "6 7 5", "1 2 2", "6 9 5"], "outputs": ["107\n", "83\n", "71\n", "98\n", "22\n", "81\n", "23\n", "101\n"]}
271
104
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.   Please complete the following python code precisely: ```pyth...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,None,5,None,4])) == [1,3,4]\n assert candidate(root = tree_node([1,None,3])) == [1,3]\n assert candidate(root = tree_node([])) == []\n\n\ncheck(Solution().rightSideView)"}
135
82
coding
Solve the programming task below in a Python markdown code block. problem One day in the cold winter, JOI Taro decided to break the thin ice in the plaza and play. The square is rectangular and is divided into m sections in the east-west direction and n sections in the north-south direction, that is, m × n. In additio...
{"inputs": ["3\n3\n1 1 0\n1 0 1\n1 1 0\n5\n3\n1 1 1 0 1\n1 1 0 1 0\n1 0 0 0 1\n0\n0", "3\n3\n1 1 0\n1 0 1\n0 1 0\n5\n3\n1 1 0 0 1\n1 1 0 1 0\n1 0 0 0 1\n0\n0", "3\n3\n1 1 0\n1 0 1\n0 1 0\n5\n3\n1 1 0 0 1\n1 1 0 1 0\n1 1 1 0 1\n0\n0", "3\n3\n1 1 0\n1 0 1\n1 1 0\n5\n3\n1 0 1 0 1\n1 1 0 1 0\n1 0 0 0 1\n0\n0", "3\n3\n1 1 0...
527
542
coding
Solve the programming task below in a Python markdown code block. Special Numbers Mani has encountered a problem on Special numbers in Bytecode. A number S is called a special number if its digits are in an arithmetic progression modulo 10. He has an array consisting of all numbers from 1 to N and needs your help to f...
{"inputs": ["123"], "outputs": ["102"]}
185
16
coding
Solve the programming task below in a Python markdown code block. Piegirl was asked to implement two table join operation for distributed database system, minimizing the network traffic. Suppose she wants to join two tables, A and B. Each of them has certain number of rows which are distributed on different number of ...
{"inputs": ["2 2\n2 6\n3 100\n", "1 1\n1889\n2867\n", "1 1\n1889\n2867\n", "2 2\n2 6\n3 100\n", "2 3\n10 10\n1 1 1\n", "2 3\n10 10\n1 1 2\n", "2 3\n10 10\n0 1 2\n", "2 3\n10 10\n0 1 0\n"], "outputs": ["11\n", "1889\n", "1889\n", "11\n", "6\n", "8\n", "6\n", "2\n"]}
386
182
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a balanced parentheses string s, return the score of the string. The score of a balanced parentheses string is based on the following rule: "()" has score 1. AB has score A + B, where A and B are balanced paren...
{"functional": "def check(candidate):\n assert candidate( \"()\") == 1\n assert candidate( \"(())\") == 2\n assert candidate( \"()()\") == 2\n assert candidate( \"(()(()))\") == 6\n\n\ncheck(Solution().scoreOfParentheses)"}
117
73
coding
Solve the programming task below in a Python markdown code block. Read problems statements in mandarin chinese, russian and vietnamese as well. Mike is a network administrator in a university. One of his primary responsibilities in the job is to create an effective firewall so that the students are not able to visit ...
{"inputs": ["4\n- codeforces\n+ codechef\n- youtube\n+ google"], "outputs": ["2\ncodef\ny"]}
561
31
coding
Solve the programming task below in a Python markdown code block. Chef is a really nice and respectful person, in sharp contrast to his little brother, who is a very nasty and disrespectful person. Chef always sends messages to his friends in all small letters, whereas the little brother sends messages in all capital l...
{"inputs": ["4\n5 1\nfrauD\n5 1\nFRAUD\n4 4\nLife\n10 4\nsTRAWBerry"], "outputs": ["chef\nbrother\nboth\nnone"]}
630
50
coding
Solve the programming task below in a Python markdown code block. A string a of length m is called antipalindromic iff m is even, and for each i (1 ≤ i ≤ m) a_{i} ≠ a_{m} - i + 1. Ivan has a string s consisting of n lowercase Latin letters; n is even. He wants to form some string t that will be an antipalindromic perm...
{"inputs": ["8\nabacabac\n1 1 1 1 1 1 1 1\n", "8\nabaccaba\n1 2 3 4 5 6 7 8\n", "8\nabacabca\n1 2 3 4 4 3 2 1\n", "8\ncdcddcda\n4 1 4 1 4 3 9 6\n", "8\ncdcddcda\n4 1 4 1 4 3 9 6\n", "8\ncdcddcda\n4 1 4 1 2 3 9 6\n", "8\nabaccaba\n1 2 3 4 5 6 7 8\n", "8\nabacabac\n1 1 1 1 1 1 1 1\n"], "outputs": ["8\n", "26\n", "17\n", ...
372
245
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string s. You are also given a 0-indexed string queryCharacters of length k and a 0-indexed array of integer indices queryIndices of length k, both of which are used to describe k queries. Th...
{"functional": "def check(candidate):\n assert candidate(s = \"babacc\", queryCharacters = \"bcb\", queryIndices = [1,3,3]) == [3,3,4]\n assert candidate(s = \"abyzz\", queryCharacters = \"aa\", queryIndices = [2,1]) == [2,3]\n\n\ncheck(Solution().longestRepeating)"}
166
86
coding
Solve the programming task below in a Python markdown code block. Chris the Rabbit has been interested in arrays ever since he was a child. At the moment he is researching arrays with the length of n, containing only integers from 1 to n. He is not good at math, that's why some simple things drive him crazy. For exampl...
{"inputs": ["1\n", "5\n", "8\n", "4\n", "7\n", "2\n", "3\n", "82\n"], "outputs": ["1\n", "247\n", "12862\n", "66\n", "3425\n", "4\n", "17\n", "105516606\n"]}
273
90
coding
Solve the programming task below in a Python markdown code block. Simon has a prime number x and an array of non-negative integers a_1, a_2, ..., a_{n}. Simon loves fractions very much. Today he wrote out number $\frac{1}{x^{a} 1} + \frac{1}{x^{a_{2}}} + \ldots + \frac{1}{x^{a_{n}}}$ on a piece of paper. After Simon l...
{"inputs": ["2 2\n2 2\n", "2 2\n2 4\n", "2 4\n2 4\n", "2 5\n2 7\n", "2 4\n2 7\n", "2 2\n2 2\n", "2 2\n5 29\n", "2 2\n7 29\n"], "outputs": ["8\n", "4\n", "16\n", "25\n", "16\n", "8\n", "32\n", "128\n"]}
659
126
coding
Solve the programming task below in a Python markdown code block. There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corr...
{"inputs": ["R\nB\n", "R\nB\n", "S\nB\n", "S\nC\n", "S\nD\n", "T\nD\n", "U\nD\n", "R\nD\n"], "outputs": ["1\n", "1", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
437
85
coding
Solve the programming task below in a Python markdown code block. 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. ...
{"inputs": ["1\n5\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n6\n", "1\n4\n", "1\n8\n", "2\n2 1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
594
88
coding
Solve the programming task below in a Python markdown code block. Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters. In this problem you should implement the similar functionality. You are given a s...
{"inputs": ["1\n_\n", "1\na\n", "1\n_\n", "1\na\n", "1\nb\n", "1\nc\n", "1\nd\n", "1\ne\n"], "outputs": ["0 0\n", "1 0\n", "0 0\n", "1 0\n", "1 0\n", "1 0\n", "1 0\n", "1 0\n"]}
596
102
coding
Solve the programming task below in a Python markdown code block. Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is ...
{"inputs": ["1\na 2400 2401\n", "1\nX 2400 2500\n", "1\nA 2400 2401\n", "1\na 2400 2455\n", "1\nx 2400 2401\n", "1\nb 2400 2401\n", "1\nx 2400 2401\n", "1\nb 2400 2401\n"], "outputs": ["YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES"]}
529
158
coding
Solve the programming task below in a Python markdown code block. Polycarp calls an array dense if the greater of any two adjacent elements is not more than twice bigger than the smaller. More formally, for any $i$ ($1 \le i \le n-1$), this condition must be satisfied: $$\frac{\max(a[i], a[i+1])}{\min(a[i], a[i+1])} \l...
{"inputs": ["6\n4\n4 2 10 1\n2\n1 3\n2\n6 1\n3\n1 4 2\n5\n1 2 3 4 3\n12\n4 27 9 1 30 20 34 46 42 16 3 16\n", "6\n4\n4 2 10 1\n2\n1 3\n2\n6 1\n3\n2 4 2\n5\n1 2 3 4 3\n12\n4 27 9 1 30 20 34 46 42 16 3 16\n", "6\n4\n4 2 10 1\n2\n1 3\n2\n6 1\n3\n2 4 2\n5\n1 2 3 4 3\n12\n4 27 9 1 30 20 54 46 42 16 3 16\n", "6\n4\n4 3 10 1\n...
688
782
coding
Solve the programming task below in a Python markdown code block. An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants ...
{"inputs": ["3\n5\n1 2 3 4 4\n3\n0 0 0\n6\n2 3 5 7 11 13\n"], "outputs": ["2\n3\n0\n"]}
590
54
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Little Egor is a huge movie fan. He likes watching different kinds of movies: from drama movies to comedy movies, from teen movies to horror movies. He is planning to visit c...
{"inputs": ["2\n2\n1 2\n2 1\n4\n2 1 4 1\n2 4 1 4", "2\n2\n1 2\n2 1\n4\n2 1 4 1\n2 5 1 4", "2\n2\n2 2\n2 1\n4\n2 1 4 1\n4 4 1 4", "2\n2\n1 2\n2 1\n4\n1 1 4 1\n2 5 1 4", "2\n2\n2 2\n2 1\n4\n2 1 4 1\n2 4 1 4", "2\n2\n2 2\n2 1\n4\n2 1 4 1\n1 4 1 4", "2\n2\n1 2\n2 1\n4\n1 1 1 1\n2 5 1 4", "2\n2\n2 2\n2 1\n3\n2 1 4 1\n1 4 1 ...
459
301
coding
Solve the programming task below in a Python markdown code block. On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of ...
{"inputs": ["2 1\nGT\n", "2 1\nTG\n", "2 1\nTG\n", "2 1\nGT\n", "3 1\nTG#\n", "3 1\nGT#\n", "3 2\nG.T\n", "3 1\nTG#\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
615
106
coding
Solve the programming task below in a Python markdown code block. Let x be a string of length at least 1. We will call x a good string, if for any string y and any integer k (k \geq 2), the string obtained by concatenating k copies of y is different from x. For example, a, bbc and cdcdc are good strings, while aa, bbbb...
{"inputs": ["ddc", "aaa", "dec", "aa`", "eec", "aa_", "cee", "ba_"], "outputs": ["1\n1\n", "3\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n"]}
518
81
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string columnTitle that represents the column title as appears in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ...   Please complet...
{"functional": "def check(candidate):\n assert candidate(columnTitle = \"A\") == 1\n assert candidate(columnTitle = \"AB\") == 28\n assert candidate(columnTitle = \"ZY\") == 701\n\n\ncheck(Solution().titleToNumber)"}
110
62
coding
Solve the programming task below in a Python markdown code block. After many years of research, Ikta has acquired the ability to predict the future! The time and money he spent on this research was enormous, but it's finally time to be rewarded. To get the money back, Ikta decided to start investing in stocks. Ikta do...
{"inputs": ["1 2 5\n4\n10000", "2 2 6\n3 2\n5 4", "1 2 7\n4\n10000", "1 1 5\n6\n10000", "2 1 8\n6\n10000", "1 2 5\n6\n10000", "2 2 5\n3 2\n5 4", "2 3 5\n4 5\n6 3\n8 6"], "outputs": ["10001\n", "12\n", "10003\n", "5\n", "8\n", "5", "9", "13\n"]}
636
170
coding
Solve the programming task below in a Python markdown code block. You are given two strings $s$ and $t$. Both strings have length $n$ and consist of lowercase Latin letters. The characters in the strings are numbered from $1$ to $n$. You can successively perform the following move any number of times (possibly, zero):...
{"inputs": ["1\nk\nk\n", "1\no\nk\n", "1\no\nk\n", "1\nk\nk\n", "1\no\nj\n", "1\nj\nk\n", "1\np\nk\n", "1\ni\nk\n"], "outputs": ["0\n\n", "-1\n", "-1", "0\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
587
102
coding
Solve the programming task below in a Python markdown code block. One day shooshuns found a sequence of n integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes k-th in the current sequence and add the same number to the e...
{"inputs": ["1 1\n1\n", "2 1\n1 1\n", "2 1\n2 1\n", "2 1\n1 2\n", "3 2\n3 1 0\n", "3 2\n2 1 0\n", "3 2\n3 1 1\n", "3 1\n3 1 1\n"], "outputs": ["0\n", "0\n", "-1\n", "-1\n", "-1\n", "-1\n", "1\n", "-1\n"]}
333
124
coding
Solve the programming task below in a Python markdown code block. You will be given a string (x) featuring a cat 'C' and a mouse 'm'. The rest of the string will be made up of '.'. You need to find out if the cat can catch the mouse from it's current position. The cat can jump over three characters. So: C.....m retu...
{"functional": "_inputs = [['C....m'], ['C..m'], ['C.....m'], ['C.m'], ['m...C']]\n_outputs = [['Escaped!'], ['Caught!'], ['Escaped!'], ['Caught!'], ['Caught!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)...
135
194
coding
Solve the programming task below in a Python markdown code block. A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elemen...
{"inputs": ["1\nz\n", "1\nz\n", "1\ny\n", "1\nx\n", "1\nlol\n", "1\nlol\n", "1\nlnl\n", "1\nlln\n"], "outputs": ["z\n", "z\n", "y\n", "x\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
422
88
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n super washing machines on a line. Initially, each washing machine has some dresses or is empty. For each move, you could choose any m (1 <= m <= n) washing machines, and pass one dress of each washing machi...
{"functional": "def check(candidate):\n assert candidate(machines = [1,0,5]) == 3\n assert candidate(machines = [0,3,0]) == 2\n assert candidate(machines = [0,2,0]) == -1\n\n\ncheck(Solution().findMinMoves)"}
164
71
coding
Solve the programming task below in a Python markdown code block. Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has a_{i} coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move...
{"inputs": ["1\n1\n", "1\n2\n", "1\n1\n", "1\n546\n", "1\n546\n", "1\n641\n", "1\n1151\n", "3\n1 2 3\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "3\n"]}
447
100
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an n x n grid, with the top-left cell at (0, 0) and the bottom-right cell at (n - 1, n - 1). You are given the integer n and an integer array startPos where startPos = [startrow, startcol] indicates that a ro...
{"functional": "def check(candidate):\n assert candidate(n = 3, startPos = [0,1], s = \"RRDDLU\") == [1,5,4,3,1,0]\n assert candidate(n = 2, startPos = [1,1], s = \"LURD\") == [4,1,0,0]\n assert candidate(n = 1, startPos = [0,0], s = \"LRUD\") == [0,0,0,0]\n\n\ncheck(Solution().executeInstructions)"}
272
121
coding
Solve the programming task below in a Python markdown code block. We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some ...
{"inputs": ["1 1\n1 3\n", "1 1\n1 3\n", "1 1\n2 3\n", "1 2\n2 3\n", "1 1\n3 3\n", "1 2\n2 4\n", "1 2\n3 6\n", "1 1\n1 1\n"], "outputs": ["14\n", "14\n", "12\n", "5\n", "8\n", "10\n", "29\n", "2\n"]}
446
123
coding
Solve the programming task below in a Python markdown code block. You are given a $sorted$ list $A$ of size $N$.You have to make a new list $B$ such that $B[i]$ is equal to the number of elements $strictly$ $greater$ than $A[i]$ in the list $A$. Print the $new$ $list$. ------ Input ------ The first line consists o...
{"inputs": ["2\n4\n1 2 4 4\n5\n1 2 2 2 2"], "outputs": ["3 2 0 0\n4 0 0 0 0"]}
535
50
coding
Solve the programming task below in a Python markdown code block. Michael is accused of violating the social distancing rules and creating a risk of spreading coronavirus. He is now sent to prison. Luckily, Michael knows exactly what the prison looks like from the inside, especially since it's very simple. The prison ...
{"inputs": ["2\n2 2\n1 3\n"], "outputs": ["4\n3\n"]}
358
24
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and an integer k. Append k unique positive integers that do not appear in nums to nums such that the resulting total sum is minimum. Return the sum of the k integers appended to num...
{"functional": "def check(candidate):\n assert candidate(nums = [1,4,25,10,25], k = 2) == 5\n assert candidate(nums = [5,6], k = 6) == 25\n\n\ncheck(Solution().minimalKSum)"}
98
68
coding
Solve the programming task below in a Python markdown code block. A non-decreasing sequence is a called a Fox sequence, iff the most frequent element in the sequence is unique. e.g. The sequence 1, 1, 2, 3, 4 is a Fox sequence, because it follows the above definition. The most frequent element is 1. It occurs twice ...
{"inputs": ["5\n2 1 1\n2 1 3\n3 1 2\n4 4 5\n10 2 4\n"], "outputs": ["1\n3\n4\n4\n60\n"]}
476
54
coding
Solve the programming task below in a Python markdown code block. The number `1035` is the smallest integer that exhibits a non frequent property: one its multiples, `3105 = 1035 * 3`, has its same digits but in different order, in other words, `3105`, is one of the permutations of `1035`. The number `125874` is the f...
{"functional": "_inputs = [[10000, 7], [5000, 7], [10000, 4], [8000, 4], [5000, 3], [10000, 3]]\n_outputs = [[1], [0], [2], [1], [1], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, ...
489
224
coding
Solve the programming task below in a Python markdown code block. Let us define the FizzBuzz sequence a_1,a_2,... as follows: - If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. - If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. - If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. - If none of t...
{"inputs": ["3", "4", "8", "1", "7", "0", "1\n", "16"], "outputs": ["3\n", "7\n", "22\n", "1\n", "14\n", "0\n", "1\n", "76\n"]}
299
67
coding
Solve the programming task below in a Python markdown code block. There is a stack of N cards, each of which has a non-negative integer written on it. The integer written on the i-th card from the top is A_i. Snuke will repeat the following operation until two cards remain: * Choose three consecutive cards from the s...
{"inputs": ["4\n1 1 4 2", "4\n1 0 4 2", "4\n1 0 2 2", "4\n2 0 2 2", "4\n2 0 3 2", "4\n2 0 6 2", "4\n2 1 6 2", "4\n2 1 6 0"], "outputs": ["14\n", "11\n", "7\n", "8\n", "10\n", "16\n", "19\n", "17\n"]}
306
132
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A wonderful string is a string where at most one letter appears an odd number of times. For example, "ccjjc" and "abab" are wonderful, but "ab" is not. Given a string word that consists of the first ten lowercase En...
{"functional": "def check(candidate):\n assert candidate(word = \"aba\") == 4\n assert candidate(word = \"aabb\") == 9\n assert candidate(word = \"he\") == 2\n\n\ncheck(Solution().wonderfulSubstrings)"}
149
59
coding
Solve the programming task below in a Python markdown code block. Polo, the Penguin, likes numbers. He says that the goodness of a number is itself multiplied by the number of digits in it's decimal representation. For example, the goodness of the integer 474 is 474*3 = 1422. Help him to count the sum of goodness of al...
{"inputs": ["1\n1 9", "1\n1 7", "1\n9 16", "1\n9 24", "1\n6 24", "1\n8 24", "1\n8 45", "1\n5 24"], "outputs": ["45\n", "28\n", "191\n", "519\n", "540\n", "527\n", "1997\n", "545\n"]}
292
115
coding
Solve the programming task below in a Python markdown code block. Two words are anagrams of one another if their letters can be rearranged to form the other word. Given a string, split it into two contiguous substrings of equal length. Determine the minimum number of characters to change to make the two substrings ...
{"inputs": ["6\naaabbb\nab\nabc\nmnop\nxyyx\nxaxbbbxx\n"], "outputs": ["3\n1\n-1\n2\n0\n1\n"]}
581
43
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the root of a binary tree and an integer distance. A pair of two different leaf nodes of a binary tree is said to be good if the length of the shortest path between them is less than or equal to distance...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,None,4]), distance = 3) == 1\n assert candidate(root = tree_node([1,2,3,4,5,6,7]), distance = 3) == 2\n assert candidate(root = tree_node([7,1,4,6,None,5,3,None,None,None,None,None,2]), distance = 3) == 1\n assert candidate(roo...
162
157
coding
Solve the programming task below in a Python markdown code block. There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other. Initially, we have a pile consisting of K stones. The two players perform the following operation alternat...
{"inputs": ["2 3\n2 3", "2 7\n1 3", "2 4\n2 5", "2 1\n1 3", "2 4\n3 5", "2 2\n1 3", "2 2\n2 3", "2 5\n2 5"], "outputs": ["First\n", "First\n", "Second\n", "First\n", "First\n", "Second\n", "First\n", "First\n"]}
332
110
coding
Solve the programming task below in a Python markdown code block. Little Petya very much likes computers. Recently he has received a new "Ternatron IV" as a gift from his mother. Unlike other modern computers, "Ternatron IV" operates with ternary and not binary logic. Petya immediately wondered how the xor operation is...
{"inputs": ["1 0\n", "0 0\n", "0 1\n", "5 5\n", "14 34\n", "50 34\n", "524 8790\n", "5849 7211\n"], "outputs": ["2\n", "0\n", "1\n", "0\n", "50\n", "14\n", "8998\n", "10146\n"]}
437
110
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The Game of Master Mind is played as follows: The computer has four slots, and each slot will contain a ball that is red (R). yellow (Y). green (G) or blue (B). For example, the computer might have RGGB (Slot #1 is re...
{"functional": "def check(candidate):\n assert candidate(solution=\"RGBY\",guess=\"GGRR\") == [1,1]\n\n\ncheck(Solution().masterMind)"}
294
39
coding
Solve the programming task below in a Python markdown code block. The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the f...
{"inputs": ["1\n5\n", "1\n5\n", "1\n2\n", "2\n0 1\n", "2\n0 5\n", "2\n0 5\n", "2\n0 1\n", "3\n1 1 1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
351
98
coding
Solve the programming task below in a Python markdown code block. ### Vaccinations for children under 5 You have been put in charge of administrating vaccinations for children in your local area. Write a function that will generate a list of vaccines for each child presented for vaccination, based on the child's age an...
{"functional": "_inputs = [['12 weeks', 'up-to-date', 'december'], ['12 months', '16 weeks', 'june'], ['40 months', '12 months', 'october']]\n_outputs = [[['fiveInOne', 'rotavirus']], [['fiveInOne', 'hibMenC', 'measlesMumpsRubella', 'meningitisB', 'pneumococcal']], [['hibMenC', 'measlesMumpsRubella', 'meningitisB', 'of...
707
267
coding
Solve the programming task below in a Python markdown code block. You task is to implement an simple interpreter for the notorious esoteric language [HQ9+](https://esolangs.org/wiki/HQ9+) that will work for a single character input: - If the input is `'H'`, return `'Hello World!'` - If the input is `'Q'`, return the i...
{"functional": "_inputs = [['X'], ['H'], ['Q']]\n_outputs = [[None], ['Hello World!'], ['Q']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b):...
412
169
coding
Solve the programming task below in a Python markdown code block. Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone number. Example: ```python create_phone_number([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) # => returns "(123) 456-7890" ``` ```f...
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], [[0, 2, 3, 0, 5, 6, 0, 8, 9, 0]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]]\n_outputs = [['(123) 456-7890'], ['(111) 111-1111'], ['(023) 056-0890'], ['(000) 000-0000']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a...
207
333
coding
Solve the programming task below in a Python markdown code block. Today Chef wants to evaluate the dishes of his $N$ students. He asks each one to cook a dish and present it to him. Chef loves his secret ingredient, and only likes dishes with at least $X$ grams of it. Given $N$, $X$ and the amount of secret ingredient ...
{"inputs": ["3\n5 100\n11 22 33 44 55\n5 50\n10 20 30 40 50\n5 45\n12 24 36 48 60"], "outputs": ["NO\nYES\nYES"]}
373
77
coding
Solve the programming task below in a Python markdown code block. As a New Year's gift, Dolphin received a string s of length 19. The string s has the following format: `[five lowercase English letters],[seven lowercase English letters],[five lowercase English letters]`. Dolphin wants to convert the comma-separated str...
{"inputs": ["gaiku,atcoder,tasks", "abgde,fchihgf,edcba", "ha,pypnewyear,enjoy", "gaiku,atcoeer,tasks", "abcde,fghihcf,edgba", "ha,pypnewzear,enjoy", "gaiku,atcoeer-tasks", "abgde,fchihgf+edcba"], "outputs": ["gaiku atcoder tasks\n", "abgde fchihgf edcba\n", "ha pypnewyear enjoy\n", "gaiku atcoeer tasks\n", "abcde fghi...
200
171
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given four integers a, b, c and d. Determine if there's a rectangle such that the lengths of its sides are a, b, c and d (in any order). ------ Input ------ The fi...
{"inputs": ["3\n1 1 2 2\n3 2 2 3\n1 2 2 2"], "outputs": ["YES\nYES\nNO"]}
240
40