task_type
stringclasses
1 value
problem
stringlengths
209
3.39k
answer
stringlengths
35
6.15k
problem_tokens
int64
60
774
answer_tokens
int64
12
2.04k
coding
Solve the programming task below in a Python markdown code block. You survived several months of exam wars and were able to enter ICPC University on a sunny day. On the day of admission, there was an enthusiastic recruitment of circles on the campus of the university, and you received a large number of pamphlets and re...
{"inputs": ["9\n4\n0", "9\n8\n0", "9\n2\n0", "9\n5\n0", "9\n3\n0", "9\n6\n0", "9\n9\n0", "9\n0\n0"], "outputs": ["2\n0\n", "2\n0\n", "2\n0\n", "2\n1\n", "2\n1\n", "2\n1\n", "2\n2\n", "2\n"]}
301
108
coding
Solve the programming task below in a Python markdown code block. Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings $a$ and $b$. It is known that $|b| \leq |a|$, that is, the length of $b$ is at most the length of $a$. The Cossack considers every substring...
{"inputs": ["0\n1\n", "0\n1\n", "01100010\n00110\n", "01100010\n10110\n", "01100010\n10100\n", "01100010\n11100\n", "01100010\n11110\n", "01100010\n11111\n"], "outputs": ["0\n", "0", "3\n", "1\n", "3\n", "1\n", "3\n", "1\n"]}
592
151
coding
Solve the programming task below in a Python markdown code block. N problems have been chosen by the judges, now it's time to assign scores to them! Problem i must get an integer score A_i between 1 and N, inclusive. The problems have already been sorted by difficulty: A_1 \le A_2 \le \ldots \le A_N must hold. Differe...
{"inputs": ["0 4548", "1 4548", "1 1010", "0 1010", "0 1000", "-1 4548", "2 666010", "2 489029"], "outputs": ["0", "1", "1", "0", "0", "0", "3", "3"]}
331
98
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a survey that consists of n questions where each question's answer is either 0 (no) or 1 (yes). The survey was given to m students numbered from 0 to m - 1 and m mentors numbered from 0 to m - 1. The answers ...
{"functional": "def check(candidate):\n assert candidate(students = [[1,1,0],[1,0,1],[0,0,1]], mentors = [[1,0,0],[0,0,1],[1,1,0]]) == 8\n assert candidate(students = [[0,0],[0,0],[0,0]], mentors = [[1,1],[1,1],[1,1]]) == 0\n\n\ncheck(Solution().maxCompatibilitySum)"}
320
108
coding
Solve the programming task below in a Python markdown code block. ## Objective Given a number `n` we will define it's sXORe to be `0 XOR 1 XOR 2 ... XOR n` where `XOR` is the [bitwise XOR operator](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Write a function that takes `n` and returns it's sXORe. ## Exampl...
{"functional": "_inputs = [[0], [1], [2], [50], [1000000], [1000001], [9999999999999999999999999]]\n_outputs = [[0], [1], [3], [51], [1000000], [1], [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...
175
235
coding
Solve the programming task below in a Python markdown code block. Find the volume of a cone whose radius and height are provided as parameters to the function `volume`. Use the value of PI provided by your language (for example: `Math.PI` in JS, `math.pi` in Python or `Math::PI` in Ruby) and round down the volume to an...
{"functional": "_inputs = [[7, 3], [56, 30], [0, 10], [10, 0], [0, 0]]\n_outputs = [[153], [98520], [0], [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 isinstance(a, (list, tuple)):\n ...
124
202
coding
Solve the programming task below in a Python markdown code block. There is a knight - the chess piece - at the origin (0, 0) of a two-dimensional grid. When the knight is at the square (i, j), it can be moved to either (i+1,j+2) or (i+2, j+1). In how many ways can the knight reach the square (X, Y)? Find the number of ...
{"inputs": ["2 0", "1 2", "0 3", "1 0", "1 3", "3 0", "4 0", "7 0"], "outputs": ["0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
256
78
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,4,3,2,5,2]), x = 3), list_node([1,2,2,4,3,5]))\n assert is_same_list(candidate(head = list_node([2,1]), x = 2), list_node([1,2]))\n\n\ncheck(Solution().partition)"}
142
92
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
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums and a target element target. A target index is an index i such that nums[i] == target. Return a list of the target indices of nums after sorting nums in non-decreasing orde...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,5,2,3], target = 2) == [1,2]\n assert candidate(nums = [1,2,5,2,3], target = 3) == [3]\n assert candidate(nums = [1,2,5,2,3], target = 5) == [4]\n assert candidate(nums = [1,2,5,2,3], target = 4) == []\n\n\ncheck(Solution().targetIndices)"...
125
124
coding
Solve the programming task below in a Python markdown code block. # Situation You have been hired by a company making electric garage doors. Accidents with the present product line have resulted in numerous damaged cars, broken limbs and several killed pets. Your mission is to write a safer version of their controller ...
{"functional": "_inputs = [[''], ['..........'], ['P..'], ['P....'], ['P......P......'], ['P.P..'], ['P.P.P....'], ['.....P.P........P....'], ['.....P......P.P..P....'], ['P.O....'], ['P......P.O....'], ['P..OP..P..'], ['P......P..OP..P...'], ['..P...O.....']]\n_outputs = [[''], ['0000000000'], ['123'], ['12345'], ['12...
359
410
coding
Solve the programming task below in a Python markdown code block. Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them: Max owns n creatures, i-th of them can be described with two num...
{"inputs": ["1 0 0\n2 1\n", "1 1 0\n3 4\n", "1 0 0\n2 1\n", "1 1 0\n3 4\n", "1 0 0\n0 1\n", "1 1 0\n3 3\n", "1 1 0\n0 1\n", "1 1 0\n10 1\n"], "outputs": ["1\n", "4\n", "1\n", "4\n", "1\n", "3\n", "1\n", "1\n"]}
517
135
coding
Solve the programming task below in a Python markdown code block. Alice became interested in periods of integer numbers. We say positive $X$ integer number is periodic with length $L$ if there exists positive integer number $P$ with $L$ digits such that $X$ can be written as $PPPP…P$. For example: $X = 123123123$ is p...
{"inputs": ["3\n991\n", "3\n901\n", "3\n643\n", "10\n86\n", "1\n6789\n", "1\n6789\n", "1\n3968\n", "3\n5248\n"], "outputs": ["992\n", "902\n", "644\n", "1000000000\n", "7777\n", "7777", "4444\n", "100100\n"]}
411
134
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 0-indexed integer array nums of size n and two integers lower and upper, return the number of fair pairs. A pair (i, j) is fair if: 0 <= i < j < n, and lower <= nums[i] + nums[j] <= upper   Please complete t...
{"functional": "def check(candidate):\n assert candidate(nums = [0,1,7,4,4,5], lower = 3, upper = 6) == 6\n assert candidate(nums = [1,7,9,2,5], lower = 11, upper = 11) == 1\n\n\ncheck(Solution().countFairPairs)"}
116
84
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a tree (i.e., a connected, undirected graph with no cycles) structure country network consisting of n cities numbered from 0 to n - 1 and exactly n - 1 roads. The capital city is city 0. You are given a 2D in...
{"functional": "def check(candidate):\n assert candidate(roads = [[0,1],[0,2],[0,3]], seats = 5) == 3\n assert candidate(roads = [[3,1],[3,2],[1,0],[0,4],[0,5],[4,6]], seats = 2) == 7\n assert candidate(roads = [], seats = 1) == 0\n\n\ncheck(Solution().minimumFuelCost)"}
229
104
coding
Solve the programming task below in a Python markdown code block. Chef is trying to solve a problem having T test cases, where, for each test case he is given a single integer N. Chef has an algorithm which takes exactly N^{2} iterations for a test case with value N. The constraints of the problem are as follows: 1 ...
{"inputs": ["4\n10 100 200\n3 10 100\n1000 1000 2200\n100 100 100\n"], "outputs": ["20000\n300\n2040000\n10000\n"]}
693
83
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Nearly everyone has used the Multiplication Table. The multiplication table of size m x n is an integer matrix mat where mat[i][j] == i * j (1-indexed). Given three integers m, n, and k, return the kth smallest elemen...
{"functional": "def check(candidate):\n assert candidate(m = 3, n = 3, k = 5) == 3\n assert candidate(m = 2, n = 3, k = 6) == 6\n\n\ncheck(Solution().findKthNumber)"}
118
65
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed 2D integer array tires where tires[i] = [fi, ri] indicates that the ith tire can finish its xth successive lap in fi * ri(x-1) seconds. For example, if fi = 3 and ri = 2, then the tire would...
{"functional": "def check(candidate):\n assert candidate(tires = [[2,3],[3,4]], changeTime = 5, numLaps = 4) == 21\n assert candidate(tires = [[1,10],[2,2],[3,4]], changeTime = 6, numLaps = 5) == 25\n\n\ncheck(Solution().minimumFinishTime)"}
248
91
coding
Solve the programming task below in a Python markdown code block. Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number t...
{"functional": "_inputs = [['XXI'], ['I'], ['IV'], ['MMVIII'], ['MDCLXVI']]\n_outputs = [[21], [1], [4], [2008], [1666]]\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 ...
285
190
coding
Solve the programming task below in a Python markdown code block. You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \...
{"inputs": ["1 1 1\n2\n", "1 1 1\n2\n", "1 1 1\n0\n", "2 1 2\n3 5\n", "2 1 2\n0 5\n", "2 2 2\n0 5\n", "1 10 1\n-10\n", "1 10 1\n-10\n"], "outputs": ["1\n", "1\n", "0\n", "4\n", "3\n", "3\n", "0\n", "0\n"]}
668
130
coding
Solve the programming task below in a Python markdown code block. Lеt's create function to play cards. Our rules: We have the preloaded `deck`: ``` deck = ['joker','2♣','3♣','4♣','5♣','6♣','7♣','8♣','9♣','10♣','J♣','Q♣','K♣','A♣', '2♦','3♦','4♦','5♦','6♦','7♦','8♦','9♦','10♦','J♦','Q♦','K♦','A♦', ...
{"functional": "_inputs = [['Q\u2663', '3\u2663', '\u2666'], ['3\u2663', 'Q\u2663', '\u2666'], ['5\u2665', 'A\u2663', '\u2666'], ['8\u2660', '8\u2660', '\u2663'], ['2\u2666', 'A\u2660', '\u2666'], ['A\u2660', '2\u2666', '\u2666'], ['joker', 'joker', '\u2666'], ['joker', '10\u2663', '\u2660'], ['10\u2663', 'joker', '\u2...
494
399
coding
Solve the programming task below in a Python markdown code block. Young Sheldon is given the task to teach Chemistry to his brother Georgie. After teaching him how to find total atomic weight, Sheldon gives him some formulas which consist of $x$, $y$ and $z$ atoms as an assignment. You already know that Georgie doesn'...
{"inputs": ["2\n(xy)2\nx(x2y)3(z)2"], "outputs": ["12\n46"]}
379
30
coding
Solve the programming task below in a Python markdown code block. If this challenge is too easy for you, check out: https://www.codewars.com/kata/5cc89c182777b00001b3e6a2 ___ Upside-Down Pyramid Addition is the process of taking a list of numbers and consecutively adding them together until you reach one number. Wh...
{"functional": "_inputs = [[[5, 2, 1]], [[84, 42, 21, 10, 2]], [[83, 47, 28, 16, 7]], [[101, 57, 29, 13, 6]], [[66, 39, 25, 15, 7]], [[45, 25, 14, 8, 6]], [[60, 32, 16, 7, 4]], [[84, 44, 21, 8, 2]], [[51, 26, 13, 6, 2]], [[78, 42, 22, 11, 6]]]\n_outputs = [[[2, 1, 1]], [[4, 7, 3, 8, 2]], [[6, 4, 3, 9, 7]], [[1, 3, 9, 7...
237
468
coding
Solve the programming task below in a Python markdown code block. We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is 0, and white if S_{i,j} is 1. We will cut the bar some nu...
{"inputs": ["3 5 8\n11100\n10101\n00111", "3 5 8\n11100\n00101\n00111", "3 5 4\n11100\n10001\n00110", "3 5 8\n11100\n10111\n00111", "3 0 8\n11100\n00101\n00111", "5 0 8\n11100\n00101\n00111", "8 0 8\n11100\n00101\n00111", "8 0 8\n11100\n00101\n01111"], "outputs": ["1\n", "0\n", "1\n", "1\n", "0\n", "0\n", "0\n", "0\n"]...
383
238
coding
Solve the programming task below in a Python markdown code block. The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then t...
{"inputs": ["5\n1\n2\n3\n4\n5"], "outputs": ["1\n1\n23\n1\n23\n456\n1\n23\n4 5\n6789\n1\n23\n4 5\n6 7\n89101112"]}
229
73
coding
Solve the programming task below in a Python markdown code block. On a weekend, Qingshan suggests that she and her friend Daniel go hiking. Unfortunately, they are busy high school students, so they can only go hiking on scratch paper. A permutation $p$ is written from left to right on the paper. First Qingshan choose...
{"inputs": ["2\n1 2\n", "2\n1 2\n", "2\n0 2\n", "2\n0 1\n", "2\n1 4\n", "2\n1 7\n", "2\n0 7\n", "2\n0 6\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
584
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings a and b that consist of lowercase letters. In one operation, you can change any character in a or b to any lowercase letter. Your goal is to satisfy one of the following three conditions: Ev...
{"functional": "def check(candidate):\n assert candidate(a = \"aba\", b = \"caa\") == 2\n assert candidate(a = \"dabadd\", b = \"cda\") == 3\n\n\ncheck(Solution().minCharacters)"}
150
56
coding
Solve the programming task below in a Python markdown code block. Chef is currently facing the north direction. Each second he rotates exactly 90 degrees in clockwise direction. Find the direction in which Chef is facing after exactly X seconds. \textbf{Note}: There are only 4 directions: North, East, South, West (in ...
{"inputs": ["3\n1\n3\n6\n"], "outputs": ["East\nWest\nSouth\n"]}
251
24
coding
Solve the programming task below in a Python markdown code block. Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all blac...
{"inputs": ["1 1\nW\n", "1 1\nW\n", "1 1\nB\n", "1 1\nB\n", "1 1\nW\n", "1 2\nBB\n", "1 2\nWW\n", "1 2\nWB\n"], "outputs": ["1\n", "1\n", "0\n", "0", "1", "-1\n", "1\n", "0\n"]}
436
100
coding
Solve the programming task below in a Python markdown code block. In Russia, there is an army-purposed station named UVB-76 or "Buzzer" (see also https://en.wikipedia.org/wiki/UVB-76). Most of time specific "buzz" noise is being broadcasted, but on very rare occasions, the buzzer signal is interrupted and a voice trans...
{"functional": "_inputs = [['Is this a right message?'], ['MDZHB 85 596 KLASA 81 00 02 91'], ['MDZHB 12 733 EDINENIE 67 79 66 32'], ['MDZHV 60 130 VATRUKH 58 89 54 54'], ['MDZHB 85 596 BRAMIRKA 81 00 02 91'], ['MDZHB 12 733 INITIAL 67 79 66 32'], ['MDZHB 60 130 KROLI5T 58 89 54 54'], ['MDZHB 85 596 KAMASIT 81 00 02 91'...
270
1,022
coding
Solve the programming task below in a Python markdown code block. Taro and Hanako decided to play hit-and-blow. The hit-and-blow rules are as follows. * Separated into questioners and respondents. * The questioner decides a 4-digit number (correct answer) that does not include duplicate numbers. * Respondents guess th...
{"inputs": ["1234 5678\n1234 1354\n1234 1200\n1230 1023\n0123 1234\n0 0", "1234 5678\n1234 1354\n1234 1234\n1957 1023\n0123 1234\n0 0", "2530 9673\n2102 1354\n1234 1234\n1230 1849\n0123 1863\n0 0", "1234 5678\n1234 2600\n1234 1234\n1230 1023\n0123 1234\n0 0", "1234 9188\n2242 1354\n1234 1234\n1230 1023\n0123 1797\n0 0"...
462
622
coding
Solve the programming task below in a Python markdown code block. wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's cons...
{"inputs": ["A\n", "F\n", "z\n", "a\n", "Z\n", "G\n", "H\n", "I\n"], "outputs": ["a\n", "f\n", "Z\n", "A\n", "z\n", "g\n", "h\n", "i\n"]}
246
70
coding
Solve the programming task below in a Python markdown code block. You've got a string $S$ consisting of $n$ lowercase English letters from your friend. It turned out that this is a number written in poman numerals. The poman numeral system is long forgotten. All that's left is the algorithm to transform number from pom...
{"inputs": ["2 -1\nba\n", "3 1\nabc\n", "3 3\nabc\n", "3 5\nabc\n", "3 7\nabc\n", "3 0\ncaa\n", "3 -7\nabc\n", "3 -3\nabc\n"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
598
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The XOR total of an array is defined as the bitwise XOR of all its elements, or 0 if the array is empty. For example, the XOR total of the array [2,5,6] is 2 XOR 5 XOR 6 = 1. Given an array nums, return the sum of a...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3]) == 6\n assert candidate(nums = [5,1,6]) == 28\n assert candidate(nums = [3,4,5,6,7,8]) == 480\n\n\ncheck(Solution().subsetXORSum)"}
166
76
coding
Solve the programming task below in a Python markdown code block. There are $n$ houses along the road where Anya lives, each one is painted in one of $k$ possible colors. Anya likes walking along this road, but she doesn't like when two adjacent houses at the road have the same color. She wants to select a long segmen...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "2 1\n1 1\n", "2 2\n1 2\n", "2 1\n1 1\n", "2 2\n1 2\n", "2 2\n1 1\n", "2 2\n2 2\n"], "outputs": ["1\n", "1", "1\n", "2\n", "1", "2", "1\n", "1\n"]}
317
111
coding
Solve the programming task below in a Python markdown code block. Jack and Jill are playing a game. They have balls numbered from `0` to `n - 1`. Jack looks the other way and asks Jill to reverse the position of the balls, for instance, to change the order from say, `0,1,2,3` to `3,2,1,0`. He further asks Jill to rever...
{"functional": "_inputs = [[4, 1], [4, 2], [4, 3], [20, 8], [20, 9], [20, 10]]\n_outputs = [[3], [2], [0], [17], [19], [18]]\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))...
323
209
coding
Solve the programming task below in a Python markdown code block. Count the number of labeled strongly connected digraphs with the given number of vertices. Input Format The first line contains $\mathbf{T}$, the number of queries. Following are $\mathbf{T}$ lines. Each line contains one integer $N$, denoting the...
{"inputs": ["5\n1\n2\n3\n4\n1000\n"], "outputs": ["1\n1\n18\n1606\n871606913\n"]}
199
47
coding
Solve the programming task below in a Python markdown code block. # The museum of incredible dull things The museum of incredible dull things wants to get rid of some exhibitions. Miriam, the interior architect, comes up with a plan to remove the most boring exhibitions. She gives them a rating, and then removes the o...
{"functional": "_inputs = [[[1, 2, 3, 4, 5]], [[1, 2, 3, 4]], [[5, 3, 2, 1, 4]], [[1, 2, 3, 1, 1]], [[]]]\n_outputs = [[[2, 3, 4, 5]], [[2, 3, 4]], [[5, 3, 2, 4]], [[2, 3, 1, 1]], [[]]]\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, r...
284
255
coding
Solve the programming task below in a Python markdown code block. Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has $n$ positions to install lamps, they correspond to the integer numbers fr...
{"inputs": ["2 1 1\n1\n1\n", "3 1 1\n2\n1\n", "3 1 1\n2\n1\n", "2 1 1\n1\n1\n", "3 1 1\n2\n0\n", "3 1 0\n2\n0\n", "2 1 2\n1\n1 2\n", "3 1 2\n2\n1 1\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "2\n", "2\n"]}
644
139
coding
Solve the programming task below in a Python markdown code block. There are H rows and W columns of white square cells. You will choose h of the rows and w of the columns, and paint all of the cells contained in those rows or columns. How many white cells will remain? It can be proved that this count does not depend on...
{"inputs": ["2 4\n2 3", "5 5\n2 2", "4 2\n2 1", "4 5\n2 2", "4 0\n2 1", "7 5\n2 2", "4 0\n0 1", "7 5\n1 2"], "outputs": ["0\n", "9\n", "2\n", "6\n", "-2\n", "15\n", "-4\n", "18\n"]}
212
112
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array intervals where intervals[i] = [li, ri] represent the interval [li, ri), remove all intervals that are covered by another interval in the list. The interval [a, b) is covered by the interval [c, d) if a...
{"functional": "def check(candidate):\n assert candidate(intervals = [[1,4],[3,6],[2,8]]) == 2\n\n\ncheck(Solution().removeCoveredIntervals)"}
123
45
coding
Solve the programming task below in a Python markdown code block. One day Greg and his friends were walking in the forest. Overall there were n people walking, including Greg. Soon he found himself in front of a river. The guys immediately decided to get across the river. Luckily, there was a boat by the river bank, ju...
{"inputs": ["1 50\n50\n", "1 204\n50\n", "1 2994\n100\n", "2 93\n50 50\n", "2 24\n50 50\n", "2 24\n96 50\n", "2 50\n50 50\n", "2 153\n100 50\n"], "outputs": ["1\n1", "1\n1", "1\n1", "-1\n0\n", "-1\n0\n", "-1\n0\n", "-1\n0", "1\n1"]}
624
150
coding
Solve the programming task below in a Python markdown code block. You have array a_1, a_2, ..., a_{n}. Segment [l, r] (1 ≤ l ≤ r ≤ n) is good if a_{i} = a_{i} - 1 + a_{i} - 2, for all i (l + 2 ≤ i ≤ r). Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l_1, r_1], is longer...
{"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n5\n", "1\n3\n", "1\n7\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
326
86
coding
Solve the programming task below in a Python markdown code block. Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as fo...
{"inputs": ["aaac\n3\n1\n2\n1\nvwxyz\n2\n3\n4\n-", "caaa\n3\n1\n2\n1\nvwxyz\n2\n3\n4\n-", "caaa\n3\n1\n2\n2\nvxxyz\n2\n3\n4\n-", "ca`a\n3\n1\n2\n2\nvwxyz\n2\n3\n4\n-", "caaa\n3\n1\n0\n2\nvwxyz\n2\n3\n4\n-", "aaac\n3\n1\n2\n1\nvwxyz\n2\n2\n4\n-", "ca`a\n3\n1\n2\n1\nvwxyz\n2\n3\n4\n-", "ca`a\n3\n1\n2\n2\nvwxyz\n2\n2\n4\n...
335
255
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 1-indexed m x n integer matrix mat, you can select any cell in the matrix as your starting cell. From the starting cell, you can move to any other cell in the same row or column, but only if the value of the d...
{"functional": "def check(candidate):\n assert candidate(mat = [[3,1],[3,4]]) == 2\n assert candidate(mat = [[1,1],[1,1]]) == 1\n assert candidate(mat = [[3,1,6],[-9,5,7]]) == 4\n\n\ncheck(Solution().maxIncreasingCells)"}
179
78
coding
Solve the programming task below in a Python markdown code block. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A bracket sequence is called a correct bracket sequence if it's...
{"inputs": ["3\n)\n(\n)\n", "3\n)\n(\n)\n", "3\n(\n(\n)\n", "2\n(())\n()\n", "2\n(((\n)))\n", "2\n(((\n)))\n", "2\n((()\n()\n", "2\n)(()\n()\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n", "0\n"]}
447
116
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. It's pretty straightforward. Your goal is to create a function that removes the first and last characters of a string. You're given one parameter, the original string. You don't have to worry with strings with less than two characters. Also feel free to...
{"functional": "_inputs = [['eloquent'], ['country'], ['person'], ['place'], ['ok'], ['ooopsss']]\n_outputs = [['loquen'], ['ountr'], ['erso'], ['lac'], [''], ['oopss']]\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_...
82
191
coding
Solve the programming task below in a Python markdown code block. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card wit...
{"inputs": ["3\n9 1\n5 4\n0 4\n3\n9 1\n5 4\n1 0\n3\n9 1\n5 5\n1 8\n0", "3\n9 1\n5 4\n0 8\n3\n9 1\n5 4\n1 0\n3\n9 1\n5 0\n1 8\n0", "3\n9 1\n5 4\n1 4\n3\n9 1\n5 4\n1 0\n3\n9 1\n5 5\n1 8\n0", "3\n9 1\n5 4\n0 8\n3\n9 1\n5 4\n1 0\n3\n9 1\n5 0\n1 1\n0", "3\n9 1\n5 4\n1 4\n3\n9 1\n6 4\n1 0\n3\n9 1\n5 5\n1 8\n0", "3\n9 1\n5 4\...
686
507
coding
Solve the programming task below in a Python markdown code block. You are given a valid XML document, and you have to print its score. The score is calculated by the sum of the score of each element. For any element, the score is equal to the number of attributes it has. Input Format The first line contains $N$, the...
{"inputs": ["6\n<feed xml:lang='en'>\n <title>HackerRank</title>\n <subtitle lang='en'>Programming challenges</subtitle>\n <link rel='alternate' type='text/html' href='http://hackerrank.com/'/>\n <updated>2013-12-25T12:00:00</updated>\n</feed>\n"], "outputs": ["5\n"]}
369
101
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef likes sequences of integers and in particular, he likes arithmetic progressions. There are two integers $N$ and $K$. Chef wants to choose a st...
{"inputs": ["2\n2 2\n3 1"], "outputs": ["1\n6"]}
499
22
coding
Solve the programming task below in a Python markdown code block. ##Task: You have to write a function `add` which takes two binary numbers as strings and returns their sum as a string. ##Note: * You are `not allowed to convert binary to decimal & vice versa`. * The sum should contain `No leading zeroes`. ##Examples:...
{"functional": "_inputs = [['111', '10'], ['1101', '101'], ['1101', '10111'], ['10111', '001010101'], ['00', '0']]\n_outputs = [['1001'], ['10010'], ['100100'], ['1101100'], ['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_to...
153
238
coding
Solve the programming task below in a Python markdown code block. B: 階層的計算機 (Hierarchical Calculator) Problem Ebi-chan has N formulae: y = a_i x for i =1, ..., N (inclusive). Now she considers a subsequence of indices with length k: s_1, s_2, ..., s_k. At first, let x_0 be 1 and evaluate s_1-th formulae with x = x_0....
{"inputs": ["4\n0 0 0 2", "4\n2 0 0 0", "4\n0 0 0 1", "4\n0 0 0 0", "4\n1 0 0 0", "4\n1 0 0 1", "4\n2 0 -1 1", "4\n2 -1 1 2"], "outputs": ["1\n4\n", "1\n1\n", "0\n", "0\n", "0\n", "0\n", "1\n1\n", "2\n1\n4\n"]}
620
136
coding
Solve the programming task below in a Python markdown code block. AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right....
{"inputs": ["1\n2\n9 8\n", "1\n2\n4 3\n", "1\n2\n6 5\n", "1\n2\n4 3\n", "1\n2\n9 8\n", "1\n2\n6 5\n", "1\n2\n10 8\n", "1\n2\n10 8\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
573
120
coding
Solve the programming task below in a Python markdown code block. During Quarantine Time Chef is at home and he was quite confused about what to cook so, he went to his son and asked about what would he prefer to have? He replied, cakes. Now, chef cook $N$ number of cake and number of layers for every cake is different...
{"inputs": ["1\n3\n2 3 5"], "outputs": ["2220"]}
420
23
coding
Solve the programming task below in a Python markdown code block. Complete the function that determines the score of a hand in the card game [Blackjack](https://en.wikipedia.org/wiki/Blackjack) (aka 21). The function receives an array of strings that represent each card in the hand (`"2"`, `"3",` ..., `"10"`, `"J"`, `...
{"functional": "_inputs = [[['2', '3']], [['4', '5', '6']], [['7', '7', '8']], [['9', '2', '10']], [['4', '7', '8']], [['J', '3']], [['J', 'Q']], [['K', 'J', 'Q']], [['A', '3']], [['A', 'J']], [['A', 'A', 'A', 'J']], [['A', '2', 'A', '9', '9']], [['A', 'A']], [['8', 'A', 'A']], [['5', '4', 'A', 'A']], [['A', '2', 'A', ...
329
374
coding
Solve the programming task below in a Python markdown code block. # Task Write a function `deNico`/`de_nico()` that accepts two parameters: - `key`/`$key` - string consists of unique letters and digits - `message`/`$message` - string with encoded message and decodes the `message` using the `key`. First create a n...
{"functional": "_inputs = [['crazy', 'cseerntiofarmit on '], ['crazy', 'cseerntiofarmit on'], ['abc', 'abcd'], ['ba', '2143658709'], ['a', 'message'], ['key', 'eky']]\n_outputs = [['secretinformation'], ['secretinformation'], ['abcd'], ['1234567890'], ['message'], ['key']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n...
359
242
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef is playing a game. Currently in the game, he is at a field full of stones. There are total N kinds of stones. There is unlimited supply of each kind of stone. Chef knows that one stone...
{"inputs": ["1\n3 0\n3 8 2\n4 4 0", "1\n3 6\n3 6 3\n3 4 1", "1\n3 5\n3 6 3\n3 4 1", "1\n3 5\n3 6 3\n2 4 1", "1\n3 6\n5 6 3\n3 5 1", "1\n1 0\n3 8 2\n4 4 0", "1\n1 0\n5 8 2\n4 4 0", "1\n3 0\n6 8 2\n4 4 0"], "outputs": ["0\n", "6\n", "3\n", "2\n", "5\n", "0\n", "0\n", "0\n"]}
500
190
coding
Solve the programming task below in a Python markdown code block. Alice is a very brilliant student. He considers '4' and '7' as Magic numbers. The numbers containing only magic numbers are also magical. Given a magic number N ,he wants to know what could be the next magical number greater than the given number. -----...
{"inputs": ["2\n4\n47\n\n"], "outputs": ["7\n74"]}
159
22
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 N red points and M blue points on a 2D plane. You are required to delete the minimum number of points(the deleted points can be of both colors) so that it's po...
{"inputs": ["1\n4 4\n0 0\n10 10\n0 10\n10 0\n12 11\n2 1\n12 1\n2 11"], "outputs": ["2"]}
464
56
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
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n soldiers standing in a line. Each soldier is assigned a unique rating value. You have to form a team of 3 soldiers amongst them under the following rules: Choose 3 soldiers with index (i, j, k) with ratin...
{"functional": "def check(candidate):\n assert candidate(rating = [2,5,3,4,1]) == 3\n assert candidate(rating = [2,1,3]) == 0\n assert candidate(rating = [1,2,3,4]) == 4\n\n\ncheck(Solution().numTeams)"}
173
76
coding
Solve the programming task below in a Python markdown code block. Chef and Chefina are best friends. Chefina wants to test the Problem Solving skills of chef so she provides Chef 2 integer number $X$ and $Y$ The task of chef is to take the two numbers $X$ and $Y$ and return their SUM. Identify whether Chef can solve ...
{"inputs": ["6 70"], "outputs": ["76"]}
181
16
coding
Solve the programming task below in a Python markdown code block. Implement a function which creates a **[radix tree](https://en.wikipedia.org/wiki/Radix_tree)** (a space-optimized trie [prefix tree]) in which each node that is the only child is merged with its parent [unless a word from the input ends there]) from ...
{"functional": "_inputs = [[''], ['abc', 'def', 'ghi', 'jklm', 'nop'], ['ape', 'apple'], ['ape', 'appendix', 'apel'], ['ape', 'apple', 'applet', 'appendix'], ['romane', 'romanus', 'romulus'], ['test', 'tester', 'testers'], ['test', 'tester', 'testers', 'tester'], ['testers', 'tester', 'test']]\n_outputs = [[{}], [{'abc...
353
387
coding
Solve the programming task below in a Python markdown code block. There is a field of size $2 \times 2$. Each cell of this field can either contain grass or be empty. The value $a_{i, j}$ is $1$ if the cell $(i, j)$ contains grass, or $0$ otherwise. In one move, you can choose one row and one column and cut all the gr...
{"inputs": ["2\n1 1\n1 1\n1 1\n1 1\n", "3\n0 0\n0 0\n1 0\n0 1\n1 1\n1 1\n", "4\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n", "16\n0 0\n1 1\n0 1\n1 0\n1 0\n0 1\n0 0\n0 0\n0 0\n0 1\n0 1\n1 1\n1 1\n0 0\n0 1\n0 1\n1 1\n0 1\n1 0\n0 0\n1 1\n1 0\n1 1\n1 1\n0 1\n0 0\n0 0\n1 0\n1 0\n1 1\n1 0\n1 0\n"], "outputs": ["2\n2\n", "0\n1\...
447
281
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin Chinese] and [Bengali]. Let's define Fibonacci concatenation sequence as follows: f[0] = 0, f[1] = 1 f[i] = f[i-1] + f[i-2], for every i ≥ 2 Here f[i] denotes the i^{th} Fibonacci concatenation number and + repres...
{"inputs": ["3\n1\n2\n3\n"], "outputs": ["1\n2\n8\n"]}
581
24
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef found a very useful open-source code for the current problem. Unfortunately, one fragment of code isn't optimized. Consider that problem: given an array D of size N and Q...
{"inputs": ["2\n2 3\n2 3\n5 100 8\n3 2\n2 2 2\n16 8"], "outputs": ["0 16 1\n2 1"]}
475
52
coding
Solve the programming task below in a Python markdown code block. _This kata is based on [Project Euler Problem 546](https://projecteuler.net/problem=546)_ # Objective Given the recursive sequence fk(n) = ∑ i = 0 n fk(floor(i / k)) where fk(0) = 1 Define a function `f` that takes arguments `k` and `n` and ...
{"functional": "_inputs = [[2, 3], [2, 200], [2, 1000], [7, 500], [100, 0], [3, 50000], [97, 100000], [100, 500000]]\n_outputs = [[6], [7389572], [264830889564], [74845], [1], [80887845303700596855], [209497156], [21469002551]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, fl...
284
303
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings s and t, your goal is to convert s into t in k moves or less. During the ith (1 <= i <= k) move you can: Choose any index j (1-indexed) from s, such that 1 <= j <= s.length and j has not been chosen...
{"functional": "def check(candidate):\n assert candidate(s = \"input\", t = \"ouput\", k = 9) == True\n assert candidate(s = \"abc\", t = \"bcd\", k = 10) == False\n assert candidate(s = \"aab\", t = \"bbb\", k = 27) == True\n\n\ncheck(Solution().canConvertString)"}
250
86
coding
Solve the programming task below in a Python markdown code block. The sum of divisors of `6` is `12` and the sum of divisors of `28` is `56`. You will notice that `12/6 = 2` and `56/28 = 2`. We shall say that `(6,28)` is a pair with a ratio of `2`. Similarly, `(30,140)` is also a pair but with a ratio of `2.4`. These ...
{"functional": "_inputs = [[1, 100], [1, 200], [1, 300], [200, 1000], [1, 1000], [100, 1000], [800, 2000]]\n_outputs = [[6], [36], [252], [1104], [2619], [2223], [2352]]\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_...
376
250
coding
Solve the programming task below in a Python markdown code block. Complete the function ```caffeineBuzz```, which takes a non-zero integer as it's one argument. If the integer is divisible by 3, return the string ```"Java"```. If the integer is divisible by 3 and divisible by 4, return the string ```"Coffee"``` If t...
{"functional": "_inputs = [[1], [3], [6], [12]]\n_outputs = [['mocha_missing!'], ['Java'], ['JavaScript'], ['CoffeeScript']]\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))...
187
179
coding
Solve the programming task below in a Python markdown code block. Gotham City is the home of Batman, and Batman likes to keep his people together. There are N houses in the city. The resident of the i^{th} house is of type A_{i}. It is known that people of the same type are friends and people of different types are n...
{"inputs": ["3\n4\naaaa\n4\nabca\n7\nbabbaab\n"], "outputs": ["4 4 4 4 4\n1 2 2 2 2\n2 3 4 4 4 4 4 4\n"]}
548
63
coding
Solve the programming task below in a Python markdown code block. You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after i...
{"inputs": ["1\n5 2547\n", "1\n54 828\n", "1\n68 2547\n", "1\n54 2042\n", "1\n45 2547\n", "1\n54 1790\n", "1\n280 602\n", "1\n45 1734\n"], "outputs": ["2823\n", "859\n", "2754\n", "2209\n", "2779\n", "1928\n", "358\n", "1876\n"]}
376
154
coding
Solve the programming task below in a Python markdown code block. You are appointed director of a famous concert hall, to save it from bankruptcy. The hall is very popular, and receives many requests to use its two fine rooms, but unfortunately the previous director was not very efficient, and it has been losing money ...
{"inputs": ["4\n1 2 10\n2 3 10\n3 3 2\n1 3 13\n6\n1 20 1000\n3 25 10000\n5 30 5000\n22 300 5500\n7 295 9000\n7 7 6000\n8\n32 251 2261\n123 281 1339\n188 235 5641\n174 217 7273\n22 255 7851\n60 198 9190\n119 274 878\n122 173 8640\n0", "4\n1 2 10\n2 3 10\n3 3 10\n1 3 10\n6\n1 20 1000\n3 25 00000\n5 15 5000\n22 165 5500\n...
643
1,740
coding
Solve the programming task below in a Python markdown code block. You are given an array $a$ consisting of $n$ integers. Let's call a pair of indices $i$, $j$ good if $1 \le i < j \le n$ and $\gcd(a_i, 2a_j) > 1$ (where $\gcd(x, y)$ is the greatest common divisor of $x$ and $y$). Find the maximum number of good index...
{"inputs": ["3\n4\n3 6 5 3\n2\n1 7\n5\n1 4 2 4 1\n", "1\n211\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
391
480
coding
Solve the programming task below in a Python markdown code block. On a random day, Neko found $n$ treasure chests and $m$ keys. The $i$-th chest has an integer $a_i$ written on it and the $j$-th key has an integer $b_j$ on it. Neko knows those chests contain the powerful mysterious green Grapes, thus Neko wants to open...
{"inputs": ["4 1\n1 1 1 2\n2\n", "4 1\n3 5 7 8\n2\n", "4 1\n2 2 3 3\n2\n", "4 1\n1 1 2 2\n2\n", "4 1\n3 5 7 8\n2\n", "4 1\n1 1 2 2\n2\n", "4 1\n1 1 1 2\n2\n", "4 1\n2 2 3 3\n2\n"], "outputs": ["1", "1", "1", "1", "1\n", "1\n", "1\n", "1\n"]}
517
162
coding
Solve the programming task below in a Python markdown code block. Takahashi has K 500-yen coins. (Yen is the currency of Japan.) If these coins add up to X yen or more, print Yes; otherwise, print No. -----Constraints----- - 1 \leq K \leq 100 - 1 \leq X \leq 10^5 -----Input----- Input is given from Standard Input i...
{"inputs": ["1 5", "2 5", "2 7", "4 2", "4 1", "5 1", "9 1", "9 0"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]}
174
78
coding
Solve the programming task below in a Python markdown code block. Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to get. At sc...
{"inputs": ["2\n5 2 3\n6 4 5\n", "2\n5 3 4\n9 4 4\n", "2\n5 2 3\n9 4 7\n", "2\n5 2 3\n1 4 7\n", "2\n5 2 4\n9 4 4\n", "2\n5 2 4\n1 4 7\n", "2\n5 4 4\n1 4 7\n", "2\n5 3 4\n9 4 5\n"], "outputs": ["Yes\nNo\n", "No\nNo\n", "Yes\nYes\n", "Yes\nNo\n", "Yes\nNo\n", "Yes\nNo\n", "No\nNo\n", "No\nYes\n"]}
694
182
coding
Solve the programming task below in a Python markdown code block. We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}. The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we ...
{"inputs": ["41 6 46\n1 89 2\n78 92 8\n5\n12\n45\n16\n57\n17", "41 6 46\n1 89 2\n78 92 8\n5\n12\n45\n16\n61\n17", "41 6 46\n1 89 2\n78 92 8\n5\n12\n15\n16\n61\n17", "41 3 46\n1 89 2\n78 92 8\n5\n12\n15\n16\n61\n17", "41 3 46\n1 89 2\n78 92 8\n5\n12\n15\n16\n94\n17", "41 3 46\n1 89 2\n78 92 8\n5\n11\n15\n16\n94\n17", "4...
459
366
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is working at his dream workplace with $N-1$ of his friends! Like any dream workplace, this one also has dream work conditions. To ensure absolute happiness of the emplo...
{"inputs": ["1\n2 12"], "outputs": ["4 4"]}
750
19
coding
Solve the programming task below in a Python markdown code block. Write a function `generatePairs` that accepts an integer argument `n` and generates an array containing the pairs of integers `[a, b]` that satisfy the following conditions: ``` 0 <= a <= b <= n ``` The pairs should be sorted by increasing values of `a`...
{"functional": "_inputs = [[2], [0]]\n_outputs = [[[[0, 0], [0, 1], [0, 2], [1, 1], [1, 2], [2, 2]]], [[[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 isinstance(a, (list, tuple)):\n ...
155
200
coding
Solve the programming task below in a Python markdown code block. Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds a_{i} candies in a box, that is given by ...
{"inputs": ["1 9\n10\n", "1 7\n10\n", "1 9\n10\n", "2 3\n1 2\n", "2 8\n7 8\n", "2 9\n4 8\n", "2 3\n3 3\n", "2 2\n1 2\n"], "outputs": ["-1", "1\n", "-1\n", "2", "2", "2", "1", "2"]}
473
110
coding
Solve the programming task below in a Python markdown code block. Given n words w[1..n], which originate from the same stem (e.g. grace, graceful, disgraceful, gracefully), we are interested in the original stem. To simplify the problem, we define the stem as the longest consecutive substring that occurs in all the n w...
{"inputs": ["1\n4\ngrace graceful disgraceful gracefully"], "outputs": ["grace"]}
240
22
coding
Solve the programming task below in a Python markdown code block. Now we will confect a reagent. There are eight materials to choose from, numbered 1,2,..., 8 respectively. We know the rules of confect: ``` material1 and material2 cannot be selected at the same time material3 and material4 cannot be selected at the sa...
{"functional": "_inputs = [[[1, 3, 7]], [[7, 1, 2, 3]], [[1, 3, 5, 7]], [[1, 5, 6, 7, 3]], [[5, 6, 7]], [[5, 6, 7, 8]], [[6, 7, 8]], [[7, 8]]]\n_outputs = [[True], [False], [False], [True], [True], [True], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):...
378
256
coding
Solve the programming task below in a Python markdown code block. In Conway's Game of Life, cells in a grid are used to simulate biological cells. Each cell is considered to be either alive or dead. At each step of the simulation each cell's current status and number of living neighbors is used to determine the status ...
{"inputs": ["4\n00011101\n000\n000001\n11110", "4\n00011101\n100\n000001\n11110", "4\n00010101\n100\n000101\n11110", "4\n00010101\n100\n010101\n11110", "4\n00010101\n000\n011111\n11110", "4\n00010101\n000\n011111\n11100", "4\n00000101\n000\n011111\n11100", "4\n00000101\n000\n010101\n11100"], "outputs": ["01100101\nMult...
505
421
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a 3 lane road of length n that consists of n + 1 points labeled from 0 to n. A frog starts at point 0 in the second lane and wants to jump to point n. However, there could be obstacles along the way. You are ...
{"functional": "def check(candidate):\n assert candidate(obstacles = [0,1,2,3,0]) == 2 \n assert candidate(obstacles = [0,1,1,3,3,0]) == 0\n assert candidate(obstacles = [0,2,1,0,3,0]) == 2\n\n\ncheck(Solution().minSideJumps)"}
340
89
coding
Solve the programming task below in a Python markdown code block. - Kids drink toddy. - Teens drink coke. - Young adults drink beer. - Adults drink whisky. Make a function that receive age, and return what they drink. **Rules:** - Children under 14 old. - Teens under 18 old. - Young under 21 old. - Adults have 21 or...
{"functional": "_inputs = [[13], [0], [17], [15], [14], [20], [18], [22], [21]]\n_outputs = [['drink toddy'], ['drink toddy'], ['drink coke'], ['drink coke'], ['drink coke'], ['drink beer'], ['drink beer'], ['drink whisky'], ['drink whisky']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or i...
189
225
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 0-indexed integer array nums, find the leftmost middleIndex (i.e., the smallest amongst all the possible ones). A middleIndex is an index where nums[0] + nums[1] + ... + nums[middleIndex-1] == nums[middleIndex...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,-1,8,4]) == 3\n assert candidate(nums = [1,-1,4]) == 2\n assert candidate(nums = [2,5]) == -1\n assert candidate(nums = [1]) == 0\n\n\ncheck(Solution().findMiddleIndex)"}
191
82
coding
Solve the programming task below in a Python markdown code block. Write a method that will search an array of strings for all strings that contain another string, ignoring capitalization. Then return an array of the found strings. The method takes two parameters, the query string and the array of strings to search, a...
{"functional": "_inputs = [['ab', ['za', 'ab', 'abc', 'zab', 'zbc']], ['aB', ['za', 'ab', 'abc', 'zab', 'zbc']], ['ab', ['za', 'aB', 'Abc', 'zAB', 'zbc']], ['abcd', ['za', 'aB', 'Abc', 'zAB', 'zbc']]]\n_outputs = [[['ab', 'abc', 'zab']], [['ab', 'abc', 'zab']], [['aB', 'Abc', 'zAB']], [['None']]]\nimport math\ndef _dee...
181
271
coding
Solve the programming task below in a Python markdown code block. A basketball competition is held where the number of players in a team does not have a maximum or minimum limit (not necessarily $5$ players in one team for each match). There are $N$ candidate players in the competition that will be trained by Pak Chane...
{"inputs": ["1 2\n1\n", "1 2\n2\n", "1 2\n3\n", "2 4\n1 2\n", "2 3\n1 2\n", "3 8\n3 2 1\n", "4 3\n2 2 5 2\n", "4 13\n3 2 1 3\n"], "outputs": ["0\n", "0\n", "1\n", "0\n", "1\n", "1\n", "2\n", "0\n"]}
533
123
coding
Solve the programming task below in a Python markdown code block. One not particularly beautiful evening Valera got very bored. To amuse himself a little bit, he found the following game. He took a checkered white square piece of paper, consisting of n × n cells. After that, he started to paint the white cells black o...
{"inputs": ["1 1\n1 1\n", "2 1\n1 1\n", "3 1\n1 3\n", "2 1\n1 2\n", "1000 1\n542 374\n", "1000 1\n542 737\n", "1000 1\n542 1000\n", "2 4\n2 1\n1 2\n1 1\n2 2\n"], "outputs": ["-1", "-1", "-1", "-1\n", "-1", "-1\n", "-1\n", "-1"]}
541
148
coding
Solve the programming task below in a Python markdown code block. Write a function name `nextPerfectSquare` that returns the first perfect square that is greater than its integer argument. A `perfect square` is a integer that is equal to some integer squared. For example 16 is a perfect square because `16=4*4`. ``` ex...
{"functional": "_inputs = [[6], [36], [0], [-5]]\n_outputs = [[9], [49], [1], [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 isinstance(a, (list, tuple)):\n if len(a) != len(b): return Fal...
177
176
coding
Solve the programming task below in a Python markdown code block. Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are n piles of cows, with the i-th pile containing ...
{"inputs": ["1 2\n3\n", "1 1\n1\n", "1 2\n1\n", "1 2\n1\n", "1 1\n1\n", "1 0\n1\n", "1 2\n2\n", "1 0\n2\n"], "outputs": ["Nicky\n", "Kevin\n", "Kevin\n", "Kevin\n", "Kevin\n", "Kevin\n", "Kevin\n", "Kevin\n"]}
414
103
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array tasks where tasks[i] = [actuali, minimumi]: actuali is the actual amount of energy you spend to finish the ith task. minimumi is the minimum amount of energy you require to begin the ith task. ...
{"functional": "def check(candidate):\n assert candidate(tasks = [[1,2],[2,4],[4,8]]) == 8\n assert candidate(tasks = [[1,3],[2,4],[10,11],[10,12],[8,9]]) == 32\n assert candidate(tasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]) == 27\n\n\ncheck(Solution().minimumEffort)"}
185
115
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Sereja has a string A consisting of n lower case English letters. Sereja calls two strings X and Y each of length n similar if they can be made equal by applying the follow...
{"inputs": ["2\nz\nabcd", "2\nz\nabcd"], "outputs": ["0\n144", "0\n144"]}
519
34
coding
Solve the programming task below in a Python markdown code block. Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of lengt...
{"inputs": ["2\n1 1", "2\n1 2", "2\n4 2", "2\n3 2", "2\n3 4", "2\n1 4", "2\n2 4", "2\n2 8"], "outputs": ["1\n1\n", "1\n2\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
305
98
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0. A self-dividing number is not allowed...
{"functional": "def check(candidate):\n assert candidate(left = 1, right = 22) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]\n assert candidate(left = 47, right = 85) == [48,55,66,77]\n\n\ncheck(Solution().selfDividingNumbers)"}
162
110
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. We can represent a sentence as an array of words, for example, the sentence "I am happy with leetcode" can be represented as arr = ["I","am",happy","with","leetcode"]. Given two sentences sentence1 and sentence2 each ...
{"functional": "def check(candidate):\n assert candidate(sentence1 = [\"great\",\"acting\",\"skills\"], sentence2 = [\"fine\",\"drama\",\"talent\"], similarPairs = [[\"great\",\"fine\"],[\"drama\",\"acting\"],[\"skills\",\"talent\"]]) == True\n assert candidate(sentence1 = [\"great\"], sentence2 = [\"great\"], si...
253
139
coding
Solve the programming task below in a Python markdown code block. Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0 ≤ 2k ≤ n) who showed the best result in t...
{"inputs": ["1\n1 2\n", "1\n2 1\n", "1\n1 2\n", "1\n2 1\n", "1\n1 4\n", "1\n2 0\n", "1\n0 1\n", "1\n2 4\n"], "outputs": ["1\n0\n", "0\n1\n", "1\n0\n", "0\n1\n", "1\n0\n", "0\n1\n", "1\n0\n", "1\n0\n"]}
761
118
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums. A subarray s of length m is called alternating if: m is greater than 1. s1 = s0 + 1. The 0-indexed subarray s looks like [s0, s1, s0, s1,...,s(m-1) % 2]. In other words, ...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,4,3,4]) == 4\n assert candidate(nums = [4,5,6]) == 2\n\n\ncheck(Solution().alternatingSubarray)"}
222
57