problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the string croakOfFrogs, which represents a combination of the string "croak" from different frogs, that is, multiple frogs can croak at the same time, so multiple "croak" are mixed. Return the minimum n...
{"functional": "def check(candidate):\n assert candidate(croakOfFrogs = \"croakcroak\") == 1 \n assert candidate(croakOfFrogs = \"crcoakroak\") == 2 \n assert candidate(croakOfFrogs = \"croakcrook\") == -1\n\n\ncheck(Solution().minNumberOfFrogs)"}
coding
186
Solve the programming task below in a Python markdown code block. We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? -----Const...
{"inputs": ["4 3\n6 3 -4 -2", "4 3\n6 1 -4 -2", "4 3\n3 1 -4 -5", "4 5\n6 3 -4 -2", "4 3\n6 1 -1 -2", "4 5\n6 3 -7 -2", "4 3\n3 3 -4 -2", "4 3\n3 3 -4 -2\n"], "outputs": ["-12\n", "-4\n", "-5\n", "8\n", "-2\n", "14\n", "-6", "-6\n"]}
coding
297
Solve the programming task below in a Python markdown code block. Write a function that takes a string and returns an array of the repeated characters (letters, numbers, whitespace) in the string. If a charater is repeated more than once, only show it once in the result array. Characters should be shown **by the orde...
{"functional": "_inputs = [['apple'], ['limbojackassin the garden'], ['11pinguin'], ['Claustrophobic'], ['apPle'], ['11 pinguin'], ['pippi'], ['Pippi'], ['kamehameha'], ['']]\n_outputs = [[['p']], [['a', 's', 'i', ' ', 'e', 'n']], [['1', 'i', 'n']], [['o']], [[]], [['1', 'i', 'n']], [['p', 'i']], [['p', 'i']], [['a', '...
coding
203
Solve the programming task below in a Python markdown code block. # SpeedCode #2 - Array Madness ## Objective Given two **integer arrays** ```a, b```, both of ```length >= 1```, create a program that returns ```true``` if the **sum of the squares** of each element in ```a``` is **strictly greater than** the **sum of ...
{"functional": "_inputs = [[[4, 5, 6], [1, 2, 3]]]\n_outputs = [[True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ...
coding
203
Solve the programming task below in a Python markdown code block. A permutation of length n is an array containing each integer from 1 to n exactly once. For example, q = [4, 5, 1, 2, 3] is a permutation. For the permutation q the square of permutation is the permutation p that p[i] = q[q[i]] for each i = 1... n. For e...
{"inputs": ["1\n1\n", "1\n1\n", "1\n1\n", "4\n2 1 4 3\n", "4\n2 1 3 4\n", "4\n1 2 4 3\n", "4\n1 4 2 3\n", "4\n3 1 2 4\n"], "outputs": ["1\n", "1\n", "1\n", "3 4 2 1\n", "-1\n", "-1\n", "1 3 4 2\n", "2 3 1 4\n"]}
coding
371
Solve the programming task below in a Python markdown code block. Are you fond of collecting some kind of stuff? Mike is crazy about collecting stamps. He is an active member of Stamp Collecting Сommunity(SCC). SCC consists of N members which are fond of philately. A few days ago Mike argued with the others from SCC....
{"inputs": ["5\n1 1 1 1 0", "5\n1 2 1 1 0", "5\n0 2 1 1 0", "5\n0 3 1 1 0", "5\n0 3 1 0 0", "5\n0 3 1 0 1", "5\n0 3 0 0 1", "5\n0 3 0 0 0"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
312
Solve the programming task below in a Python markdown code block. A programming competition site AtCode provides algorithmic problems. Each problem is allocated a score based on its difficulty. Currently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points. These p_1 + … +...
{"inputs": ["1 100\n1 100\n", "2 431\n3 500\n5 800", "2 110\n3 500\n5 800", "2 431\n3 896\n5 800", "2 400\n3 500\n5 800", "2 700\n3 500\n5 800", "2 700\n3 500\n5 800\n", "2 400\n3 500\n5 800\n"], "outputs": ["1\n", "3\n", "1\n", "3\n", "2", "3", "3\n", "2\n"]}
coding
575
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Vietnamese], and [Russian] as well. Alice and Bob play the classic game of odds and evens. In this game, each of the two players choose a number between 1 and 5 without revealing to their opponent. Both of the pla...
{"inputs": ["2\n1 1\n1 2\n"], "outputs": ["Bob\nAlice\n"]}
coding
346
Solve the programming task below in a Python markdown code block. Pig Latin is an English language game where the goal is to hide the meaning of a word from people not aware of the rules. So, the goal of this kata is to wite a function that encodes a single word string to pig latin. The rules themselves are rather ea...
{"functional": "_inputs = [['Hello'], ['CCCC'], ['tes3t5'], ['ay'], [''], ['YA'], ['123'], ['ya1'], ['yaYAya'], ['YayayA']]\n_outputs = [['ellohay'], ['ccccay'], [None], ['ayway'], [None], ['ayay'], [None], [None], ['ayayayay'], ['ayayayay']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or i...
coding
272
Solve the programming task below in a Python markdown code block. After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency. These were the great news for Alice, whose grand...
{"inputs": ["3\n13 7 6\n6 2\n", "3\n13 2 6\n6 2\n", "3\n23 2 2\n6 2\n", "3\n23 2 4\n6 6\n", "3\n13 2 2\n6 2\n", "3\n23 2 2\n6 3\n", "3\n23 2 4\n6 3\n", "3\n20 7 6\n6 2\n"], "outputs": ["4\n", "2\n", "6\n", "12\n", "2\n", "6\n", "6\n", "6\n"]}
coding
490
Solve the programming task below in a Python markdown code block. Snuke is buying a lamp. The light of the lamp can be adjusted to m levels of brightness, represented by integers from 1 through m, by the two buttons on the remote control. The first button is a "forward" button. When this button is pressed, the brightne...
{"inputs": ["4 8\n1 5 1 4", "4 8\n1 5 1 5", "1 8\n1 5 2 1", "4 6\n0 5 1 4", "4 6\n2 3 2 1", "2 8\n1 5 1 5", "2 8\n1 5 1 0", "2 8\n1 5 1 1"], "outputs": ["7\n", "6\n", "0\n", "5\n", "4\n", "1\n", "1\n", "1\n"]}
coding
462
Solve the programming task below in a Python markdown code block. Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters. There is a filler word ogo in Oleg's speech. All words t...
{"inputs": ["1\no\n", "1\na\n", "1\ng\n", "1\nz\n", "1\no\n", "1\ng\n", "1\nz\n", "1\na\n"], "outputs": ["o\n", "a\n", "g\n", "z\n", "o\n", "g\n", "z\n", "a\n"]}
coding
411
Please solve the programming task below using a self-contained code snippet in a markdown code block. In the universe Earth C-137, Rick discovered a special form of magnetic force between two balls if they are put in his new invented basket. Rick has n empty baskets, the ith basket is at position[i], Morty has m balls...
{"functional": "def check(candidate):\n assert candidate(position = [1,2,3,4,7], m = 3) == 3\n assert candidate(position = [5,4,3,2,1,1000000000], m = 2) == 999999999\n\n\ncheck(Solution().maxDistance)"}
coding
159
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\...
coding
608
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n servers numbered from 0 to n - 1 connected by undirected server-to-server connections forming a network where connections[i] = [ai, bi] represents a connection between servers ai and bi. Any server can rea...
{"functional": "def check(candidate):\n assert candidate(n = 4, connections = [[0,1],[1,2],[2,0],[1,3]]) == [[1,3]]\n assert candidate(n = 2, connections = [[0,1]]) == [[0,1]]\n\n\ncheck(Solution().criticalConnections)"}
coding
144
Solve the programming task below in a Python markdown code block. Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now. Sasha and Masha are about...
{"inputs": ["5 4 3\n", "6 8 2\n", "0 0 1\n", "0 1 1\n", "1 0 1\n", "9 7 5\n", "4 4 8\n", "0 0 1\n"], "outputs": ["3 1\n", "7 0\n", "0 0\n", "1 0\n", "1 0\n", "3 1\n", "1 4\n", "0 0\n"]}
coding
639
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space. Return a string of the words in reverse order c...
{"functional": "def check(candidate):\n assert candidate(s = \"the sky is blue\") == \"blue is sky the\"\n assert candidate(s = \" \u00a0hello world \u00a0\") == \"world hello\"\n assert candidate(s = \"a good \u00a0 example\") == \"example good a\"\n\n\ncheck(Solution().reverseWords)"}
coding
136
Solve the programming task below in a Python markdown code block. Chef and Paja are bored, so they are playing an infinite game of ping pong. The rules of the game are as follows: - The players play an infinite number of games. At the end of each game, the player who won it scores a point. - In each game, one of the pl...
{"inputs": ["3\n1 3 3\n5 7 2\n38657 76322 564"], "outputs": ["Paja\nChef\nPaja"]}
coding
465
Solve the programming task below in a Python markdown code block. The snail crawls up the column. During the day it crawls up some distance. During the night she sleeps, so she slides down for some distance (less than crawls up during the day). Your function takes three arguments: 1. The height of the column (meters) ...
{"functional": "_inputs = [[3, 2, 1], [10, 3, 1], [10, 3, 2], [100, 20, 5], [5, 10, 3]]\n_outputs = [[2], [5], [8], [7], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)...
coding
147
Solve the programming task below in a Python markdown code block. Converting a 24-hour time like "0830" or "2030" to a 12-hour time (like "8:30 am" or "8:30 pm") sounds easy enough, right? Well, let's see if you can do it! You will have to define a function named "to12hourtime", and you will be given a four digit tim...
{"functional": "_inputs = [['0000'], ['0001'], ['0002'], ['0003'], ['0004'], ['0005'], ['0006'], ['0007'], ['0008'], ['0009'], ['0010'], ['0011'], ['0012'], ['0013'], ['0014'], ['0015'], ['0016'], ['0017'], ['0018'], ['0019'], ['0020'], ['0021'], ['0022'], ['0023'], ['0024'], ['0025'], ['0026'], ['0027'], ['0028'], ['0...
coding
232
Solve the programming task below in a Python markdown code block. DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value w_{c}. For each special string s = s_1s_2... s_{|}s| (|s| is the length of the string) he represents its value with a function f(s)...
{"inputs": ["a\n0\n5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "a\n0\n5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "a\n0\n5 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "a\n1\n5 1 1 1 1 1 1 0 2 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1\n", "a\n0\n5 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1...
coding
370
Solve the programming task below in a Python markdown code block. Chef has an array of N natural numbers most of them are repeated. Cheffina challenges chef to find all numbers(in ascending order) whose frequency is strictly more than K. -----Input:----- - First-line will contain $T$, the number of test cases. Then th...
{"inputs": ["1\n5 1\n5 2 1 2 5"], "outputs": ["2 5"]}
coding
196
Solve the programming task below in a Python markdown code block. Consider the infinite sequence $s$ of positive integers, created by repeating the following steps: Find the lexicographically smallest triple of positive integers $(a, b, c)$ such that $a \oplus b \oplus c = 0$, where $\oplus$ denotes the bitwise XO...
{"inputs": ["9\n1\n2\n3\n4\n5\n6\n7\n8\n9\n", "9\n1\n3\n3\n4\n5\n6\n7\n8\n9\n", "9\n1\n5\n3\n4\n5\n6\n7\n8\n9\n", "9\n1\n3\n3\n2\n5\n6\n7\n8\n9\n", "9\n1\n3\n3\n2\n7\n6\n7\n8\n9\n", "9\n2\n3\n3\n2\n7\n6\n7\n8\n9\n", "9\n1\n2\n3\n4\n6\n6\n7\n8\n9\n", "9\n1\n3\n3\n4\n3\n6\n7\n8\n9\n"], "outputs": ["1\n2\n3\n4\n8\n12\n5\n...
coding
469
Solve the programming task below in a Python markdown code block. Write a program which converts uppercase/lowercase letters to lowercase/uppercase for a given string. Constraints * The length of the input string < 1200 Input A string is given in a line. Output Print the converted string in a line. Note that you ...
{"inputs": ["f@IR, LATER, OCCASIONALLY CLOUDY.", "f@IR, LATER, YLLANOISACCO CLOUDY.", "f@IR, LATER, OLLANOISACCY CLOUDY.", "f@IR, LATER, OLKANOISACCY CLOUDY.", ",RI@f LATER, OLKANOISACCY CLOUDY.", ",RI@f KATER, OLKANOISACCY CLOUDY.", ",RI@g KATER, OLKANOISACCY CLOUDY.", ",RI@g KATER, OLKANOISACCY CLOUDX."], "outputs": ...
coding
110
Please solve the programming task below using a self-contained code snippet in a markdown code block. A happy string is a string that: consists only of letters of the set ['a', 'b', 'c']. s[i] != s[i + 1] for all values of i from 1 to s.length - 1 (string is 1-indexed). For example, strings "abc", "ac", "b" and "abc...
{"functional": "def check(candidate):\n assert candidate(n = 1, k = 3) == \"c\"\n assert candidate(n = 1, k = 4) == \"\"\n assert candidate(n = 3, k = 9) == \"cab\"\n assert candidate(n = 2, k = 7) == \"\"\n assert candidate(n = 10, k = 100) == \"abacbabacb\"\n\n\ncheck(Solution().getHappyString)"}
coding
204
Solve the programming task below in a Python markdown code block. In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimate...
{"inputs": ["1\n0\n", "1\n0\n", "1\n9\n", "1\n12\n", "1\n17\n", "1\n14\n", "1\n10\n", "1\n12\n"], "outputs": ["0", "0\n", "0\n", "0", "0\n", "0\n", "0\n", "0\n"]}
coding
414
Solve the programming task below in a Python markdown code block. There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to t...
{"inputs": ["4", "1", "3", "6", "2", "12", "19", "24"], "outputs": ["3\n", "1\n", "2\n", "3", "2", "5\n", "6\n", "7\n"]}
coding
217
Solve the programming task below in a Python markdown code block. Problem There is a grid of $ R \ times C $ squares with $ (0, 0) $ in the upper left and $ (R-1, C-1) $ in the lower right. When you are in a square ($ e $, $ f $), from there $ (e + 1, f) $, $ (e-1, f) $, $ (e, f + 1) $, $ (e) , f-1) $, $ (e, 0) $, $ (...
{"inputs": ["2 2 0 0 0 1", "1 2 0 0 0 0", "5 6 0 0 4 4", "8 6 0 0 4 4", "2 2 1 0 0 1", "2 4 0 0 1 1", "5 5 0 0 4 4", "1 1 0 0 0 0"], "outputs": ["1 2\n", "0 1\n", "3 3\n", "6 30\n", "2 8\n", "2 4\n", "2 2", "0 1"]}
coding
624
Solve the programming task below in a Python markdown code block. Santa has $n$ candies and he wants to gift them to $k$ kids. He wants to divide as many candies as possible between all $k$ kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all. Suppose the kid who recieves the ...
{"inputs": ["1\n49845 2\n", "1\n96290 2\n", "1\n51548 1\n", "1\n25702 1\n", "1\n25113 1\n", "1\n49777 3\n", "1\n38068 2\n", "1\n49845 1\n"], "outputs": ["49845\n", "96290\n", "51548\n", "25702\n", "25113\n", "49777\n", "38068\n", "49845\n"]}
coding
700
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order. ...
{"functional": "def check(candidate):\n assert candidate(candidates = [2,3,6,7], target = 7) == [[2,2,3],[7]]\n\n\ncheck(Solution().combinationSum)"}
coding
155
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, where nums[i] is a digit between 0 and 9 (inclusive). The triangular sum of nums is the value of the only element present in nums after the following process terminates: ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4,5]) == 8\n assert candidate(nums = [5]) == 5\n\n\ncheck(Solution().triangularSum)"}
coding
209
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times. Return the length of the lo...
{"functional": "def check(candidate):\n assert candidate(s = \"ABAB\", k = 2) == 4\n assert candidate(s = \"AABABBA\", k = 1) == 4\n\n\ncheck(Solution().characterReplacement)"}
coding
110
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integer arrays arr1 and arr2, and the integer d, return the distance value between the two arrays. The distance value is defined as the number of elements arr1[i] such that there is not any element arr2[j] w...
{"functional": "def check(candidate):\n assert candidate(arr1 = [4,5,8], arr2 = [10,9,1,8], d = 2) == 2\n assert candidate(arr1 = [1,4,2,3], arr2 = [-4,-3,6,10,20,30], d = 3) == 2\n assert candidate(arr1 = [2,1,100,3], arr2 = [-5,-2,10,-3,7], d = 6) == 1\n\n\ncheck(Solution().findTheDistanceValue)"}
coding
123
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an undirected graph. You are given an integer n which is the number of nodes in the graph and an array edges, where each edges[i] = [ui, vi] indicates that there is an undirected edge between ui and vi. ...
{"functional": "def check(candidate):\n assert candidate(n = 6, edges = [[1,2],[1,3],[3,2],[4,1],[5,2],[3,6]]) == 3\n assert candidate(n = 7, edges = [[1,3],[4,1],[4,3],[2,5],[5,6],[6,7],[7,5],[2,6]]) == 0\n\n\ncheck(Solution().minTrioDegree)"}
coding
176
Solve the programming task below in a Python markdown code block. You visit a doctor on a date given in the format $yyyy:mm:dd$. Your doctor suggests you to take pills every alternate day starting from that day. You being a forgetful person are pretty sure won’t be able to remember the last day you took the medicine an...
{"inputs": ["1\n2019:03:31"], "outputs": ["1"]}
coding
385
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n projects numbered from 0 to n - 1. You are given an integer array milestones where each milestones[i] denotes the number of milestones the ith project has. You can work on the projects following these two ...
{"functional": "def check(candidate):\n assert candidate(milestones = [1,2,3]) == 6\n assert candidate(milestones = [5,2,1]) == 7\n\n\ncheck(Solution().numberOfWeeks)"}
coding
207
Solve the programming task below in a Python markdown code block. A particular month has 30 days, numbered from 1 to 30. Day 1 is a Monday, and the usual 7-day week is followed (so day 2 is Tuesday, day 3 is Wednesday, and so on). Every Saturday and Sunday is a holiday. There are N festival days, which are also holid...
{"inputs": ["3\n2\n5 7\n3\n23 1 6\n1\n13\n"], "outputs": ["9\n10\n8\n"]}
coding
668
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Not everyone probably knows that Chef has younger brother Jeff. Currently Jeff learns to read. He knows some subset of the letter of Latin alphabet. In order to help Jeff to...
{"inputs": ["act\n2\ncat\ndog"], "outputs": ["Yes\nNo"]}
coding
410
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary search tree and an integer k, return true if there exist two elements in the BST such that their sum is equal to k, or false otherwise.   Please complete the following python code precisely:...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([5,3,6,2,4,None,7]), k = 9) == True\n assert candidate(root = tree_node([5,3,6,2,4,None,7]), k = 28) == False\n\n\ncheck(Solution().findTarget)"}
coding
140
Solve the programming task below in a Python markdown code block. Spin-off of this kata, here you will have to figure out an efficient strategy to solve the problem of finding the sole duplicate number among an unsorted array/list of numbers starting from 1 up to n. Hints: a solution in linear time can be found; using...
{"functional": "_inputs = [[[1, 1, 2, 3]], [[1, 2, 2, 3]], [[5, 4, 3, 2, 1, 1]], [[1, 3, 2, 5, 4, 5, 7, 6]], [[8, 2, 6, 3, 7, 2, 5, 1, 4]]]\n_outputs = [[1], [2], [1], [5], [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=t...
coding
109
Solve the programming task below in a Python markdown code block. One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the ...
{"inputs": ["3 1\n", "2 3\n", "7 3\n", "1 1\n", "1 1\n", "2 1\n", "2 0\n", "7 5\n"], "outputs": ["1 1\n", "2 0\n", "3 2\n", "1 0\n", "1 0\n", "1 0\n", "0 1\n", "5 1\n"]}
coding
364
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef has 3 boxes of sizes A, B, and C respectively. He puts the boxes in bags of size D (A ≤ B ≤ C ≤ D). Find the minimum number of bags Chef needs so that he...
{"inputs": ["3\n2 3 5 10\n1 2 3 5\n3 3 4 4\n"], "outputs": ["1\n2\n3\n"]}
coding
405
Solve the programming task below in a Python markdown code block. There is a stack of N cards, each of which has a non-negative integer written on it. The integer written on the i-th card from the top is A_i. Snuke will repeat the following operation until two cards remain: * Choose three consecutive cards from the s...
{"inputs": ["4\n1 1 4 2", "4\n1 0 4 2", "4\n1 0 2 2", "4\n2 0 2 2", "4\n2 0 3 2", "4\n2 0 6 2", "4\n2 1 6 2", "4\n2 1 6 0"], "outputs": ["14\n", "11\n", "7\n", "8\n", "10\n", "16\n", "19\n", "17\n"]}
coding
306
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given two binary strings $A$ and $B$ with the same length. You may perform the following operation any number of times (including zero): pi...
{"inputs": ["3\n100001\n110111\n1010\n1010\n000\n111"], "outputs": ["2\n0\n2"]}
coding
523
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line. A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on ...
{"inputs": ["1\n3\n1 3\n2 5\n6 9", "1\n3\n1 3\n0 5\n6 9", "1\n3\n1 3\n2 5\n1 6", "1\n3\n1 3\n2 5\n6 6", "1\n3\n0 3\n0 5\n6 9", "1\n3\n0 3\n1 5\n6 9", "1\n3\n1 3\n2 2\n6 9", "1\n3\n0 3\n0 5\n5 9"], "outputs": ["2", "2\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
coding
428
Solve the programming task below in a Python markdown code block. You are given two positive integers $N$ and $K$, where $K \le N$. Find a sequence $A_1, A_2, \ldots, A_N$ such that: - for each valid $i$, $A_i$ is either $i$ or $-i$ - there are exactly $K$ values of $i$ such that $1 \le i \le N$ and $A_1 + A_2 + \ldots...
{"inputs": ["1\n3 3"], "outputs": ["1 2 3"]}
coding
327
Solve the programming task below in a Python markdown code block. Each floating-point number should be formatted that only the first two decimal places are returned. You don't need to check whether the input is a valid number because only valid numbers are used in the tests. Don't round the numbers! Just cut them af...
{"functional": "_inputs = [[10.1289767789], [-7488.83485834983], [4.653725356]]\n_outputs = [[10.12], [-7488.83], [4.65]]\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...
coding
171
Solve the programming task below in a Python markdown code block. # Task Timed Reading is an educational tool used in many schools to improve and advance reading skills. A young elementary student has just finished his very first timed reading exercise. Unfortunately he's not a very good reader yet, so whenever he enc...
{"functional": "_inputs = [[4, \"The Fox asked the stork, 'How is the soup?'\"], [1, '...'], [3, 'This play was good for us.'], [3, 'Suddenly he stopped, and glanced up at the houses'], [6, 'Zebras evolved among the Old World horses within the last four million years.'], [5, 'Although zebra species may have overlapping...
coding
316
Solve the programming task below in a Python markdown code block. The "Western calendar" is a concept imported from the West, but in Japan there is a concept called the Japanese calendar, which identifies the "era name" by adding a year as a method of expressing the year on the calendar. For example, this year is 2016 ...
{"inputs": ["4 2", "3 1", "2 0", "3 2", "4 1", "1 0", "3 0", "4 0"], "outputs": ["1990\n", "1926\n", "1911\n", "1927\n", "1989\n", "1867\n", "1925\n", "1988\n"]}
coding
629
Solve the programming task below in a Python markdown code block. Snuke loves puzzles. Today, he is working on a puzzle using S- and c-shaped pieces. In this puzzle, you can combine two c-shaped pieces into one S-shaped piece, as shown in the figure below: Snuke decided to create as many Scc groups as possible by putti...
{"inputs": ["1 6\n", "12345 678901\n"], "outputs": ["2\n", "175897\n"]}
coding
208
Solve the programming task below in a Python markdown code block. You are given a string of characters, or numbers. Find the minimum number of characters to be inserted into the string in order to obtain a palindrome. A palindrome is a word, phrase, number, or other sequence of symbols or elements that reads the same ...
{"inputs": ["1\n20\neeeeeeeeeeeeeeeeeeee", "1\n20\n0ziG30WBD79ow1E0fu1X", "1\n20\nWbHRKhSxoS18CnGxola3"], "outputs": ["0", "17", "17"]}
coding
222
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai an...
{"functional": "def check(candidate):\n assert candidate(n = 6, edges = [[0,1],[0,2],[1,3],[1,4],[2,5]], values = [2,8,3,6,2,5]) == 24\n assert candidate(n = 3, edges = [[0,1],[1,2]], values = [4,6,1]) == 0\n\n\ncheck(Solution().maxXor)"}
coding
253
Solve the programming task below in a Python markdown code block. Chef is playing a mobile game. In the game, Chef's character *Chefario* can perform special attacks. However, one special attack costs X mana points to Chefario. If Chefario currently has Y mana points, determine the maximum number of special attacks h...
{"inputs": ["3\n10 30\n6 41\n50 2\n"], "outputs": ["3\n6\n0\n"]}
coding
344
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s. A split is called good if you can split s into two non-empty strings sleft and sright where their concatenation is equal to s (i.e., sleft + sright = s) and the number of distinct letters in ...
{"functional": "def check(candidate):\n assert candidate(s = \"aacaba\") == 2\n assert candidate(s = \"abcd\") == 1\n assert candidate(s = \"aaaaa\") == 4\n assert candidate(s = \"acbadbaada\") == 2\n\n\ncheck(Solution().numSplits)"}
coding
123
Solve the programming task below in a Python markdown code block. Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to h...
{"inputs": ["1 1\n-27\n61769\n", "1 1\n1\n-164538\n", "1 1\n1\n-4000000\n", "1 1\n1\n-4000000\n", "1 1\n1\n-1911669\n", "1 1\n1\n-1398610\n", "1 1\n1\n-1396982\n", "1 1\n-659\n61769\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
542
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 distinct integers nums. There is an element in nums that has the lowest value and an element that has the highest value. We call them the minimum and maximum respectively. Your goal ...
{"functional": "def check(candidate):\n assert candidate(nums = [2,10,7,5,4,1,8,6]) == 5\n assert candidate(nums = [0,-4,19,1,8,-2,-3,5]) == 3\n assert candidate(nums = [101]) == 1\n\n\ncheck(Solution().minimumDeletions)"}
coding
153
Solve the programming task below in a Python markdown code block. You are given a binary matrix $A$ of size $n \times n$. Let's denote an $x$-compression of the given matrix as a matrix $B$ of size $\frac{n}{x} \times \frac{n}{x}$ such that for every $i \in [1, n], j \in [1, n]$ the condition $A[i][j] = B[\lceil \frac{...
{"inputs": ["4\n7\nF\nF\nF\n", "4\n3\nC\n3\nC\n", "4\n0\n0\n0\n1\n", "4\nA\nA\nA\nA\n", "4\n3\n3\n3\n3\n", "4\nE\nE\nE\nE\n", "4\nF\n0\nF\n0\n", "4\n3\nF\nF\nF\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "1\n", "1\n", "1\n"]}
coding
610
Solve the programming task below in a Python markdown code block. It's autumn now, the time of the leaf fall. Sergey likes to collect fallen leaves in autumn. In his city, he can find fallen leaves of maple, oak and poplar. These leaves can be of three different colors: green, yellow or red. Sergey has collected some l...
{"inputs": ["1\n1 2 3\n3 2 1\n1 3 4"], "outputs": ["7"]}
coding
595
Solve the programming task below in a Python markdown code block. Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter. Iahub wants to choose some contig...
{"inputs": ["1\n1\n", "1\n2\n", "2\n1 1\n", "2\n1 2\n", "2\n2 2\n", "2\n2 1\n", "2\n1 4\n", "2\n2 4\n"], "outputs": ["0\n", "0\n", "2\n", "0\n", "2\n", "0\n", "0\n", "0\n"]}
coding
487
Solve the programming task below in a Python markdown code block. # Convert number to reversed array of digits Given a random non-negative number, you have to return the digits of this number within an array in reverse order. ## Example: ``` 348597 => [7,9,5,8,4,3] ``` Also feel free to reuse/extend the following st...
{"functional": "_inputs = [[35231], [23582357], [984764738], [45762893920], [548702838394]]\n_outputs = [[[1, 3, 2, 5, 3]], [[7, 5, 3, 2, 8, 5, 3, 2]], [[8, 3, 7, 4, 6, 7, 4, 8, 9]], [[0, 2, 9, 3, 9, 8, 2, 6, 7, 5, 4]], [[4, 9, 3, 8, 3, 8, 2, 0, 7, 8, 4, 5]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstan...
coding
93
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 2D integer array circles where circles[i] = [xi, yi, ri] represents the center (xi, yi) and radius ri of the ith circle drawn on a grid, return the number of lattice points that are present inside at least one...
{"functional": "def check(candidate):\n assert candidate(circles = [[2,2,1]]) == 5\n assert candidate(circles = [[2,2,2],[3,4,1]]) == 16\n\n\ncheck(Solution().countLatticePoints)"}
coding
135
Solve the programming task below in a Python markdown code block. ## Description The task is described in the title: find the sum of all numbers with the same digits(permutations) **including** duplicates. However, due to the fact that this is a performance edition kata, `num` can go up to `10**10000`. That's a number...
{"functional": "_inputs = [[123], [1185]]\n_outputs = [[1332], [99990]]\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 ...
coding
376
Solve the programming task below in a Python markdown code block. Remember the movie with David Bowie: 'The Labyrinth'? You can remember your childhood here: https://www.youtube.com/watch?v=2dgmgub8mHw In this scene the girl is faced with two 'Knights" and two doors. One door leads the castle where the Goblin King an...
{"functional": "_inputs = [[True], [False], ['4+2==5'], ['2+2==4'], ['not True and False or False or False'], ['3 is 3'], ['True'], ['not True'], ['2+2==5'], ['4+1==5'], ['4 is 3'], ['9+2==3'], ['105+30076==30181'], ['3 is 3 is 3 is 9'], ['False'], ['\"orange\" is not \"red\"'], ['4 is \"blue\"'], ['True is not False']...
coding
376
Solve the programming task below in a Python markdown code block. The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N pa...
{"inputs": ["2\n1 5\n2 4\n3 6\n", "3\n1 1 1\n2 2 2\n3 3 3\n", "6\n3 14 159 2 6 53\n58 9 79 323 84 6\n2643 383 2 79 50 288\n"], "outputs": ["3\n", "27\n", "87\n"]}
coding
470
Solve the programming task below in a Python markdown code block. >When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said # Description: ```if:javascript Given an array `arr` that contains some integers(positive, negative or 0...
{"functional": "_inputs = [[[1, -2, 3, 4, -5, -4, 3, 2, 1], [[1, 3], [0, 4], [6, 8]]], [[1, -2, 3, 4, -5, -4, 3, 2, 1], [[1, 3]]], [[1, -2, 3, 4, -5, -4, 3, 2, 1], [[1, 4], [2, 5]]], [[11, -22, 31, 34, -45, -46, 35, 32, 21], [[1, 4], [0, 3], [6, 8], [0, 8]]]]\n_outputs = [[6], [5], [0], [88]]\nimport math\ndef _deep_eq...
coding
556
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s, a string chars of distinct characters and an integer array vals of the same length as chars. The cost of the substring is the sum of the values of each character in the substring. The cost of...
{"functional": "def check(candidate):\n assert candidate(s = \"adaa\", chars = \"d\", vals = [-1000]) == 2\n assert candidate(s = \"abc\", chars = \"abc\", vals = [-1,-1,-1]) == 0\n\n\ncheck(Solution().maximumCostSubstring)"}
coding
224
Solve the programming task below in a Python markdown code block. Santa Claus has n candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give a...
{"inputs": ["5\n", "9\n", "2\n", "1\n", "3\n", "4\n", "6\n", "7\n"], "outputs": ["2\n1 4 \n", "3\n1 2 6 \n", "1\n2 \n", "1\n1 \n", "2\n1 2 \n", "2\n1 3 \n", "3\n1 2 3 \n", "3\n1 2 4 \n"]}
coding
198
Solve the programming task below in a Python markdown code block. One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y): * point (x', y') is (x, y)'s right neighbo...
{"inputs": ["1\n262 5\n", "1\n357 5\n", "1\n271 5\n", "1\n520 5\n", "1\n206 5\n", "1\n206 8\n", "1\n487 56\n", "1\n143 75\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
506
Solve the programming task below in a Python markdown code block. The Padovan sequence is the sequence of integers `P(n)` defined by the initial values `P(0)=P(1)=P(2)=1` and the recurrence relation `P(n)=P(n-2)+P(n-3)` The first few values of `P(n)` are `1, 1, 1, 2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37, 49, 65, 8...
{"functional": "_inputs = [[100]]\n_outputs = [[1177482265857]]\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 ...
coding
255
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a hidden integer array arr that consists of n non-negative integers. It was encoded into another integer array encoded of length n - 1, such that encoded[i] = arr[i] XOR arr[i + 1]. For example, if arr = [1,0...
{"functional": "def check(candidate):\n assert candidate(encoded = [1,2,3], first = 1) == [1,0,2,1]\n assert candidate(encoded = [6,2,7,3], first = 4) == [4,2,0,7,4]\n\n\ncheck(Solution().decode)"}
coding
171
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Phantasialand boasts of its famous theme park. The park is frequently visited. It is quite large park that some tourists visit it more than once to fully appreciate its offer...
{"inputs": ["2\n3 1", "2\n4 1", "2\n3 0", "2\n4 0", "2\n3 2", "2\n7 1", "2\n4 2", "2\n3 1"], "outputs": ["2", "3\n", "2\n", "2\n", "3\n", "4\n", "3\n", "2\n"]}
coding
725
Solve the programming task below in a Python markdown code block. Given are three integers A_1, A_2, and A_3. If A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win. -----Constraints----- - 1 \leq A_i \leq 13 \ \ (i=1,2,3) - All values in input are integers. -----Input----- Input is given f...
{"inputs": ["5 7 4", "5 1 4", "5 1 0", "0 9 4", "5 1 1", "0 1 4", "6 1 1", "0 2 4"], "outputs": ["win\n", "win\n", "win\n", "win\n", "win\n", "win\n", "win\n", "win\n"]}
coding
178
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an m x n matrix that is initialized to all 0's. There is also a 2D array indices where each indices[i] = [ri, ci] represents a 0-indexed location to perform some increment operations on the matrix. For each l...
{"functional": "def check(candidate):\n assert candidate(m = 2, n = 3, indices = [[0,1],[1,1]]) == 6\n assert candidate(m = 2, n = 2, indices = [[1,1],[0,0]]) == 0\n\n\ncheck(Solution().oddCells)"}
coding
166
Solve the programming task below in a Python markdown code block. Just like in the ["father" kata](http://www.codewars.com/kata/find-fibonacci-last-digit/), you will have to return the last digit of the nth element in the Fibonacci sequence (starting with 1,1, to be extra clear, not with 0,1 or other numbers). You wil...
{"functional": "_inputs = [[1], [21], [302], [4003], [50004], [600005], [7000006], [80000007], [900000008], [1000000009]]\n_outputs = [[1], [6], [1], [7], [8], [5], [3], [8], [1], [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, re...
coding
261
Solve the programming task below in a Python markdown code block. Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you ...
{"inputs": ["2\n1 1\n1 1\n", "2\n1 1\n1 1\n", "2\n1 0\n1 1\n", "2\n1 0\n1 0\n", "2\n1 1\n1 0\n", "2\n2 1\n1 0\n", "2\n2 1\n1 1\n", "2\n2 2\n1 1\n"], "outputs": ["0\n", "0\n", "1\n", "2\n", "1\n", "1\n", "1\n", "2\n"]}
coding
295
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Sebi likes solving Rubik's cube a lot. He spends a lot of time in getting expertize in solving not only the 3 * 3 * 3 cube, but also the cubes of higher dimensions like 4 * 4...
{"inputs": ["2\n2 5\n2 2"], "outputs": ["YES\nNO"]}
coding
615
Solve the programming task below in a Python markdown code block. In genetic the reverse complement of a sequence is formed by **reversing** the sequence and then taking the complement of each symbol. The four nucleotides in DNA is Adenine (A), Cytosine (C), Guanine (G) and Thymine (Thymine). - A is the complement o...
{"functional": "_inputs = [['TTCCGGAA'], ['GACTGACTGTA'], [''], ['XYZ']]\n_outputs = [['TTCCGGAA'], ['TACAGTCAGTC'], [''], ['Invalid sequence']]\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 isinstan...
coding
229
Solve the programming task below in a Python markdown code block. At the store, the salespeople want to make all prices round. In this problem, a number that is a power of $10$ is called a round number. For example, the numbers $10^0 = 1$, $10^1 = 10$, $10^2 = 100$ are round numbers, but $20$, $110$ and $256$ are not ...
{"inputs": ["4\n1\n1\n1\n1\n", "1\n100000000\n", "14\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "7\n1\n2\n178\n20\n999999999\n9000\n987654321\n", "7\n100\n40000000\n89657\n326894\n2325566\n74444\n200055\n"], "outputs": ["0\n0\n0\n0\n", "0\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "0\n1\n78\n10\n899999999\n80...
coding
651
Solve the programming task below in a Python markdown code block. There are n walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left...
{"inputs": ["1 1\n", "2 1\n", "6 8\n", "2 2\n", "1 2\n", "3 4\n", "1 4\n", "1 6\n"], "outputs": ["0", "0\n", "2\n", "1\n", "0\n", "1\n", "0\n", "0\n"]}
coding
440
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n cities numbered from 0 to n - 1 and n - 1 roads such that there is only one way to travel between two different cities (this network form a tree). Last year, The ministry of transport decided to orient the...
{"functional": "def check(candidate):\n assert candidate(n = 6, connections = [[0,1],[1,3],[2,3],[4,0],[4,5]]) == 3\n assert candidate(n = 5, connections = [[1,0],[1,2],[3,2],[3,4]]) == 2\n assert candidate(n = 3, connections = [[1,0],[2,0]]) == 0\n\n\ncheck(Solution().minReorder)"}
coding
209
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it. All of the tickets belong to a ...
{"functional": "def check(candidate):\n assert candidate(tickets = [[\"MUC\",\"LHR\"],[\"JFK\",\"MUC\"],[\"SFO\",\"SJC\"],[\"LHR\",\"SFO\"]]) == [\"JFK\",\"MUC\",\"LHR\",\"SFO\",\"SJC\"]\n assert candidate(tickets = [[\"JFK\",\"SFO\"],[\"JFK\",\"ATL\"],[\"SFO\",\"ATL\"],[\"ATL\",\"JFK\"],[\"ATL\",\"SFO\"]]) == [\...
coding
196
Solve the programming task below in a Python markdown code block. At a break Vanya came to the class and saw an array of $n$ $k$-bit integers $a_1, a_2, \ldots, a_n$ on the board. An integer $x$ is called a $k$-bit integer if $0 \leq x \leq 2^k - 1$. Of course, Vanya was not able to resist and started changing the nu...
{"inputs": ["1 1\n1\n", "1 1\n0\n", "1 2\n3\n", "1 2\n3\n", "1 1\n1\n", "1 1\n0\n", "1 2\n4\n", "1 2\n0\n"], "outputs": ["1", "1", "1", "1", "1", "1", "1\n", "1\n"]}
coding
740
Solve the programming task below in a Python markdown code block. The Professor is facing the North. Tokyo is in trouble, and she is facing the South. Professor being her guardian angel wants to help her. So, The Professor will follow some instructions, given as a string S of length N, and will turn either left or rig...
{"inputs": ["3\n12\nLRLRRRLRLLLL\n2\nLR\n4\nLRRL\n"], "outputs": ["YES\nNO\nYES\n"]}
coding
407
Solve the programming task below in a Python markdown code block. The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai. Additionally the Little Elephant has m queries to the array, each query is characterised ...
{"inputs": ["1 2\n1\n1 1\n1 1\n", "1 1\n1000000000\n1 1\n", "1 1\n1100000000\n1 1\n", "7 2\n3 1 2 2 3 6 7\n1 7\n3 4\n", "7 2\n3 1 2 2 1 6 7\n1 7\n3 4\n", "7 2\n2 1 2 2 1 6 7\n1 7\n3 4\n", "7 2\n3 1 2 2 3 6 7\n1 6\n3 4\n", "7 2\n3 1 2 2 3 3 7\n1 7\n3 4\n"], "outputs": ["1\n1\n", "0\n", "0\n", "2\n1\n", "1\n1\n", "0\n1\n...
coding
316
Solve the programming task below in a Python markdown code block. Dreamoon wants to climb up a stair of n steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer m. What is the minimal number of moves making him climb to the top of the stairs that satisfies his...
{"inputs": ["3 5\n", "2 2\n", "1 2\n", "4 2\n", "6 3\n", "3 2\n", "6 4\n", "5 2\n"], "outputs": ["-1\n", "2\n", "-1\n", "2\n", "3\n", "2\n", "4\n", "4\n"]}
coding
270
Solve the programming task below in a Python markdown code block. There are N balls in a row. Initially, the i-th ball from the left has the integer A_i written on it. When Snuke cast a spell, the following happens: * Let the current number of balls be k. All the balls with k written on them disappear at the same tim...
{"inputs": ["5 3\n1 1 5 4 5\n1 2\n2 5\n5 4", "5 3\n1 1 3 1 5\n1 2\n2 5\n5 4", "5 3\n0 1 5 1 5\n1 2\n2 5\n5 4", "5 3\n1 2 3 4 5\n1 2\n2 5\n5 4", "5 3\n1 1 5 4 5\n2 2\n2 5\n1 4", "5 3\n0 1 5 1 3\n1 4\n2 4\n5 4", "5 3\n1 2 3 4 5\n1 2\n1 5\n5 2", "5 3\n1 1 5 4 5\n1 2\n2 0\n5 4"], "outputs": ["1\n1\n1\n", "1\n0\n0\n", "1\n0...
coding
562
Solve the programming task below in a Python markdown code block. There are N piles of candies on the table. The piles are numbered 1 through N. At first, pile i contains a_i candies. Snuke and Ciel are playing a game. They take alternating turns. Snuke goes first. In each turn, the current player must perform one of ...
{"inputs": ["2\n0 3", "2\n1 4", "2\n1 0", "2\n1 5", "2\n1 9", "2\n0 5", "2\n1 6", "2\n2 4"], "outputs": ["Second\n", "First\n", "Second\n", "First\n", "First\n", "Second\n", "First\n", "Second\n"]}
coding
261
Solve the programming task below in a Python markdown code block. You are given a sequence $a_1, a_2, \dots, a_n$ consisting of $n$ integers. You can choose any non-negative integer $D$ (i.e. $D \ge 0$), and for each $a_i$ you can: add $D$ (only once), i. e. perform $a_i := a_i + D$, or subtract $D$ (only once), i...
{"inputs": ["2\n2 8\n", "1\n100\n", "2\n1 1\n", "2\n2 7\n", "2\n5 8\n", "2\n3 1\n", "2\n2 5\n", "2\n3 8\n"], "outputs": ["3\n", "0\n", "0\n", "5\n", "3\n", "1\n", "3\n", "5\n"]}
coding
556
Solve the programming task below in a Python markdown code block. You are given $n$ chips on a number line. The $i$-th chip is placed at the integer coordinate $x_i$. Some chips can have equal coordinates. You can perform each of the two following types of moves any (possibly, zero) number of times on any chip: Mov...
{"inputs": ["1\n1\n", "1\n5\n", "1\n2\n", "1\n2\n", "1\n5\n", "1\n1\n", "1\n3\n", "1\n0\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
489
Solve the programming task below in a Python markdown code block. Dmitry has an array of $n$ non-negative integers $a_1, a_2, \dots, a_n$. In one operation, Dmitry can choose any index $j$ ($1 \le j \le n$) and increase the value of the element $a_j$ by $1$. He can choose the same index $j$ multiple times. For each $...
{"inputs": ["5\n3\n0 1 3\n7\n0 1 2 3 4 3 2\n4\n3 0 0 0\n7\n4 6 2 3 5 0 5\n5\n4 0 1 0 4\n", "5\n3\n0 1 3\n7\n0 1 2 3 4 3 2\n4\n3 0 0 0\n7\n4 6 2 3 6 0 5\n5\n4 0 1 0 4\n", "5\n3\n0 1 3\n7\n0 1 2 3 4 3 2\n4\n3 0 0 0\n7\n4 0 2 3 5 0 5\n5\n4 0 1 0 4\n", "5\n3\n0 1 3\n7\n0 1 2 3 4 0 2\n4\n3 0 0 0\n7\n4 6 2 3 5 0 5\n5\n4 0 1 ...
coding
698
Solve the programming task below in a Python markdown code block. Mario transforms each time he eats a mushroom as follows: If he is currently small, he turns normal. If he is currently normal, he turns huge. If he is currently huge, he turns small. Given that Mario was initially normal, find his size after eating X m...
{"inputs": ["3\n2\n4\n12"], "outputs": ["SMALL\nHUGE\nNORMAL"]}
coding
384
Solve the programming task below in a Python markdown code block. Snuke is visiting a shop in Tokyo called 109 to buy some logs. He wants n logs: one of length 1, one of length 2, ..., and one of length n. The shop has n+1 logs in stock: one of length 1, one of length 2, \dots, and one of length n+1. Each of these logs...
{"inputs": ["4\n", "1\n", "2\n", "3\n", "5\n", "11200\n", "39435\n", "812742\n"], "outputs": ["3\n", "1\n", "1\n", "2\n", "3\n", "11052\n", "39156\n", "811469\n"]}
coding
337
Solve the programming task below in a Python markdown code block. One of Arkady's friends works at a huge radio telescope. A few decades ago the telescope has sent a signal $s$ towards a faraway galaxy. Recently they've received a response $t$ which they believe to be a response from aliens! The scientists now want to ...
{"inputs": ["01\naaaaaa\n", "01\naabaaa\n", "01\naabbaa\n", "01\nbabbaa\n", "01\ncabbaa\n", "01\nbacbaa\n", "01\naacbaa\n", "01\naacaaa\n"], "outputs": ["4\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n"]}
coding
552
Solve the programming task below in a Python markdown code block. It's year 2018 and it's Christmas time! Before going for vacations, students of Hogwarts School of Witchcraft and Wizardry had their end semester exams. $N$ students attended the semester exam. Once the exam was over, their results were displayed as eith...
{"inputs": ["1\n4\n3 2 2 2"], "outputs": ["1"]}
coding
451
Solve the programming task below in a Python markdown code block. Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n. The cost of the i-th stone is v_{i}. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: She wi...
{"inputs": ["1\n1\n2\n1 1 1\n2 1 1\n", "1\n1\n2\n1 1 1\n2 1 1\n", "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n", "6\n6 6 3 8 5 4\n3\n2 2 3\n2 1 5\n1 1 5\n", "6\n6 6 3 8 5 4\n3\n2 2 3\n2 1 5\n1 1 5\n", "6\n6 6 3 8 5 6\n3\n2 2 3\n2 1 5\n1 1 5\n", "6\n1 6 3 8 5 6\n3\n2 2 3\n2 1 5\n1 1 5\n", "6\n1 1 3 8 5 6\n3\n2 2 3\n2 1 5\n...
coding
603
Solve the programming task below in a Python markdown code block. Given a set of numbers, return the additive inverse of each. Each positive becomes negatives, and the negatives become positives. ~~~if-not:racket ``` invert([1,2,3,4,5]) == [-1,-2,-3,-4,-5] invert([1,-2,3,-4,5]) == [-1,2,-3,4,-5] invert([]) == [] ``` ~...
{"functional": "_inputs = [[[1, 2, 3, 4, 5]], [[1, -2, 3, -4, 5]], [[]], [[0]]]\n_outputs = [[[-1, -2, -3, -4, -5]], [[-1, 2, -3, 4, -5]], [[]], [[0]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if i...
coding
262
Solve the programming task below in a Python markdown code block. This is a story in a depopulated area. In this area, houses are sparsely built along a straight road called Country Road. Until now, there was no electricity in this area, but this time the government will give us some generators. You can install the gen...
{"inputs": ["6\n5 2\n10 30 69 70 110\n7 3\n3 7 10 2 21 26 28\n1 1\n100\n2 1\n0 1010000\n3 5\n30 70 37\n6 4\n0 0 20 7 40 50", "6\n5 2\n10 30 40 70 110\n7 3\n3 12 10 2 21 26 28\n1 1\n100\n2 1\n0 1010000\n3 8\n30 70 69\n6 4\n0 0 20 7 40 50", "6\n5 2\n10 30 69 70 110\n7 3\n3 7 10 2 21 26 28\n1 1\n100\n2 1\n-1 1010000\n3 5\...
coding
590
Solve the programming task below in a Python markdown code block. # Definition **_Extra perfect number_** *is the number that* **_first_** and **_last_** *bits* are **_set bits_**. ____ # Task **_Given_** *a positive integer* `N` , **_Return_** the **_extra perfect numbers_** *in range from* `1` to `N` . ___...
{"functional": "_inputs = [[3], [5], [7], [28], [39]]\n_outputs = [[[1, 3]], [[1, 3, 5]], [[1, 3, 5, 7]], [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27]], [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isin...
coding
480
Solve the programming task below in a Python markdown code block. We are interested in obtaining two scores from a given integer: **First score**: The sum of all the integers obtained from the power set of the digits of the given integer that have the same order E.g: ``` integer = 1234 ---> (1 + 2 + 3 + 4) + (12 + 1...
{"functional": "_inputs = [[100, 300], [100, 500], [300, 900]]\n_outputs = [[[7, 294]], [[7, 294, 468]], [[7, 468, 834]]]\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...
coding
634
Solve the programming task below in a Python markdown code block. Valera's finally decided to go on holiday! He packed up and headed for a ski resort. Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has n objects (we will consider t...
{"inputs": ["1\n1\n0\n", "1\n1\n0\n", "2\n1 1\n0 0\n", "2\n1 1\n0 0\n", "2\n0 1\n0 0\n", "4\n1 0 0 0\n2 3 4 2\n", "4\n1 0 0 0\n2 3 4 2\n", "5\n0 0 0 0 1\n0 1 2 3 4\n"], "outputs": ["1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n2\n", "1\n1\n", "1\n1\n", "5\n1 2 3 4 5\n"]}
coding
674