task_type
stringclasses
4 values
problem
stringlengths
14
5.23k
solution
stringlengths
1
8.29k
problem_tokens
int64
9
1.02k
solution_tokens
int64
1
1.98k
coding
Solve the programming task below in a Python markdown code block. In this Kata we focus on finding a sum S(n) which is the total number of divisors taken for all natural numbers less or equal to n. More formally, we investigate the sum of n components denoted by d(1) + d(2) + ... + d(n) in which for any i starting from...
{"functional": "_inputs = [[5], [10], [20], [59], [105], [785], [1001], [8009], [9999999999999], [9999999999998], [9999999999995], [9999999949950]]\n_outputs = [[10], [27], [66], [249], [510], [5364], [7077], [73241], [300880375389561], [300880375389537], [300880375389493], [300880373832097]]\nimport math\ndef _deep_eq...
466
355
coding
Solve the programming task below in a Python markdown code block. Emma is really fond of integers and loves playing with them. Her friends were jealous, and to test her, one of them gave her a problem. Emma is given a list ${A}$ of $N$ integers and is asked a set of ${Q}$ queries. Each query is denoted by an integer ...
{"inputs": ["3\n1 2 2\n1\n2\n", "3\n1 2 3\n2\n1\n2\n"], "outputs": ["8\n", "6\n11\n"]}
566
47
coding
Solve the programming task below in a Python markdown code block. For an integer N, we will choose a permutation \{P_1, P_2, ..., P_N\} of \{1, 2, ..., N\}. Then, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i. Find the maximum possible value of M_1 + M_2 + \cdots + M_N. -----Constraints----- ...
{"inputs": ["3", "4", "6", "0", "8", "9", "7", "2"], "outputs": ["3\n", "6\n", "15\n", "0\n", "28\n", "36\n", "21\n", "1"]}
217
65
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order.   Please complete the following python code precis...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,2,1], nums2 = [2,2]) == [2]\n assert candidate(nums1 = [4,9,5], nums2 = [9,4,9,8,4]) == [9,4]\n\n\ncheck(Solution().intersection)"}
90
80
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return the sum of floor(nums[i] / nums[j]) for all pairs of indices 0 <= i, j < nums.length in the array. Since the answer may be too large, return it modulo 109 + 7. The floor() function ...
{"functional": "def check(candidate):\n assert candidate(nums = [2,5,9]) == 10\n assert candidate(nums = [7,7,7,7,7,7,7]) == 49\n\n\ncheck(Solution().sumOfFlooredPairs)"}
118
64
coding
Solve the programming task below in a Python markdown code block. You are given an integer $n$. A set, $\mbox{S}$, of triples $(x_i,y_i,z_i)$ is beautiful if and only if: $0\leq x_i,y_i,z_i$ $x_i+y_i+z_i=n,\forall i:1\leq i\leq|S|$ Let $\mbox{X}$ be the set of different $x_i$'s in $\mbox{S}$, $\mathbf{Y}$ be the set o...
{"inputs": ["3\n"], "outputs": ["3\n0 1 2\n2 0 1\n1 2 0\n"]}
600
32
coding
Solve the programming task below in a Python markdown code block. Batman is about to face Superman so he decides to prepare for the battle by upgrading his Batmobile. He manufactures multiple duplicates of his standard Batmobile each tweaked in a different way such that the maximum speed of each is never less than that...
{"inputs": ["2\n4\n1 2 3 4 5\n5\n1 10 100 1000 10000 100000"], "outputs": ["4\n5"]}
310
55
coding
Solve the programming task below in a Python markdown code block. A number `n` is called `prime happy` if there is at least one prime less than `n` and the `sum of all primes less than n` is evenly divisible by `n`. Write `isPrimeHappy(n)` which returns `true` if `n` is `prime happy` else `false`. Also feel free to reu...
{"functional": "_inputs = [[5], [8], [25], [32], [2], [0]]\n_outputs = [[True], [False], [True], [True], [False], [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)):\...
102
188
coding
Solve the programming task below in a Python markdown code block. In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you ca...
{"inputs": ["9", "7", "4", "53", "17", "28", "13", "25"], "outputs": [" 3 6 9\n", " 3 6\n", " 3\n", " 3 6 9 12 13 15 18 21 23 24 27 30 31 32 33 34 35 36 37 38 39 42 43 45 48 51 53\n", " 3 6 9 12 13 15\n", " 3 6 9 12 13 15 18 21 23 24 27\n", " 3 6 9 12 13\n", " 3 6 9 12 13 15 18 21 23 24\n"]}
318
233
coding
Solve the programming task below in a Python markdown code block. Complete the function that counts the number of unique consonants in a string (made up of printable ascii characters). Consonants are letters used in English other than `"a", "e", "i", "o", "u"`. We will count `"y"` as a consonant. Remember, your funct...
{"functional": "_inputs = [['sillystring'], ['aeiou'], ['abcdefghijklmnopqrstuvwxyz'], ['Count my unique consonants!!']]\n_outputs = [[7], [0], [21], [7]]\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 i...
246
183
coding
Solve the programming task below in a Python markdown code block. A ticket is a string consisting of six digits. A ticket is considered lucky if the sum of the first three digits is equal to the sum of the last three digits. Given a ticket, output if it is lucky or not. Note that a ticket can have leading zeroes. ---...
{"inputs": ["1\n114514\n", "1\n975310\n", "1\n666999\n", "1\n975319\n", "2\n193758\n123456\n", "2\n192758\n123456\n", "5\n213132\n973894\n045207\n000000\n055776\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\nNO\n", "NO\nNO\n", "YES\nNO\nYES\nYES\nNO\n"]}
428
165
coding
Solve the programming task below in a Python markdown code block. In Byteland there are N cities, numbered 1 through N. Some pairs of cities are connected by bi-directional roads in such a way that starting from any one city you can visit all other cities either directly or indirectly. Chef is currently at city A and ...
{"inputs": ["2\n3\n1 2\n1 3\n1\n5\n1 2\n1 3\n2 4\n2 5\n1"], "outputs": ["2\n4"]}
578
46
coding
Solve the programming task below in a Python markdown code block. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to k. On the i-th day the festival will show a movie of genre a_{i}. W...
{"inputs": ["2 2\n1 2\n", "2 2\n1 2\n", "7 3\n3 1 3 2 3 1 2\n", "7 3\n3 1 2 2 3 1 2\n", "7 3\n3 1 2 3 3 1 2\n", "7 3\n3 1 3 2 3 1 2\n", "10 3\n1 1 2 3 2 3 3 1 1 3\n", "10 2\n1 2 2 1 1 2 1 1 2 2\n"], "outputs": ["1", "1\n", "1", "1\n", "1\n", "1\n", "3", "1"]}
676
188
coding
Solve the programming task below in a Python markdown code block. Li and Lu have $n$ integers, $a_1,a_2,\ldots,a_n$, that they want to divide fairly between the two of them. They decide that if Li gets integers with indices $I=\{i_1,i_2,\ldots,i_k\}$ (which implies that Lu gets integers with indices $J=\{1,\ldots,n\}\s...
{"inputs": ["4 2\n4 3 1 2\n", "4 1\n3 3 3 1\n"], "outputs": [" 6\n", "2\n"]}
529
43
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Compute: floor[1*e] + floor[2*e] + floor[3*e] + ... + floor[n*e], where floor[x] is the largest integer that is not greater than x, and e is Euler's number: 2.7182818284... ...
{"inputs": ["3"], "outputs": ["15"]}
296
13
coding
Solve the programming task below in a Python markdown code block. Create a function that takes a string as a parameter and does the following, in this order: 1. replaces every letter with the letter following it in the alphabet (see note below) 2. makes any vowels capital 3. makes any consonants lower case **Note:** ...
{"functional": "_inputs = [['Cat30'], ['Alice'], ['sponge1'], ['Hello World'], ['dogs'], ['z']]\n_outputs = [['dbU30'], ['bmjdf'], ['tqpOhf1'], ['Ifmmp xpsmE'], ['Epht'], ['A']]\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=t...
137
205
coding
Solve the programming task below in a Python markdown code block. A new task for you! You have to create a method, that corrects a given time string. There was a problem in addition, so many of the time strings are broken. Time-Format is european. So from "00:00:00" to "23:59:59". Some examples: "09:10:01" -> "09:1...
{"functional": "_inputs = [[None], [''], ['001122'], ['00;11;22'], ['0a:1c:22'], ['09:10:01'], ['11:70:10'], ['19:99:99'], ['24:01:01'], ['52:01:01'], ['14:59:94']]\n_outputs = [[None], [''], [None], [None], [None], ['09:10:01'], ['12:10:10'], ['20:40:39'], ['00:01:01'], ['04:01:01'], ['15:00:34']]\nimport math\ndef _d...
260
315
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 two integers key and k. A k-distant index is an index i of nums for which there exists at least one index j such that |i - j| <= k and nums[j] == key. Return a list of ...
{"functional": "def check(candidate):\n assert candidate(nums = [3,4,9,1,3,9,5], key = 9, k = 1) == [1,2,3,4,5,6]\n assert candidate(nums = [2,2,2,2,2], key = 2, k = 2) == [0,1,2,3,4]\n\n\ncheck(Solution().findKDistantIndices)"}
127
105
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. Ksusha is a beginner coder. Today she starts studying arrays. She has array a_1, a_2, ..., a_{n}, consisting of n positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help...
{"inputs": ["2\n4 6\n", "2\n6 8\n", "2\n6 4\n", "2\n6 4\n", "2\n4 6\n", "2\n6 8\n", "2\n6 3\n", "2\n6 6\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "3\n", "6\n"]}
245
103
coding
Solve the programming task below in a Python markdown code block. In the previous Kata we discussed the OR case. We will now discuss the AND case, where rather than calculating the probablility for either of two (or more) possible results, we will calculate the probability of receiving all of the viewed outcomes. For...
{"functional": "_inputs = [[[['red', 'blue', 'yellow', 'green', 'red', 'blue', 'yellow', 'green', 'red', 'blue'], ['red', 'blue'], True]], [[['red', 'blue', 'yellow', 'green', 'red', 'blue', 'yellow', 'green', 'red', 'blue'], ['red', 'red'], True]], [[['red', 'red', 'yellow', 'green', 'red', 'red', 'yellow', 'green', '...
650
370
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integers a and b, return the sum of the two integers without using the operators + and -.   Please complete the following python code precisely: ```python class Solution: def getSum(self, a: int, b: int)...
{"functional": "def check(candidate):\n assert candidate(a = 1, b = 2) == 3\n assert candidate(a = 2, b = 3) == 5\n\n\ncheck(Solution().getSum)"}
73
53
coding
Solve the programming task below in a Python markdown code block. # Challenge : Write a function that takes a single argument `n` that is a string representation of a simple mathematical expression and evaluates it as a floating point value. # Commands : - positive or negative decimal numbers - `+, -, *, /, ( / )....
{"functional": "_inputs = [['2*3*4*5+99']]\n_outputs = [[219]]\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\n return a...
415
164
coding
Solve the programming task below in a Python markdown code block. The snail crawls up the column. During the day it crawls up some distance. During the night she sleeps, so she slides down for some distance (less than crawls up during the day). Your function takes three arguments: 1. The height of the column (meters) ...
{"functional": "_inputs = [[3, 2, 1], [10, 3, 1], [10, 3, 2], [100, 20, 5], [5, 10, 3]]\n_outputs = [[2], [5], [8], [7], [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, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)...
147
214
coding
Solve the programming task below in a Python markdown code block. A palindrome is a series of characters that read the same forwards as backwards such as "hannah", "racecar" and "lol". For this Kata you need to write a function that takes a string of characters and returns the length, as an integer value, of longest a...
{"functional": "_inputs = [['A'], ['Hannah'], ['xyz__a_/b0110//a_zyx'], ['$aaabbbccddd_!jJpqlQx_.///yYabababhii_'], ['']]\n_outputs = [[1], [6], [13], [25], [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)...
160
216
coding
Solve the programming task below in a Python markdown code block. Alice and Bob are playing a game. They have an array of positive integers $a$ of size $n$. Before starting the game, Alice chooses an integer $k \ge 0$. The game lasts for $k$ stages, the stages are numbered from $1$ to $k$. During the $i$-th stage, Ali...
{"inputs": ["7\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "4\n3\n1 1 2\n4\n4 4 4 4\n1\n1\n5\n1 3 2 1 1\n", "13\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "13\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n"], "outputs": ...
423
298
coding
Solve the programming task below in a Python markdown code block. Let S(n) denote the sum of the digits in the decimal notation of n. For example, S(123) = 1 + 2 + 3 = 6. We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds. Given an intege...
{"inputs": ["7", "5", "8", "2", "6", "4", "1", "3"], "outputs": ["1\n2\n3\n4\n5\n6\n7\n", "1\n2\n3\n4\n5\n", "1\n2\n3\n4\n5\n6\n7\n8\n", "1\n2\n", "1\n2\n3\n4\n5\n6\n", "1\n2\n3\n4\n", "1\n", "1\n2\n3\n"]}
211
118
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed integer arrays nums1 and nums2 of length n. A range [l, r] (inclusive) where 0 <= l <= r < n is balanced if: For every i in the range [l, r], you pick either nums1[i] or nums2[i]. The sum ...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,5], nums2 = [2,6,3]) == 3\n assert candidate(nums1 = [0,1], nums2 = [1,0]) == 4\n\n\ncheck(Solution().countSubranges)"}
267
70
coding
Solve the programming task below in a Python markdown code block. You will be given a string (x) featuring a cat 'C', a dog 'D' and a mouse 'm'. The rest of the string will be made up of '.'. You need to find out if the cat can catch the mouse from it's current position. The cat can jump (j) characters. Also, the c...
{"functional": "_inputs = [['..D.....C.m', 2], ['............C.............D..m...', 8], ['m.C...', 5], ['.CD......m.', 10], ['.CD......m.', 1]]\n_outputs = [['Caught!'], ['Escaped!'], ['boring without all three'], ['Protected!'], ['Escaped!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or...
255
220
coding
Solve the programming task below in a Python markdown code block. Chefina is always interested to play with string. But due to exam pressure she has no time to solve a string problem. She wants your help. Can you help her to solve that problem? You are given a string. You have to find out the $Wonder$ $Sum$ of the st...
{"inputs": ["2\ncab\nsdef"], "outputs": ["903\n7630"]}
503
25
coding
Solve the programming task below in a Python markdown code block. You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}]. Is it possible to partition A into two non-empty [subsequences] S_{1} and S_{2} such that sum(S_{1}) \times sum(S_{2}) is odd? Here, sum(S_{1}) denotes the sum of elements in S_{1}, and sum(S_{2...
{"inputs": ["4\n4\n1 1 2 2\n6\n1 2 4 6 8 10\n2\n3 5\n3\n1 3 5"], "outputs": ["YES\nNO\nYES\nNO"]}
635
57
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 2D array of characters grid of size m x n, you need to find if there exists any cycle consisting of the same value in grid. A cycle is a path of length 4 or more in the grid that starts and ends at the same ce...
{"functional": "def check(candidate):\n assert candidate(grid = [[\"a\",\"a\",\"a\",\"a\"],[\"a\",\"b\",\"b\",\"a\"],[\"a\",\"b\",\"b\",\"a\"],[\"a\",\"a\",\"a\",\"a\"]]) == True\n assert candidate(grid = [[\"c\",\"c\",\"c\",\"a\"],[\"c\",\"d\",\"c\",\"c\"],[\"c\",\"c\",\"e\",\"c\"],[\"f\",\"c\",\"c\",\"c\"]]) ==...
232
150
coding
Solve the programming task below in a Python markdown code block. Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems. There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer takes a spec...
{"inputs": ["1\n1\n1\n1\n", "1\n2\n1\n1\n", "1\n4\n1\n1\n", "1\n3\n1\n0\n", "1\n4\n1\n2\n", "1\n3\n1\n1\n", "1\n1\n3\n3 1 1\n", "1\n1\n7\n1 1 1 1 1 1 0\n"], "outputs": ["1", "1", "1\n", "0\n", "2\n", "1\n", "3", "2\n"]}
544
131
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 n × n array A of non-negative integers. He wants to divide this array by p-1 horizontal dividers and p-1 vertical dividers into p^{2} blocks such that maximum sum of...
{"inputs": ["4 3\n1 1 2 2\n2 1 2 2\n3 1 4 2\n4 4 2 2"], "outputs": ["2 3\n1 3"]}
719
52
coding
Solve the programming task below in a Python markdown code block. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following for integers greater than or equal to 0. (Processing flow) * ...
{"inputs": ["3\n2\n2\n4", "3\n0\n42\n4", "3\n0\n37\n4", "3\n16\n2\n7", "3\n29\n2\n7", "3\n9\n99\n39", "3\n3\n127\n5", "3\n1\n169\n6"], "outputs": ["0\n0\n0\n", "0\n1\n0\n", "0\n2\n0\n", "1\n0\n0\n", "2\n0\n0\n", "0\n2\n3\n", "0\n3\n0\n", "0\n4\n0\n"]}
618
152
coding
Solve the programming task below in a Python markdown code block. There is a field divided into $n$ rows and $m$ columns. Some cells are empty (denoted as E), other cells contain robots (denoted as R). You can send a command to all robots at the same time. The command can be of one of the four types: move up; move r...
{"inputs": ["6\n1 3\nERR\n2 2\nER\nRE\n2 2\nER\nER\n1 1\nR\n4 3\nEEE\nEEE\nERR\nEER\n3 3\nEEE\nEER\nREE\n"], "outputs": ["YES\nNO\nYES\nYES\nYES\nNO\n"]}
559
76
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the customer visit log of a shop represented by a 0-indexed string customers consisting only of characters 'N' and 'Y': if the ith character is 'Y', it means that customers come at the ith hour whereas ...
{"functional": "def check(candidate):\n assert candidate(customers = \"YYNY\") == 2\n assert candidate(customers = \"NNNNN\") == 0\n assert candidate(customers = \"YYYY\") == 4\n\n\ncheck(Solution().bestClosingTime)"}
213
62
coding
Solve the programming task below in a Python markdown code block. Sometimes Mister B has free evenings when he doesn't know what to do. Fortunately, Mister B found a new game, where the player can play against aliens. All characters in this game are lowercase English letters. There are two players: Mister B and his co...
{"inputs": ["1 1 1 1\n", "4 1 1 9\n", "4 5 1 1\n", "3 3 3 8\n", "4 1 1 4\n", "1 2 1 1\n", "5 3 3 8\n", "1 1 1 2\n"], "outputs": ["1", "7", "1", "3", "4\n", "1\n", "3\n", "1\n"]}
539
114
coding
Solve the programming task below in a Python markdown code block. $N$ sages are sitting around a round table with $N$ seats. Each sage holds chopsticks with his dominant hand to eat his dinner. The following happens in this situation. * If sage $i$ is right-handed and a left-handed sage sits on his right, a level of f...
{"inputs": ["3\n0 0 0\n1 1 3", "3\n0 1 0\n1 1 2", "3\n0 0 1\n1 2 5", "3\n0 0 1\n1 0 7", "3\n0 0 1\n2 1 7", "3\n0 0 1\n1 1 8", "3\n0 0 0\n1 1 2", "3\n0 0 0\n1 2 5"], "outputs": ["0\n", "2\n", "6\n", "7\n", "8\n", "9\n", "0\n", "0\n"]}
400
158
coding
Solve the programming task below in a Python markdown code block. Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive). -----Constraints----- - 1 \leq N \leq 10^4 - 1 \leq A \leq B \leq 36 - All input values are integers. -----Input----- In...
{"inputs": ["4 1 6", "2 0 8", "2 2 2", "3 0 4", "6 2 3", "6 2 5", "4 4 6", "5 1 0"], "outputs": ["10\n", "3\n", "2\n", "6\n", "5\n", "14\n", "4\n", "0\n"]}
223
96
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Aditi recently discovered a new magic trick. First, she gives you an integer N and asks you to think an integer between 1 and N. Then she gives you a bundle of cards each having a sorted list (...
{"inputs": ["2\n1\n4", "2\n1\n3", "2\n2\n4", "2\n2\n8", "2\n4\n4", "2\n2\n7", "2\n4\n8", "2\n8\n8"], "outputs": ["1\n3", "1\n3\n", "2\n3\n", "2\n5\n", "3\n3\n", "2\n4\n", "3\n5\n", "5\n5\n"]}
676
109
coding
Solve the programming task below in a Python markdown code block. $n$ people gathered to hold a jury meeting of the upcoming competition, the $i$-th member of the jury came up with $a_i$ tasks, which they want to share with each other. First, the jury decides on the order which they will follow while describing the ta...
{"inputs": ["1\n3\n11 11 154\n", "1\n3\n11 11 154\n", "1\n3\n13 11 154\n", "1\n3\n11 20 154\n", "1\n3\n13 11 297\n", "1\n3\n19 11 297\n", "1\n3\n38 11 297\n", "4\n2\n1 2\n3\n5 5 5\n4\n1 3 3 7\n6\n3 4 2 1 3 3\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n6\n0\n540\n"]}
709
200
coding
Solve the programming task below in a Python markdown code block. Given are N pairwise distinct non-negative integers A_1,A_2,\ldots,A_N. Find the number of ways to choose a set of between 1 and K numbers (inclusive) from the given numbers so that the following two conditions are satisfied: * The bitwise AND of the ch...
{"inputs": ["3 3 0 3\n0 2 3", "3 3 0 6\n0 2 3", "3 4 0 3\n1 2 3", "3 6 0 3\n0 2 3", "0 3 0 6\n0 2 3", "3 3 0 3\n1 2 3", "3 3 -1 6\n0 2 3", "3 3 -1 7\n0 2 3"], "outputs": ["2", "0", "2", "2", "0", "2", "0", "0"]}
283
150
coding
Solve the programming task below in a Python markdown code block. Chef solved so many hard questions, now he wants to solve some easy problems for refreshment. Chef asks Cheffina for the new question. Cheffina challenges the chef to print the total number of 0's in the binary representation of N(natural number). -----...
{"inputs": ["2\n2\n4"], "outputs": ["1\n2"]}
235
18
coding
Solve the programming task below in a Python markdown code block. These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute. He was asked ...
{"inputs": ["1 1\n0 0\n", "1 5\n1 0\n", "1 2\n3 0\n", "1 5\n0 6\n", "1 2\n2 3\n", "1 2\n2 3\n", "1 1\n0 0\n", "1 2\n3 0\n"], "outputs": ["0 2\n", "0 0\n", "0 0\n", "0 0\n", "0 0\n", "0 0\n", "0 2\n", "0 0\n"]}
597
134
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s consisting of only the characters 'a' and 'b', return true if every 'a' appears before every 'b' in the string. Otherwise, return false.   Please complete the following python code precisely: ```pytho...
{"functional": "def check(candidate):\n assert candidate(s = \"aaabbb\") == True\n assert candidate(s = \"abab\") == False\n assert candidate(s = \"bbb\") == True\n\n\ncheck(Solution().checkString)"}
85
55
coding
Solve the programming task below in a Python markdown code block. Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units. Constraints * 3 \leq N \leq 100 Input Input is given from Standard Input in the following...
{"inputs": ["5", "9", "7", "2", "4", "8", "6", "3"], "outputs": ["540\n", "1260\n", "900\n", "0\n", "360\n", "1080\n", "720\n", "180"]}
127
77
coding
Solve the programming task below in a Python markdown code block. In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n exte...
{"inputs": ["5 5 1 2 3\n2 2 3\n", "3 4 1 1 3\n2 3 2\n", "5 5 1 2 3\n2 2 2\n", "5 5 1 2 3\n2 2 3\n", "3 4 1 1 3\n2 3 2\n", "1 1 1 1 1\n100000\n", "1 1 1 1 1\n100000\n", "3 3 2 4 4\n2 5 4 10\n"], "outputs": ["-1\n", "3\n", "-1\n", "-1", "3", "0\n", "0", "1\n"]}
502
185
coding
Solve the programming task below in a Python markdown code block. JJ loves playing with medians. He has an array A of length N (N is odd). He wants to partition the array A into two non-empty subsets P and Q such that the value of |median(P) - median(Q)| is as small as possible. (Note that each A_{i} must belong to eit...
{"inputs": ["3\n5\n2 7 4 8 2\n3\n1 2 3\n5\n1 1 1 1 1\n"], "outputs": ["2\n1\n0"]}
591
49
coding
Solve the programming task below in a Python markdown code block. Limak is a little polar bear. He has n balls, the i-th ball has size t_{i}. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: No two friends can get balls of ...
{"inputs": ["3\n3 1 2\n", "3\n1 1 2\n", "3\n2 3 2\n", "3\n1 2 1\n", "3\n1 2 3\n", "3\n1 1 1\n", "3\n2 2 3\n", "3\n1 2 2\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
537
118
coding
Solve the programming task below in a Python markdown code block. Chef has an 8 \times 8 chessboard. He placed a knight on the square (X_{1}, Y_{1}). Note that, the square at the intersection of the i^{th} row and j^{th} column is denoted by (i, j). Chef wants to determine whether the knight can end up at the square ...
{"inputs": ["3\n1 1 1 1\n8 8 7 6\n8 8 8 6\n"], "outputs": ["YES\nNO\nYES"]}
580
41
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n people standing in a queue, and they numbered from 0 to n - 1 in left to right order. You are given an array heights of distinct integers where heights[i] represents the height of the ith person. A person ...
{"functional": "def check(candidate):\n assert candidate(heights = [10,6,8,5,11,9]) == [3,1,2,1,1,0]\n assert candidate(heights = [5,1,2,3,10]) == [4,1,1,1,0]\n\n\ncheck(Solution().canSeePersonsCount)"}
193
88
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given four integers length, width, height, and mass, representing the dimensions and mass of a box, respectively, return a string representing the category of the box. The box is "Bulky" if: Any of the dimensions ...
{"functional": "def check(candidate):\n assert candidate(length = 1000, width = 35, height = 700, mass = 300) == \"Heavy\"\n assert candidate(length = 200, width = 50, height = 800, mass = 50) == \"Neither\"\n\n\ncheck(Solution().categorizeBox)"}
263
91
coding
Solve the programming task below in a Python markdown code block. There are three cities and thus three EVMs. An insider told Chef that his party got A, B, C votes respectively in these three cities according to the EVMs. Also, the total number of votes cast are P, Q, R respectively for the three cities. Chef, being ...
{"inputs": ["3\n1 1 1 3 3 3\n49 1 49 50 100 50\n0 0 0 1 1 1\n"], "outputs": ["YES\nYES\nNO\n"]}
610
60
coding
Solve the programming task below in a Python markdown code block. There are $n$ cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from $1$ to $n$. Two fairs are currently taking place in B...
{"inputs": ["3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n4 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 4 1\...
696
774
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.   Please complete the following python code precisely: ```python class Solution: def generateParenthesis(self...
{"functional": "def check(candidate):\n assert candidate(n = 3) == [\"((()))\",\"(()())\",\"(())()\",\"()(())\",\"()()()\"]\n assert candidate(n = 1) == [\"()\"]\n\n\ncheck(Solution().generateParenthesis)"}
67
65
coding
Solve the programming task below in a Python markdown code block. A programming competition site AtCode provides algorithmic problems. Each problem is allocated a score based on its difficulty. Currently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points. These p_1 + … +...
{"inputs": ["1 100\n1 100\n", "2 431\n3 500\n5 800", "2 110\n3 500\n5 800", "2 431\n3 896\n5 800", "2 400\n3 500\n5 800", "2 700\n3 500\n5 800", "2 700\n3 500\n5 800\n", "2 400\n3 500\n5 800\n"], "outputs": ["1\n", "3\n", "1\n", "3\n", "2", "3", "3\n", "2\n"]}
575
185
coding
Solve the programming task below in a Python markdown code block. There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and...
{"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "6\n1 2 3 4 5 6\n", "6\n6 5 4 3 2 1\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n"]}
326
114
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and an integer k. Find the longest subsequence of nums that meets the following requirements: The subsequence is strictly increasing and The difference between adjacent elements in...
{"functional": "def check(candidate):\n assert candidate(nums = [4,2,1,4,3,4,5,8,15], k = 3) == 5\n assert candidate(nums = [7,4,5,1,8,12,4,7], k = 5) == 4\n assert candidate(nums = [1,5], k = 1) == 1\n\n\ncheck(Solution().lengthOfLIS)"}
142
106
coding
Solve the programming task below in a Python markdown code block. How to make a cake you'll never eat. Ingredients. * 2 carrots * 0 calories * 100 g chocolate spread * 1 pack of flour * 1 egg Method. 1. Put calories into the mixing bowl. 2. Take carrots from refrigerator. 3. Chop carrots. 4. T...
{"inputs": ["4 1 1 3 4\n", "4 2 1 3 4\n", "4 1 2 3 4\n", "3 452 979 51\n", "3 287 979 395\n", "3 887 104 641\n", "3 452 979 395\n", "4 802 765 992 1\n"], "outputs": ["28\n", "29\n", "30", "2563\n", "3430", "3018", "3595\n", "5312"]}
293
169
coding
Solve the programming task below in a Python markdown code block. Your task is to determine how many files of the copy queue you will be able to save into your Hard Disk Drive. The files must be saved in the order they appear in the queue. ### Input: * Array of file sizes `(0 <= s <= 100)` * Capacity of the HD `(0 <...
{"functional": "_inputs = [[[4, 4, 4, 3, 3], 12], [[4, 4, 4, 3, 3], 11], [[4, 8, 15, 16, 23, 42], 108], [[13], 13], [[1, 2, 3, 4], 250], [[100], 500], [[11, 13, 15, 17, 19], 8], [[45], 12]]\n_outputs = [[3], [2], [6], [1], [4], [1], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or i...
234
302
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n persons numbered from 0 to n - 1 and a door. Each person can enter or exit through the door once, taking one second. You are given a non-decreasing integer array arrival of size n, where arrival[i] is the ...
{"functional": "def check(candidate):\n assert candidate(arrival = [0,1,1,2,4], state = [0,1,0,0,1]) == [0,3,1,2,4]\n assert candidate(arrival = [0,0,0], state = [1,0,1]) == [0,2,1]\n\n\ncheck(Solution().timeTaken)"}
315
93
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums of length n, you want to create an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed). Specifically, ans is the concatenation of two nums ar...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,1]) == [1,2,1,1,2,1]\n assert candidate(nums = [1,3,2,1]) == [1,3,2,1,1,3,2,1]\n\n\ncheck(Solution().getConcatenation)"}
120
81
coding
Solve the programming task below in a Python markdown code block. Determine if an N-sided polygon (not necessarily convex) with sides of length L_1, L_2, ..., L_N can be drawn in a two-dimensional plane. You can use the following theorem: Theorem: an N-sided polygon satisfying the condition can be drawn if and only if ...
{"inputs": ["4\n3 5 5 1", "4\n3 3 4 1", "4\n3 5 6 1", "4\n4 3 4 1", "4\n3 5 0 1", "4\n4 1 4 1", "4\n3 5 0 0", "4\n2 1 4 1"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n"]}
235
126
coding
Solve the programming task below in a Python markdown code block. Two players A and B have a list of $n$ integers each. They both want to maximize the subtraction between their score and their opponent's score. In one turn, a player can either add to his score any element from his list (assuming his list is not empty...
{"inputs": ["2\n1 4\n5 1\n", "2\n2 1\n5 6\n", "2\n2 1\n5 2\n", "2\n1 4\n5 1\n", "2\n2 1\n5 6\n", "3\n100 100 100\n100 100 100\n", "3\n100 100 100\n100 100 101\n", "3\n100 100 100\n100 100 100\n"], "outputs": ["0", "-3", "0\n", "0\n", "-3\n", "0", "0\n", "0\n"]}
678
179
coding
Solve the programming task below in a Python markdown code block. Kate has a set $S$ of $n$ integers $\{1, \dots, n\} $. She thinks that imperfection of a subset $M \subseteq S$ is equal to the maximum of $gcd(a, b)$ over all pairs $(a, b)$ such that both $a$ and $b$ are in $M$ and $a \neq b$. Kate is a very neat g...
{"inputs": ["2\n", "3\n", "4\n", "5\n", "6\n", "6\n", "4\n", "5\n"], "outputs": ["1 ", "1 1 ", "1 1 2 ", "1 1 1 2 ", "1 1 1 2 3 ", "1 1 1 2 3", "1 1 2", "1 1 1 2"]}
405
100
coding
Solve the programming task below in a Python markdown code block. $\textit{ABC}$ is a right triangle, $90^{\circ}$ at $\mbox{B}$. Therefore, $\angle ABC=90°$. Point $\mbox{M}$ is the midpoint of hypotenuse $\mbox{AC}$. You are given the lengths $\boldsymbol{AB}$ and $\mbox{BC}$. Your task is to find $\measuredangl...
{"inputs": ["10\n10\n"], "outputs": ["45\u00b0\n"]}
334
24
coding
Solve the programming task below in a Python markdown code block. You are given an array A of size N. You are also given an integer Q. Can you figure out the answer to each of the Q queries? Each query contains 2 integers x and y, and you need to find whether the value find(x,y) is Odd or Even: find(int x,int y) { ...
{"inputs": ["3\n3 2 7\n2\n1 2\n2 3\n"], "outputs": ["Odd\nEven\n"]}
331
32
coding
Solve the programming task below in a Python markdown code block. In this kata you will have to change every letter in a given string to the next letter in the alphabet. You will write a function `nextLetter` to do this. The function will take a single parameter `s` (string). Examples: ``` "Hello" --> "Ifmmp" "What ...
{"functional": "_inputs = [['Hello'], ['What is your name?'], ['zOo']]\n_outputs = [['Ifmmp'], ['Xibu jt zpvs obnf?'], ['aPp']]\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, tupl...
157
184
coding
Solve the programming task below in a Python markdown code block. There's a new security company in Paris, and they decided to give their employees an algorithm to make first name recognition faster. In the blink of an eye, they can now detect if a string is a first name, no matter if it is a one-word name or an hyphen...
{"functional": "_inputs = [['Francis'], ['Jean-Eluard'], ['Le Mec'], ['Bernard-Henry-Levy'], ['Meme Gertrude'], ['A-a-a-a----a-a'], ['Z-------------'], ['Jean-luc'], ['Jean--Luc'], ['JeanLucPicard'], ['-Jean-Luc'], ['Jean-Luc-Picard-']]\n_outputs = [[True], [True], [False], [True], [False], [False], [False], [False], [...
321
258
coding
Solve the programming task below in a Python markdown code block. Chef recently learned about concept of periodicity of strings. A string is said to have a period P, if P divides N and for each i, the i-th of character of the string is same as i-Pth character (provided it exists), e.g. "abab" has a period P = 2, It als...
{"inputs": ["5\n3 1\n2 2\n3 3\n4 4\n6 3"], "outputs": ["impossible\nimpossible\naba\nabba\nabaaba"]}
504
44
coding
Solve the programming task below in a Python markdown code block. Initially, there is a magical stone of mass 2^{N} lying at the origin of the number line. For the next N seconds, the following event happens: Let us define the *decomposition* of a magical stone as follows: If there is a magical stone of mass M > 1 ly...
{"inputs": ["3\n2 -2 2\n2 0 2\n150000 48 48\n"], "outputs": ["1 0 2 0 1\n2 0 1\n122830846\n"]}
659
63
coding
Solve the programming task below in a Python markdown code block. Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that $\frac{p}{s} = k$, where p is the product of a...
{"inputs": ["1 1\n1\n", "1 1\n2\n", "1 1\n1\n", "4 2\n6 3 8 1\n", "4 2\n6 3 8 1\n", "4 2\n6 3 12 1\n", "5 21\n4 9 5 3 2\n", "5 15\n10 9 5 2 2\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "0\n", "0\n"]}
431
140
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, return the number of segments in the string. A segment is defined to be a contiguous sequence of non-space characters.   Please complete the following python code precisely: ```python class Solution:...
{"functional": "def check(candidate):\n assert candidate(s = \"Hello, my name is John\") == 5\n assert candidate(s = \"Hello\") == 1\n\n\ncheck(Solution().countSegments)"}
75
48
coding
Solve the programming task below in a Python markdown code block. [3R2 as DJ Mashiro - Happiness Breeze](https://open.spotify.com/track/2qGqK8GRS65Wlf20qUBEak) [Ice - DJ Mashiro is dead or alive](https://soundcloud.com/iceloki/dj-mashiro-is-dead-or-alive) NEKO#ΦωΦ has just got a new maze game on her PC! The game's m...
{"inputs": ["4 1\n1 4\n", "5 1\n1 4\n", "2 2\n2 1\n1 2\n", "2 4\n2 1\n1 2\n1 2\n1 2\n", "4 4\n2 1\n1 2\n1 2\n1 2\n", "4 4\n2 1\n1 2\n1 2\n2 2\n", "5 5\n2 3\n2 4\n2 4\n2 3\n1 4\n", "5 5\n2 3\n1 4\n2 4\n2 3\n1 4\n"], "outputs": ["Yes\n", "Yes\n", "Yes\nNo\n", "Yes\nNo\nYes\nNo\n", "Yes\nNo\nYes\nNo\n", "Yes\nNo\nYes\nYes...
714
226
coding
Solve the programming task below in a Python markdown code block. Compute A \times B, truncate its fractional part, and print the result as an integer. -----Constraints----- - 0 \leq A \leq 10^{15} - 0 \leq B < 10 - A is an integer. - B is a number with two digits after the decimal point. -----Input----- Input is...
{"inputs": ["2 0.01", "4 1.10", "2 1.10", "3 1.10", "1 0.01", "1 0.01\n", "0 9.98\n", "74 1.10"], "outputs": ["0\n", "4\n", "2\n", "3\n", "0", "0\n", "0\n", "81\n"]}
169
105
coding
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is $r$ units. Some very rich customers a...
{"inputs": ["2 4\n2 -3\n4 -3\n", "2 4\n2 -3\n4 -3\n", "2 4\n1 -3\n4 -3\n", "3 1\n3 -4\n3 4\n3 4\n", "3 1\n3 -4\n3 4\n3 4\n", "3 1\n2 -4\n3 4\n3 4\n", "3 4\n4 6\n10 -2\n8 -1\n", "3 4\n2 6\n10 -2\n8 -1\n"], "outputs": ["1\n", "1", "1\n", "0\n", "0", "0\n", "3\n", "3\n"]}
525
170
coding
Solve the programming task below in a Python markdown code block. The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N pa...
{"inputs": ["2\n1 5\n2 4\n3 6\n", "3\n1 1 1\n2 2 2\n3 3 3\n", "6\n3 14 159 2 6 53\n58 9 79 323 84 6\n2643 383 2 79 50 288\n"], "outputs": ["3\n", "27\n", "87\n"]}
470
116
coding
Solve the programming task below in a Python markdown code block. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10^{k}. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10^{k}. For example, if k = 3, in the number 30...
{"inputs": ["0 1\n", "0 9\n", "0 9\n", "0 1\n", "10 1\n", "10 2\n", "10 9\n", "10 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "0\n"]}
422
90
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string sentence that consist of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to "Goat Latin" (a made-up language similar ...
{"functional": "def check(candidate):\n assert candidate(sentence = \"I speak Goat Latin\") == \"Imaa peaksmaaa oatGmaaaa atinLmaaaaa\"\n assert candidate(sentence = \"The quick brown fox jumped over the lazy dog\") == \"heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ...
274
109
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a directed graph of n nodes with each node labeled from 0 to n - 1. The graph is represented by a 0-indexed 2D integer array graph where graph[i] is an integer array of nodes adjacent to node i, meaning there...
{"functional": "def check(candidate):\n assert candidate(graph = [[1,2],[2,3],[5],[0],[5],[],[]]) == [2,4,5,6]\n assert candidate(graph = [[1,2,3,4],[1,2],[3,4],[0,4],[]]) == [4]\n\n\ncheck(Solution().eventualSafeNodes)"}
177
88
coding
Solve the programming task below in a Python markdown code block. Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying a + b = ?, and that the base of the positional notation wasn’t written a...
{"inputs": ["9 7\n", "3 1\n", "1 2\n", "1 3\n", "2 3\n", "3 2\n", "2 2\n", "2 1\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
402
86
coding
Solve the programming task below in a Python markdown code block. You must have tried to solve the Rubik’s cube. You might even have succeeded at it. Rubik’s cube is a 3x3x3 cube which has 6 different color for each face.The Rubik’s cube is made from 26 smaller pieces which are called cubies. There are 6 cubies at the ...
{"inputs": ["1\n3\n3\n3"], "outputs": ["12"]}
403
19
coding
Solve the programming task below in a Python markdown code block. Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and...
{"inputs": ["1 1\n1\n", "1 6\n1\n", "1 5\n1\n", "1 3\n4\n", "1 6\n1\n", "1 3\n4\n", "1 1\n1\n", "1 5\n1\n"], "outputs": ["0\n", "1\n", "0\n", "-1\n", "1\n", "-1\n", "0\n", "0\n"]}
584
102
coding
Solve the programming task below in a Python markdown code block. Pupils decided to go to amusement park. Some of them were with parents. In total, n people came to the park and they all want to get to the most extreme attraction and roll on it exactly once. Tickets for group of x people are sold on the attraction, th...
{"inputs": ["1 2 2\n1\n", "1 2 2\n1\n", "1 4 2\n1\n", "1 6 2\n1\n", "1 2 4\n1\n", "1 4 0\n1\n", "1 6 1\n1\n", "1 2 5\n1\n"], "outputs": ["2\n", "2\n", "4\n", "6\n", "2\n", "4\n", "6\n", "2\n"]}
539
118
coding
Solve the programming task below in a Python markdown code block. The Little Elephant loves chess very much. One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 × 8 checkered board, each square is painted either black or white. Th...
{"inputs": ["WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n", "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW\n", "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\n", "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBW...
591
402
coding
Solve the programming task below in a Python markdown code block. Find the difference of two sets $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$, $A - B$. Constraints * $1 \leq n, m \leq 200,000$ * $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$ * $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$ ...
{"inputs": ["5\n1 2 3 5 8\n2\n4 5", "5\n1 2 3 5 8\n0\n4 5", "5\n0 2 3 5 8\n0\n0 5", "5\n0 2 3 5 8\n2\n4 5", "5\n0 2 3 5 7\n2\n4 9", "5\n0 2 3 5 6\n3\n4 9", "5\n1 2 4 5 8\n0\n0 2", "5\n1 2 4 6 8\n0\n2 5"], "outputs": ["1\n2\n3\n8\n", "1\n2\n3\n5\n8\n", "0\n2\n3\n5\n8\n", "0\n2\n3\n8\n", "0\n2\n3\n5\n7\n", "0\n2\n3\n5\n6...
280
250
coding
Solve the programming task below in a Python markdown code block. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elepha...
{"inputs": ["1\n1 2\n", "1\n1 1\n", "1\n1 4\n", "1\n2 1\n", "2\n1 1\n1 1\n", "2\n1 2\n2 3\n", "2\n1 2\n2 1\n", "2\n1 1\n0 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
421
118
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Trans bought a calculator at creatnx's store. Unfortunately, it is fake. It has many bugs. One of them is adding two numbers without carrying. Example expression: 12 + 9 will...
{"inputs": ["2\n12 9\n25 25"], "outputs": ["11\n40"]}
241
27
coding
Solve the programming task below in a Python markdown code block. There are $n$ students numerated from $1$ to $n$. The level of the $i$-th student is $a_i$. You need to split the students into stable groups. A group of students is called stable, if in the sorted array of their levels no two neighboring elements differ...
{"inputs": ["1 2 9\n5\n", "1 2 9\n5\n", "2 3 1\n1 6\n", "2 5 1\n1 8\n", "2 3 1\n1 6\n", "2 5 1\n1 8\n", "2 1 1\n1 6\n", "2 9 1\n1 8\n"], "outputs": ["1", "1\n", "2", "2", "2\n", "2\n", "2", "1\n"]}
680
126
coding
Solve the programming task below in a Python markdown code block. Hello everyone. I have a simple challenge for you today. In mathematics, the formula for finding the sum to infinity of a geometric sequence is: **ONLY IF** `-1 < r < 1` where: * `a` is the first term of the sequence * `r` is the common ratio of t...
{"functional": "_inputs = [[[1, 0.5, 0.25, 0.125]], [[250, 100, 40, 16]], [[21, 4.2, 0.84, 0.168]], [[5, -2.5, 1.25, -0.625]]]\n_outputs = [[2], [416.667], [26.25], [3.333]]\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, ...
210
258
coding
Solve the programming task below in a Python markdown code block. Given are three integers A_1, A_2, and A_3. If A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win. -----Constraints----- - 1 \leq A_i \leq 13 \ \ (i=1,2,3) - All values in input are integers. -----Input----- Input is given f...
{"inputs": ["5 7 4", "5 1 4", "5 1 0", "0 9 4", "5 1 1", "0 1 4", "6 1 1", "0 2 4"], "outputs": ["win\n", "win\n", "win\n", "win\n", "win\n", "win\n", "win\n", "win\n"]}
178
94
coding
Solve the programming task below in a Python markdown code block. You will have a list of rationals in the form ``` lst = [ [numer_1, denom_1] , ... , [numer_n, denom_n] ] ``` or ``` lst = [ (numer_1, denom_1) , ... , (numer_n, denom_n) ] ``` where all numbers are positive integers. You have to produce their sum `N /...
{"functional": "_inputs = [[[[1, 2], [1, 3], [1, 4]]], [[[1, 3], [5, 3]]], [[[12, 3], [15, 3]]], [[[2, 7], [1, 3], [1, 12]]], [[[69, 130], [87, 1310], [3, 4]]], [[[77, 130], [84, 131], [60, 80]]], [[[6, 13], [187, 1310], [31, 41]]], [[[8, 15], [7, 111], [4, 25]]], [[]], [[[81345, 15786], [87546, 11111111], [43216, 2556...
587
528
coding
Solve the programming task below in a Python markdown code block. Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: * it is up to a passenger to choose a plane to fly on; * if the chosen plane has x (x > 0) empty ...
{"inputs": ["1 1\n6\n", "2 1\n7\n", "7 1\n7\n", "4 1\n7\n", "2 1\n12\n", "7 1\n15\n", "4 1\n12\n", "1 1\n20\n"], "outputs": ["6 6\n", "13 13\n", "28 28\n", "22 22\n", "23 23\n", "84 84\n", "42 42\n", "20 20\n"]}
562
136
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. During the Indian Programming Camp (IPC), there are N trainers. The camp runs for D days. Each day, there can be at most one lecture. The i-th trainer arrives on day D_{i} an...
{"inputs": ["3\n2 3\n1 2 300\n2 2 100\n2 3\n1 1 100\n2 2 300\n2 3\n3 2 150\n1 1 200"], "outputs": ["100\n0\n150"]}
731
80
coding
Solve the programming task below in a Python markdown code block. Sagheer is playing a game with his best friend Soliman. He brought a tree with n nodes numbered from 1 to n and rooted at node 1. The i-th node has a_{i} apples. This tree has a special property: the lengths of all paths from the root to any leaf have th...
{"inputs": ["3\n2 2 3\n1 1\n", "3\n1 2 3\n1 1\n", "3\n1 1 3\n1 1\n", "3\n2 2 3\n1 2\n", "3\n2 0 3\n1 2\n", "3\n2 0 1\n1 2\n", "3\n1 2 3\n1 1\n", "3\n2 2 3\n1 1\n"], "outputs": ["1\n", "0\n", "1\n", "1\n", "0\n", "0\n", "0\n", "1\n"]}
739
150
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and two integers indexDiff and valueDiff. Find a pair of indices (i, j) such that: i != j, abs(i - j) <= indexDiff. abs(nums[i] - nums[j]) <= valueDiff, and Return true if such pa...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,1], indexDiff = 3, valueDiff = 0) == True\n assert candidate(nums = [1,5,9,1,5,9], indexDiff = 2, valueDiff = 3) == False\n\n\ncheck(Solution().containsNearbyAlmostDuplicate)"}
127
84
coding
Solve the programming task below in a Python markdown code block. Finally, after purchasing a water cooler during the April long challenge, Chef noticed that his water cooler requires 2 liters of water to cool for one hour. How much water (in liters) would be required by the cooler to cool for N hours? ------ Input F...
{"inputs": ["2\n1\n2"], "outputs": ["2\n4\n"]}
260
19
coding
Solve the programming task below in a Python markdown code block. Arun has an integer N. His friend likes the number 1, so Arun wants to reduce N to 1. To do so, he can perform the following move several times (possibly, zero): Pick two integers X and Y such that X+Y is even and X^{Y} is a divisor of N. Then, replace ...
{"inputs": ["2\n25\n24\n"], "outputs": ["1\n-1"]}
453
22
coding
Solve the programming task below in a Python markdown code block. You are given a string $s$ of even length $n$. String $s$ is binary, in other words, consists only of 0's and 1's. String $s$ has exactly $\frac{n}{2}$ zeroes and $\frac{n}{2}$ ones ($n$ is even). In one operation you can reverse any substring of $s$. ...
{"inputs": ["3\n2\n10\n4\n0110\n8\n11101000\n", "3\n2\n10\n4\n0110\n8\n11100001\n", "3\n2\n10\n4\n1010\n8\n11101000\n", "3\n2\n10\n4\n0011\n8\n11101000\n", "3\n2\n10\n4\n0101\n8\n11100001\n", "3\n2\n10\n4\n0101\n8\n11101000\n", "3\n2\n10\n4\n0011\n8\n11100001\n", "3\n2\n10\n4\n1001\n8\n11101000\n"], "outputs": ["0\n1\n...
507
286