task_type
stringclasses
1 value
problem
stringlengths
261
3.34k
answer
stringlengths
35
6.15k
problem_tokens
int64
62
774
answer_tokens
int64
12
2.04k
coding
Solve the programming task below in a Python markdown code block. Alice and Bob play a game. The game consists of several sets, and each set consists of several rounds. Each round is won either by Alice or by Bob, and the set ends when one of the players has won $x$ rounds in a row. For example, if Bob won five rounds ...
{"inputs": ["1\n0\n", "1\n1\n", "1\n?\n", "1\n0\n", "1\n1\n", "1\n?\n", "5\n01?01\n", "5\n10?10\n"], "outputs": ["1 \n", "1 \n", "1 \n", "1\n", "1\n", "1\n", "5 1 0 0 0 \n", "5 1 0 0 0\n"]}
597
114
coding
Solve the programming task below in a Python markdown code block. Some number of people (this number is even) have stood in a circle. The people stand in the circle evenly. They are numbered clockwise starting from a person with the number $1$. Each person is looking through the circle's center at the opposite person. ...
{"inputs": ["1\n1 2 3\n", "1\n2 3 4\n", "1\n1 2 3\n", "1\n2 3 4\n", "1\n1 3 4\n", "1\n1 7 4\n", "1\n9 10 1\n", "1\n9 10 1\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "2\n", "10\n", "-1\n", "-1\n"]}
605
122
coding
Solve the programming task below in a Python markdown code block. Alice has an array of N integers — A_{1}, A_{2}, \ldots, A_{N}. She wants the product of all the elements of the array to be a non-negative integer. That is, it can be either 0 or positive. But she doesn't want it to be negative. To do this, she is will...
{"inputs": ["4\n3\n1 9 8\n4\n2 -1 9 100\n4\n2 -1 0 100\n4\n2 -1 -1 100\n"], "outputs": ["0\n1\n0\n0\n"]}
579
64
coding
Solve the programming task below in a Python markdown code block. ## Task: You have to create a function `isPronic` to check whether the argument passed is a Pronic Number and return true if it is & false otherwise. ### Description: `Pronic Number` -A pronic number, oblong number, rectangular number or heteromecic nu...
{"functional": "_inputs = [[2], [3], [4], [5], [6], [-3], [-27]]\n_outputs = [[True], [False], [False], [False], [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, ...
314
192
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. An axis-aligned rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) is the coordinate of its bottom-left corner, and (x2, y2) is the coordinate of its top-right corner. Its top and bottom edges are par...
{"functional": "def check(candidate):\n assert candidate(rec1 = [0,0,2,2], rec2 = [1,1,3,3]) == True\n assert candidate(rec1 = [0,0,1,1], rec2 = [1,0,2,1]) == False\n assert candidate(rec1 = [0,0,1,1], rec2 = [2,2,3,3]) == False\n\n\ncheck(Solution().isRectangleOverlap)"}
188
110
coding
Solve the programming task below in a Python markdown code block. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests recei...
{"inputs": ["1\n1 1\n1\n1\n", "1\n2 1\n1\n1\n", "1\n2 1\n1\n1\n", "1\n1 1\n1\n1\n", "1\n0 1\n1\n1\n", "1\n0 1\n1\n2\n", "1\n0 1\n1\n3\n", "1\n0 1\n1\n5\n"], "outputs": ["1 1\n1 1\n", "0 0\n", "0 0\n", "1 1\n1 1\n", "1 1\n1 1\n", "1 1\n1 1\n", "1 1\n1 1\n", "1 1\n1 1\n"]}
592
174
coding
Solve the programming task below in a Python markdown code block. One of the first algorithm used for approximating the integer square root of a positive integer `n` is known as "Hero's method", named after the first-century Greek mathematician Hero of Alexandria who gave the first description of the method. Hero's me...
{"functional": "_inputs = [[25, 1], [125348, 300], [125348981764, 356243], [236, 12], [48981764, 8000], [6999, 700], [16000, 400], [16000, 100], [2500, 60], [250000, 600], [95367431640625, 1], [9094947017729282379150390625, 1], [835871232077058, 1], [246391990316004, 1], [403832254158749, 1], [217414278071071, 1], [639...
501
604
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation. Evaluate the expression. Return an integer that represents the value of the expression. Note that: The v...
{"functional": "def check(candidate):\n assert candidate(tokens = [\"2\",\"1\",\"+\",\"3\",\"*\"]) == 9\n assert candidate(tokens = [\"4\",\"13\",\"5\",\"/\",\"+\"]) == 6\n assert candidate(tokens = [\"10\",\"6\",\"9\",\"3\",\"+\",\"-11\",\"*\",\"/\",\"*\",\"17\",\"+\",\"5\",\"+\"]) == 22\n\n\ncheck(Solution()...
159
105
coding
Solve the programming task below in a Python markdown code block. # Covfefe Your are given a string. You must replace the word(s) `coverage` by `covfefe`, however, if you don't find the word `coverage` in the string, you must add `covfefe` at the end of the string with a leading space. For the languages where the st...
{"functional": "_inputs = [['coverage'], ['coverage coverage'], ['nothing'], ['double space '], ['covfefe']]\n_outputs = [['covfefe'], ['covfefe covfefe'], ['nothing covfefe'], ['double space covfefe'], ['covfefe covfefe']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float...
126
205
coding
Solve the programming task below in a Python markdown code block. Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all ...
{"inputs": ["2\nTH\n", "2\nHT\n", "3\nHHT\n", "3\nTHH\n", "3\nHTH\n", "4\nHTHT\n", "4\nHTTH\n", "4\nTTHH\n"], "outputs": ["0", "0\n", "0\n", "0\n", "0", "1", "0", "0\n"]}
419
89
coding
Solve the programming task below in a Python markdown code block. ### Background In classical cryptography, the Hill cipher is a polygraphic substitution cipher based on linear algebra. It was invented by Lester S. Hill in 1929. ### Task This cipher involves a text key which has to be turned into a matrix and text...
{"functional": "_inputs = [['', 'azyb'], ['hello', 'hill'], ['This is a good day', 'bbaa'], ['CODEWARS IS GREAT', 'wxyz'], ['Five + Seven = Twelve', 'math'], ['+-*/ &*%^$', 'azyb']]\n_outputs = [[''], ['DRJIMN'], ['AAAAAAGACAGAYA'], ['CICQQIIASSDXKSFP'], ['IVSLIGSLAQEECSWR'], ['']]\nimport math\ndef _deep_eq(a, b, tol=...
648
243
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string, message, and a positive integer, limit. You must split message into one or more parts based on limit. Each resulting part should have the suffix "<a/b>", where "b" is to be replaced with the to...
{"functional": "def check(candidate):\n assert candidate(message = \"this is really a very awesome message\", limit = 9) == [\"thi<1/14>\",\"s i<2/14>\",\"s r<3/14>\",\"eal<4/14>\",\"ly <5/14>\",\"a v<6/14>\",\"ery<7/14>\",\" aw<8/14>\",\"eso<9/14>\",\"me<10/14>\",\" m<11/14>\",\"es<12/14>\",\"sa<13/14>\",\"ge<14/14...
232
214
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two arrays of unique digits nums1 and nums2, return the smallest number that contains at least one digit from each array.   Please complete the following python code precisely: ```python class Solution: def ...
{"functional": "def check(candidate):\n assert candidate(nums1 = [4,1,3], nums2 = [5,7]) == 15\n assert candidate(nums1 = [3,5,2,6], nums2 = [3,1,7]) == 3\n\n\ncheck(Solution().minNumber)"}
81
74
coding
Solve the programming task below in a Python markdown code block. You are given an array $a_1, a_2, \dots, a_n$ consisting of $n$ distinct integers. Count the number of pairs of indices $(i, j)$ such that $i < j$ and $a_i \cdot a_j = i + j$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 10^...
{"inputs": ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2\n", "3\n2\n3 1\n3\n4 1 5\n5\n3 1 5 9 2\n", "3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 4\n", "3\n2\n2 1\n3\n4 1 5\n5\n3 1 4 9 2\n", "3\n2\n3 1\n3\n4 2 5\n5\n3 1 4 5 2\n", "3\n2\n3 2\n3\n2 1 5\n5\n3 1 5 9 4\n", "3\n2\n3 1\n3\n4 1 5\n5\n6 1 5 9 4\n", "3\n2\n3 2\n3\n4 1 5\n5\n6 1 5 9 4\...
426
310
coding
Solve the programming task below in a Python markdown code block. Mr. Square is going on a holiday. He wants to bring 2 of his favorite squares with him, so he put them in his rectangle suitcase. Write a function that, given the size of the squares and the suitcase, return whether the squares can fit inside the suitca...
{"functional": "_inputs = [[1, 2, 3, 2], [1, 2, 2, 1], [3, 2, 3, 2], [1, 2, 1, 2], [6, 5, 8, 7], [6, 6, 12, 6], [7, 1, 7, 8], [10, 10, 11, 11], [7, 2, 9, 7], [7, 2, 8, 7], [4, 1, 5, 3], [1, 2, 3, 4], [1, 2, 4, 3], [1, 3, 2, 4], [1, 3, 4, 2], [1, 4, 2, 3], [1, 4, 3, 2], [2, 1, 3, 4], [2, 1, 4, 3], [2, 3, 1, 4], [2, 3, 4...
193
679
coding
Solve the programming task below in a Python markdown code block. Initially, Chef had an array A of length N. Chef performs the following operation on A at most once: Select L and R such that 1 ≤ L ≤ R ≤ N and set A_{i} := A_{i} + 1 for all L ≤ i ≤ R. Determine the maximum number of *inversions* Chef can decrease from...
{"inputs": ["3\n5\n4 2 3 1 5\n6\n1 2 3 4 5 6\n4\n2 1 1 1\n"], "outputs": ["2\n0\n3\n"]}
704
54
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, which contains distinct elements and an integer k. A subset is called a k-Free subset if it contains no two elements with an absolute difference equal to k. Notice that the empty s...
{"functional": "def check(candidate):\n assert candidate(nums = [5,4,6], k = 1) == 5\n assert candidate(nums = [2,3,5,8], k = 5) == 12\n assert candidate(nums = [10,5,9,11], k = 20) == 16\n\n\ncheck(Solution().countTheNumOfKFreeSubsets)"}
137
97
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two non-negative integers, num1 and num2 represented as string, return the sum of num1 and num2 as a string. You must solve the problem without using any built-in library for handling large integers (such as Big...
{"functional": "def check(candidate):\n assert candidate(num1 = \"11\", num2 = \"123\") == \"134\"\n assert candidate(num1 = \"456\", num2 = \"77\") == \"533\"\n assert candidate(num1 = \"0\", num2 = \"0\") == \"0\"\n\n\ncheck(Solution().addStrings)"}
112
89
coding
Solve the programming task below in a Python markdown code block. You are given an array $a$ consisting of $n$ integers. In one move, you can jump from the position $i$ to the position $i - a_i$ (if $1 \le i - a_i$) or to the position $i + a_i$ (if $i + a_i \le n$). For each position $i$ from $1$ to $n$ you want to kn...
{"inputs": ["10\n4 5 7 6 7 5 4 4 6 4\n", "10\n4 9 7 6 7 5 4 4 6 4\n", "10\n4 9 7 6 7 5 4 4 6 0\n", "10\n4 9 7 6 7 5 4 4 6 1\n", "10\n4 5 7 6 7 5 4 4 6 4\n", "10\n4 17 7 6 7 5 4 4 6 1\n", "10\n4 17 7 6 7 5 4 4 12 1\n", "10\n4 17 1 6 7 5 4 4 12 1\n"], "outputs": ["1 1 1 2 -1 1 1 3 1 1 \n", "1 -1 1 2 -1 1 1 3 1 1\n", "1 -...
397
389
coding
Solve the programming task below in a Python markdown code block. A sequence a=\{a_1,a_2,a_3,......\} is determined as follows: - The first term s is given as input. - Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd. - a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1. Find...
{"inputs": ["2", "6", "5", "9", "8", "7", "8\n", "7\n"], "outputs": ["4\n", "10\n", "7\n", "21\n", "5", "18", "5\n", "18\n"]}
276
66
coding
Solve the programming task below in a Python markdown code block. In discus throw, a player is given 3 throws and the throw with the longest distance is regarded as their final score. You are given the distances for all 3 throws of a player. Determine the final score of the player. ------ Input Format ------ - Firs...
{"inputs": ["3\n10 15 8\n32 32 32\n82 45 54\n"], "outputs": ["15\n32\n82\n"]}
310
47
coding
Solve the programming task below in a Python markdown code block. An adult game master and N children are playing a game on an ice rink. The game consists of K rounds. In the i-th round, the game master announces: * Form groups consisting of A_i children each! Then the children who are still in the game form as man...
{"inputs": ["4\n3 3 2 2", "4\n4 3 2 2", "4\n3 5 3 2", "4\n1 1 2 2", "4\n3 4 2 2", "4\n3 6 2 2", "4\n3 6 4 2", "4\n3 4 3 2"], "outputs": ["3 5\n", "4 7\n", "6 11\n", "2 3\n", "-1\n", "-1\n", "-1\n", "6 8"]}
372
136
coding
Solve the programming task below in a Python markdown code block. One day the Codeforces round author sat exams. He had n exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend too much time and effort to...
{"inputs": ["1 2\n", "1 5\n", "3 7\n", "4 9\n", "2 5\n", "2 6\n", "3 8\n", "1 4\n"], "outputs": ["1\n", "0\n", "2\n", "3\n", "1\n", "0\n", "1\n", "0\n"]}
390
86
coding
Solve the programming task below in a Python markdown code block. Chef is given two arrays A and B of length N each. In one operation Chef can choose one element of A and one element of B and increase them by 1. More formally: Chef can pick two integers i, j (1≤ i, j ≤ N) and increment A_{i} and B_{j} by 1. Determin...
{"inputs": ["3\n2\n1 2\n2 1\n3\n1 1 2\n2 2 1\n3\n4 6 8\n5 7 6\n"], "outputs": ["1\n-1\n2\n"]}
634
57
coding
Solve the programming task below in a Python markdown code block. Given a string, turn each letter into its ASCII character code and join them together to create a number - let's call this number `total1`: ``` 'ABC' --> 'A' = 65, 'B' = 66, 'C' = 67 --> 656667 ``` Then replace any incidence of the number `7` with the ...
{"functional": "_inputs = [['abcdef'], ['ifkhchlhfd'], ['aaaaaddddr'], ['jfmgklf8hglbe'], ['jaam'], ['abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ']]\n_outputs = [[6], [6], [30], [6], [12], [96]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ma...
227
202
coding
Solve the programming task below in a Python markdown code block. You are given a string S of length N. You can apply the following operation on the string any number of times: Choose an index i (1≤ i < N), and swap S_{i} with S_{i+1}, if S_{i} and S_{i+1} contain adjacent characters. For example, a and b are adjace...
{"inputs": ["2\n5\ncbaba\n6\ndbbced"], "outputs": ["bbcaa\ncdbbde"]}
619
30
coding
Solve the programming task below in a Python markdown code block. Same as [the original](https://www.codewars.com/kata/simple-fun-number-258-is-divisible-by-6) (same rules, really, go there for example and I strongly recommend completing it first), but with more than one asterisk (but always at least one). For example...
{"functional": "_inputs = [['*2'], ['*21'], ['**1'], ['*2*'], ['***']]\n_outputs = [[['12', '42', '72']], [[]], [[]], [['024', '120', '126', '222', '228', '324', '420', '426', '522', '528', '624', '720', '726', '822', '828', '924']], [['000', '006', '012', '018', '024', '030', '036', '042', '048', '054', '060', '066', ...
268
1,106
coding
Solve the programming task below in a Python markdown code block. ```if-not:rust Your task is to write a function `toLeetSpeak` that converts a regular english sentence to Leetspeak. ``` ```if:rust Your task is to write a function `to_leet_speak` that converts a regular english sentence to Leetspeak. ``` More about Le...
{"functional": "_inputs = [['LEET'], ['CODEWARS'], ['HELLO WORLD'], ['LOREM IPSUM DOLOR SIT AMET'], ['THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG']]\n_outputs = [['1337'], ['(0D3W@R$'], ['#3110 W0R1D'], ['10R3M !P$UM D010R $!7 @M37'], ['7#3 QU!(K 8R0WN F0X JUMP$ 0V3R 7#3 1@2Y D06']]\nimport math\ndef _deep_eq(a, b, tol...
367
279
coding
Solve the programming task below in a Python markdown code block. The new PIN is hard to remember. I was told that I shouldn't take notes, but I don't think I can remember them. Therefore, I decided to embed a numerical value in the text and make a note of the PIN. Here, the sum of all the numbers is the PIN. Create a...
{"inputs": ["Thereare100yenonthetable.Iam17yearsold.\n.mp6taemohogdluohsI", ".dlosr`ey71maI.elbasehtnoney001eraerehT\n.mp6taelohdgoltohsI", ".closr`ey71maI-elbasegtnoney001eragrehT\nIshptkogdhomemt5q`.", "Thergarn100yeeontgesable-Iam17ye`rsolc.\nIshptkogdhomemt5q`.", "Thergarn10Iyeeontgesable-0am17ye`rsolc.\nIshptkogdh...
205
332
coding
Solve the programming task below in a Python markdown code block. # Task John is an orchard worker. There are `n` piles of fruits waiting to be transported. Each pile of fruit has a corresponding weight. John's job is to combine the fruits into a pile and wait for the truck to take them away. Every time, John can co...
{"functional": "_inputs = [[[1, 2, 9]], [[100]], [[1, 2]], [[4, 3, 5, 6, 10, 20]], [[87, 84, 42, 34, 24, 81, 60, 48, 75]], [[11, 9, 20, 10, 21, 35, 15, 34, 48, 76, 94, 28, 79, 16, 4, 41, 98, 30, 35, 92, 93, 33, 100, 93, 64, 23, 37, 6, 86, 27, 48, 16, 66, 99, 61, 83, 3, 5, 95]]]\n_outputs = [[15], [0], [3], [111], [1663...
452
402
coding
Solve the programming task below in a Python markdown code block. Two words are anagrams of one another if their letters can be rearranged to form the other word. Given a string, split it into two contiguous substrings of equal length. Determine the minimum number of characters to change to make the two substrings ...
{"inputs": ["6\naaabbb\nab\nabc\nmnop\nxyyx\nxaxbbbxx\n"], "outputs": ["3\n1\n-1\n2\n0\n1\n"]}
581
43
coding
Solve the programming task below in a Python markdown code block. Given is a string S. Replace every character in S with x and print the result. -----Constraints----- - S is a string consisting of lowercase English letters. - The length of S is between 1 and 100 (inclusive). -----Input----- Input is given from Stan...
{"inputs": ["x\n", "a\n", "z\n", "i\n", "xxwx", "gpne", "wxwx", "gpnd"], "outputs": ["x\n", "x\n", "x\n", "x\n", "xxxx\n", "xxxx\n", "xxxx\n", "xxxx\n"]}
120
70
coding
Solve the programming task below in a Python markdown code block. Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a ...
{"inputs": ["1\n1\n", "2\n2 1\n", "2\n1 2\n", "3\n1 3 2\n", "4\n2 3 4 1\n", "5\n5 4 3 2 1\n", "6\n4 3 6 5 1 2\n", "7\n2 1 5 7 3 4 6\n"], "outputs": ["1 \n", "2 1 \n", "1 2 \n", "1 3 2 \n", "4 1 2 3 \n", "5 4 3 2 1 \n", "5 6 2 1 4 3 \n", "2 1 5 6 3 7 4 \n"]}
386
182
coding
Solve the programming task below in a Python markdown code block. Arya is new to matrices. With lots of subtopics in the chapter, he finds it difficult in getting good in all of them. As of now, he is practising matrix multiplications. He takes two different matrices and checks in how many different ways could they be ...
{"inputs": ["11\n12 4 3 12\n12 4 4 12\n18 20 10 23\n10 13 11 8\n3 20 3 14\n13 23 12 20\n12 17 5 19\n15 22 22 9\n20 20 15 3\n7 19 18 8\n2 16 6 19", "36\n30 2 2 30\n14 1 2 14\n30 6 38 40\n9 24 25 11\n7 48 10 18\n18 22 21 19\n4 24 24 23\n31 38 6 22\n30 49 34 48\n46 1 6 6\n9 31 11 48\n9 17 10 36\n42 15 20 19\n24 10 42 46\n...
258
1,588
coding
Solve the programming task below in a Python markdown code block. This kata requires you to convert minutes (`int`) to hours and minutes in the format `hh:mm` (`string`). If the input is `0` or negative value, then you should return `"00:00"` **Hint:** use the modulo operation to solve this challenge. The modulo oper...
{"functional": "_inputs = [[0], [-6], [8], [32], [75], [63], [134], [180], [970], [565757]]\n_outputs = [['00:00'], ['00:00'], ['00:08'], ['00:32'], ['01:15'], ['01:03'], ['02:14'], ['03:00'], ['16:10'], ['9429:17']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
173
264
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. The following is an easy game that the setter of this problem played when he was 8: A boatman, a wolf, a sheep, and a cabbage are on the bank of a river. They have a small boat that is capable...
{"inputs": ["2\n3 2\n1 2\n2 3\n3 3\n1 2\n2 3\n1 3", "2\n3 2\n1 2\n2 3\n3 3\n1 2\n2 3\n2 3", "2\n4 2\n1 2\n4 3\n3 3\n1 2\n3 3\n2 2", "2\n3 2\n1 2\n2 5\n3 2\n1 2\n2 3\n1 1", "2\n7 4\n1 2\n2 3\n4 3\n1 2\n2 0\n2 4", "2\n4 2\n1 2\n2 3\n3 3\n1 2\n2 3\n2 3", "2\n3 2\n1 2\n1 3\n3 3\n1 2\n2 3\n2 3", "2\n4 2\n1 2\n2 3\n3 3\n1 2\...
608
301
coding
Solve the programming task below in a Python markdown code block. N of us are going on a trip, by train or taxi. The train will cost each of us A yen (the currency of Japan). The taxi will cost us a total of B yen. How much is our minimum total travel expense? -----Constraints----- - All values in input are integers....
{"inputs": ["6 2 7", "4 4 9", "3 2 8", "6 1 0", "6 4 1", "7 4 2", "5 2 5", "5 2 8"], "outputs": ["7\n", "9\n", "6\n", "0\n", "1\n", "2\n", "5\n", "8\n"]}
199
94
coding
Solve the programming task below in a Python markdown code block. In this problem the input will consist of a number of lines of English text consisting of the letters of the English alphabet, the punctuation marks ' (apostrophe), . (full stop), , (comma), ; (semicolon), :(colon) and white space characters (blank, newl...
{"inputs": ["2\nThis is a sample piece of text to illustrate this\nproblem."], "outputs": ["10\na\nillustrate\nis\nof\npiece\nproblem\nsample\ntext\nthis\nto"]}
374
50
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 2D integer array groups of length n. You are also given an integer array nums. You are asked if you can choose n disjoint subarrays from the array nums such that the ith subarray is equal to groups[i] ...
{"functional": "def check(candidate):\n assert candidate(groups = [[1,-1,-1],[3,-2,0]], nums = [1,-1,0,1,-1,-1,3,-2,0]) == True\n assert candidate(groups = [[10,-2],[1,2,3,4]], nums = [1,2,3,4,10,-2]) == False\n assert candidate(groups = [[1,2,3],[3,4]], nums = [7,7,1,2,3,4,7,7]) == False\n\n\ncheck(Solution()...
204
137
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef Aditi keeps changing the flavours of her dishes and she wants to analyse feedback from her customers in order to improve her performance. The cu...
{"inputs": ["4 3\n1 3 2 4\n1 4\n2 3\n2 4"], "outputs": ["NO\nNO\nYES"]}
768
38
coding
Solve the programming task below in a Python markdown code block. The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A message is a sequence of n integers a1, a2...
{"inputs": ["3 1 5\n1 2 3\n7\n", "3 1 5\n1 0 3\n7\n", "3 1 5\n1 1 3\n7\n", "3 1 1\n1 0 3\n7\n", "3 1 1\n2 0 3\n7\n", "3 1 1\n2 0 0\n7\n", "3 1 5\n1 2 3\n4\n", "3 1 1\n2 0 0\n14\n"], "outputs": ["3 4 0\n", "3 2 0\n", "3 3 0\n", "0 0 0\n", "0 0 0\n", "0 0 0\n", "0 1 2 ", "0 0 0\n"]}
580
198
coding
Solve the programming task below in a Python markdown code block. Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel be...
{"inputs": ["1\n2\n", "1\n4\n", "1\n8\n", "1\n1\n", "2\n1 2\n", "2\n2 2\n", "2\n1 1\n", "2\n0 1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "0\n", "1\n"]}
436
94
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Some robots are standing on an infinite number line with their initial coordinates given by a 0-indexed integer array nums and will start moving once given the command to move. The robots will move a unit distance eac...
{"functional": "def check(candidate):\n assert candidate(nums = [-2,0,2], s = \"RLL\", d = 3) == 8\n assert candidate(nums = [1,0], s = \"RL\", d = 2) == 5\n\n\ncheck(Solution().sumDistance)"}
394
70
coding
Solve the programming task below in a Python markdown code block. # Task Smartphones software security has become a growing concern related to mobile telephony. It is particularly important as it relates to the security of available personal information. For this reason, Ahmed decided to encrypt phone numbers of co...
{"functional": "_inputs = [['353'], ['444'], ['123456'], ['147'], ['4334']]\n_outputs = [['123'], ['404'], ['738496'], ['377'], ['impossible']]\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 isinstanc...
554
204
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings s and part, perform the following operation on s until all occurrences of the substring part are removed: Find the leftmost occurrence of the substring part and remove it from s. Return s after rem...
{"functional": "def check(candidate):\n assert candidate(s = \"daabcbaabcbc\", part = \"abc\") == \"dab\"\n assert candidate(s = \"axxxxyyyyb\", part = \"xy\") == \"ab\"\n\n\ncheck(Solution().removeOccurrences)"}
110
64
coding
Solve the programming task below in a Python markdown code block. Your algorithm is so good at predicting the market that you now know what the share price of Mahindra & Mahindra. (M&M) will be for the next N days. Each day, you can either buy one share of M&M, sell any number of shares of M&M that you own, or not mak...
{"inputs": ["3\n3\n5 3 2\n3\n1 2 100\n4\n1 3 1 2"], "outputs": ["0\n197\n3"]}
341
46
coding
Solve the programming task below in a Python markdown code block. The cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese. When counting pencils in Japanese, the counter word "本" follows the number. The pronunciation of this word varies depending on the number. Spe...
{"inputs": ["4", "6", "9", "8", "5", "0", "1", "7"], "outputs": ["hon\n", "pon\n", "hon\n", "pon\n", "hon\n", "pon\n", "pon\n", "hon\n"]}
270
62
coding
Solve the programming task below in a Python markdown code block. Chef has gone shopping with his 5-year old son. They have bought N items so far. The items are numbered from 1 to N, and the item i weighs Wi grams. Chef's son insists on helping his father in carrying the items. He wants his dad to give him a few items...
{"inputs": ["2\n5 2\n3 2 5 2 1\n8 3\n1 1 1 1 1 1 0 1", "2\n5 2\n3 2 5 0 6\n8 3\n1 0 1 1 1 1 1 1", "2\n5 1\n3 2 5 2 1\n8 3\n1 1 1 1 1 1 0 1", "2\n5 2\n3 4 5 1 6\n8 3\n0 1 1 0 1 1 0 1", "2\n5 2\n3 2 5 2 8\n8 4\n1 1 1 1 1 1 1 1", "2\n5 2\n3 2 5 0 6\n8 3\n0 0 1 1 1 1 1 1", "2\n5 1\n3 2 5 2 1\n8 3\n1 1 1 1 1 0 0 1", "2\n5 2...
485
357
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. There are N cards placed in a row, where every card has two numbers written on it, one on the top and one on the bottom. The numbers are between 1 and N (both inclusive). Every number i...
{"inputs": ["2\n3\n1 3 2\n2 1 3\n8\n3 8 4 2 6 1 5 7\n5 2 4 3 8 7 6 1"], "outputs": ["2\n4"]}
732
62
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Our chef Remy ate all the delicious food he made. As a result, he has become really fat :). Chef's assistant Linguini has taken up the herculean task of bringing back chef Remy to shape. Ling...
{"inputs": ["3\n2 1\nR 1\n3 1\nA 2\n6 2\nA 2\nB 6"], "outputs": ["1\n1\n4"]}
668
44
coding
Solve the programming task below in a Python markdown code block. Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i. He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditio...
{"inputs": ["3\n4 2 3\n", "4\n5 4 2 1", "4\n5 2 2 1", "4\n8 2 2 1", "4\n8 2 1 1", "4\n6 4 2 1", "4\n5 4 3 1", "4\n6 2 2 1"], "outputs": ["1\n", "1\n", "1\n", "1\n", "0\n", "0\n", "1\n", "1\n"]}
252
125
coding
Solve the programming task below in a Python markdown code block. In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there. Most damage those strange creatures inflicted upon the kingd...
{"inputs": ["7.6\n", "7.5\n", "8.3\n", "9.8\n", "0.9\n", "4.4\n", "2.6\n", "5.0\n"], "outputs": ["8", "8", "8", "GOTO Vasilisa.", "1", "4", "3", "5"]}
652
82
coding
Solve the programming task below in a Python markdown code block. Master Shifu is training Po to become The Dragon Warrior and as a final assignment he must obtain maximum deliciousness from dumplings. There are $N$ plates of dumplings in front of him with deliciousness $A_1, A_2, \ldots, A_N$, Po can choose any numbe...
{"inputs": ["2\n4\n1 2 3 4\n5\n3 2 0 3 0"], "outputs": ["4\n4"]}
313
36
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. As we all know, Binomial Coefficient C(n, r) is defined by the following formula. Also define S(n) as follows. Note that n will be provided to you as an input parameter. Since S(n) can be ...
{"inputs": ["5\n1\n2\n3\n4\n5"], "outputs": ["2\n4\n2\n4\n8"]}
258
30
coding
Solve the programming task below in a Python markdown code block. Bridge Removal ICPC islands once had been a popular tourist destination. For nature preservation, however, the government decided to prohibit entrance to the islands, and to remove all the man-made structures there. The hardest part of the project is to...
{"inputs": ["4\n1 2 2\n10 20 30\n10\n1 2 2 2 5 5 1 8 9\n9 1 1 20 2 2 5 1 1\n3\n1 1\n2 2\n0", "4\n1 2 2\n10 20 30\n10\n1 2 2 2 5 5 1 8 9\n9 1 1 20 2 2 5 1 2\n3\n1 1\n2 2\n0", "4\n1 2 2\n10 20 30\n10\n1 2 3 2 5 5 1 8 9\n9 1 1 20 2 2 5 1 2\n3\n1 1\n2 2\n0", "4\n1 2 2\n10 20 30\n10\n1 2 3 2 5 5 1 8 9\n9 1 1 20 2 4 5 1 2\n3...
659
650
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. We are given n different types of stickers. Each sticker has a lowercase English word on it. You would like to spell out the given string target by cutting individual letters from your collection of stickers and rearr...
{"functional": "def check(candidate):\n assert candidate( stickers = [\"with\",\"example\",\"science\"], target = \"thehat\") == 3\n assert candidate(stickers = [\"notice\",\"possible\"], target = \"basicbasic\") == -1\n\n\ncheck(Solution().minStickers)"}
179
68
coding
Solve the programming task below in a Python markdown code block. Let's call a permutation $p$ of length $n$ anti-Fibonacci if the condition $p_{i-2} + p_{i-1} \ne p_i$ holds for all $i$ ($3 \le i \le n$). Recall that the permutation is the array of length $n$ which contains each integer from $1$ to $n$ exactly once. ...
{"inputs": ["2\n4\n3\n"], "outputs": ["1 4 3 2\n2 4 3 1\n3 4 2 1\n4 3 2 1\n1 3 2\n2 3 1\n3 2 1\n"]}
332
66
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Dr.D got so famous thanks to his first problem that he decided to commemorate it by making yet another problem with an almost identical statement — he only cha...
{"inputs": ["4\n1 3\n4 5\n1031 93714\n1000000000123 1000000123456"], "outputs": ["3\n5\n131071\n1000000192511"]}
306
82
coding
Solve the programming task below in a Python markdown code block. Suppose Chef is stuck on an island and currently he has $x$ units of food supply and $y$ units of water supply in total that he could collect from the island. He needs $x_{r}$ units of food supply and $y_{r}$ units of water supply per day at the minimal ...
{"inputs": ["3\n4 2 1 1 1\n4 2 1 3 1\n4 2 4 2 2"], "outputs": ["YES\nNO\nNO"]}
637
46
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n. There are n rooms numbered from 0 to n - 1. You are given a 2D integer array meetings where meetings[i] = [starti, endi] means that a meeting will be held during the half-closed time interv...
{"functional": "def check(candidate):\n assert candidate(n = 2, meetings = [[0,10],[1,5],[2,7],[3,4]]) == 0\n assert candidate(n = 3, meetings = [[1,20],[2,10],[3,5],[4,9],[6,8]]) == 1\n\n\ncheck(Solution().mostBooked)"}
253
89
coding
Solve the programming task below in a Python markdown code block. > [Run-length encoding](https://en.wikipedia.org/w/index.php?title=Run-length_encoding) (RLE) is a very simple form of data compression in which runs of data (that is, sequences in which the same data value occurs in many consecutive data elements) are s...
{"functional": "_inputs = [[''], ['abc'], ['aab'], ['hello world!'], ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbb']]\n_outputs = [[[]], [[[1, 'a'], [1, 'b'], [1, 'c']]], [[[2, 'a'], [1, 'b']]], [[[1, 'h'], [1, 'e'], [2, 'l'], [1, 'o'], [1, ' '], [1, 'w'], [1, 'o'], [1, 'r'], [1, 'l'], [1, 'd'], [1, '!']]], [[[34, 'a'], [3, ...
366
285
coding
Solve the programming task below in a Python markdown code block. Let $length(A)$ denote the count of digits of a number $\mbox{A}$ in its decimal representation. John is looking for new methods of determining which numbers are strange all day long. All non-negative numbers of length 1 are strange. Further, a numbe...
{"inputs": ["5\n7 25\n45 50\n1 100\n99 103\n0 1000000\n"], "outputs": ["10\n1\n26\n0\n96\n"]}
387
59
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the root of a binary tree. A ZigZag path for a binary tree is defined as follow: Choose any node in the binary tree and a direction (right or left). If the current direction is right, move to the right ...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,None,1,1,1,None,None,1,1,None,1,None,None,None,1,None,1])) == 3\n assert candidate(root = tree_node([1,1,1,None,1,None,None,1,1,None,1])) == 4\n assert candidate(root = tree_node([1])) == 0\n\n\ncheck(Solution().longestZigZag)"}
234
105
coding
Solve the programming task below in a Python markdown code block. The only difference between the two versions is that in this version $n \leq 1000$ and the sum of $n$ over all test cases does not exceed $1000$. A terminal is a row of $n$ equal segments numbered $1$ to $n$ in order. There are two terminals, one above ...
{"inputs": ["4\n7\n4 1 4 6 7 7 5\n2\n2 1\n1\n1\n3\n2 2 2\n"], "outputs": ["6\n1\n0\n3\n"]}
518
54
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a string and your task is to return the most valuable character. The value of a character is the difference between the index of its last occurrence and the index of its first occurrence. Return the character that has the ...
{"functional": "_inputs = [['a'], ['aa'], ['bcd'], ['axyzxyz'], ['dcbadcba'], ['aabccc'], ['efgefg'], ['efghijefghi'], ['acefacef'], ['acefacefacef']]\n_outputs = [['a'], ['a'], ['b'], ['x'], ['a'], ['c'], ['e'], ['e'], ['a'], ['a']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance...
174
225
coding
Solve the programming task below in a Python markdown code block. For a [permutation] P of the integers 1 to N, we define a new array A_{P} of length N-2 as follows: For 1 ≤ i ≤ N-2, (A_{P})_i denotes the number of [inversions] in the subarray P[i : i+2], i.e, the number of inversions in the array [P_{i}, P_{i+1}, P_{...
{"inputs": ["4\n4\n0 1 3 2\n4\n0 1 2 3\n4\n0 0 0 0\n5\n0 1 2 1 0"], "outputs": ["YES\nNO\nYES\nNO"]}
676
60
coding
Solve the programming task below in a Python markdown code block. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi,...
{"inputs": ["1 1\n1 1\n1 1\n", "1 1\n1 1\n2 2\n", "1 1\n1 1\n1 2\n", "1 1\n1 2\n2 2\n", "1 1\n2 1\n1 2\n", "1 1\n1 2\n1 2\n", "1 1\n0 1\n1 2\n", "1 1\n0 1\n2 2\n"], "outputs": ["1 1\n", "0 0\n", "0 0\n", "1 0\n", "0 0\n", "1 1\n", "0 0\n", "0 0\n"]}
491
166
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, return the zigzag level order traversal of its nodes' values. (i.e., from left to right, then right to left for the next level and alternate between).   Please complete the following p...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([3,9,20,None,None,15,7])) == [[3],[20,9],[15,7]]\n assert candidate(root = tree_node([1])) == [[1]]\n assert candidate(root = tree_node([])) == []\n\n\ncheck(Solution().zigzagLevelOrder)"}
146
88
coding
Solve the programming task below in a Python markdown code block. The sum of digits of a non-negative integer $a$ is the result of summing up its digits together when written in the decimal system. For example, the sum of digits of $123$ is $6$ and the sum of digits of $10$ is $1$. In a formal way, the sum of digits of...
{"inputs": ["5\n1\n161\n67\n1206\n19\n"], "outputs": ["0 1\n130 31\n33 34\n103 1103\n14 5\n"]}
429
60
coding
Solve the programming task below in a Python markdown code block. Chef is playing a game with his brother Chefu. He asked Chefu to choose a positive integer $N$, multiply it by a given integer $A$, then choose a divisor of $N$ (possibly $N$ itself) and add it to the product. Let's denote the resulting integer by $M$; m...
{"inputs": ["3\n3 35\n5 50\n4 65"], "outputs": ["1\n10\n0\n3\n13 15 16"]}
397
43
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of points in the X-Y plane points where points[i] = [xi, yi]. Return the minimum area of a rectangle formed from these points, with sides parallel to the X and Y axes. If there is not any such r...
{"functional": "def check(candidate):\n assert candidate([[1,1],[1,3],[3,1],[3,3],[2,2]]) == 4\n assert candidate([[1,1],[1,3],[3,1],[3,3],[4,1],[4,3]]) == 2\n\n\ncheck(Solution().minAreaRect)"}
107
80
coding
Solve the programming task below in a Python markdown code block. Chef Shifu wanted to celebrate the success of his new restaurant with all his employees. He was willing to host a party and he had decided the location of the party as well. However, Chef Shifu was a shy person and wanted to communicate with the least po...
{"inputs": ["2\n3 3\n1 2\n2 3\n1 3\n4 3\n1 2\n2 3\n3 4"], "outputs": ["1\n2"]}
510
46
coding
Solve the programming task below in a Python markdown code block. Given an array of numbers, calculate the largest sum of all possible blocks of consecutive elements within the array. The numbers will be a mix of positive and negative values. If all numbers of the sequence are nonnegative, the answer will be the sum of...
{"functional": "_inputs = [[[-1, -2, -3]], [[]], [[1, 2, 3, 4]], [[31, -41, 59, 26, -53, 58, 97, -93, -23, 84]]]\n_outputs = [[0], [0], [10], [187]]\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 isin...
281
228
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string num, representing a large integer. Return the largest-valued odd integer (as a string) that is a non-empty substring of num, or an empty string "" if no odd integer exists. A substring is a cont...
{"functional": "def check(candidate):\n assert candidate(num = \"52\") == \"5\"\n assert candidate(num = \"4206\") == \"\"\n assert candidate(num = \"35427\") == \"35427\"\n\n\ncheck(Solution().largestOddNumber)"}
104
71
coding
Solve the programming task below in a Python markdown code block. Late last night in the Tanner household, ALF was repairing his spaceship so he might get back to Melmac. Unfortunately for him, he forgot to put on the parking brake, and the spaceship took off during repair. Now it's hovering in space. ALF has the tech...
{"functional": "_inputs = [['X'], ['X\\n.'], ['.X\\n..'], ['..\\n.X'], ['..\\nX.'], ['.......\\nX.......'], ['..........\\n..........\\n.......X..\\n..........\\n..........'], ['..........\\n..........\\n..........\\n........X.\\n..........'], ['........................'], ['\\n\\n\\n\\n']]\n_outputs = [[[0, 0]], [[0, ...
351
292
coding
Solve the programming task below in a Python markdown code block. zscoder wants to generate an input file for some programming competition problem. His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor. Initially, the text editor...
{"inputs": ["8 1 1\n", "1 1 1\n", "1 1 1\n", "1 1 0\n", "8 1 2\n", "2 1 0\n", "8 1 0\n", "4 1 0\n"], "outputs": ["4\n", "1\n", "1", "1", "6", "1", "1", "1"]}
249
96
coding
Solve the programming task below in a Python markdown code block. There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n. The i-th child wants to get at least a_{i} candies. Jzzhu asks children to line up. Initially, the i-th child stands at the i...
{"inputs": ["1 3\n5\n", "1 4\n3\n", "1 4\n3\n", "1 3\n5\n", "1 8\n3\n", "1 3\n6\n", "1 2\n3\n", "1 6\n6\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
470
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. We build a table of n rows (1-indexed). We start by writing 0 in the 1st row. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10. For e...
{"functional": "def check(candidate):\n assert candidate(n = 1, k = 1) == 0\n assert candidate(n = 2, k = 1) == 0\n assert candidate(n = 2, k = 2) == 1\n\n\ncheck(Solution().kthGrammar)"}
181
71
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin, Russian and Vietnamese as well. There are N sets of integers from 1 to K both inclusive. Find out number of pairs of sets whose union contains all the K elements. ------ Input ------ The first line contains an i...
{"inputs": ["3\n2 2\n1 1\n1 1\n3 2\n2 1 2\n2 1 2\n2 1 2\n3 4\n3 1 2 3\n4 1 2 3 4\n3 2 3 4"], "outputs": ["0\n3\n3"]}
429
80
coding
Solve the programming task below in a Python markdown code block. There is a field with plants — a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$); out of its $NM$ cells, $K$ cells contain plants, while the rest contain weeds. Two cells are adjacent if they have a common side. Y...
{"inputs": ["2\n4 4 9\n1 4\n2 1\n2 2\n2 3\n3 1\n3 3\n4 1\n4 2\n4 3\n4 4 1\n1 1"], "outputs": ["20\n4"]}
651
67
coding
Solve the programming task below in a Python markdown code block. There are N towns in JOI, which are connected by M bidirectional roads. There are shopping malls in K towns, and the people go to one of those towns through the road to shop. Depending on the location of your home, you may have to travel long distances ...
{"inputs": ["4 3 1\n1 2 1\n2 3 1\n3 1 1\n1", "4 3 1\n1 2 1\n2 3 2\n1 1 1\n1", "4 3 1\n1 2 1\n2 3 1\n1 2 1\n2", "4 3 1\n1 2 1\n2 3 4\n1 1 1\n1", "8 3 1\n1 1 2\n2 3 4\n3 1 0\n1", "4 3 1\n1 2 2\n2 4 4\n1 1 1\n1", "4 3 1\n1 1 0\n1 3 0\n3 2 0\n1", "4 3 1\n1 2 1\n2 3 1\n1 1 1\n1"], "outputs": ["2\n", "3\n", "1\n", "5\n", "4\...
490
254
coding
Solve the programming task below in a Python markdown code block. Chef _c8kbf_ has an unrooted, weighted tree with N nodes, where vertices u and v are connected by an edge with weight w. The value of the simple path from x to y is defined as the [bitwise XOR] of the weights of the edges it consists of. Recall that a...
{"inputs": ["3\n4\n1 2 1\n2 3 2\n2 4 3\n4\n1 2 2\n2 3 4\n2 4 8\n3\n1 2 5\n2 3 0"], "outputs": ["1 4 2 3\n-1\n1 2 1 3"]}
748
83
coding
Solve the programming task below in a Python markdown code block. If the strings are consecutive, you can replace the characters with a rule to shorten the string. For example, for the string AAAA, the expression @ 4A will compress one character. Create a program that restores the character string compressed by this ru...
{"inputs": ["ab@5C1@8050\n@99,1=1@90", "ab@5C2@8050\n@99,1=1@90", "ab@5C2?8050\n@99,1=1@90", "ab@5C1@8050\nA99+1=1@90", "ab@5C2@8050\n@89,1=1@90", "ab@5C2?8050\n@91,1=9@90", "`b@5C1@8050\nA99+1=1@90", "ab@5C3@8050\n@89,1=1@90"], "outputs": ["abCCCCC10000000050\n999999999,1=1000000000", "abCCCCC20000000050\n999999999,1=...
238
478
coding
Solve the programming task below in a Python markdown code block. Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers. Now the party is ready to start its journey, but firstly they have to choose kayaks. There ar...
{"inputs": ["2\n1 2 3 4\n", "2\n1 2 3 2\n", "2\n1 2 3 1\n", "2\n1 2 5 1\n", "2\n1 2 5 2\n", "2\n2 2 5 2\n", "2\n1 2 3 4\n", "2\n55 5 3 51\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "2\n"]}
367
136
coding
Solve the programming task below in a Python markdown code block. There are N piles where the i^{th} pile consists of A_{i} stones. Chef and Chefina are playing a game taking alternate turns with Chef starting first. In his/her turn, a player can choose any non-empty pile and remove exactly 1 stone from it. The ga...
{"inputs": ["3\n2\n2 2\n1\n10\n3\n1 5 6\n"], "outputs": ["CHEFINA\nCHEFINA\nCHEF\n"]}
454
42
coding
Solve the programming task below in a Python markdown code block. Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has n buses and m trolleys, the buses are numbered by integers from 1 to n, the trolleys are numbered by integers from 1 to m. Public transport is...
{"inputs": ["4 4 4 1\n1 1\n0\n0\n", "4 4 4 1\n1 1\n0\n0\n", "4 3 2 1\n1 3\n798\n1 2 3\n", "1 1 3 4\n2 3\n1 1\n1 1 1\n", "1 1 3 4\n2 3\n1 1\n1 1 1\n", "4 3 1 1\n1 3\n798\n1 2 3\n", "1 2 3 4\n2 3\n1 1\n1 1 1\n", "4 3 1 1\n1 3\n798\n2 2 3\n"], "outputs": ["0\n", "0", "1\n", "4\n", "4", "1\n", "4\n", "1\n"]}
660
216
coding
Solve the programming task below in a Python markdown code block. The final match of the Berland Football Cup has been held recently. The referee has shown $n$ yellow cards throughout the match. At the beginning of the match there were $a_1$ players in the first team and $a_2$ players in the second team. The rules of ...
{"inputs": ["2\n3\n5\n1\n8\n", "8\n4\n1\n2\n9\n", "1\n7\n2\n3\n5\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n2\n", "1\n1\n7\n1\n2\n", "1\n1\n1\n3\n4\n", "8\n4\n1\n2\n9\n"], "outputs": ["0 4\n", "5 8\n", "0 2\n", "1 1\n", "2 2\n", "0 1\n", "2 2\n", "5 8\n"]}
661
150
coding
Solve the programming task below in a Python markdown code block. Welcome to Codeforces Stock Exchange! We're pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope you'll still be able to make profit from the market! In the morning, there are $n$ opportunities to buy shares. The $i$-th...
{"inputs": ["1 1 1\n1\n1\n", "1 1 4\n3\n4\n", "1 1 7\n5\n6\n", "1 1 7\n5\n7\n", "1 1 5\n5\n6\n", "1 1 4\n4\n5\n", "1 1 5\n1\n4\n", "1 1 4\n8\n7\n"], "outputs": ["1\n", "5\n", "8\n", "9\n", "6\n", "5\n", "20\n", "4\n"]}
573
135
coding
Solve the programming task below in a Python markdown code block. Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. L...
{"inputs": ["1\n", "2\n", "1\n", "3\n", "4\n", "5\n", "6\n", "7\n"], "outputs": ["1\n", "2\n", "1\n", "3\n", "4\n", "5\n", "6\n", "7\n"]}
316
70
coding
Solve the programming task below in a Python markdown code block. You are provided with array of positive non-zero ints and int n representing n-th power (n >= 2). For the given array, calculate the sum of each value to the n-th power. Then subtract the sum of the original array. Example 1: Input: {1, 2, 3}, 3 --> (1...
{"functional": "_inputs = [[[1, 2, 3], 3], [[1, 2], 5], [[3, 5, 7], 2], [[1, 2, 3, 4, 5], 3], [[2, 7, 13, 17], 2], [[2, 5, 8], 3], [[2, 4, 6, 8], 6], [[5, 10, 15], 4], [[3, 6, 9, 12], 3]]\n_outputs = [[30], [30], [68], [210], [472], [630], [312940], [61220], [2670]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if i...
194
322
coding
Solve the programming task below in a Python markdown code block. Implement `String#whitespace?(str)` (Ruby), `String.prototype.whitespace(str)` (JavaScript), `String::whitespace(str)` (CoffeeScript), or `whitespace(str)` (Python), which should return `true/True` if given object consists exclusively of zero or more whi...
{"functional": "_inputs = [[''], [' '], ['\\n\\r\\n\\r'], ['a'], ['w\\n'], ['\\t'], [' a\\n'], ['\\t \\n\\r\\n '], ['\\n\\r\\n\\r '], ['\\n\\r\\n\\r 3']]\n_outputs = [[True], [True], [True], [False], [False], [True], [False], [True], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, fl...
102
246
coding
Solve the programming task below in a Python markdown code block. Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants....
{"inputs": ["1 1\n0\n", "1 1\n1\n", "1 1\n-1\n", "1 1\n555\n", "1 1\n-24\n", "4 2\n7 1 0 -7\n", "4 2\n7 0 0 -7\n", "2 2\n-742 -187\n"], "outputs": ["0\n", "0\n", "1\n", "0\n", "24\n", "7\n", "7\n", "929\n"]}
268
129
coding
Solve the programming task below in a Python markdown code block. We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. - Swap the con...
{"inputs": ["2 2 3", "2 2 5", "2 2 7", "3 2 7", "4 1 9", "3 1 9", "3 2 9", "1 2 3"], "outputs": ["3 2 2\n", "5 2 2\n", "7 2 2\n", "7 3 2\n", "9 4 1\n", "9 3 1\n", "9 3 2\n", "3 1 2"]}
248
125
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level x such that the sum of all the values of nodes at level x is maximal.   Please complete...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,7,0,7,-8,None,None])) == 2\n assert candidate(root = tree_node([989,None,10250,98693,-89388,None,None,None,-32127])) == 2\n\n\ncheck(Solution().maxLevelSum)"}
152
88
coding
Solve the programming task below in a Python markdown code block. AmShZ has traveled to Italy from Iran for the Thom Yorke concert. There are $n$ cities in Italy indexed from $1$ to $n$ and $m$ directed roads indexed from $1$ to $m$. Initially, Keshi is located in the city $1$ and wants to go to AmShZ's house in the ci...
{"inputs": ["2 1\n1 2\n", "4 4\n1 2\n1 4\n2 4\n1 4\n", "5 7\n1 2\n2 3\n3 5\n1 4\n4 3\n4 5\n3 1\n"], "outputs": ["1\n", "2\n", "4\n"]}
713
84
coding
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Let next(x) be the minimum lucky n...
{"inputs": ["3 4\n", "1 2\n", "5 6\n", "1 1\n", "4 7\n", "1 9\n", "6 6\n", "6 9\n"], "outputs": ["8\n", "8\n", "14\n", "4\n", "25\n", "125\n", "7\n", "102\n"]}
334
92
coding
Solve the programming task below in a Python markdown code block. We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}. Print the string of length 3 that can be obtained by concatenating the lette...
{"inputs": ["ant\nobe\nrfc", "ddu\ncat\nion", "ant\nobe\nrcf", "ddu\ncat\nioo", "ddu\ncat\nooi", "una\nobe\nrcf", "edu\nbau\nooi", "una\npbe\nfdr"], "outputs": ["abc\n", "dan\n", "abf\n", "dao\n", "dai\n", "ubf\n", "eai\n", "ubr\n"]}
267
113
coding
Solve the programming task below in a Python markdown code block. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room o...
{"inputs": ["1\n1\n", "2\n1 1\n", "2\n1 2\n", "3\n1 1 3\n", "4\n1 2 2 3\n", "4\n1 2 2 4\n", "4\n1 2 2 1\n", "4\n1 1 2 3\n"], "outputs": ["2\n", "6\n", "4\n", "8\n", "14\n", "10\n", "18\n", "20\n"]}
460
122
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. Initially on minute 0, the array is unchanged. Every minute, the leftmost element in nums is removed until no elements remain. Then, every minute, one element is appended ...
{"functional": "def check(candidate):\n assert candidate(nums = [0,1,2], queries = [[0,2],[2,0],[3,2],[5,0]]) == [2,2,-1,0]\n assert candidate(nums = [2], queries = [[0,0],[1,0],[2,0],[3,0]]) == [2,-1,2,-1]\n\n\ncheck(Solution().elementInNums)"}
301
101
coding
Solve the programming task below in a Python markdown code block. #### Task: Your job here is to implement a function `factors`, which takes a number `n`, and outputs an array of arrays comprised of two parts, `sq` and `cb`. The part `sq` will contain all the numbers that, when squared, yield a number which is a facto...
{"functional": "_inputs = [[1], [4], [16], [81], [80], [100], [5], [120], [18], [8]]\n_outputs = [[[[], []]], [[[2], []]], [[[2, 4], [2]]], [[[3, 9], [3]]], [[[2, 4], [2]]], [[[2, 5, 10], []]], [[[], []]], [[[2], [2]]], [[[3], []]], [[[2], [2]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) ...
485
260