task_type
stringclasses
1 value
problem
stringlengths
209
3.39k
answer
stringlengths
35
6.15k
problem_tokens
int64
60
774
answer_tokens
int64
12
2.04k
coding
Solve the programming task below in a Python markdown code block. Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible diverse words in lexicographical order. A word is called d...
{"inputs": ["cba", "bca", "bac", "abd", "bad", "acb", "cab", "dba"], "outputs": ["cbad\n", "bcad\n", "bacd\n", "abdc\n", "badc\n", "acbd\n", "cabd\n", "dbac\n"]}
368
71
coding
Solve the programming task below in a Python markdown code block. A binary gap within a positive number ```num``` is any sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of ```num```. For example: ```9``` has binary representation ```1001``` and contains a bin...
{"functional": "_inputs = [[9]]\n_outputs = [[2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x...
233
154
coding
Solve the programming task below in a Python markdown code block. Once N boys and M girls attended a party. You are given a matrix A of N rows and M columns where Aij is 1 if the i-th boy likes the j-th girl, otherwise it will be 0. Note that it is not necessary that if a boy x likes girl y, then girl y should like boy...
{"inputs": ["2\n4 3\n111\n100\n011\n100\n0 1\n10\n1", "2\n4 3\n101\n100\n011\n100\n0 1\n10\n1", "2\n4 3\n101\n100\n001\n100\n0 1\n10\n1", "2\n4 3\n101\n100\n110\n000\n1 2\n10\n2", "2\n4 3\n101\n100\n110\n000\n0 1\n10\n0", "2\n4 3\n101\n100\n010\n100\n2 1\n10\n0", "2\n4 3\n101\n101\n100\n000\n2 1\n10\n0", "2\n4 3\n101\n...
415
310
coding
Solve the programming task below in a Python markdown code block. Given a string, you progressively need to concatenate the first letter from the left and the first letter to the right and "1", then the second letter from the left and the second letter to the right and "2", and so on. If the string's length is odd dro...
{"functional": "_inputs = [['abc def'], ['CodeWars'], ['CodeWars Rocks'], ['1234567890'], [\"$'D8KB)%PO@s\"]]\n_outputs = [['af1be2cd3'], ['Cs1or2da3eW4'], ['Cs1ok2dc3eo4WR5a 6rs7'], ['101292383474565'], [\"$s1'@2DO38P4K%5B)6\"]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, ...
138
257
coding
Solve the programming task below in a Python markdown code block. YouKn0wWho has an integer sequence a_1, a_2, …, a_n. He will perform the following operation until the sequence becomes empty: select an index i such that 1 ≤ i ≤ |a| and a_i is not divisible by (i + 1), and erase this element from the sequence. Here |a|...
{"inputs": ["5\n3\n1 8 3\n1\n2\n2\n7 7\n10\n384836991 191890310 15674376 782177068 172478243 550654647 954291757 278929746 405393865 840594328\n8\n6 69 696 69696 687972 87299 69696969 1602686280\n", "5\n3\n1 8 3\n1\n2\n2\n7 7\n10\n384836991 191890310 15674376 892143751 172478243 550654647 954291757 278929746 405393865 ...
645
1,500
coding
Solve the programming task below in a Python markdown code block. There is a task in Among Us in which $N$ temperature scale with unique readings are given and you have to make all of them equal. In one second you can choose an odd number and add or subtract that number in any one temperature value. Find minimum time (...
{"inputs": ["3\n5\n1 2 3 4 5\n4\n5 2 3 8\n2\n50 53"], "outputs": ["5\n4\n1"]}
346
46
coding
Solve the programming task below in a Python markdown code block. Finally, the pandemic is over in ChefLand, and the chef is visiting the school again. Chef likes to climb the stairs of his school's floor by skipping one step, sometimes chef climbs the stairs one by one. Simply, the chef can take one or 2 steps in one ...
{"inputs": ["1\n3"], "outputs": ["2"]}
326
14
coding
Solve the programming task below in a Python markdown code block. The mayor of your city has decided to throw a party to gather the favour of his people in different regions of the city. There are 3 distinct regions in the city namely A, B, C comprising of P_{A}, P_{B} and P_{C} number of people respectively. Howev...
{"inputs": ["3\n2 3 4\n1 5 2\n8 8 8\n"], "outputs": ["6\n5\n16\n"]}
384
37
coding
Solve the programming task below in a Python markdown code block. # Making Change Complete the method that will determine the minimum number of coins needed to make change for a given amount in American currency. Coins used will be half-dollars, quarters, dimes, nickels, and pennies, worth 50¢, 25¢, 10¢, 5¢ and 1¢, r...
{"functional": "_inputs = [[0], [1], [5], [43], [91], [101], [239]]\n_outputs = [[{}], [{'P': 1}], [{'N': 1}], [{'Q': 1, 'D': 1, 'N': 1, 'P': 3}], [{'H': 1, 'Q': 1, 'D': 1, 'N': 1, 'P': 1}], [{'H': 2, 'P': 1}], [{'H': 4, 'Q': 1, 'D': 1, 'P': 4}]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) ...
342
281
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n grid where each cell can have one of three values: 0 representing an empty cell, 1 representing a fresh orange, or 2 representing a rotten orange. Every minute, any fresh orange that is 4-dire...
{"functional": "def check(candidate):\n assert candidate(grid = [[2,1,1],[1,1,0],[0,1,1]]) == 4\n assert candidate(grid = [[2,1,1],[0,1,1],[1,0,1]]) == -1\n assert candidate(grid = [[0,2]]) == 0\n\n\ncheck(Solution().orangesRotting)"}
135
91
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array of strings details. Each element of details provides information about a given passenger compressed into a string of length 15. The system is such that: The first ten characters consis...
{"functional": "def check(candidate):\n assert candidate(details = [\"7868190130M7522\",\"5303914400F9211\",\"9273338290F4010\"]) == 2\n assert candidate(details = [\"1313579440F2036\",\"2921522980M5644\"]) == 0\n\n\ncheck(Solution().countSeniors)"}
152
124
coding
Solve the programming task below in a Python markdown code block. Given a complete binary tree with the height of H, we index the nodes respectively top-down and left-right from 1. The i-th node stores a positive integer V_{i}. Define P_{i} as follows: P_{i}=V_{i} if the i-th node is a leaf, otherwise P_{i}=max(V_{i}*P...
{"inputs": ["2\n1 2 3\n3\n3 1 5 2 6 4 7\n0", "2\n1 2 3\n3\n3 1 1 2 6 4 7\n0", "2\n1 2 3\n3\n3 1 1 2 6 1 8\n0", "2\n1 2 1\n3\n3 1 1 2 3 1 8\n0", "2\n1 2 3\n3\n3 2 1 2 6 1 7\n0", "2\n1 2 1\n3\n4 1 1 2 3 1 8\n0", "2\n1 2 3\n3\n1 2 1 2 6 1 7\n0", "2\n2 2 3\n3\n3 1 1 2 6 4 7\n0"], "outputs": ["3\n105", "3\n21\n", "3\n24\n",...
347
278
coding
Solve the programming task below in a Python markdown code block. A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7. The Little Elephant has K favorite lucky strings A_{1}, A_{2}, ..., A_{K}. He thinks that the lucky string S is good if either |...
{"inputs": ["1 5\n52\n13\n486\n7\n1488\n894750131415894825036585194360843535399018392", "1 5\n52\n26\n2866\n7\n9112\n36086970008929625185698756226496234693333611129", "1 3\n7\n953\n744\n7\n10930\n141638385126219138109036667514165414693490507346", "2 4\n0\n548\n1250\n823\n8088\n124534097804456856492029119035654256201331...
731
646
coding
Solve the programming task below in a Python markdown code block. Pankhuri hates Algebra. Doesn't matter how hard she tries, she always fails to get good marks in her assessments. One of her marked assessments has been recently returned. She noticed that this time, the professor has only given per question marks and fi...
{"inputs": ["3 \n3 \n8 - 1 - 25\n2\n38 + 20\n4\n40 - 8 - 1 + 25"], "outputs": ["32\n58\n58"]}
616
56
coding
Solve the programming task below in a Python markdown code block. Chef is a private detective. He was asked to investigate a case of murder in the city of Frangton. Chef arrived in Frangton to find out that the mafia was involved in the case. Chef spent some time watching for people that belong to the clan and was able...
{"inputs": ["6\n0 1 1 2 2 3"], "outputs": ["4 5 6"]}
405
28
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array nums of positive integers. In one operation, you can choose any number from nums and reduce it to exactly half the number. (Note that you may choose this reduced number in future operations.) Re...
{"functional": "def check(candidate):\n assert candidate(nums = [5,19,8,1]) == 3\n assert candidate(nums = [3,8,20]) == 3\n\n\ncheck(Solution().halveArray)"}
109
56
coding
Solve the programming task below in a Python markdown code block. Lauren has a chart of distinct projected prices for a house over the next several years. She must buy the house in one year and sell it in another, and she must do so at a loss. She wants to minimize her financial loss. Example $price=[20,15,8,2,1...
{"inputs": ["3\n5 10 3\n", "5\n20 7 8 2 5\n"], "outputs": ["2\n", "2\n"]}
445
40
coding
Solve the programming task below in a Python markdown code block. Regex Failure - Bug Fixing #2 Oh no, Timmy's received some hate mail recently but he knows better. Help Timmy fix his regex filter so he can be awesome again! Also feel free to reuse/extend the following starter code: ```python def filter_words(phrase): ...
{"functional": "_inputs = [[\"You're Bad! timmy!\"], [\"You're MEAN! timmy!\"], [\"You're UGLY!! timmy!\"], [\"You're horrible! timmy!\"], [\"You're HiDeOuS!! timmy!\"]]\n_outputs = [[\"You're awesome! timmy!\"], [\"You're awesome! timmy!\"], [\"You're awesome!! timmy!\"], [\"You're awesome! timmy!\"], [\"You're awesom...
74
263
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array code of length of n and a key k. To decrypt the code, you must replace every number. All the numbers are re...
{"functional": "def check(candidate):\n assert candidate(code = [5,7,1,4], k = 3) == [12,10,16,13]\n assert candidate(code = [1,2,3,4], k = 0) == [0,0,0,0]\n assert candidate(code = [2,4,9,3], k = -2) == [12,5,6,13]\n\n\ncheck(Solution().decrypt)"}
214
114
coding
Solve the programming task below in a Python markdown code block. Monocarp has just learned a new card trick, and can't wait to present it to you. He shows you the entire deck of $n$ cards. You see that the values of cards from the topmost to the bottommost are integers $a_1, a_2, \dots, a_n$, and all values are differ...
{"inputs": ["3\n2\n1 2\n3\n1 1 1\n4\n3 1 4 2\n2\n3 1\n5\n2 1 5 4 3\n5\n3 2 1 2 1\n"], "outputs": ["2\n3\n3\n"]}
638
72
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. n evenly spaced points have been marked around the edge of a circle. There is a number written at each point. You choose a positive real number k. Then you may repeatedly select a set of 2 or more points which are evenly spaced, and either increase all n...
{"inputs": ["3\n000\n", "3\n007\n", "3\n007\n", "3\n000\n", "3\n111\n", "3\n100\n", "3\n001\n", "3\n101\n"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
404
102
coding
Solve the programming task below in a Python markdown code block. Given two numbers and an arithmetic operator (the name of it, as a string), return the result of the two numbers having that operator used on them. ```a``` and ```b``` will both be positive integers, and ```a``` will always be the first number in the o...
{"functional": "_inputs = [[1, 2, 'add'], [8, 2, 'subtract'], [5, 2, 'multiply'], [8, 2, 'divide']]\n_outputs = [[3], [6], [10], [4]]\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...
219
197
coding
Solve the programming task below in a Python markdown code block. You are given a number of sticks of varying lengths. You will iteratively cut the sticks into smaller sticks, discarding the shortest pieces until there are none left. At each iteration you will determine the length of the shortest stick remaining, cut...
{"inputs": ["6\n5 4 4 2 2 8\n", "8\n1 2 3 4 3 3 2 1\n"], "outputs": ["6\n4\n2\n1\n", "8\n6\n4\n1\n"]}
704
62
coding
Solve the programming task below in a Python markdown code block. You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above. The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner? -----Constraints----- - -40 \leq X \leq 40...
{"inputs": ["3", "1", "5", "0", "6", "2", "4", "8"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
129
62
coding
Solve the programming task below in a Python markdown code block. You are given an array of integers. Your task is to sort odd numbers within the array in ascending order, and even numbers in descending order. Note that zero is an even number. If you have an empty array, you need to return it. For example: ``` [5, 3...
{"functional": "_inputs = [[[5, 3, 2, 8, 1, 4, 11]], [[2, 22, 37, 11, 4, 1, 5, 0]], [[1, 111, 11, 11, 2, 1, 5, 0]], [[]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], [[0, 1, 2, 3, 4, 9, 8, 7, 6, 5]]]\n_outputs = [[[1, 3, 8, 4, 5, 2, 11]], [[22, 4, 1, 5, 2, 11, 37, 0]], [[1, 1, 5, 11, 2, 11, 111,...
162
486
coding
Solve the programming task below in a Python markdown code block. You are visiting a large electronics store to buy a refrigerator and a microwave. The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j-th microw...
{"inputs": ["2 2 1\n3 1\n3 5\n2 2 2", "2 2 1\n3 2\n3 8\n2 2 2", "2 4 0\n2 1\n1 5\n1 2 2", "2 4 0\n2 1\n0 5\n1 2 2", "2 2 1\n2 1\n3 5\n2 2 2", "2 2 1\n2 1\n3 8\n2 2 2", "2 2 1\n3 1\n3 8\n2 2 2", "2 4 1\n2 1\n3 5\n2 2 2"], "outputs": ["4\n", "5\n", "2\n", "1\n", "4\n", "4\n", "4\n", "4\n"]}
432
206
coding
Solve the programming task below in a Python markdown code block. Penny has an array of $n$ integers, $[a_0,a_1,\ldots,a_{n-1}]$. She wants to find the number of unique multisets she can form using elements from the array such that the bitwise XOR of all the elements of the multiset is a prime number. Recall that a mul...
{"inputs": ["1 \n3 \n3511 3671 4153 \n"], "outputs": ["4\n"]}
535
37
coding
Solve the programming task below in a Python markdown code block. As we know, Danny has a huge army and each time she wins a battle the size of her army is increased. Missandei, her advisor and Handmaiden, keeps the log of each battle and the amount and strength of soldiers won in a battle. Now, Danny has some questi...
{"inputs": ["5 3\n2 3 1 6 5\n1 2 3 4 5\n2 3\n1 1\n1 5"], "outputs": ["9\n2\n60"]}
481
51
coding
Solve the programming task below in a Python markdown code block. You are given two integers K and S. Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K. How many different assignments of values to X, Y and Z are there such that X + Y + Z = S? -----Constraints----- - 2≤K≤2500 - 0≤S≤3K - K and...
{"inputs": ["2 2\n", "5 15\n", "1050 0\n", "148 35\n", "602 293\n", "446 491\n", "2500 3750\n", "2500 7500\n"], "outputs": ["6\n", "1\n", "1\n", "666\n", "43365\n", "118173\n", "4691251\n", "1\n"]}
260
130
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array arr which consists of only zeros and ones, divide the array into three non-empty parts such that all of these parts represent the same binary value. If it is possible, return any [i, j] with i +...
{"functional": "def check(candidate):\n assert candidate(arr = [1,0,1,0,1]) == [0,3]\n assert candidate(arr = [1,1,0,1,1]) == [-1,-1]\n assert candidate(arr = [1,1,0,0,1]) == [0,2]\n\n\ncheck(Solution().threeEqualParts)"}
254
89
coding
Solve the programming task below in a Python markdown code block. -----Problem Statement----- Sereja has a sequence of n integers a[1], a[2], ..., a[n]. Sereja can do following transformation of the array: - create a new sequence of n integers b[1], b[2], ..., b[n]in this way: (1 ≤ i ≤ n) - Replace the sequence a ...
{"inputs": ["3\n1 1 1 1\n2 2 1 1\n2 3 1 1", "3\n0 1 1 1\n2 2 1 1\n2 3 1 1", "3\n0 1 1 1\n4 2 1 1\n2 3 1 1", "3\n0 1 1 1\n4 1 1 1\n2 3 1 1", "3\n1 1 1 1\n2 2 1 1\n2 3 1 1", "3\n-1 1 1 0\n4 1 1 1\n2 3 0 1", "3\n-1 1 1 1\n4 1 1 1\n2 3 1 1", "3\n-1 1 1 0\n4 1 1 1\n2 3 1 1"], "outputs": ["0\n2\n4", "0\n2\n4\n", "0\n14\n4\n"...
398
288
coding
Solve the programming task below in a Python markdown code block. There's a waiting room with N chairs set in single row. Chairs are consecutively numbered from 1 to N. First is closest to the entrance (which is exit as well). For some reason people choose a chair in the following way 1. Find a place as far from oth...
{"functional": "_inputs = [[10]]\n_outputs = [[9]]\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 all(_deep_eq(...
230
156
coding
Solve the programming task below in a Python markdown code block. Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. There are three friends; let's call them A, B, C. They made the following statements: A: "I have $x$ Rupees more than B." B: "I have $y$ rupees more than C."...
{"inputs": ["2\n1 2 1\n1 1 1"], "outputs": ["yes\nno"]}
512
26
coding
Solve the programming task below in a Python markdown code block. The Chef has reached the finals of the Annual Inter-school Declamation contest. For the finals, students were asked to prepare 10 topics. However, Chef was only able to prepare three topics, numbered A, B and C — he is totally blank about the other topi...
{"inputs": ["2 3 7 3", "4 6 8 5"], "outputs": ["Yes", "No"]}
468
30
coding
Solve the programming task below in a Python markdown code block. For given two circles $c1$ and $c2$, print 4 if they do not cross (there are 4 common tangent lines), 3 if they are circumscribed (there are 3 common tangent lines), 2 if they intersect (there are 2 common tangent lines), 1 if a circle is...
{"inputs": ["0 0 0\n1 0 2", "1 2 1\n3 4 2", "1 2 0\n4 2 2", "0 0 1\n0 1 2", "0 0 0\n0 0 2", "1 1 1\n9 2 2", "0 1 0\n0 0 2", "1 2 1\n5 4 2"], "outputs": ["0\n", "2\n", "4\n", "1\n", "0\n", "4\n", "0\n", "4\n"]}
413
142
coding
Solve the programming task below in a Python markdown code block. Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread. Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content...
{"inputs": ["1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "2\n0 0\n", "2\n1 0\n", "2\n1 0\n", "2\n1 1\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "0\n", "1\n", "1\n", "2\n"]}
466
94
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums and an integer k, find three non-overlapping subarrays of length k with maximum sum and return them. Return the result as a list of indices representing the starting position of each interv...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,1,2,6,7,5,1], k = 2) == [0,3,5]\n assert candidate(nums = [1,2,1,2,1,2,1,2,1], k = 2) == [0,2,4]\n\n\ncheck(Solution().maxSumOfThreeSubarrays)"}
118
97
coding
Solve the programming task below in a Python markdown code block. These days, chef is very much interested in Mathematics. He has started attending Recitations too! His hunger for problems is increasing day by day! Today, chef was a given a crumpled maths problem, which he is stuck with . He needs your help to do it He...
{"inputs": ["2\n10 3\n20 2"], "outputs": ["Case #1: 43\nCase #2: 180"]}
287
37
coding
Solve the programming task below in a Python markdown code block. The Collatz conjecture is one of the most famous one. Take any positive integer n, if it is even divide it by 2, if it is odd multiply it by 3 and add 1 and continue indefinitely.The conjecture is that whatever is n the sequence will reach 1. There is ma...
{"functional": "_inputs = [[0], [1], [4], [30], [1000], [1000000], ['a'], [-1], [['a']]]\n_outputs = [[[]], [[1, 1]], [[3, 8]], [[27, 112]], [[871, 179]], [[837799, 525]], [[]], [[]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, ...
470
241
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. A smelt fishing tournament was held at Lake Hibara. It seems that catch and release is recommended this time. Create a program that reads the participant number and the number of fish caught or released in order as one event, and outputs the participant...
{"inputs": ["3 5\n1 4\n2 5\n1 3\n3 4\n2 7", "3 5\n1 4\n2 3\n1 3\n3 6\n2 7", "3 5\n1 4\n2 3\n1 3\n3 6\n2 1", "3 5\n1 4\n2 3\n2 3\n3 6\n2 1", "3 5\n1 4\n2 0\n2 3\n3 6\n2 1", "3 5\n1 4\n2 5\n2 3\n3 4\n2 7", "3 5\n1 2\n2 3\n1 3\n3 6\n2 7", "3 5\n1 4\n2 3\n1 3\n3 8\n2 1"], "outputs": ["1 4\n2 5\n1 7\n1 7\n2 12\n", "1 4\n1 4...
321
386
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, return the least number of perfect square numbers that sum to n. A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For ...
{"functional": "def check(candidate):\n assert candidate(n = 12) == 3 \n assert candidate(n = 13) == 2\n\n\ncheck(Solution().numSquares)"}
123
47
coding
Solve the programming task below in a Python markdown code block. Polycarp has an array $a$ consisting of $n$ integers. He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains $n-1$ elements). For each...
{"inputs": ["5\n1 5 7 8 2\n", "5\n2 1 1 1 1\n", "5\n1 1 1 1 1\n", "5\n1 1 1 1 1\n", "5\n2 1 1 1 1\n", "5\n2 1 1 1 2\n", "5\n1 5 7 1 2\n", "5\n1 5 7 2 2\n"], "outputs": ["0\n", "2\n", "4\n", "4\n", "2\n", "0\n", "2\n", "0\n"]}
480
150
coding
Solve the programming task below in a Python markdown code block. You are given the firstname and lastname of a person on two different lines. Your task is to read them and print the following: Hello firstname lastname! You just delved into python. Function Description Complete the print_full_name function in th...
{"inputs": ["Ross\nTaylor\n"], "outputs": ["Hello Ross Taylor! You just delved into python.\n"]}
223
26
coding
Solve the programming task below in a Python markdown code block. G: Working Kou decided to do the same number of jobs every day for the next $ N $. $ A_i $ jobs are added on the $ i $ day of the $ N $ day. Mr. Kou has no work to do now, and he doesn't have to finish all the work by the $ N $ day. How many jobs can...
{"inputs": ["5\n4 2 5 3 0", "5\n4 2 3 3 0", "5\n6 2 3 3 0", "5\n6 3 0 3 0", "5\n6 3 0 2 0", "5\n8 3 0 2 0", "5\n9 3 0 2 0", "5\n9 3 0 4 0"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "3\n"]}
339
142
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
Solve the programming task below in a Python markdown code block. The Kingdom of Kremland is a tree (a connected undirected graph without cycles) consisting of $n$ vertices. Each vertex $i$ has its own value $a_i$. All vertices are connected in series by edges. Formally, for every $1 \leq i < n$ there is an edge betwee...
{"inputs": ["1\n1\n", "1\n1\n", "3\n2 1 3\n", "3\n2 1 2\n", "3\n2 0 2\n", "3\n3 0 2\n", "3\n2 1 3\n", "4\n2 1 1 3\n"], "outputs": ["1", "1\n", "7", "7\n", "8\n", "7\n", "7\n", "11"]}
674
110
coding
Solve the programming task below in a Python markdown code block. The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death...
{"inputs": ["1\nO\nO\n", "1\nX\nO\n", "1\nO\nO\n", "1\nX\nO\n", "2\nXX\nOO\nXO\nOX\n", "2\nOX\nXX\nOX\nXX\n", "2\nOX\nXO\nXO\nOX\n", "2\nOX\nOX\nXX\nOX\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "No\n", "No\n", "Yes\n", "Yes\n", "No\n"]}
449
121
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. Chef has opened a new airline. Chef has 10 airplanes where each airplane has a capacity of X passengers. On the first day itself, Y people are willing to book a seat in any one of Chef's airplanes. Given that Chef charges Z rupees for each ticket, fi...
{"inputs": ["4\n2 15 10\n1 10 1\n5 60 100\n1 11 7\n"], "outputs": ["150\n10\n5000\n70\n"]}
689
58
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string text of words that are placed among some number of spaces. Each word consists of one or more lowercase English letters and are separated by at least one space. It's guaranteed that text contains...
{"functional": "def check(candidate):\n assert candidate(text = \" this is a sentence \") == \"this is a sentence\"\n assert candidate(text = \" practice makes perfect\") == \"practice makes perfect \"\n assert candidate(text = \"hello world\") == \"hello world\"\n assert candidate(tex...
159
132
coding
Solve the programming task below in a Python markdown code block. As you might know, cooking is the process of taking a food item and subjecting it to various processes(like heating, roasting, baking etc). A food item gets prepared after it has been subjected to exactly N processes. The order in which the processes are...
{"inputs": ["3\n2 2\n2 3\n1 3", "3\n0 2\n2 3\n1 3", "3\n0 2\n2 3\n1 5", "3\n0 2\n2 5\n1 5", "3\n2 2\n2 3\n2 3", "3\n0 2\n2 4\n1 5", "3\n0 1\n2 5\n1 5", "3\n0 2\n3 4\n1 5"], "outputs": ["2\n18\n6", "2\n18\n6\n", "2\n18\n20\n", "2\n260\n20\n", "2\n18\n18\n", "2\n84\n20\n", "0\n260\n20\n", "2\n588\n20\n"]}
732
206
coding
Solve the programming task below in a Python markdown code block. Let's say we have a number, `num`. Find the number of values of `n` such that: there exists `n` consecutive **positive** values that sum up to `num`. A positive number is `> 0`. `n` can also be 1. ```python #Examples num = 1 #1 return 1 num = 15 #15, (...
{"functional": "_inputs = [[1], [15], [48], [97]]\n_outputs = [[1], [4], [2], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return Fal...
215
176
coding
Solve the programming task below in a Python markdown code block. Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bil...
{"inputs": ["4\n", "5\n", "1\n", "7\n", "7\n", "6\n", "1\n", "5\n"], "outputs": ["4\n", "1\n", "1\n", "3\n", "3\n", "2\n", "1\n", "1\n"]}
298
70
coding
Solve the programming task below in a Python markdown code block. Given an array $a=[a_1,a_2,\dots,a_n]$ of $n$ positive integers, you can do operations of two types on it: Add $1$ to every element with an odd index. In other words change the array as follows: $a_1 := a_1 +1, a_3 := a_3 + 1, a_5 := a_5+1, \dots$. Add...
{"inputs": ["1\n2\n514 514\n", "4\n3\n1 2 1\n4\n2 2 2 3\n4\n2 2 2 2\n5\n1000 1 1000 1 1000\n"], "outputs": ["YES\n", "YES\nNO\nYES\nYES\n"]}
708
87
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. We want to split a group of n people (labeled from 1 to n) into two groups of any size. Each person may dislike some other people, and they should not go into the same group. Given the integer n and the array dislikes...
{"functional": "def check(candidate):\n assert candidate(n = 4, dislikes = [[1,2],[1,3],[2,4]]) == True\n assert candidate(n = 3, dislikes = [[1,2],[1,3],[2,3]]) == False\n assert candidate(n = 5, dislikes = [[1,2],[2,3],[3,4],[4,5],[1,5]]) == False\n\n\ncheck(Solution().possibleBipartition)"}
147
108
coding
Solve the programming task below in a Python markdown code block. Daniel is watching a football team playing a game during their training session. They want to improve their passing skills during that session. The game involves $n$ players, making multiple passes towards each other. Unfortunately, since the balls were...
{"inputs": ["1\n2\n1000000000 0\n", "1\n5\n1000000000 1000000000 1000000000 1000000000 1000000000\n", "1\n6\n100000000 999999999 999999999 999999999 999999999 1000000000\n", "4\n4\n2 3 3 2\n3\n1 5 2\n2\n0 0\n4\n1000000000 1000000000 1000000000 1000000000\n", "1\n10\n1000000000 1000000000 1000000000 1000000000 100000000...
552
791
coding
Solve the programming task below in a Python markdown code block. You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on). You can reverse at most one subarray (continuous subsegment) of this array. Recall that t...
{"inputs": ["3\n5\n17 6 4 4 4\n7\n19 5 13 11 12 13 5\n1\n213567876\n", "3\n5\n17 6 4 4 4\n7\n19 5 13 11 12 13 5\n1\n213567876\n", "3\n5\n27 6 4 4 4\n7\n19 5 13 11 12 13 5\n1\n213567876\n", "3\n5\n27 6 4 4 4\n7\n36 2 13 11 12 13 8\n1\n213567876\n", "3\n5\n27 6 4 4 4\n7\n19 2 13 11 12 13 5\n1\n213567876\n", "3\n5\n27 6 4...
520
572
coding
Solve the programming task below in a Python markdown code block. We held two competitions: Coding Contest and Robot Maneuver. In each competition, the contestants taking the 3-rd, 2-nd, and 1-st places receive 100000, 200000, and 300000 yen (the currency of Japan), respectively. Furthermore, a contestant taking the f...
{"inputs": ["1 2", "4 5", "4 2", "2 2", "2 1", "5 4", "4 8", "9 3"], "outputs": ["500000\n", "0\n", "200000\n", "400000\n", "500000\n", "0\n", "0\n", "100000\n"]}
254
103
coding
Solve the programming task below in a Python markdown code block. # Task Imagine `n` horizontal lines and `m` vertical lines. Some of these lines intersect, creating rectangles. How many rectangles are there? # Examples For `n=2, m=2,` the result should be `1`. there is only one 1x1 rectangle. For `n=2, m=3`, the...
{"functional": "_inputs = [[2, 3], [2, 2], [1, 1], [0, 1], [3, 3], [100, 100]]\n_outputs = [[3], [1], [0], [0], [9], [24502500]]\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, tup...
274
213
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 intervals where intervals[i] = [starti, endi] represents all the integers from starti to endi inclusively. A containing set is an array nums where each interval from intervals has at l...
{"functional": "def check(candidate):\n assert candidate(intervals = [[1,3],[3,7],[8,9]]) == 5\n assert candidate(intervals = [[1,3],[1,4],[2,5],[3,5]]) == 3\n assert candidate(intervals = [[1,2],[2,3],[2,4],[4,5]]) == 5\n\n\ncheck(Solution().intersectionSizeTwo)"}
166
97
coding
Solve the programming task below in a Python markdown code block. You receive the name of a city as a string, and you need to return a string that shows how many times each letter shows up in the string by using an asterisk (`*`). For example: ``` "Chicago" --> "c:**,h:*,i:*,a:*,g:*,o:*" ``` As you can see, the le...
{"functional": "_inputs = [['Chicago'], ['Bangkok'], ['Las Vegas'], ['Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch']]\n_outputs = [['c:**,h:*,i:*,a:*,g:*,o:*'], ['b:*,a:*,n:*,g:*,k:**,o:*'], ['l:*,a:**,s:**,v:*,e:*,g:*'], ['l:***********,a:***,n:****,f:*,i:***,r:****,p:*,w:****,g:*******,y:*****,o:******,...
263
309
coding
Solve the programming task below in a Python markdown code block. Katsusando loves omelette rice. Besides, he loves crème brûlée, tenderloin steak and so on, and believes that these foods are all loved by everyone. To prove that hypothesis, he conducted a survey on M kinds of foods and asked N people whether they like ...
{"inputs": ["1 50\n1 4 3 1", "1 52\n5 9 7 8", "1 50\n1 7 6 3", "1 30\n5 4 2 30", "1 30\n6 4 2 30", "1 30\n3 2 3 30", "1 30\n6 6 2 30", "1 30\n5 4 10 6"], "outputs": ["3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n"]}
363
155
coding
Solve the programming task below in a Python markdown code block. Petya has n positive integers a_1, a_2, ..., a_{n}. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one lette...
{"inputs": ["1\nh\n", "1\na\n", "1\na\n", "1\nh\n", "1\nb\n", "1\ni\n", "1\nc\n", "2\na\na\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n"]}
556
88
coding
Solve the programming task below in a Python markdown code block. You are given a permutation p consisting of n integers 1, 2, ..., n (a permutation is an array where each element from 1 to n occurs exactly once). Let's call an array a bipartite if the following undirected graph is bipartite: * the graph consists o...
{"inputs": ["4\n3\n1 2 3\n6\n1 3 2 6 5 4\n4\n4 1 3 2\n8\n3 2 1 6 7 8 5 4\n", "4\n3\n1 2 3\n6\n1 3 2 6 5 4\n4\n4 1 3 2\n8\n3 0 1 6 7 8 5 4\n", "4\n3\n1 2 3\n6\n1 3 2 6 5 4\n4\n4 1 3 2\n8\n3 2 1 6 7 1 5 4\n", "4\n3\n1 2 0\n6\n1 3 2 6 5 4\n4\n4 1 3 2\n8\n3 0 1 6 7 8 5 4\n", "4\n3\n1 2 3\n6\n1 3 2 6 5 1\n4\n4 1 3 2\n8\n3 2...
403
722
coding
Solve the programming task below in a Python markdown code block. Madison is a little girl who is fond of toys. Her friend Mason works in a toy manufacturing factory . Mason has a 2D board $\mbox{A}$ of size $H\times W$ with $\mbox{H}$ rows and $\mbox{W}$ columns. The board is divided into cells of size $1\times1$ with...
{"inputs": ["1 1\n1\n", "3 3\n1 3 4\n2 2 3\n1 2 4\n"], "outputs": ["6\n", "60\n"]}
506
47
coding
Solve the programming task below in a Python markdown code block. Chef is on his way to become the new big bull of the stock market but is a bit weak at calculating whether he made a profit or a loss on his deal. Given that Chef bought the stock at value X and sold it at value Y. Help him calculate whether he made a p...
{"inputs": ["4\n4 2\n8 8\n3 4\n2 1\n"], "outputs": ["LOSS\nNEUTRAL\nPROFIT\nLOSS\n"]}
372
39
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Sheokand loves strings. Chef has $N$ strings $S_{1}, S_{2}, \dots, S_{N}$ which he wants to give to Sheokand; however, he doesn't want to give them away for free, so Sheokand...
{"inputs": ["4\nabcd\nabce\nabcdex\nabcde\n3\n3 abcy\n3 abcde\n4 abcde"], "outputs": ["abcd\nabcdex\nabcde"]}
630
43
coding
Solve the programming task below in a Python markdown code block. There is data that records the customer number of the business partner and the trading date on a monthly basis. Please create a program that reads this month's data and last month's data and outputs the customer number of the company with which you have ...
{"inputs": ["123,10\n56,12\n35,14\n\n123,3\n56,4\n123,5", "123,10\n56,12\n45,13\n\n113,4\n56,4\n123,5", "132,10\n56,12\n45,13\n\n113,4\n56,4\n123,5", "123,10\n51,62\n34,14\n\n124,3\n56,4\n123,5", "123,10\n65,12\n34,14\n\n123,3\n56,4\n123,5", "123,10\n57,12\n35,14\n\n123,3\n57,4\n123,5", "0032,1\n56,12\n21,45\n\n12,34\n...
261
391
coding
Solve the programming task below in a Python markdown code block. Vasya decided to go to the grocery store. He found in his wallet $a$ coins of $1$ burle and $b$ coins of $2$ burles. He does not yet know the total cost of all goods, so help him find out $s$ ($s > 0$): the minimum positive integer amount of money he can...
{"inputs": ["1\n69 74\n", "1\n99 101\n", "1\n3947394 7\n", "1\n3534 1834\n", "1\n9999999 0\n", "1\n12345 12345\n", "1\n112311 11332\n", "1\n1223111 133212\n"], "outputs": ["218\n", "302\n", "3947409\n", "7203\n", "10000000\n", "37036\n", "134976\n", "1489536\n"]}
567
188
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Write an algorithm to print all ways of arranging n queens on an n x n chess board so that none of them share the same row, column, or diagonal. In this case, "diagonal" means all diagonals, not just the two that bise...
{"functional": "def check(candidate):\n assert candidate(4) == [[\".Q..\",\"...Q\",\"Q...\",\"..Q.\"],[\"..Q.\",\"Q...\",\"...Q\",\".Q..\"]]\n\n\ncheck(Solution().solveNQueens)"}
125
62
coding
Solve the programming task below in a Python markdown code block. Vlad went into his appartment house entrance, now he is on the $1$-th floor. He was going to call the elevator to go up to his apartment. There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor ...
{"inputs": ["1\n1902 3 5\n", "1\n2001 1 2\n", "1\n2001 1 3\n", "1\n5086 1 2\n", "1\n2002 1 2\n", "1\n2003 3 2\n", "1\n2002 2 3\n", "1\n5086 5607 4560\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "1\n"]}
598
148
coding
Solve the programming task below in a Python markdown code block. You are batting at the pitch and all eyes are on you, the best player in all of IPL! The opposing team will relentlessly bowl at you an infinite number of balls! You notice that you only ever score a boundary on the M^{th} ball, if N mod M ≤ N/2, where ...
{"inputs": ["1\n3"], "outputs": ["3"]}
313
14
coding
Solve the programming task below in a Python markdown code block. Find a cycle in a directed graph G(V, E). Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 1,000 * si ≠ ti Input A directed graph G is given in the following format: |V| |E| s0 t0 s1 t1 : s|E|-1 t|E|-1 |V| is the number of nodes and |E| is the number of e...
{"inputs": ["5 3\n0 1\n0 2\n1 2", "8 3\n0 1\n0 2\n1 2", "8 3\n0 2\n0 2\n1 2", "5 3\n0 2\n0 2\n1 2", "8 2\n0 1\n0 2\n1 2", "8 3\n1 2\n0 2\n1 2", "8 2\n0 1\n0 2\n1 4", "8 2\n0 1\n0 2\n2 4"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
219
174
coding
Solve the programming task below in a Python markdown code block. Find the last element of the given argument(s). ## Examples ```python last([1, 2, 3, 4]) ==> 4 last("xyz") ==> "z" last(1, 2, 3, 4) ==> 4 ``` In **javascript** and **CoffeeScript** a **list** will be an `array`, a `string` or the list of `ar...
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [['a', 'b', 'c', 'k', 'x', 'y', 'z']], ['abckxyz'], ['a', 'b', 'c', 'z']]\n_outputs = [[10], [10], ['z'], ['z'], ['z']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
157
264
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. You are given an array consisting of all integers from $[l, r]$ inclusive. For example, if $l = 2$ and $r = 5$, the array would be $[2, 3, 4, 5]$. What's the minimum number of elements you can delete to make the bitwise AND of the array non-zero? A bitw...
{"inputs": ["5\n1 2\n2 8\n4 5\n1 5\n100000 200000\n", "5\n1 2\n2 8\n4 5\n2 5\n100000 200000\n", "5\n1 2\n2 8\n4 5\n4 5\n100000 200000\n", "5\n2 2\n2 8\n4 5\n2 5\n100000 200000\n", "5\n1 2\n2 8\n4 5\n4 5\n110000 200000\n", "5\n2 2\n2 8\n4 5\n2 5\n100100 200000\n", "5\n1 2\n2 8\n4 5\n1 5\n100001 200000\n", "5\n1 2\n2 8\n...
486
402
coding
Solve the programming task below in a Python markdown code block. You are given an array a of size n, and q queries to it. There are queries of two types: 1 l_{i} r_{i} — perform a cyclic shift of the segment [l_{i}, r_{i}] to the right. That is, for every x such that l_{i} ≤ x < r_{i} new value of a_{x} + 1 becomes ...
{"inputs": ["1 1 1\n474812122\n2 1 1\n1\n", "1 1 1\n474812122\n2 1 1\n1\n", "1 1 1\n474812122\n4 1 1\n1\n", "1 1 1\n474702042\n5 1 1\n1\n", "1 1 1\n474812122\n5 1 1\n1\n", "5 2 5\n64 3 4 665 2\n1 1 3\n2 1 5\n1 2 3 4 5\n", "5 2 5\n64 3 4 665 2\n1 1 3\n2 1 5\n1 2 3 4 5\n", "5 2 5\n64 3 1 665 2\n1 1 3\n2 1 5\n1 2 3 4 5\n"...
497
370
coding
Solve the programming task below in a Python markdown code block. The Chef commutes to work every day using the city's underground metro. The schedule for the trains has recently been changed and he wants to know how long it will take to travel from the station nearest to his house and the station nearest to his restau...
{"inputs": ["3\n2\n1 1 7\n0 6 5\n2\n0 1 1\n0 1 1\n2\n0 2 3\n0 1 3", "3\n2\n0 4 7\n0 6 5\n2\n0 1 2\n6 2 10\n2\n1 2 3\n0 2 3", "3\n2\n0 4 7\n0 6 5\n2\n0 1 2\n6 2 10\n2\n1 2 5\n0 2 3", "3\n2\n0 4 7\n0 6 5\n2\n0 1 2\n6 4 10\n2\n1 2 5\n0 2 3", "3\n2\n0 3 7\n0 6 5\n2\n0 1 2\n8 4 10\n2\n1 1 5\n0 2 3", "3\n2\n0 3 7\n0 6 5\n2\n...
737
448
coding
Solve the programming task below in a Python markdown code block. You are given a binary array$^{\dagger}$ of length $n$. You are allowed to perform one operation on it at most once. In an operation, you can choose any element and flip it: turn a $0$ into a $1$ or vice-versa. What is the maximum number of inversions$^...
{"inputs": ["5\n4\n1 0 1 0\n6\n0 1 0 0 1 0\n2\n0 0\n8\n1 0 1 1 0 0 0 1\n3\n1 1 1\n"], "outputs": ["3\n7\n1\n13\n2\n"]}
635
79
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef had a hard time arguing with his friend, and after getting a great old kick Chef saw a colored array with N cells, numbered from 1 to N. The kick was so strong that Chef suddenly understo...
{"inputs": ["1\n4 2 1\n1 1 2 2\n1 1\n1 1\n1 1\n3 1\n0 1\n0 1\n1 0\n1 0", "1\n4 2 1\n1 1 2 2\n1 1\n1 1\n1 1\n3 1\n0 1\n0 1\n1 0\n1 0"], "outputs": ["5", "5"]}
728
110
coding
Solve the programming task below in a Python markdown code block. Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to $1$ meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously ...
{"inputs": ["5\nNNN\nNS\nWWEN\nWWEE\nNWNWS\n", "5\nNNN\nNS\nWWEN\nEEWW\nNWNWS\n", "5\nNNN\nNS\nWWEN\nEWEW\nNWNWS\n", "5\nNNN\nNS\nWWEN\nEWEW\nNSNWW\n", "5\nNNN\nNS\nNEWW\nWWEE\nNSNWW\n", "5\nNNN\nNS\nNEWW\nEEWW\nSNNWW\n", "5\nNNN\nNS\nWEWN\nEWWE\nSWNWN\n", "5\nNNN\nNS\nENWW\nWWEE\nSNNWW\n"], "outputs": ["15\n6\n16\n12\...
319
286
coding
Solve the programming task below in a Python markdown code block. In this Kata, you're to complete the function `sum_square_even_root_odd`. You will be given a list of numbers, `nums`, as the only argument to the function. Take each number in the list and *square* it if it is even, or *square root* the number if it is...
{"functional": "_inputs = [[[4, 5, 7, 8, 1, 2, 3, 0]], [[1, 14, 9, 8, 17, 21]]]\n_outputs = [[91.61], [272.71]]\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...
141
211
coding
Solve the programming task below in a Python markdown code block. Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meet...
{"inputs": ["1\n?\n", "1\nq\n", "1\np\n", "1\nr\n", "1\ns\n", "1\nt\n", "1\nu\n", "1\no\n"], "outputs": ["a", "q", "p\n", "r\n", "s\n", "t\n", "u\n", "o\n"]}
487
84
coding
Solve the programming task below in a Python markdown code block. Nikita has a row of $N$ white tiles indexed from $\mbox{1}$ to $N$. This time, she's painting them green! Find the number of ways Nikita can paint certain tiles in green so that the indices of the green tiles form an Arithmetic Progression. As this val...
{"inputs": ["3\n3\n4\n5\n"], "outputs": ["7\n13\n22\n"]}
454
26
coding
Solve the programming task below in a Python markdown code block. # Task Christmas is coming. In the [previous kata](https://www.codewars.com/kata/5a405ba4e1ce0e1d7800012e), we build a custom Christmas tree with the specified characters and the specified height. Now, we are interested in the center of the Christmas t...
{"functional": "_inputs = [[''], ['a'], ['ab'], ['abc'], ['abab'], ['abcde'], ['aaaaaaaaaaaaaa'], ['abaabaaab'], ['dbdbebedbddbedededeeddbbdeddbeddeebdeddeebbbb'], ['vttussvutvuvvtustsvsvtvu']]\n_outputs = [[''], ['a'], ['a'], ['aba'], ['a'], ['aecea'], ['a'], ['aba'], ['deededebddeebeddeddeddbddeddeddebeeddbededeed'],...
593
266
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two positive integer arrays nums1 and nums2, both of length n. The absolute sum difference of arrays nums1 and nums2 is defined as the sum of |nums1[i] - nums2[i]| for each 0 <= i < n (0-indexed). You ca...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,7,5], nums2 = [2,3,5]) == 3\n assert candidate(nums1 = [2,4,6,8,10], nums2 = [2,4,6,8,10]) == 0\n assert candidate(nums1 = [1,10,4,4,2,7], nums2 = [9,3,5,1,7,4]) == 20\n\n\ncheck(Solution().minAbsoluteSumDiff)"}
197
126
coding
Solve the programming task below in a Python markdown code block. Chef is making polygon cakes in his kitchen today! Since the judge panel is very strict, Chef's cakes must be beautiful and have sharp and precise $internal$ angles in arithmetic progression. Given the number of sides, $N$, of the cake Chef is baking t...
{"inputs": ["1\n3 30 2"], "outputs": ["60 1"]}
312
22
coding
Solve the programming task below in a Python markdown code block. There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = E, and west if S_i = W. You will appoint on...
{"inputs": ["5\nWEEWW\n", "8\nWWWWWEEE\n", "12\nWEWEWEEEWWWE\n"], "outputs": ["1\n", "3\n", "4\n"]}
333
46
coding
Solve the programming task below in a Python markdown code block. The princess is going to escape the dragon's cave, and she needs to plan it carefully. The princess runs at vp miles per hour, and the dragon flies at vd miles per hour. The dragon will discover the escape after t hours and will chase the princess immed...
{"inputs": ["1\n2\n1\n1\n6\n", "1\n2\n2\n1\n8\n", "1\n2\n1\n1\n8\n", "2\n1\n1\n1\n10\n", "2\n2\n1\n1\n10\n", "1\n2\n1\n1\n10\n", "83\n7\n7\n7\n46\n", "5\n3\n3\n3\n999\n"], "outputs": ["1\n", "1\n", "1\n", "0\n", "0\n", "2\n", "0\n", "0\n"]}
532
141
coding
Solve the programming task below in a Python markdown code block. The Chessboard Distance for any two points (X_{1}, Y_{1}) and (X_{2}, Y_{2}) on a Cartesian plane is defined as max(|X_{1} - X_{2}|, |Y_{1} - Y_{2}|). You are given two points (X_{1}, Y_{1}) and (X_{2}, Y_{2}). Output their Chessboard Distance. Note ...
{"inputs": ["3\n2 4 5 1\n5 5 5 3\n1 4 3 3\n"], "outputs": ["3\n2\n2\n"]}
513
42
coding
Solve the programming task below in a Python markdown code block. I assume most of you are familiar with the ancient legend of the rice (but I see wikipedia suggests [wheat](https://en.wikipedia.org/wiki/Wheat_and_chessboard_problem), for some reason) problem, but a quick recap for you: a young man asks as a compensati...
{"functional": "_inputs = [[0], [1], [2], [3], [4]]\n_outputs = [[0], [1], [2], [2], [3]]\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): ret...
311
179
coding
Solve the programming task below in a Python markdown code block. WW3 is near and Gru wants to recruit minions for his team. Gru went to the planet of minions to recruit minions, he saw that there are two villages separated by a river. He cannot recruit minions from both villages because then his team will have interna...
{"inputs": ["3\n1 0\n0 5 5\n0 6 5\n0 -8 20"], "outputs": ["20"]}
360
36
coding
Solve the programming task below in a Python markdown code block. In the world of birding there are four-letter codes for the common names of birds. These codes are created by some simple rules: * If the bird's name has only one word, the code takes the first four letters of that word. * If the name is made up of two...
{"functional": "_inputs = [[['American Redstart', 'Northern Cardinal', 'Pine Grosbeak', 'Barred Owl', 'Starling', \"Cooper's Hawk\", 'Pigeon']], [['Great Crested Flycatcher', 'Bobolink', 'American White Pelican', 'Red-Tailed Hawk', 'Eastern Screech Owl', 'Blue Jay']], [['Black-Crowned Night Heron', 'Northern Mockingbir...
316
476
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 is an undirected graph with n vertices, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connect...
{"functional": "def check(candidate):\n assert candidate(n = 6, edges = [[0,1],[0,2],[1,2],[3,4]]) == 3\n assert candidate(n = 6, edges = [[0,1],[0,2],[1,2],[3,4],[3,5]]) == 1\n\n\ncheck(Solution().countCompleteComponents)"}
186
86
coding
Solve the programming task below in a Python markdown code block. A total of n depots are located on a number line. Depot i lies at the point x_i for 1 ≤ i ≤ n. You are a salesman with n bags of goods, attempting to deliver one bag to each of the n depots. You and the n bags are initially at the origin 0. You can carr...
{"inputs": ["4\n5 1\n1 1 3 4 1\n9 3\n-9 -6 -6 6 5 8 3 7 4\n5 3\n1 1 6 3 4\n4 2\n1000000000 1000000000 1000000000 1010100000\n", "4\n5 1\n1 1 3 4 1\n9 3\n-9 -18 -6 6 6 8 3 7 4\n5 3\n1 2 6 3 4\n4 2\n1000000010 1000000000 1000000000 1000000000\n", "4\n5 1\n1 1 3 4 1\n9 3\n-9 -22 -6 6 6 8 3 7 4\n5 3\n1 2 6 3 4\n4 2\n100000...
670
1,010
coding
Solve the programming task below in a Python markdown code block. Some large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMSC. For that, he asked to give him the sta...
{"inputs": ["1\n1 1\n", "1\n1 1\n", "2\n1 1\n2 1\n", "2\n1 1\n4 1\n", "2\n1 1\n4 2\n", "2\n1 1\n4 4\n", "2\n1 2\n4 6\n", "2\n2 3\n4 9\n"], "outputs": ["2 1\n", "2 1", "3 1\n", "5 1\n", "6 2\n", "8 4\n", "10 6\n", "14 10\n"]}
759
144
coding
Solve the programming task below in a Python markdown code block. An onion array is an array that satisfies the following condition for all values of `j` and `k`: If all of the following are `true`: * `j >= 0` * `k >= 0` * `j + k = array.length - 1` * `j != k` then: * `a[j] + a[k] <= 10` ### Examples: ``` [1, 2...
{"functional": "_inputs = [[[6, 0, 4]], [[1, 1, 15, 10, -1]]]\n_outputs = [[True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): r...
274
182
coding
Solve the programming task below in a Python markdown code block. Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when represent...
{"inputs": ["1 3", "1 6", "3 2", "4 5", "1 2", "3 10", "3 14", "2 14"], "outputs": ["3\n", "6\n", "2\n", "5\n", "2", "10\n", "14\n", "7\n"]}
295
82