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
Please solve the programming task below using a self-contained code snippet in a markdown code block. A string can be abbreviated by replacing any number of non-adjacent, non-empty substrings with their lengths. The lengths should not have leading zeros. For example, a string such as "substitution" could be abbreviate...
{"functional": "def check(candidate):\n assert candidate(word = \"internationalization\", abbr = \"i12iz4n\") == True\n assert candidate(word = \"apple\", abbr = \"a2e\") == False\n\n\ncheck(Solution().validWordAbbreviation)"}
253
64
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of n strings strs, all of the same length. We may choose any deletion indices, and we delete all the characters in those indices for each string. For example, if we have strs = ["abcdef","uvwxyz...
{"functional": "def check(candidate):\n assert candidate(strs = [\"babca\",\"bbazb\"]) == 3\n assert candidate(strs = [\"edcba\"]) == 4\n assert candidate(strs = [\"ghi\",\"def\",\"abc\"]) == 0\n\n\ncheck(Solution().minDeletionSize)"}
240
76
coding
Solve the programming task below in a Python markdown code block. After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the recta...
{"inputs": ["1\n1 1\n", "1\n0 1\n", "1\n1 1\n", "1\n14 304\n", "1\n15 304\n", "2\n0 0\n1 1\n", "1\n-188 17\n", "1\n71 -740\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "1\n", "-1\n", "-1\n"]}
371
120
coding
Solve the programming task below in a Python markdown code block. An array is defined to be `inertial`if the following conditions hold: ``` a. it contains at least one odd value b. the maximum value in the array is even c. every odd value is greater than every even value that is not the maximum value. ``` eg:- ``` S...
{"functional": "_inputs = [[[]], [[581, -384, 140, -287]], [[11, 4, 20, 9, 2, 8]]]\n_outputs = [[False], [False], [True]]\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...
238
202
coding
Solve the programming task below in a Python markdown code block. There is an integer $n$ without zeros in its decimal representation. Alice and Bob are playing a game with this integer. Alice starts first. They play the game in turns. On her turn, Alice must swap any two digits of the integer that are on different po...
{"inputs": ["3\n12\n132\n487456398\n"], "outputs": ["2\n1\n3\n"]}
365
35
coding
Solve the programming task below in a Python markdown code block. Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minim...
{"inputs": ["1 0\n7\n", "1 1\n8\n", "1 1\n5\n", "1 0\n0\n", "1 1\n9\n", "1 0\n5\n", "1 0\n1\n", "1 1\n0\n"], "outputs": ["7\n", "0\n", "0\n", "0\n", "0\n", "5\n", "1\n", "0\n"]}
303
102
coding
Solve the programming task below in a Python markdown code block. It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive nu...
{"inputs": ["1 1 1\n0\n", "1 0 1\n0\n", "2 3 1\n2 2\n", "2 2 1\n2 2\n", "2 3 1\n2 3\n", "3 2 2\n1 1 3\n", "3 2 2\n0 1 3\n", "3 2 2\n4 1 3\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "0\n", " 2"]}
677
137
coding
Solve the programming task below in a Python markdown code block. Given an array $a$ consisting of $n$ elements, find the maximum possible sum the array can have after performing the following operation any number of times: Choose $2$ adjacent elements and flip both of their signs. In other words choose an index $i$ s...
{"inputs": ["5\n3\n-1 -1 -1\n5\n1 5 -5 0 2\n3\n1 2 3\n6\n-1 10 9 8 7 6\n2\n-1 -1\n"], "outputs": ["1\n13\n6\n39\n2\n"]}
602
76
coding
Solve the programming task below in a Python markdown code block. Ringo is giving a present to Snuke. Ringo has found out that Snuke loves yakiniku (a Japanese term meaning grilled meat. yaki: grilled, niku: meat). He supposes that Snuke likes grilled things starting with `YAKI` in Japanese, and does not like other th...
{"inputs": ["KAY", "JAY", "JAZ", "ZAJ", "[AJ", "[AK", "KA[", "LA["], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
209
68
coding
Solve the programming task below in a Python markdown code block. # Task A common way for prisoners to communicate secret messages with each other is to encrypt them. One such encryption algorithm goes as follows. You take the message and place it inside an `nx6` matrix (adjust the number of rows depending on the me...
{"functional": "_inputs = [['Attack at noon or we are done for'], [\"Let's kill them all\"], ['Meet me behind the kitchen tomorrow at seven in the evening']]\n_outputs = [['A.ow.f tanedo tt..or a.oan. cnrre. ko.e..'], [\"Lkhl eie. tlm. 'l.. s.a. .tl.\"], ['Men.eoaete e.dknrtnhn eb.i.r..ei tetttosi.n .hhcoweneg miehm.v....
280
255
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. On an infinite plane, a robot initially stands at (0, 0) and faces north. Note that: The north direction is the positive direction of the y-axis. The south direction is the negative direction of the y-axis. The east ...
{"functional": "def check(candidate):\n assert candidate(instructions = \"GGLLGG\") == True\n assert candidate(instructions = \"GG\") == False\n assert candidate(instructions = \"GL\") == True\n\n\ncheck(Solution().isRobotBounded)"}
210
60
coding
Solve the programming task below in a Python markdown code block. The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular phone) and every phone connects to the BTS with the strongest signal (in a littl...
{"inputs": ["6\n2\n188\n100\n415\n571\n92075", "6\n2\n188\n100\n415\n571\n216675", "6\n1\n37\n110\n671\n28\n11057064", "6\n1\n37\n110\n671\n36\n11057064", "6\n2\n37\n100\n671\n36\n11057064", "6\n3\n71\n100\n287\n4581\n8735373", "6\n8\n2\n100\n637\n31879\n8735373", "6\n3\n100\n100\n287\n351\n8735373"], "outputs": ["0\n4...
619
425
coding
Solve the programming task below in a Python markdown code block. Subodh is having N branches, where each branches have positive integral student. A minimize operation is performed on the branch such that all of them are reduced by the minimum number student in a branch. Suppose we have 5 branches and all of them have...
{"inputs": ["6\n5 4 4 2 2 8"], "outputs": ["6\n4\n2\n1"]}
278
30
coding
Solve the programming task below in a Python markdown code block. In this kata we are focusing on the Numpy python package. You must write a function called `looper` which takes three integers `start, stop and number` as input and returns a list from `start` to `stop` with `number` total values in the list. Five examp...
{"functional": "_inputs = [[1, 5, 1], [1, 5, 2], [1, 5, 3], [1, 5, 4], [1, 5, 5]]\n_outputs = [[[1.0]], [[1.0, 5.0]], [[1.0, 3.0, 5.0]], [[1.0, 2.333333333333333, 3.6666666666666665, 5.0]], [[1.0, 2.0, 3.0, 4.0, 5.0]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
271
297
coding
Solve the programming task below in a Python markdown code block. Correct this code so that it takes one argument, `x`, and returns "`x` is more than zero" if `x` is positive (and nonzero), and otherwise, returns "`x` is equal to or less than zero." In both cases, replace `x` with the actual value of `x`. Also feel fre...
{"functional": "_inputs = [[8], [1], [-2], [-1], [0]]\n_outputs = [['8 is more than zero.'], ['1 is more than zero.'], ['-2 is equal to or less than zero.'], ['-1 is equal to or less than zero.'], ['0 is equal to or less than zero.']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstanc...
97
211
coding
Solve the programming task below in a Python markdown code block. Due to the COVID pandemic, maintaining social distancing is of utmost importance. In this problem, you'd calculate how many days would it take to reach an apocalypse from an initial case if nobody maintains social distancing. The Earth is flat (for this ...
{"inputs": ["2\n4 5\n2 1\n3 4\n1 1"], "outputs": ["5\n3"]}
614
30
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef is a software developer, so he has to switch between different languages sometimes. Each programming language has some features, which are represented by integer...
{"inputs": ["3\n1 2 2 1 3 4\n3 4 2 1 4 3\n1 2 1 3 2 4"], "outputs": ["1\n2\n0"]}
494
52
coding
Solve the programming task below in a Python markdown code block. Welcome to the exciting class of Professor Manasa. In each lecture she used to play some game while teaching a new concept. Today's topic is Set Theory. For today's game, she had given a set A = {a_{1}, a_{2}, ...a_{N}} of N integers to her students and ...
{"inputs": ["3\n1 2 2\n", "4\n2 4 6 1\n"], "outputs": ["3\n", "7\n"]}
656
36
coding
Solve the programming task below in a Python markdown code block. A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after x is the smallest prime number greater than x. For example, the next prime numbe...
{"inputs": ["2 6\n", "7 8\n", "5 9\n", "2 3\n", "3 7\n", "3 9\n", "5 6\n", "5 7\n"], "outputs": ["NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n"]}
400
86
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two positive integers left and right with left <= right. Calculate the product of all integers in the inclusive range [left, right]. Since the product may be very large, you will abbreviate it following ...
{"functional": "def check(candidate):\n assert candidate(left = 1, right = 4) == \"24e0\"\n assert candidate(left = 2, right = 11) == \"399168e2\"\n assert candidate(left = 371, right = 375) == \"7219856259e3\"\n\n\ncheck(Solution().abbreviateProduct)"}
360
100
coding
Solve the programming task below in a Python markdown code block. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try t...
{"inputs": ["1\n0\n", "1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n-1\n", "1\n-2\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
365
88
coding
Solve the programming task below in a Python markdown code block. You have found $M$ different types of jewels in a mine and each type of jewel is present in an infinite number. There are $N$ different boxes located at position $(1 ,2 ,3 ,...N)$. Each box can collect jewels up to a certain number ( box at position $i$ ...
{"inputs": ["2\n1 10\n5 2"], "outputs": ["1\n64"]}
295
24
coding
Solve the programming task below in a Python markdown code block. When a warrior wants to talk with another one about peace or war he uses a smartphone. In one distinct country warriors who spent all time in training kata not always have enough money. So if they call some number they want to know which operator serve...
{"functional": "_inputs = [['80661111841'], ['80671991111'], ['80631551111'], ['80931551111'], ['80111551111']]\n_outputs = [['MTS'], ['Kyivstar'], ['Life:)'], ['Life:)'], ['no info']]\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, re...
294
235
coding
Solve the programming task below in a Python markdown code block. There is an array $a$ with $n-1$ integers. Let $x$ be the bitwise XOR of all elements of the array. The number $x$ is added to the end of the array $a$ (now it has length $n$), and then the elements are shuffled. You are given the newly formed array $a$...
{"inputs": ["4\n4\n4 3 2 5\n5\n6 1 10 7 10\n6\n6 6 6 6 6 6\n3\n100 100 0\n"], "outputs": ["5\n10\n6\n0\n"]}
726
71
coding
Solve the programming task below in a Python markdown code block. You're writing an excruciatingly detailed alternate history novel set in a world where [Daniel Gabriel Fahrenheit](https://en.wikipedia.org/wiki/Daniel_Gabriel_Fahrenheit) was never born. Since Fahrenheit never lived the world kept on using the [Rømer s...
{"functional": "_inputs = [[24], [8], [29]]\n_outputs = [[20.1], [11.7], [22.725]]\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 Fal...
234
182
coding
Solve the programming task below in a Python markdown code block. Ram and Shyam are sitting next to each other, hoping to cheat on an exam. However, the examination board has prepared $p$ different sets of questions (numbered $0$ through $p-1$), which will be distributed to the students in the following way: - The stud...
{"inputs": ["1\n2 6"], "outputs": ["3"]}
365
16
coding
Solve the programming task below in a Python markdown code block. Consider the following series: `1, 2, 4, 8, 16, 22, 26, 38, 62, 74, 102, 104, 108, 116, 122` It is generated as follows: * For single digit integers, add the number to itself to get the next element. * For other integers, multiply all the non-zero dig...
{"functional": "_inputs = [[3], [5], [10], [15], [500], [5000]]\n_outputs = [[5], [6], [5], [2], [29], [283]]\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 l...
515
194
coding
Solve the programming task below in a Python markdown code block. You are given n integer numbers a_1, a_2, ..., a_n. Consider graph on n nodes, in which nodes i, j (i≠ j) are connected if and only if, a_i AND a_j≠ 0, where AND denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND). F...
{"inputs": ["3\n5 5 5\n", "3\n1 1 3\n", "3\n2 5 5\n", "3\n1 1 2\n", "4\n1 2 4 8\n", "4\n3 6 28 9\n", "5\n25 3 44 6 48\n", "5\n49 3 6 44 24\n"], "outputs": ["3\n", "3\n", "-1\n", "-1\n", "-1\n", "4\n", "3\n", "3\n"]}
299
137
coding
Solve the programming task below in a Python markdown code block. Bleatrix Trotter the sheep has devised a strategy that helps her fall asleep faster. First, she picks a number N. Then she starts naming N, 2 × N, 3 × N, and so on. Whenever she names a number, she thinks about all of the digits in that number. She keeps...
{"functional": "_inputs = [[1692], [2], [7], [100], [1], [11], [163444], [206929], [459923], [691520], [0], [12500], [1250000]]\n_outputs = [[5076], [90], [70], [900], [10], [110], [653776], [620787], [4139307], [2074560], ['INSOMNIA'], [900000], [90000000]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstanc...
383
310
coding
Solve the programming task below in a Python markdown code block. An area named Renus, is divided into $(N \times M)$ cells. According to archaeological survey the area contains huge amount of treasure. Some cells out of $(N \times M)$ cells contain treasure. But problem is, you can't go to every cell as some of the ce...
{"inputs": ["1\n3 3\n2\n1 1\n1 3\n2\n2 1\n2 2"], "outputs": ["0 1 0\nX X 1\n4 3 2"]}
666
51
coding
Solve the programming task below in a Python markdown code block. There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left...
{"inputs": ["1\nB 1\nW 1\n", "1\nB 1\nW 1\n", "1\nW 1\nB 1\n", "2\nW 2\nB 1\nW 1\nB 2\n", "3\nB 1\nW 1\nB 3\nW 2\nW 3\nB 2", "3\nB 1\nW 1\nB 2\nW 2\nW 3\nB 3", "3\nB 1\nW 1\nB 3\nW 3\nW 2\nB 2", "3\nB 1\nW 2\nB 2\nW 1\nW 3\nB 3"], "outputs": ["0\n", "0\n", "0\n", "2\n", "3", "0", "4", "2"]}
457
198
coding
Solve the programming task below in a Python markdown code block. You are given two integers a and b. Determine if a+b=15 or a\times b=15 or neither holds. Note that a+b=15 and a\times b=15 do not hold at the same time. Constraints * 1 \leq a,b \leq 15 * All values in input are integers. Input Input is given from ...
{"inputs": ["8 7", "3 7", "2 1", "3 8", "4 1", "8 5", "3 0", "4 0"], "outputs": ["+\n", "x\n", "x\n", "x\n", "x\n", "x\n", "x\n", "x\n"]}
171
78
coding
Solve the programming task below in a Python markdown code block. Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. You are given an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Let's define the *useful number* of a subsequence of $A$ as the number of distinct primes $p$...
{"inputs": ["1\n5\n2 2 4 17 8"], "outputs": ["4"]}
448
25
coding
Solve the programming task below in a Python markdown code block. ```if-not:julia,racket Write a function that returns the total surface area and volume of a box as an array: `[area, volume]` ``` ```if:julia Write a function that returns the total surface area and volume of a box as a tuple: `(area, volume)` ``` ```if:...
{"functional": "_inputs = [[4, 2, 6], [1, 1, 1], [1, 2, 1], [1, 2, 2], [10, 10, 10]]\n_outputs = [[[88, 48]], [[6, 1]], [[10, 2]], [[16, 4]], [[600, 1000]]]\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 ...
131
235
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer num, repeatedly add all its digits until the result has only one digit, and return it.   Please complete the following python code precisely: ```python class Solution: def addDigits(self, num: int...
{"functional": "def check(candidate):\n assert candidate(num = 38) == 2\n assert candidate(num = 0) == 0\n\n\ncheck(Solution().addDigits)"}
69
44
coding
Solve the programming task below in a Python markdown code block. Three guys play a game: first, each person writes down $n$ distinct words of length $3$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of...
{"inputs": ["1\n1\niiy\niiy\niiy\n", "3\n1\nabc\ndef\nabc\n3\norz for qaq\nqaq orz for\ncod for ces\n5\niat roc hem ica lly\nbac ter iol ogi sts\nbac roc lly iol iat\n"], "outputs": ["0 0 0 \n", "1 3 1 \n2 2 6 \n9 11 5 \n"]}
417
111
coding
Solve the programming task below in a Python markdown code block. For a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ which is sorted by ascending order, eliminate all equivalent elements. Constraints * $1 \leq n \leq 100,000$ * $-1000,000,000 \leq a_i \leq 1,000,000,000$ * $a_0 \leq a_1 \leq ... \leq a_{n-...
{"inputs": ["4\n0 2 2 4", "4\n0 2 2 3", "4\n0 2 2 2", "4\n0 1 2 2", "4\n0 0 0 4", "4\n0 0 1 4", "4\n1 2 2 3", "4\n0 0 2 8"], "outputs": ["0 2 4\n", "0 2 3\n", "0 2\n", "0 1 2\n", "0 4\n", "0 1 4\n", "1 2 3\n", "0 2 8\n"]}
211
154
coding
Solve the programming task below in a Python markdown code block. ##Task: You have to write a function **pattern** which creates the following pattern upto n number of rows. *If the Argument is 0 or a Negative Integer then it should return "" i.e. empty string.* ##Pattern: (n) (n)(n-1) (n)(n-1)(n-2) ...
{"functional": "_inputs = [[1], [2], [5], [0], [-25]]\n_outputs = [['1'], ['2\\n21'], ['5\\n54\\n543\\n5432\\n54321'], [''], ['']]\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, t...
275
202
coding
Solve the programming task below in a Python markdown code block. Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food. Iahu...
{"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n", "2\n1 2\n", "2\n2 2\n", "4\n1 1 1 4\n", "4\n1 1 1 3\n", "4\n1 1 1 3\n"], "outputs": ["YES", "YES\n", "NO", "NO\n", "NO\n", "YES", "NO", "NO\n"]}
327
106
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. We build a table of n rows (1-indexed). We start by writing 0 in the 1st row. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10. For e...
{"functional": "def check(candidate):\n assert candidate(n = 1, k = 1) == 0\n assert candidate(n = 2, k = 1) == 0\n assert candidate(n = 2, k = 2) == 1\n\n\ncheck(Solution().kthGrammar)"}
181
71
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a binary string s, return true if the longest contiguous segment of 1's is strictly longer than the longest contiguous segment of 0's in s, or return false otherwise. For example, in s = "110100010" the longest...
{"functional": "def check(candidate):\n assert candidate(s = \"1101\") == True\n assert candidate(s = \"111000\") == False\n assert candidate(s = \"110100010\") == False\n\n\ncheck(Solution().checkZeroOnes)"}
169
70
coding
Solve the programming task below in a Python markdown code block. Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions x (0 < x < 10^9) of the equation:x = b·s(x)^{a} + c, where a, b, c are some predetermined ...
{"inputs": ["3 2 8\n", "1 1 0\n", "4 4 6\n", "5 1 0\n", "1 1 0\n", "5 1 0\n", "4 4 6\n", "4 4 7\n"], "outputs": ["3\n10 2008 13726 ", "9\n1 2 3 4 5 6 7 8 9 ", "13\n10 1030 40006 114250 202506 262150 521290 937030 1562506 2458630 3694090 4743690 7496650 ", "5\n1 17210368 52521875 60466176 205962976 ", "9\n1 2 3 4 5 6 7 ...
326
414
coding
Solve the programming task below in a Python markdown code block. You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are als...
{"inputs": ["6\n9 2\n010001010\n9 3\n111100000\n7 4\n1111111\n10 3\n1001110101\n1 1\n1\n1 1\n0\n", "6\n9 2\n010001010\n9 3\n111100000\n7 4\n1111111\n10 3\n1001110101\n1 1\n0\n1 1\n0\n", "6\n9 2\n010001010\n9 5\n111100000\n7 4\n1111111\n10 3\n1001110101\n1 1\n0\n1 1\n0\n", "6\n9 2\n011001010\n9 3\n111100000\n7 4\n111111...
589
694
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of integers stones where stones[i] is the weight of the ith stone. We are playing a game with the stones. On each turn, we choose any two stones and smash them together. Suppose the stones have ...
{"functional": "def check(candidate):\n assert candidate(stones = [2,7,4,1,8,1]) == 1\n assert candidate(stones = [31,26,33,21,40]) == 5\n\n\ncheck(Solution().lastStoneWeightII)"}
187
70
coding
Solve the programming task below in a Python markdown code block. In computing, the collection of four bits is called a nibble. Chef defines a program as: Good, if it takes exactly X nibbles of memory, where X is a positive integer. Not Good, otherwise. Given a program which takes N bits of memory, determine whether ...
{"inputs": ["4\n8\n17\n52\n3"], "outputs": ["Good\nNot Good\nGood\nNot Good"]}
498
30
coding
Solve the programming task below in a Python markdown code block. Aleksey has $n$ friends. He is also on a vacation right now, so he has $m$ days to play this new viral cooperative game! But since it's cooperative, Aleksey will need one teammate in each of these $m$ days. On each of these days some friends will be ava...
{"inputs": ["2\n4 6\n1 1\n2 1 2\n3 1 2 3\n4 1 2 3 4\n2 2 3\n1 3\n2 2\n1 1\n1 1\n"], "outputs": ["YES\n1 2 1 1 2 3 \nNO\n"]}
645
83
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer num, return the number of steps to reduce it to zero. In one step, if the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it.   Please complete the following...
{"functional": "def check(candidate):\n assert candidate(num = 14) == 6\n assert candidate(num = 8) == 4\n assert candidate(num = 123) == 12\n\n\ncheck(Solution().numberOfSteps)"}
94
59
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. Vadim and Roman like discussing challenging problems with each other. One day Vadim told his friend following problem: Given N points on a plane. Each point p is defined by it's two inte...
{"inputs": ["2\n2\n1 2\n0 0\n3\n3 3\n0 0\n0 3", "2\n2\n1 2\n1 0\n3\n3 3\n0 0\n0 3", "2\n2\n1 2\n1 0\n3\n3 3\n1 0\n0 3", "2\n2\n1 2\n1 0\n3\n3 3\n2 0\n0 3", "2\n2\n1 2\n1 0\n3\n3 3\n2 0\n0 0", "2\n2\n1 2\n0 0\n3\n3 6\n0 0\n0 3", "2\n2\n1 2\n0 0\n3\n3 5\n0 0\n0 3", "2\n2\n1 2\n1 0\n3\n3 0\n1 0\n0 3"], "outputs": ["3\n0",...
629
269
coding
Solve the programming task below in a Python markdown code block. Did you know that Chwee kueh, a cuisine of Singapore, means water rice cake ? Its a variety of the most popular South Indian savory cake, only that we call it here idli :). The tastiest idlis are made in Chennai, by none other than our famous chef, Dexte...
{"inputs": ["3\n4\n1 2 2 3\n2\n1 2\n7\n1 2 3 4 5 6 7", "3\n4\n1 2 2 3\n2\n1 2\n7\n1 0 3 4 5 6 7", "3\n4\n1 4 2 3\n2\n1 2\n7\n1 0 3 4 5 6 7", "3\n4\n0 2 2 3\n2\n1 2\n7\n1 2 3 4 5 6 7", "3\n4\n1 1 1 1\n2\n1 2\n7\n1 4 0 1 6 6 7", "3\n4\n1 4 2 3\n2\n1 2\n7\n1 0 4 4 6 6 7", "3\n4\n1 2 2 3\n2\n1 2\n7\n1 4 3 2 5 6 7", "3\n4\n...
774
360
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef has two piles of stones with him, one has n_{1} stones and the other has n_{2} stones. Fired up by boredom, he invented a game with the two piles. Before the start of t...
{"inputs": ["3\n1 1 1\n1 2 1\n4 5 2"], "outputs": ["0\n1\n3"]}
668
34
coding
Solve the programming task below in a Python markdown code block. A rabbit is playing a role-playing game. Just before entering the castle, he was ambushed by an enemy! It was a battle between one hero operated by a rabbit and n enemies. Each character has four stats, health hi, attack power ai, defense power di, and ...
{"inputs": ["2\n10 3 1 2\n2 4 1 3\n1 2 1 1", "2\n10 3 1 2\n2 4 1 3\n1 3 1 1", "2\n10 3 1 2\n3 4 1 3\n1 3 1 1", "2\n10 3 2 2\n3 4 1 3\n1 3 1 1", "2\n10 3 2 2\n3 8 1 3\n1 3 1 1", "2\n10 3 2 2\n3 8 1 3\n1 6 1 1", "2\n10 2 2 2\n3 8 1 3\n1 6 1 1", "2\n10 2 2 2\n3 5 1 3\n1 6 1 1"], "outputs": ["4\n", "5\n", "9\n", "6\n", "-1...
366
262
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n integer matrix points (0-indexed). Starting with 0 points, you want to maximize the number of points you can get from the matrix. To gain points, you must pick one cell in each row. Picking the ...
{"functional": "def check(candidate):\n assert candidate(points = [[1,2,3],[1,5,1],[3,1,1]]) == 9\n assert candidate(points = [[1,5],[2,3],[4,2]]) == 11\n\n\ncheck(Solution().maxPoints)"}
231
70
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A complex number can be represented as a string on the form "real+imaginaryi" where: real is the real part and is an integer in the range [-100, 100]. imaginary is the imaginary part and is an integer in the range [-...
{"functional": "def check(candidate):\n assert candidate(num1 = \"1+1i\", num2 = \"1+1i\") == \"0+2i\"\n assert candidate(num1 = \"1+-1i\", num2 = \"1+-1i\") == \"0+-2i\"\n\n\ncheck(Solution().complexNumberMultiply)"}
151
78
coding
Solve the programming task below in a Python markdown code block. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where a_{i}, j = 1 if the i-th switch turns on the j-th lamp and a_{i}, j = 0 if the i-t...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "2 1\n0\n1\n", "2 1\n0\n1\n", "2 1\n1\n1\n", "1 5\n11111\n", "2 2\n10\n11\n", "2 2\n01\n11\n"], "outputs": ["NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n"]}
454
120
coding
Solve the programming task below in a Python markdown code block. You are given an array a. Some element of this array a_{i} is a local minimum iff it is strictly less than both of its neighbours (that is, a_{i} < a_{i} - 1 and a_{i} < a_{i} + 1). Also the element can be called local maximum iff it is strictly greater ...
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n0\n", "1\n4\n", "1\n3\n", "1\n8\n", "1\n5\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
296
86
coding
Solve the programming task below in a Python markdown code block. — Do you have a wish? — I want people to stop gifting each other arrays. O_o and Another Young Boy An array of $n$ positive integers $a_1,a_2,\ldots,a_n$ fell down on you from the skies, along with a positive integer $k \le n$. You can apply the foll...
{"inputs": ["6\n3 1\n2 4 1\n3 2\n1 9 84\n3 1\n10 2 6\n3 2\n179 17 1000000000\n2 1\n5 9\n2 2\n4 2\n"], "outputs": ["4\n168\n10\n1000000000\n9\n1000000000\n"]}
670
115
coding
Solve the programming task below in a Python markdown code block. Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry. He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1. Watson g...
{"inputs": ["3\n", "4\n", "1\n", "2\n", "1\n", "2\n", "1\n", "4\n"], "outputs": ["2\n1 1 2 \n", "2\n1 1 2 1 \n", "1\n1 \n", "1\n1 1 \n", "1\n1 \n", "1\n1 1 \n", "1\n1 ", "2\n1 1 2 1 "]}
362
111
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef invited N of his friends in his birthday party. All the friends are numbered from 1 to N. Some of the friends might know each other. You are given this information by M ...
{"inputs": ["3\n3 2\n1 2\n2 3\n4 3\n1 2\n2 3\n2 4\n6 7\n1 2\n1 3\n2 3\n2 4\n4 5\n4 6\n5 6"], "outputs": ["YES\nNO\nYES"]}
652
76
coding
Solve the programming task below in a Python markdown code block. You are given an integer $n$. In $1$ move, you can do one of the following actions: erase any digit of the number (it's acceptable that the number before the operation has exactly one digit and after the operation, it is "empty"); add one digit to the ...
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n4\n", "1\n7\n", "1\n6\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "2\n", "0\n", "2\n", "1\n"]}
691
86
coding
Solve the programming task below in a Python markdown code block. Heiankyo is known as a town with a grid of roads. Hokusai, a cat who lives in Heiankyo, has to go from his home to a secret place on the outskirts of town every day for patrol. However, I get tired of following the same path every day, and there is a ri...
{"inputs": ["4\n2 2\n0\n1 2\n2\n0 0 0 1\n0 0 1 0\n4 3\n4\n1 0 0 0\n3 3 2 3\n4 0 4 0\n0 2 0 3\n1 3\n0", "4\n2 2\n0\n0 2\n2\n0 0 0 1\n0 0 2 0\n2 3\n4\n1 0 0 0\n3 1 4 3\n5 0 1 0\n0 2 0 3\n3 4\n0", "4\n3 2\n0\n0 2\n2\n0 0 0 1\n0 0 1 0\n2 3\n4\n1 0 0 0\n3 1 4 3\n7 0 1 0\n0 2 0 1\n5 3\n0", "4\n3 2\n0\n0 2\n2\n0 0 0 1\n0 0 1 ...
629
752
coding
Solve the programming task below in a Python markdown code block. ## The Problem James is a DJ at a local radio station. As it's getting to the top of the hour, he needs to find a song to play that will be short enough to fit in before the news block. He's got a database of songs that he'd like you to help him filter ...
{"functional": "_inputs = [[215], [270], [13], [300]]\n_outputs = [['For Reasons Unknown'], ['YYZ'], [False], ['Surfing With The Alien']]\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, (...
477
188
coding
Solve the programming task below in a Python markdown code block. The magic sum of 3s is calculated on an array by summing up odd numbers which include the digit `3`. Write a function `magic_sum` which accepts an array of integers and returns the sum. *Example:* `[3, 12, 5, 8, 30, 13]` results in `16` (`3` + `13`) If...
{"functional": "_inputs = [[[3]], [[3, 13]], [[30, 34, 330]], [[3, 12, 5, 8, 30, 13]], [[]], [None]]\n_outputs = [[3], [16], [0], [16], [0], [0]]\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 isinsta...
131
218
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, you have two types of operation: Choose an index i in the string, and let c be the character in position i. Delete the closest occurrence of c to the left of i (if exists). Choose an index i in the ...
{"functional": "def check(candidate):\n assert candidate(s = \"aaabc\") == 3\n assert candidate(s = \"cbbd\") == 3\n assert candidate(s = \"dddaaa\") == 2\n\n\ncheck(Solution().minimizedStringLength)"}
156
61
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n people, each person has a unique id between 0 and n-1. Given the arrays watchedVideos and friends, where watchedVideos[i] and friends[i] contain the list of watched videos and the list of friends respectiv...
{"functional": "def check(candidate):\n assert candidate(watchedVideos = [[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 1) == [\"B\",\"C\"] \n assert candidate(watchedVideos = [[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]], friends = [[1,2],[0,3],[0,3],[1,2]], i...
226
152
coding
Solve the programming task below in a Python markdown code block. A happy number is a number defined by the following process: starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a...
{"functional": "_inputs = [[1], [7], [16]]\n_outputs = [[True], [True], [False]]\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...
322
168
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. After IOI Ilya decided to make a business. He found a social network called "TheScorpyBook.com". It currently has N registered users. As in any social network two users can be friends. ...
{"inputs": ["4\n0111\n1000\n1000\n1000", "4\n1111\n1000\n1000\n1000", "4\n0111\n1100\n0000\n1001", "4\n1111\n1010\n1000\n1010", "4\n0011\n0000\n0000\n1001", "4\n1111\n1100\n0000\n1001", "4\n0110\n1000\n0000\n1001", "4\n0011\n1000\n0000\n1000"], "outputs": ["6", "6\n", "2\n", "4\n", "0\n", "2\n", "2\n", "2\n"]}
362
221
coding
Solve the programming task below in a Python markdown code block. Write a function ```python alternate_sort(l) ``` that combines the elements of an array by sorting the elements ascending by their **absolute value** and outputs negative and non-negative integers alternatingly (starting with the negative value, if any)....
{"functional": "_inputs = [[[5, 2, -3, -9, -4, 8]], [[5, -42, 2, -3, -4, 8, 9]], [[5, -42, 8, 2, -3, -4, 9]], [[5, -42, -8, 2, -3, -4, -9]], [[5, 2, 3, 4, 8, 9]], [[-5, -2, -3, -4, -8, -9]], [[-5, -2, 3, 4, -8, 0, -9]], [[-5, -2, 3, 9, 4, -2, -8, 0, 9, -9]]]\n_outputs = [[[-3, 2, -4, 5, -9, 8]], [[-3, 2, -4, 5, -42, 8,...
265
502
coding
Solve the programming task below in a Python markdown code block. You're hanging out with your friends in a bar, when suddenly one of them is so drunk, that he can't speak, and when he wants to say something, he writes it down on a paper. However, none of the words he writes make sense to you. He wants to help you, so ...
{"functional": "_inputs = [['yvvi'], ['Blf zoivzwb szw 10 yvvih'], [\"Ovg'h hdrn rm gsv ulfmgzrm!\"], [{'brand': 'Starobrno'}], [\"Tl slnv, blf'iv wifmp\"], [\"Hfiv r xzm wzmxv lm xlk'h xzi, slow nb yvvi\"], [True], [\"Hvv? R'n mlg gszg wifmp, r xzm hgroo gzpv nb xolgsvh luu\"], [123], [['Beer']]]\n_outputs = [['beer']...
183
379
coding
Solve the programming task below in a Python markdown code block. Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all thr...
{"inputs": ["1\n1000 256 1 100\n", "1\n1000 477 1 100\n", "1\n1000 477 1 101\n", "1\n1000 784 1 101\n", "1\n1200 512 300 700\n", "1\n1619 512 300 700\n", "1\n1619 579 300 700\n", "1\n1619 375 300 700\n"], "outputs": ["1", "1\n", "1\n", "1\n", "1", "1\n", "1\n", "1\n"]}
494
196
coding
Solve the programming task below in a Python markdown code block. Given a binary number $S$ containing only of 1's and 0's, find two binary numbers $A$ and $B$ such that the sum of the number of 1's in $A$ and $B$ is minimum and $A-B=S$. If there are many such numbers, you can print any. The binary number $S$ has some...
{"inputs": ["1110000"], "outputs": ["10000000 10000"]}
361
31
coding
Solve the programming task below in a Python markdown code block. Base on the fairy tale [Diamonds and Toads](https://en.wikipedia.org/wiki/Diamonds_and_Toads) from Charles Perrault. In this kata you will have to complete a function that take 2 arguments: - A string, that correspond to what the daugther says. - A str...
{"functional": "_inputs = [['Ruby and Crystal', 'good'], ['This string contain some Ruby and some Crystal in it', 'good'], ['Python and Squirrel', 'evil'], ['This string contain some Python and some Squirrel in it', 'evil']]\n_outputs = [[{'ruby': 3, 'crystal': 2}], [{'ruby': 4, 'crystal': 3}], [{'python': 2, 'squirrel...
318
254
coding
Solve the programming task below in a Python markdown code block. We define the function `f1(n,k)`, as the least multiple of `n` that has all its digits less than `k`. We define the function `f2(n,k)`, as the least multiple of `n` that has all the digits that are less than `k`. Each digit may occur more than once in...
{"functional": "_inputs = [[542, 5], [1750, 6], [14990, 7], [3456, 4], [30500, 3], [62550, 5], [568525, 7], [9567100, 8]]\n_outputs = [[547], [1799], [14996], [3462], [30501], [62557], [568531], [9567115]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ...
657
286
coding
Solve the programming task below in a Python markdown code block. Professor Sahil is a master artist, he always finds creative ways to teach lessons to his students. Today in Painting class he took all the students of the class to a wall. Professor Sahil asked every student to paint the wall upto a certain integral hei...
{"inputs": ["3\n5 4\n1 2 3 4 5\n3 3 3 3 3\n5 4\n3 5 1 2 3\n1 2 3 4 3\n5 5 \n5 4 3 2 3\n1 2 3 4 5"], "outputs": ["1\n2\n3"]}
657
89
coding
Solve the programming task below in a Python markdown code block. A faro shuffle of a deck of playing cards is a shuffle in which the deck is split exactly in half and then the cards in the two halves are perfectly interwoven, such that the original bottom card is still on the bottom and the original top card is still ...
{"functional": "_inputs = [[2], [52], [542], [1250], [1954]]\n_outputs = [[1], [8], [540], [156], [30]]\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) ...
233
193
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of logs. Each log is a space-delimited string of words, where the first word is the identifier. There are two types of logs: Letter-logs: All words (except the identifier) consist of lowercase ...
{"functional": "def check(candidate):\n assert candidate(logs = [\"dig1 8 1 5 1\",\"let1 art can\",\"dig2 3 6\",\"let2 own kit dig\",\"let3 art zero\"]) == [\"let1 art can\",\"let3 art zero\",\"let2 own kit dig\",\"dig1 8 1 5 1\",\"dig2 3 6\"]\n assert candidate(logs = [\"a1 9 2 3 1\",\"g1 act car\",\"zo4 4 7\",\...
181
185
coding
Solve the programming task below in a Python markdown code block. You are given a rooted tree on N vertices. The nodes are numbered from 1 to N, and Node 1 is the root. Each node u has an associated value attached to it: Au. For each vertex v, we consider the path going upwards from v to the root. Suppose that path is ...
{"inputs": ["8\n1 1 1 1 5 8 6\n1 2 3 4 5 15 70 10"], "outputs": ["1 3 4 5 6 21 96 26"]}
644
62
coding
Solve the programming task below in a Python markdown code block. There are $n$ block towers, numbered from $1$ to $n$. The $i$-th tower consists of $a_i$ blocks. In one move, you can move one block from tower $i$ to tower $j$, but only if $a_i > a_j$. That move increases $a_j$ by $1$ and decreases $a_i$ by $1$. You c...
{"inputs": ["4\n3\n1 2 3\n3\n1 2 2\n2\n1 1000000000\n10\n3 8 6 7 4 1 2 4 10 1\n"], "outputs": ["3\n2\n500000001\n9\n"]}
575
83
coding
Solve the programming task below in a Python markdown code block. Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was. Its most important components are a button and a line ...
{"inputs": ["1\n0\n", "1\n0\n", "2\n1 0\n", "2\n0 0\n", "2\n0 1\n", "2\n1 0\n", "2\n1 1\n", "2\n1 1\n"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "Yes\n", "No\n", "No\n"]}
503
98
coding
Solve the programming task below in a Python markdown code block. Chef has to attend an exam that starts in X minutes, but of course, watching shows takes priority. Every episode of the show that Chef is watching, is 24 minutes long. If he starts watching a new episode now, will he finish watching it strictly before...
{"inputs": ["4\n30\n23\n60\n24\n"], "outputs": ["Yes\nNo\nYes\nNo\n"]}
420
32
coding
Solve the programming task below in a Python markdown code block. Calculate the number of items in a vector that appear at the same index in each vector, with the same value. ```python vector_affinity([1, 2, 3, 4, 5], [1, 2, 2, 4, 3]) # => 0.6 vector_affinity([1, 2, 3], [1, 2, 3]) # => 1.0 ``` Affinity value s...
{"functional": "_inputs = [[[1, 2, 3], [1, 2, 3, 4, 5]], [[1, 2, 3, 4], [1, 2, 3, 5]], [[1, 2, 3, 4, 5], []], [[1, 2, 3], [1, 2, 3]], [[6, 6, 6, 6, 6, 6], [6, None, None, 6, 6, None]], [[6], [6, 6, 6, 6, 6, 6]], [[], []], [[None], [None]]]\n_outputs = [[0.6], [0.75], [0.0], [1.0], [0.5], [0.16666666666666666], [1.0], [...
201
353
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef is very adventurous, so he asked Bob to give him a task. Bob gave him a sequence of blocks with heights A_{1}, A_{2}, \ldots, A_{N}. Chef is at the first block ...
{"inputs": ["2\n5\n9 15 8 13 8\n9\n20 16 13 9 17 11 15 8 7"], "outputs": ["-1\n4"]}
589
55
coding
Solve the programming task below in a Python markdown code block. A system is transmitting messages in binary, however it is not a perfect transmission, and sometimes errors will occur which result in a single bit flipping from 0 to 1, or from 1 to 0. To resolve this, A 2-dimensional Parity Bit Code is used: https://e...
{"functional": "_inputs = [[1, 1, '111'], [1, 1, '011'], [1, 1, '101'], [1, 1, '110'], [2, 3, '11111010001'], [2, 3, '11011010001'], [2, 3, '11111011001'], [2, 3, '11111010011']]\n_outputs = [['111'], ['111'], ['111'], ['111'], ['11111010001'], ['11111010001'], ['11111010001'], ['11111010001']]\nimport math\ndef _deep_...
647
339
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. A competition with $N$ participants (numbered $1$ through $N$) is taking place in Chefland. There are $N-1$ rounds in the competition; in each round...
{"inputs": ["1\n3\n1110001101\n1010101011\n0000000011"], "outputs": ["4"]}
651
47
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the b...
{"functional": "def check(candidate):\n assert candidate(a = 2, b = 6, c = 5) == 3\n assert candidate(a = 4, b = 2, c = 7) == 1\n assert candidate(a = 1, b = 2, c = 3) == 0\n\n\ncheck(Solution().minFlips)"}
128
86
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Given an integer A that contains n > 1 digits. You are asked to remove exactly one digit to make the result number is divisible by 6, also make it biggest possible.   ------ ...
{"inputs": ["3\n123\n100222\n10003"], "outputs": ["12\n00222\n-1"]}
296
39
coding
Solve the programming task below in a Python markdown code block. Sammy and Simmy love candies and frequently visit the local candy shop. Sammy and Simmy have bought $N$ candy packs. Packet $i$ contains $A_{i}$ candies. Sammy being the elder one is happy only if she has strictly more candies than Simmy. However Simmy, ...
{"inputs": ["1 \n2 \n5 2"], "outputs": ["YES"]}
408
22
coding
Solve the programming task below in a Python markdown code block. # Introduction There is a war and nobody knows - the alphabet war! There are two groups of hostile letters. The tension between left side letters and right side letters was too high and the war began. # Task Write a function that accepts `fight` str...
{"functional": "_inputs = [['z'], ['zdqmwpbs'], ['wq'], ['zzzzs'], ['wwwwww']]\n_outputs = [['Right side wins!'], [\"Let's fight again!\"], ['Left side wins!'], ['Right side wins!'], ['Left side wins!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ma...
264
205
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integers m and n representing the dimensions of a 0-indexed m x n grid. You are also given a 0-indexed 2D integer matrix coordinates, where coordinates[i] = [x, y] indicates that the cell with coordi...
{"functional": "def check(candidate):\n assert candidate(m = 3, n = 3, coordinates = [[0,0]]) == [3,1,0,0,0]\n assert candidate(m = 3, n = 3, coordinates = [[0,0],[1,1],[0,2]]) == [0,2,2,0,0]\n\n\ncheck(Solution().countBlackBlocks)"}
257
94
coding
Solve the programming task below in a Python markdown code block. Let's dive into decorators! You are given $N$ mobile numbers. Sort them in ascending order then print them in the standard format shown below: +91 xxxxx xxxxx The given mobile numbers may have $+91$, $91$ or $\mbox{0}$ written before the actual $10$ di...
{"inputs": ["3\n07895462130\n919875641230\n9195969878\n"], "outputs": ["+91 78954 62130\n+91 91959 69878\n+91 98756 41230\n"]}
322
96
coding
Solve the programming task below in a Python markdown code block. # Task Let's say that `"g" is happy` in the given string, if there is another "g" immediately to the right or to the left of it. Find out if all "g"s in the given string are happy. # Example For `str = "gg0gg3gg0gg"`, the output should be `true`. ...
{"functional": "_inputs = [['gg0gg3gg0gg'], ['gog'], ['ggg ggg g ggg'], ['A half of a half is a quarter.'], ['good grief'], ['bigger is ggooder'], ['gggggggggg']]\n_outputs = [[True], [False], [False], [True], [False], [True], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstanc...
180
222
coding
Solve the programming task below in a Python markdown code block. For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order. Constraints * $1 \leq n \leq 9$ * $a_i$ consist of $1, 2, ..., n$ Input A sequence is given in the following form...
{"inputs": ["3\n3 3 1", "3\n3 1 3", "3\n3 3 2", "3\n6 1 3", "3\n3 5 2", "3\n0 5 2", "3\n6 1 4", "3\n6 1 6"], "outputs": ["3 1 3\n3 3 1\n", "1 3 3\n3 1 3\n3 3 1\n", "3 2 3\n3 3 2\n", "3 6 1\n6 1 3\n6 3 1\n", "3 2 5\n3 5 2\n5 2 3\n", "0 2 5\n0 5 2\n2 0 5\n", "4 6 1\n6 1 4\n6 4 1\n", "1 6 6\n6 1 6\n6 6 1\n"]}
225
226
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Russian] Chef is having a candlelit dinner with his girlfriend at his place. Currently, it is time $0$, Chef just managed to light a candle, but he is out of matchsticks. Since Chef has an infinite supply of (unlit) candles,...
{"inputs": ["3\n1 1 1\n1 2 1\n2 2 1"], "outputs": ["1\n2\n2"]}
691
34
coding
Solve the programming task below in a Python markdown code block. A and B are preparing themselves for programming contests. An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the ne...
{"inputs": ["2 6\n", "4 5\n", "1 1\n", "3 3\n", "0 0\n", "0 1\n", "1 0\n", "0 6\n"], "outputs": ["2\n", "3\n", "0\n", "2\n", "0\n", "0\n", "0\n", "0\n"]}
365
86
coding
Solve the programming task below in a Python markdown code block. A spoonerism is a spoken phrase in which the first letters of two of the words are swapped around, often with amusing results. In its most basic form a spoonerism is a two word phrase in which only the first letters of each word are swapped: ```"not pi...
{"functional": "_inputs = [['not picking'], ['wedding bells'], ['jelly beans'], ['pop corn']]\n_outputs = [['pot nicking'], ['bedding wells'], ['belly jeans'], ['cop porn']]\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, ...
290
187
coding
Solve the programming task below in a Python markdown code block. Alice and Bob are playing a game on a line with n cells. There are n cells labeled from 1 through n. For each i from 1 to n-1, cells i and i+1 are adjacent. Alice initially has a token on some cell on the line, and Bob tries to guess where it is. Bob ...
{"inputs": ["1 2\n1 1\n", "6 3\n5 1 4\n", "6 3\n4 2 3\n", "9 3\n5 1 4\n", "6 3\n5 2 4\n", "6 3\n5 2 3\n", "6 3\n5 2 1\n", "6 3\n5 4 3\n"], "outputs": ["0\n", "12\n", "11\n", "21\n", "12\n", "12\n", "12\n", "11\n"]}
722
139
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Consider a matrix M with dimensions width * height, such that every cell has value 0 or 1, and any square sub-matrix of M of size sideLength * sideLength has at most maxOnes ones. Return the maximum possible number of...
{"functional": "def check(candidate):\n assert candidate(width = 3, height = 3, sideLength = 2, maxOnes = 1) == 4\n assert candidate(width = 3, height = 3, sideLength = 2, maxOnes = 2) == 6\n\n\ncheck(Solution().maximumNumberOfOnes)"}
127
81
coding
Solve the programming task below in a Python markdown code block. Andrey's favourite number is n. Andrey's friends gave him two identical numbers n as a New Year present. He hung them on a wall and watched them adoringly. Then Andrey got bored from looking at the same number and he started to swap digits first in one,...
{"inputs": ["50\n", "24\n", "545\n", "404\n", "685\n", "672\n", "258\n", "157\n"], "outputs": ["50\n50\n", "42\n42\n", "545\n455", "440\n440", "865\n865\n", "762\n762\n", "852\n528\n", "715\n715\n"]}
290
126
coding
Solve the programming task below in a Python markdown code block. Americans are odd people: in their buildings, the first floor is actually the ground floor and there is no 13th floor (due to superstition). Write a function that given a floor in the american system returns the floor in the european system. With the 1...
{"functional": "_inputs = [[1], [0], [5], [10], [12], [14], [15], [37], [200], [-2], [-5]]\n_outputs = [[0], [0], [4], [9], [11], [12], [13], [35], [198], [-2], [-5]]\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...
216
228
coding
Solve the programming task below in a Python markdown code block. You are given $n$ integers $w_i (i = 0, 1, ..., n-1)$ to be sorted in ascending order. You can swap two integers $w_i$ and $w_j$. Each swap operation has a cost, which is the sum of the two integers $w_i + w_j$. You can perform the operations any number ...
{"inputs": ["4\n8 3 2 1", "4\n3 5 2 1", "4\n4 0 2 1", "4\n0 3 2 1", "4\n4 5 2 1", "4\n6 5 2 1", "4\n4 3 1 2", "4\n6 7 2 1"], "outputs": ["14\n", "13\n", "5\n", "4\n", "14\n", "14\n", "12\n", "18\n"]}
247
132
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a strange printer with the following two special properties: The printer can only print a sequence of the same character each time. At each turn, the printer can print new characters starting from and ending...
{"functional": "def check(candidate):\n assert candidate(s = \"aaabbb\") == 2\n assert candidate(s = \"aba\") == 2\n\n\ncheck(Solution().strangePrinter)"}
116
46