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. We take a line segment of length $\textbf{C}$ on a one-dimensional plane and bend it to create a circle with circumference $\textbf{C}$ that's indexed from $0$ to $\boldsymbol{c-1}$. For example, if $c=4$: We denote a pair of points, $a$ and $\boldsymbo...
{"inputs": ["2 1000\n0 10\n10 20\n", "5 8\n0 4\n2 6\n1 5\n3 7\n4 4\n"], "outputs": ["0\n", "2\n"]}
707
60
coding
Solve the programming task below in a Python markdown code block. The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then t...
{"inputs": ["4\n1\n2\n3\n4"], "outputs": ["1\n12\n34\n123\n456\n789\n1234\n5678\n9101112\n13141516"]}
223
65
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A message containing letters from A-Z can be encoded into numbers using the following mapping: 'A' -> "1" 'B' -> "2" ... 'Z' -> "26" To decode an encoded message, all the digits must be grouped then mapped back into...
{"functional": "def check(candidate):\n assert candidate(s = \"*\") == 9\n assert candidate(s = \"1*\") == 18\n assert candidate(s = \"2*\") == 15\n\n\ncheck(Solution().numDecodings)"}
350
60
coding
Solve the programming task below in a Python markdown code block. Chef has a sequence $A_{1}, A_{2}, \ldots, A_{N}$. For a positive integer $M$, sequence $B$ is defined as $B = A*M$ that is, appending $A$ exactly $M$ times. For example, If $A = [1, 2]$ and $M = 3$, then $B = A*M = [1, 2, 1, 2, 1, 2]$ You have to help ...
{"inputs": ["3\n2\n2 1\n2\n1 2\n5\n1 3 2 1 2"], "outputs": ["2\n1\n2"]}
463
40
coding
Solve the programming task below in a Python markdown code block. In Math, an improper fraction is a fraction where the numerator (the top number) is greater than or equal to the denominator (the bottom number) For example: ```5/3``` (five third). A mixed numeral is a whole number and a fraction combined into one "mix...
{"functional": "_inputs = [['74/3'], ['9999/24'], ['74/30'], ['13/5'], ['5/3'], ['1/1'], ['10/10'], ['900/10'], ['9920/124'], ['6/2'], ['9/77'], ['96/100'], ['12/18'], ['6/36'], ['1/18'], ['-64/8'], ['-6/8'], ['-9/78'], ['-504/26'], ['-47/2'], ['-21511/21']]\n_outputs = [['24 2/3'], ['416 15/24'], ['2 14/30'], ['2 3/5'...
275
429
coding
Solve the programming task below in a Python markdown code block. Let f be a [permutation] of length N, where N is even. The *riffle* of f is defined to be the permutation g = (f(1), f(3), \ldots, f(N-1), f(2), f(4), \ldots, f(N)) You are given two integers N and K. Output the resultant permutation when you riffle the...
{"inputs": ["3\n6 1\n8 2\n14 452"], "outputs": ["1 3 5 2 4 6\n1 5 2 6 3 7 4 8\n1 10 6 2 11 7 3 12 8 4 13 9 5 14"]}
598
86
coding
Solve the programming task below in a Python markdown code block. Kate and Michael want to buy a pizza and share it. Depending on the price of the pizza, they are going to divide the costs: * If the pizza is less than €5,- Michael invites Kate, so Michael pays the full price. * Otherwise Kate will contribute 1/3 of th...
{"functional": "_inputs = [[15], [4], [4.99], [5], [30], [80], [22], [5.9181], [28.789], [4.325]]\n_outputs = [[10], [4], [4.99], [3.33], [20], [70], [14.67], [3.95], [19.19], [4.33]]\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...
134
254
coding
Solve the programming task below in a Python markdown code block. You are given four distinct integers $a$, $b$, $c$, $d$. Timur and three other people are running a marathon. The value $a$ is the distance that Timur has run and $b$, $c$, $d$ correspond to the distances the other three participants ran. Output the nu...
{"inputs": ["1\n2 9 10 1\n", "1\n4455 4 5 10\n", "4\n2 3 4 1\n10000 0 1 2\n500 600 400 300\n0 9999 10000 9998\n"], "outputs": ["2\n", "0\n", "2\n0\n1\n3\n"]}
404
111
coding
Solve the programming task below in a Python markdown code block. Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp n...
{"inputs": ["1\nz\ny\n", "1\na\nb\n", "2\nab\nba\n", "2\nab\nac\n", "2\nba\nca\n", "2\ner\nre\n", "2\nac\ncb\n", "2\nab\naa\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "1\n", "2\n"]}
394
103
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s and an array of strings words, return the number of words[i] that is a subsequence of s. A subsequence of a string is a new string generated from the original string with some characters (can be none)...
{"functional": "def check(candidate):\n assert candidate(s = \"abcde\", words = [\"a\",\"bb\",\"acd\",\"ace\"]) == 3\n assert candidate(s = \"dsahjpjauf\", words = [\"ahjpjau\",\"ja\",\"ahbwzgqnuk\",\"tnmlanowax\"]) == 2\n\n\ncheck(Solution().numMatchingSubseq)"}
129
88
coding
Solve the programming task below in a Python markdown code block. There is a town with N people and initially, the i^{th} person has A_{i} coins. However, some people of the town decide to become *monks*. If the i^{th} person becomes a monk, then: He leaves the town thereby reducing the number of people in the town by ...
{"inputs": ["3\n4\n6 6 6 6\n3\n5 1 4\n5\n2 1 2 1 1\n"], "outputs": ["0\n1\n2\n"]}
666
48
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will remove the left-most duplicates from a list of integers and return the result. ```python # Remove the 3's at indices 0 and 3 # followed by removing a 4 at index 1 solve([3, 4, 4, 3, 6, 3]) # => [4, 6, 3] ``` More examples can be ...
{"functional": "_inputs = [[[3, 4, 4, 3, 6, 3]], [[1, 2, 1, 2, 1, 2, 3]], [[1, 2, 3, 4]], [[1, 1, 4, 5, 1, 2, 1]]]\n_outputs = [[[4, 6, 3]], [[1, 2, 3]], [[1, 2, 3, 4]], [[4, 5, 2, 1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, r...
129
262
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array nums of positive integers, return the longest possible length of an array prefix of nums, such that it is possible to remove exactly one element from this prefix so that every number that has appeared i...
{"functional": "def check(candidate):\n assert candidate(nums = [2,2,1,1,5,3,3,5]) == 7\n assert candidate(nums = [1,1,1,2,2,2,3,3,3,4,4,4,5]) == 13\n\n\ncheck(Solution().maxEqualFreq)"}
128
83
coding
Solve the programming task below in a Python markdown code block. The chef is trying to solve some series problems, Chef wants your help to code it. Chef has one number N. Help the chef to find N'th number in the series. 0, 1, 5, 14, 30, 55 ….. -----Input:----- - First-line will contain $T$, the number of test cases. ...
{"inputs": ["3\n1\n7\n8"], "outputs": ["0\n91\n140"]}
188
25
coding
Solve the programming task below in a Python markdown code block. You are given a binary string S of length N. You can perform the following operation on S: Pick any set of indices such that no two picked indices are adjacent. Flip the values at the picked indices (i.e. change 0 to 1 and 1 to 0). For example, conside...
{"inputs": ["3\n6\n101001\n5\n00000\n3\n111\n"], "outputs": ["1\n0\n2\n"]}
419
41
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef is really interested in the XOR operation. He wants to take a sequence $A_{0}, A_{1}, \ldots, A_{N-1}$ and for each $i$ from $0$ to $K-1$ inclus...
{"inputs": ["1\n2 2\n1 2"], "outputs": ["3 1"]}
429
22
coding
Solve the programming task below in a Python markdown code block. The chef won a duet singing award at Techsurge & Mridang 2012. From that time he is obsessed with the number 2. He just started calculating the powers of two. And adding the digits of the results. But he got puzzled after a few calculations. So gave yo...
{"inputs": ["3\n5\n10\n4"], "outputs": ["5\n7\n7"]}
199
23
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will be given two numbers, n and k and your task will be to return the k-digit array that sums to n and has the maximum possible GCD. For example, given `n = 12, k = 3`, there are a number of possible `3-digit` arrays that sum to `12`,...
{"functional": "_inputs = [[12, 7], [12, 3], [12, 4], [18, 3], [18, 5], [24, 3], [24, 4], [24, 5], [24, 6], [276, 12]]\n_outputs = [[[]], [[2, 4, 6]], [[1, 2, 3, 6]], [[3, 6, 9]], [[1, 2, 3, 4, 8]], [[4, 8, 12]], [[2, 4, 6, 12]], [[1, 2, 3, 4, 14]], [[1, 2, 3, 4, 5, 9]], [[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 78]]]...
225
370
coding
Solve the programming task below in a Python markdown code block. You are given two binary strings $S$ and $P$, each with length $N$. A binary string contains only characters '0' and '1'. For each valid $i$, let's denote the $i$-th character of $S$ by $S_i$. You have to convert the string $S$ into $P$ using zero or mor...
{"inputs": ["3\n2\n00\n00\n3\n101\n010\n4\n0110\n0011"], "outputs": ["Yes\nNo\nYes"]}
551
46
coding
Solve the programming task below in a Python markdown code block. Some languages like Chinese, Japanese, and Thai do not have spaces between words. However, most natural languages processing tasks like part-of-speech tagging require texts that have segmented words. A simple and reasonably effective algorithm to segment...
{"functional": "_inputs = [['']]\n_outputs = [[[]]]\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...
732
153
coding
Solve the programming task below in a Python markdown code block. Polycarp's workday lasts exactly $n$ minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has $k$ bars at the beginning of the workday. In some minutes of the workday Polycarp has important things to do and in such minutes ...
{"inputs": ["2 2\n00\n", "2 2\n00\n", "2 3\n00\n", "3 3\n010\n", "3 2\n010\n", "3 2\n000\n", "3 3\n000\n", "3 3\n000\n"], "outputs": ["0\n", "0", "0\n", "1\n", "1\n", "1\n", "0\n", "0"]}
574
113
coding
Solve the programming task below in a Python markdown code block. Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are n piles of cows, with the i-th pile containing ...
{"inputs": ["1 1\n1\n", "1 2\n1\n", "1 0\n3\n", "1 2\n3\n", "2 3\n7 7\n", "2 2\n2 5\n", "2 2\n2 4\n", "2 2\n2 2\n"], "outputs": ["Kevin\n", "Kevin\n", "Nicky\n", "Nicky\n", "Nicky\n", "Kevin\n", "Kevin\n", "Nicky\n"]}
400
114
coding
Solve the programming task below in a Python markdown code block. Now I have a card with n numbers on it. Consider arranging some or all of these appropriately to make numbers. Find the number obtained by adding all the numbers created at this time. For example, if you have 1 and 2, you will get 4 numbers 1, 2, 12, 21...
{"inputs": ["2\n2\n2", "2\n2\n0", "2\n1\n0", "2\n2\n9", "2\n1\n9", "2\n0\n9", "2\n3\n9", "2\n2\n1"], "outputs": ["48\n", "22\n", "11\n", "132\n", "120\n", "99\n", "144\n", "36\n"]}
366
105
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. In a special ranking system, each voter gives a rank from highest to lowest to all teams participating in the competition. The ordering of teams is decided by who received the most position-one votes. If two or more t...
{"functional": "def check(candidate):\n assert candidate(votes = [\"ABC\",\"ACB\",\"ABC\",\"ACB\",\"ACB\"]) == \"ACB\"\n assert candidate(votes = [\"WXYZ\",\"XYZW\"]) == \"XWYZ\"\n assert candidate(votes = [\"ZMNAGUEDSJYLBOPHRQICWFXTVK\"]) == \"ZMNAGUEDSJYLBOPHRQICWFXTVK\"\n assert candidate(votes = [\"BCA\...
189
163
coding
Solve the programming task below in a Python markdown code block. Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs a_{i} rubles. Only one person can hang clothes on one hook. Tonight Sere...
{"inputs": ["1 1\n1\n2\n", "1 1\n1\n1\n", "1 1\n1\n2\n", "1 1\n1\n1\n", "1 1\n2\n2\n", "1 2\n1\n2\n", "2 1\n2 1\n2\n", "2 1\n2 1\n2\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "1\n", "-1\n", "3\n", "3\n"]}
390
122
coding
Solve the programming task below in a Python markdown code block. Berland year consists of $m$ months with $d$ days each. Months are numbered from $1$ to $m$. Berland week consists of $w$ days. The first day of the year is also the first day of the week. Note that the last week of the year might be shorter than $w$ day...
{"inputs": ["5\n6 5 2\n8 2 12\n2 30 6\n4 2 1\n2663549 214779 659567\n", "5\n6 5 2\n8 2 12\n12 30 6\n4 2 1\n2663549 214779 659567\n", "5\n6 7 4\n8 9 3\n12 11 3\n0 1 1\n7341628 25065973 296620\n", "5\n6 7 4\n8 9 3\n12 11 3\n0 1 1\n7341628 21556586 296620\n", "5\n6 5 2\n8 2 12\n0 30 6\n2 2 1\n2663549 10298779 625324\n", "...
385
585
coding
Solve the programming task below in a Python markdown code block. Short Phrase A Short Phrase (aka. Tanku) is a fixed verse, inspired by Japanese poetry Tanka and Haiku. It is a sequence of words, each consisting of lowercase letters 'a' to 'z', and must satisfy the following condition: > (The Condition for a Short P...
{"inputs": ["9\ndo\nhet\nbest\n`nd\nenjoy\ntoday\nat\nacm\nicpc\n0\noh\nyes\nby\nfar\nit\nis\nwow\nso\nbda\nto\nmd\nyou\nknow\nhey\n15\nedcba\nfghijkl\nmnopq\nrstuvwx\nyzz\nabcde\nlkkihgf\nmnopq\nxwvutsr\nyz\nabcde\nfghijkl\nmnopq\nrstuvwx\nyz\n0", "9\ndo\nhet\nbest\n`nd\nenjoy\ntoday\nat\nacm\nicpc\n0\noh\nyes\nby\nfa...
729
975
coding
Solve the programming task below in a Python markdown code block. The annual snake festival is upon us, and all the snakes of the kingdom have gathered to participate in the procession. Chef has been tasked with reporting on the procession, and for this he decides to first keep track of all the snakes. When he sees a s...
{"inputs": ["6\n18\n..H..T...HTH....T.\n3\n...\n10\nH..H..T..T\n2\nHT\n11\n.T...H..H.T\n7\nH..T..H"], "outputs": ["Valid\nValid\nInvalid\nValid\nInvalid\nInvalid"]}
626
73
coding
Solve the programming task below in a Python markdown code block. Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length. Once Polycarpus needed to figure out Tarasov city phone co...
{"inputs": ["2\n4\n9\n", "2\n1\n0\n", "2\n2\n0\n", "2\n2\n1\n", "2\n3\n9\n", "2\n0\n2\n", "2\n3\n1\n", "2\n3\n2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
499
102
coding
Solve the programming task below in a Python markdown code block. Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" a...
{"inputs": ["1\n?\n", "1\n(\n", "1\n)\n", "1\n)\n", "1\n?\n", "1\n(\n", "2\n??\n", "2\n((\n"], "outputs": [":(\n", ":(\n", ":(\n", ":(\n", ":(\n", ":(\n", "()\n", ":(\n"]}
526
95
coding
Solve the programming task below in a Python markdown code block. In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that t...
{"inputs": ["1 0\n0", "1 2\n0", "1 1\n0", "2 4\n0 2", "2 4\n0 4", "2 6\n0 3", "2 8\n0 5", "2 9\n0 1"], "outputs": ["0\n", "2\n", "1", "6\n", "8\n", "9\n", "13\n", "10\n"]}
369
105
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 binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water. An isla...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,1,0,0,0],[1,0,0,0,0],[0,0,0,0,1],[0,0,0,1,1]]) == 1\n assert candidate(grid = [[1,1,0,0,0],[1,1,0,0,0],[0,0,0,1,1],[0,0,0,1,1]]) == 1\n\n\ncheck(Solution().numDistinctIslands2)"}
160
122
coding
Solve the programming task below in a Python markdown code block. Given a lowercase Latin character (letter), check if it appears in the string ${codeforces}$. -----Input----- The first line of the input contains an integer $t$ ($1 \leq t \leq 26$) — the number of test cases. The only line of each test case contain...
{"inputs": ["1\na\n", "1\ns\n", "2\na\na\n", "10\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\n", "26\nq\na\nz\nw\ns\nx\ne\nd\nc\nr\nf\nv\nt\ng\nb\ny\nh\nn\nu\nj\nm\ni\nk\no\nl\np\n"], "outputs": ["NO\n", "YES\n", "NO\nNO\n", "NO\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\n", "NO\nNO\nNO\nNO\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nNO...
215
198
coding
Solve the programming task below in a Python markdown code block. Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses...
{"inputs": ["7\n", "9\n", "6\n", "8\n", "5\n", "3\n", "4\n", "2\n"], "outputs": ["3\n", "4\n", "3\n", "4\n", "3\n", "2\n", "2\n", "1\n"]}
446
70
coding
Solve the programming task below in a Python markdown code block. You have to create a method "compoundArray" which should take as input two int arrays of different length and return one int array with numbers of both arrays shuffled one by one. ```Example: Input - {1,2,3,4,5,6} and {9,8,7,6} Output - {1,9,2,8,3,7,4...
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6], [9, 8, 7, 6]], [[0, 1, 2], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]], [[11, 12], [21, 22, 23, 24]], [[2147483647, 2147483646, 2147483645, 2147483644, 2147483643], [9]], [[214, 215, 216, 217, 218], []], [[], [214, 215, 219, 217, 218]], [[], []]]\n_outputs = [[[1, 9, 2, 8, 3, 7, 4, 6...
128
571
coding
Solve the programming task below in a Python markdown code block. Captain Flint and his crew keep heading to a savage shore of Byteland for several months already, drinking rum and telling stories. In such moments uncle Bogdan often remembers his nephew Denis. Today, he has told a story about how Denis helped him to co...
{"inputs": ["1\n2\n", "1\n2\n", "1\n4\n", "1\n5\n", "1\n1\n", "1\n7\n", "1\n3\n", "1\n6\n"], "outputs": ["98\n", "98\n", "9998\n", "99988\n", "8\n", "9999988\n", "998\n", "999988\n"]}
675
108
coding
Solve the programming task below in a Python markdown code block. # A History Lesson The Pony Express was a mail service operating in the US in 1859-60. It reduced the time for messages to travel between the Atlantic and Pacific coasts to about 10 days, before it was made obsolete by the transcontinental telegrap...
{"functional": "_inputs = [[[43, 23, 40, 13], 4], [[18, 15], 2], [[43, 23, 40, 13], 3], [[33, 8, 16, 47, 30, 30, 46], 5], [[6, 24, 6, 8, 28, 8, 23, 47, 17, 29, 37, 18, 40, 49], 2], [[50, 50], 2], [[50, 50, 25, 50, 24], 3], [[50, 51, 25, 50, 25], 3], [[50, 100, 25, 50, 26], 3], [[100], 2], [[50, 50], 3], [[50, 51], 3]]\...
575
430
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array rectangles where rectangles[i] = [xi, yi, ai, bi] represents an axis-aligned rectangle. The bottom-left point of the rectangle is (xi, yi) and the top-right point of it is (ai, bi). Return true if all t...
{"functional": "def check(candidate):\n assert candidate(rectangles = [[1,1,3,3],[3,1,4,2],[3,2,4,4],[1,3,2,4],[2,3,3,4]]) == True\n assert candidate(rectangles = [[1,1,2,3],[1,3,2,4],[3,1,4,2],[3,2,4,4]]) == False\n assert candidate(rectangles = [[1,1,3,3],[3,1,4,2],[1,3,2,4],[2,2,4,4]]) == False\n\n\ncheck(S...
116
154
coding
Solve the programming task below in a Python markdown code block. In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two ...
{"inputs": ["2\n0 1\n1 -2\n", "2\n0 1\n1 -3\n", "2\n0 1\n1 -6\n", "2\n0 1\n1 -1\n", "3\n0 1\n1 2\n2 -2\n", "3\n0 1\n1 1\n2 -2\n", "3\n-1 1\n1 2\n2 -2\n", "5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n"], "outputs": ["NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n"]}
354
162
coding
Solve the programming task below in a Python markdown code block. Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other. Galya doesn't know th...
{"inputs": ["1 1 1 0\n0\n", "2 2 1 0\n00\n", "1 1 1 -1\n0\n", "1 1 1 -2\n0\n", "1 1 1 -3\n0\n", "2 2 1 -1\n00\n", "5 4 1 0\n00000\n", "5 1 2 1\n00100\n"], "outputs": ["1\n1 ", "1\n1 ", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "2\n1 2 ", "2\n2 5 "]}
524
161
coding
Solve the programming task below in a Python markdown code block. There is an airplane which has n rows from front to back. There will be m people boarding this airplane. This airplane has an entrance at the very front and very back of the plane. Each person has some assigned seat. It is possible for multiple people ...
{"inputs": ["3 3\n", "1 1\n", "1 1\n", "2 1\n", "1 2\n", "3 3\n", "10 1\n", "10 1\n"], "outputs": ["128\n", "2\n", "2\n", "4\n", "0\n", "128\n", "20\n", "20\n"]}
445
94
coding
Solve the programming task below in a Python markdown code block. This kata is all about adding numbers. You will create a function named add. It will return the sum of all the arguments. Sounds easy, doesn't it? Well Here's the Twist. The inputs will gradually decrease with their index as parameter to the function. ...
{"functional": "_inputs = [[100, 200, 300], [2], [4, -3, -2], [-1, -2, -3, -4]]\n_outputs = [[300], [2], [2], [-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, tuple)):\n ...
225
200
coding
Solve the programming task below in a Python markdown code block. You are given a pyramid of the following form with an infinite number of rows: 1 2\ 3 4\ 5\ 6 7\ 8\ 9\ 10 ........... From a cell, you can move to either the bottom-left cell or the bottom-right cell directly in contact with the current one (For examp...
{"inputs": ["3\n2 7\n1 5\n5 3"], "outputs": ["1\n2\n0"]}
515
28
coding
Solve the programming task below in a Python markdown code block. You are a coach of a group consisting of $n$ students. The $i$-th student has programming skill $a_i$. All students have distinct programming skills. You want to divide them into teams in such a way that: No two students $i$ and $j$ such that $|a_i - a_...
{"inputs": ["1\n1\n100\n", "1\n1\n100\n", "1\n2\n1 5\n", "1\n1\n101\n", "1\n1\n111\n", "1\n2\n1 8\n", "1\n1\n011\n", "1\n1\n010\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
578
118
coding
Solve the programming task below in a Python markdown code block. Let's imagine we have a popular online RPG. A player begins with a score of 0 in class E5. A1 is the highest level a player can achieve. Now let's say the players wants to rank up to class E4. To do so the player needs to achieve at least 100 points to ...
{"functional": "_inputs = [[-1], [0], [45], [59], [64], [100], [105], [111], [118], [332532105]]\n_outputs = [[False], [False], [False], [False], [False], ['Well done! You have advanced to the qualifying stage. Win 2 out of your next 3 games to rank up.'], ['Well done! You have advanced to the qualifying stage. Win 2 o...
210
348
coding
Solve the programming task below in a Python markdown code block. ### Count the number of Duplicates Write a function that will return the count of **distinct case-insensitive** alphabetic characters and numeric digits that occur more than once in the input string. The input string can be assumed to contain only alp...
{"functional": "_inputs = [[''], ['abcde'], ['abcdeaa'], ['abcdeaB'], ['Indivisibilities']]\n_outputs = [[0], [0], [1], [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, tu...
256
186
coding
Solve the programming task below in a Python markdown code block. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degree_{v} and s_{v}, were the fir...
{"inputs": ["1\n0 0\n", "1\n0 0\n", "1\n0 1\n", "1\n0 2\n", "1\n0 3\n", "1\n0 -1\n", "1\n0 -2\n", "1\n0 -3\n"], "outputs": ["0\n", "0\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n"]}
443
108
coding
Solve the programming task below in a Python markdown code block. How many ways are there to place a black and a white knight on an N * M chessboard such that they do not attack each other? The knights have to be placed on different squares. A knight can move two squares horizontally and one square vertically, or two s...
{"inputs": ["3\n2 2\n2 3\n4 5", "3\n2 2\n2 3\n2 5", "3\n2 2\n2 1\n4 5", "3\n4 2\n2 3\n2 5", "3\n4 2\n2 6\n2 5", "3\n2 2\n2 3\n5 5", "3\n2 2\n2 3\n2 6", "3\n2 2\n2 1\n4 6"], "outputs": ["12\n26\n312", "12\n26\n78\n", "12\n2\n312\n", "48\n26\n78\n", "48\n116\n78\n", "12\n26\n504\n", "12\n26\n116\n", "12\n2\n464\n"]}
209
217
coding
Solve the programming task below in a Python markdown code block. Ayush is learning how to decrease a number by one, but he does it wrong with a number consisting of two or more digits. Ayush subtracts one from a number by the following algorithm: if the last digit of the number is non-zero, he decreases the number by ...
{"inputs": ["512 4", "1000000000 9"], "outputs": ["50", "1"]}
263
34
coding
Solve the programming task below in a Python markdown code block. You are given a tree consisting of n nodes numbered from 1 to n. The weights of edges of the tree can be any binary integer satisfying following Q conditions. - Each condition is of form u, v, x where u, v are nodes of the tree and x is a binary numb...
{"inputs": ["3\n3 2\n1 2\n1 3\n1 2 0\n1 3 0\n3 0\n1 2\n2 3\n3 1\n1 2\n2 3\n1 2 1"], "outputs": ["1\n4\n2"]}
644
70
coding
Solve the programming task below in a Python markdown code block. Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in ...
{"inputs": ["2 1", "3 1", "1 1", "2 0", "1 9", "1 7", "4 8", "4 1"], "outputs": ["2\n", "3\n", "1\n", "0\n", "9\n", "7\n", "8\n", "4\n"]}
215
78
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, invert the tree, and return its root.   Please complete the following python code precisely: ```python # Definition for a binary tree node. # class TreeNode: # def __init__(self, v...
{"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([4,2,7,1,3,6,9])), tree_node([4,7,2,9,6,3,1]))\n assert is_same_tree(candidate(root = tree_node([2,1,3])), tree_node([2,3,1]))\n assert is_same_tree(candidate(root = tree_node([])), tree_node([]))\n\n\ncheck(Solution().inver...
119
109
coding
Solve the programming task below in a Python markdown code block. Let's denote a m-free matrix as a binary (that is, consisting of only 1's and 0's) matrix such that every square submatrix of size m × m of this matrix contains at least one zero. Consider the following problem: You are given two integers n and m. You...
{"inputs": ["1\n4\n", "1\n9\n", "1\n6\n", "1\n2\n", "1\n9\n", "1\n2\n", "1\n6\n", "1\n4\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
428
87
coding
Solve the programming task below in a Python markdown code block. Recently, the students of School 179 have developed a unique algorithm, which takes in a binary string $s$ as input. However, they soon found out that if some substring $t$ of $s$ is a palindrome of length greater than 1, the algorithm will work incorrec...
{"inputs": ["1\n6\n101010\n", "4\n1\n1\n2\n10\n2\n01\n4\n1010\n", "1\n26\n01111111111111111111111111\n"], "outputs": ["NO\n", "YES\nYES\nYES\nNO\n", "NO\n"]}
450
96
coding
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is the length of the string. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems. Kirk has a binary string $s$ (a string which consists of ze...
{"inputs": ["0\n", "1\n", "1\n", "0\n", "110\n", "010\n", "100\n", "000\n"], "outputs": ["0\n", "0\n", "0", "0", "010\n", "010\n", "100\n", "000\n"]}
690
84
coding
Solve the programming task below in a Python markdown code block. King of Berland Berl IV has recently died. Hail Berl V! As a sign of the highest achievements of the deceased king the new king decided to build a mausoleum with Berl IV's body on the main square of the capital. The mausoleum will be constructed from 2n...
{"inputs": ["3 0\n", "2 0\n", "3 0\n", "35 0\n", "30 0\n", "30 0\n", "35 0\n", "3 1\n2 > 3\n"], "outputs": ["9\n", "3\n", "9\n", "16677181699666569\n", "68630377364883\n", "68630377364883\n", "16677181699666569", "1\n"]}
665
152
coding
Solve the programming task below in a Python markdown code block. You are playing a very popular computer game. The next level consists of $n$ consecutive locations, numbered from $1$ to $n$, each of them containing either land or water. It is known that the first and last locations contain land, and for completing the...
{"inputs": ["3\n2\n1 1\n5\n1 0 1 0 1\n4\n1 0 1 1\n"], "outputs": ["0\n4\n2\n"]}
576
46
coding
Solve the programming task below in a Python markdown code block. Hello everyone. I have a simple challenge for you today. In mathematics, the formula for finding the sum to infinity of a geometric sequence is: **ONLY IF** `-1 < r < 1` where: * `a` is the first term of the sequence * `r` is the common ratio of t...
{"functional": "_inputs = [[[1, 0.5, 0.25, 0.125]], [[250, 100, 40, 16]], [[21, 4.2, 0.84, 0.168]], [[5, -2.5, 1.25, -0.625]]]\n_outputs = [[2], [416.667], [26.25], [3.333]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, ...
210
258
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return the skyline formed by these bu...
{"functional": "def check(candidate):\n assert candidate(buildings = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]]) == [[2,10],[3,15],[7,12],[12,0],[15,10],[20,8],[24,0]]\n assert candidate(buildings = [[0,2,3],[2,5,3]]) == [[0,3],[5,0]]\n\n\ncheck(Solution().getSkyline)"}
366
137
coding
Solve the programming task below in a Python markdown code block. Timur has a stairway with $n$ steps. The $i$-th step is $a_i$ meters higher than its predecessor. The first step is $a_1$ meters higher than the ground, and the ground starts at $0$ meters. The stairs for the first test case. Timur has $q$ questions, e...
{"inputs": ["3\n4 5\n1 2 1 5\n1 2 4 9 10\n2 2\n1 1\n0 1\n3 1\n1000000000 1000000000 1000000000\n1000000000\n", "11\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n"], "outputs": ["1 4 4 9 9 \n0 2 \n3000...
734
317
coding
Solve the programming task below in a Python markdown code block. We all know how great ABD aka AB-DE-VILLIERS is. However his team mates were jealous of him and posed a problem for him to solve.The problem description is as follows : Given an array of integers,find the length of the largest subarray(contiguous) of th...
{"inputs": ["4\n2 4 8 3"], "outputs": ["1"]}
317
20
coding
Solve the programming task below in a Python markdown code block. ButCoder Inc. runs a programming competition site called ButCoder. In this site, a user is given an integer value called rating that represents his/her skill, which changes each time he/she participates in a contest. The initial value of a new user's rat...
{"inputs": ["31 144 600", "1131 7 0000", "1131 8 0000", "1152 8 0000", "5856 883 583", "6439 987 572", "5856 500 2000", "4000 2000 312"], "outputs": ["1\n", "323\n", "283\n", "287\n", "35\n", "29\n", "-1\n", "5\n"]}
360
155
coding
Solve the programming task below in a Python markdown code block. Give me Chocolate Anushka wants to buy chocolates.there are many chocolates in front of her, tagged with their prices. Anushka has only a certain amount to spend, and she wants to maximize the number of chocolates she buys with this money. Given a lis...
{"inputs": ["7 50\n1 12 5 111 200 1000 10"], "outputs": ["4"]}
326
38
coding
Solve the programming task below in a Python markdown code block. For a square matrix of integers of size $n \times n$, let's define its beauty as follows: for each pair of side-adjacent elements $x$ and $y$, write out the number $|x-y|$, and then find the number of different numbers among them. For example, for the m...
{"inputs": ["2\n2\n3\n"], "outputs": ["4 1\n2 3\n9 1 8\n3 7 2\n6 4 5\n"]}
401
42
coding
Solve the programming task below in a Python markdown code block. Alice, Bob, and Charlie participated in a 400-metre race. The time taken by Alice, Bob, and Charlie to complete the race was X, Y, and Z seconds respectively. Note that X, Y, and Z are distinct. Determine the person having the highest average speed in...
{"inputs": ["3\n1 2 8\n4 100 1\n7 3 5\n"], "outputs": ["ALICE\nCHARLIE\nBOB\n"]}
555
42
coding
Solve the programming task below in a Python markdown code block. 10^9 contestants, numbered 1 to 10^9, will compete in a competition. There will be two contests in this competition. The organizer prepared N problems, numbered 1 to N, to use in these contests. When Problem i is presented in a contest, it will be solve...
{"inputs": ["4\n4 7\n1 4\n5 8\n2 8", "4\n4 7\n1 4\n2 8\n2 8", "4\n2 0\n0 0\n8 1\n1 1", "4\n4 7\n1 4\n5 8\n2 5", "4\n4 12\n1 4\n2 8\n2 8", "4\n4 1\n1 4\n1 8\n2 10", "4\n5 2\n1 1\n2 12\n0 8", "4\n0 2\n2 1\n2 16\n0 4"], "outputs": ["7", "8", "1", "6", "12", "9", "11", "15"]}
539
189
coding
Solve the programming task below in a Python markdown code block. You are given three positive integers N, x, and y. Count the number of arrays P of length N such that: P_{1} = P_{N} = 1 There are exactly x indices i such that P_{i}=1 There are exactly y indices i such that P_{i}=2 There are exactly N-x-y indices i su...
{"inputs": ["5 3 1\n", "10 4 3\n"], "outputs": ["2", "44"]}
422
30
coding
Solve the programming task below in a Python markdown code block. Write a function that rearranges an integer into its largest possible value. ```python super_size(123456) # 654321 super_size(105) # 510 super_size(12) # 21 ``` ``` haskell superSize 123456 `shouldBe` 654321 superSize 105 `shouldBe` 510 su...
{"functional": "_inputs = [[69], [513], [2017], [414], [608719], [123456789], [700000000001], [666666], [2], [0]]\n_outputs = [[96], [531], [7210], [441], [987610], [987654321], [710000000000], [666666], [2], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
179
282
coding
Solve the programming task below in a Python markdown code block. Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either ...
{"inputs": ["2 4 5\n2 5 C\n2 1 D\n", "2 1 1\n1 1 C\n1 1 D\n", "2 1 1\n1 1 C\n1 1 D\n", "2 1 0\n1 1 C\n1 1 D\n", "2 2 1\n1 1 C\n1 1 D\n", "2 4 5\n2 1 C\n3 1 D\n", "2 4 5\n2 5 C\n3 1 D\n", "2 1 0\n1 1 D\n1 1 D\n"], "outputs": ["0\n", "2\n", "2\n", "0\n", "2\n", "5\n", "0\n", "0\n"]}
485
182
coding
Solve the programming task below in a Python markdown code block. Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem: Find k integers such that the sum of two to the power of each number equals to the number n a...
{"inputs": ["1 2\n", "1 1\n", "7 2\n", "7 3\n", "7 4\n", "1 4\n", "9 4\n", "3 4\n"], "outputs": ["Yes\n-1 -1 \n", "Yes\n0 \n", "No\n", "Yes\n2 1 0 \n", "Yes\n1 1 1 0 \n", "Yes\n-2 -2 -2 -2 \n", "Yes\n2 2 -1 -1 \n", "Yes\n0 0 -1 -1 \n"]}
729
139
coding
Solve the programming task below in a Python markdown code block. I found this interesting interview question just today: > *8 coins are given where all the coins have equal weight, except one. The odd one weights less than the others, not being of pure gold. In the worst case, how many iterations are actually needed ...
{"functional": "_inputs = [[1], [2], [3], [8], [100]]\n_outputs = [[0], [1], [1], [2], [5]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): r...
226
183
coding
Solve the programming task below in a Python markdown code block. Calculate the product of all elements in an array. ```if:csharp If the array is *null*, you should throw `ArgumentNullException` and if the array is empty, you should throw `InvalidOperationException`. As a challenge, try writing your method in just one...
{"functional": "_inputs = [[[5, 4, 1, 3, 9]], [[-2, 6, 7, 8]], [[10]], [[0, 2, 9, 7]], [None], [[]]]\n_outputs = [[540], [-672], [10], [0], [None], [None]]\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 ...
289
219
coding
Solve the programming task below in a Python markdown code block. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} which are between 1 and n inclusive, and add 2^{x-1} to each c...
{"inputs": ["3\n4\n1 7 6 5\n5\n1 2 3 4 5\n2\n0 -7\n", "3\n4\n1 7 6 5\n5\n1 2 1 4 5\n2\n0 -7\n", "3\n4\n1 7 0 5\n5\n1 2 1 4 5\n2\n0 -7\n", "3\n4\n1 7 0 5\n5\n1 2 1 4 5\n2\n1 -7\n", "3\n4\n1 7 6 5\n5\n1 2 6 4 5\n2\n0 -4\n", "3\n4\n1 7 6 5\n5\n1 2 5 4 5\n2\n0 -7\n", "3\n4\n1 7 6 5\n5\n1 4 1 4 5\n2\n0 -7\n", "3\n4\n1 7 1 5...
529
326
coding
Solve the programming task below in a Python markdown code block. Chef recently saw the movie Matrix. He loved the movie overall but he didn't agree with some things in it. Particularly he didn't agree with the bald boy when he declared - There is no spoon. Being a chef, he understands the importance of the spoon and r...
{"inputs": ["3\n3 6\nabDefb\nbSpoon\nNIKHil\n6 6\naaaaaa\nssssss\nxuisdP\noooooo\nioowoo\nbdylan\n6 5\nbdfhj\ncacac\nopqrs\nddddd\nindia\nyucky", "3\n3 6\nabDefb\nbSpoon\nNIKHil\n6 6\naaaaaa\nssssss\nxuisdP\noooooo\nioowoo\nbdylan\n6 5\njhfdb\ncacac\nopqrs\nddddd\nindia\nyucky", "3\n3 6\nabDefb\nbSpoon\nNIKHil\n6 6\naa...
487
745
coding
Solve the programming task below in a Python markdown code block. ## Your story You've always loved both Fizz Buzz katas and cuckoo clocks, and when you walked by a garage sale and saw an ornate cuckoo clock with a missing pendulum, and a "Beyond-Ultimate Raspberry Pi Starter Kit" filled with all sorts of sensors and m...
{"functional": "_inputs = [['13:34'], ['21:00'], ['11:15'], ['03:03'], ['14:30'], ['08:55'], ['00:00'], ['12:00']]\n_outputs = [['tick'], ['Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo'], ['Fizz Buzz'], ['Fizz'], ['Cuckoo'], ['Buzz'], ['Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cu...
720
333
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. You want to maximize the number of points you get by performing the following operation any number of times: Pick any nums[i] and delete it to earn nums[i] points. Afterwards, you...
{"functional": "def check(candidate):\n assert candidate(nums = [3,4,2]) == 6\n assert candidate(nums = [2,2,3,3,3,4]) == 9\n\n\ncheck(Solution().deleteAndEarn)"}
138
58
coding
Solve the programming task below in a Python markdown code block. There is one card each with the numbers from "1" to "10", for a total of 10 cards. This card has numbers on the front and nothing on the back. Using this card, you and your opponent will play the game according to the following rules. 1. You and your op...
{"inputs": ["1 2 3\n5 2 8\n8 1 5", "1 2 3\n5 1 8\n8 1 5", "1 2 3\n8 2 9\n8 2 6", "1 2 3\n6 2 8\n8 1 5", "1 2 3\n6 2 8\n8 1 4", "1 2 3\n6 2 8\n4 1 5", "1 2 3\n5 1 8\n8 1 9", "1 2 3\n6 1 8\n5 2 8"], "outputs": ["YES\nYES\nYES\n", "YES\nYES\nYES\n", "YES\nYES\nYES\n", "YES\nYES\nYES\n", "YES\nYES\nYES\n", "YES\nYES\nYES\n...
459
222
coding
Solve the programming task below in a Python markdown code block. You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximiz...
{"inputs": ["1\n68972", "1\n99999", "7\n3 1 7 1 5 9 2", "7\n3 1 7 1 5 9 0", "7\n3 1 2 1 5 9 1", "7\n1 2 2 0 1 2 1", "7\n3 1 2 1 5 9 0", "7\n3 1 2 0 5 9 1"], "outputs": ["1\n", "1", "4\n", "3\n", "5\n", "7\n", "4\n", "4\n"]}
240
157
coding
Solve the programming task below in a Python markdown code block. The chef has a number N, Cheffina challenges chef to form the largest number X from the digits of N. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single line of input,...
{"inputs": ["2\n2\n212"], "outputs": ["2\n221"]}
151
22
coding
Solve the programming task below in a Python markdown code block. Do you know Just Odd Inventions? The business of this company is to "just odd inventions". Here, it is abbreviated as JOI. JOI is conducting research to confine many microorganisms in one petri dish alive. There are N microorganisms to be investigated, ...
{"inputs": ["6\n2 8\n1 9\n1 4\n6 2\n6 2\n6 9", "6\n2 8\n1 9\n1 5\n6 2\n6 2\n6 9", "6\n2 0\n0 9\n2 4\n8 0\n6 2\n6 9", "6\n2 8\n2 9\n1 5\n6 2\n6 2\n6 9", "6\n2 0\n0 9\n2 4\n0 0\n6 2\n6 9", "6\n2 8\n5 9\n2 4\n10 4\n6 1\n6 5", "6\n2 8\n5 9\n2 4\n10 4\n6 2\n6 5", "6\n2 8\n5 9\n2 4\n10 4\n6 2\n6 9"], "outputs": ["4\n", "4\n"...
529
257
coding
Solve the programming task below in a Python markdown code block. There are two towers consisting of blocks of two colors: red and blue. Both towers are represented by strings of characters B and/or R denoting the order of blocks in them from the bottom to the top, where B corresponds to a blue block, and R corresponds...
{"inputs": ["1\n1 1\nR\nB\n", "2\n1 2\nR\nRB\n1 2\nR\nRB\n", "5\n1 1\nB\nB\n1 1\nB\nB\n1 1\nB\nB\n1 1\nB\nB\n1 1\nB\nB\n", "5\n1 1\nR\nR\n1 1\nR\nR\n1 1\nR\nR\n1 1\nR\nR\n1 1\nR\nR\n", "5\n1 1\nR\nB\n1 1\nR\nB\n1 1\nR\nB\n1 1\nR\nB\n1 1\nR\nB\n", "7\n1 1\nR\nR\n1 1\nR\nR\n1 1\nR\nR\n1 1\nR\nR\n1 1\nR\nR\n1 1\nR\nR\n1 1...
532
416
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef is playing a card game with his friend Rick Sanchez. He recently won against Rick's grandson Morty; however, Rick is not as easy to beat. The ru...
{"inputs": ["3\n3 5\n28 18\n14 24"], "outputs": ["1 1\n1 2\n0 2"]}
619
38
coding
Solve the programming task below in a Python markdown code block. Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, .....
{"inputs": ["3\na\nA\na\nA\nb\n", "3\na\nA\na\nA\na\n", "3\nb\nA\na\nA\nb\n", "3\nb\nA\na\nB\nb\n", "3\nab\nBa\naB\nABBA\nl\n", "3\nab\nBa\naB\nABBA\na\n", "3\nab\nBa\naB\nABBB\nl\n", "3\nab\naB\naB\nABBA\na\n"], "outputs": ["B\n", "B\n", "B\n", "A\n", "LLLL\n", "BAAB\n", "LLBB\n", "BABA\n"]}
693
162
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a square board of characters. You can move on the board starting at the bottom right square marked with the character 'S'. You need to reach the top left square marked with the character 'E'. The rest of...
{"functional": "def check(candidate):\n assert candidate(board = [\"E23\",\"2X2\",\"12S\"]) == [7,1]\n assert candidate(board = [\"E12\",\"1X1\",\"21S\"]) == [4,2]\n assert candidate(board = [\"E11\",\"XXX\",\"11S\"]) == [0,0]\n\n\ncheck(Solution().pathsWithMaxScore)"}
215
100
coding
Solve the programming task below in a Python markdown code block. You are given three integers, A, B and C. Among them, two are the same, but the remaining one is different from the rest. For example, when A=5,B=7,C=5, A and C are the same, but B is different. Find the one that is different from the rest among the g...
{"inputs": ["5 8 5", "1 1 4", "1 1 5", "5 9 5", "5 6 5", "0 0 7", "1 1 3", "1 1 2"], "outputs": ["8\n", "4\n", "5\n", "9\n", "6\n", "7\n", "3\n", "2\n"]}
193
94
coding
Solve the programming task below in a Python markdown code block. The citizens of Codeland read each word from right to left, meaning that lexicographical comparison works differently in their language. Namely, string ```a``` is lexicographically smaller than string ```b``` if either: ```a``` is a suffix of ```b``` (in...
{"functional": "_inputs = [[['nigeb', 'ta', 'eht', 'gninnigeb']], [['a', 'b', 'a', 'd', 'c']]]\n_outputs = [[['ta', 'nigeb', 'gninnigeb', 'eht']], [['a', 'a', 'b', 'c', 'd']]]\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...
293
220
coding
Solve the programming task below in a Python markdown code block. Your users passwords were all stole in the Yahoo! hack, and it turns out they have been lax in creating secure passwords. Create a function that checks their new password (passed as a string) to make sure it meets the following requirements: Between 8...
{"functional": "_inputs = [[''], ['password'], ['P1@p'], ['P1@pP1@p'], ['P1@pP1@pP1@pP1@pP1@pP1@p']]\n_outputs = [['not valid'], ['not valid'], ['not valid'], ['valid'], ['not valid']]\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...
140
214
coding
Solve the programming task below in a Python markdown code block. There is a string s of length 3 or greater. No two neighboring characters in s are equal. Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first: * Remove one of the c...
{"inputs": ["abb", "aaa", "baa", "bba", "aa`", "aab", "`aa", "bca"], "outputs": ["First\n", "Second\n", "First\n", "First\n", "First\n", "First\n", "First\n", "First\n"]}
224
66
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two lists of closed intervals, firstList and secondList, where firstList[i] = [starti, endi] and secondList[j] = [startj, endj]. Each list of intervals is pairwise disjoint and in sorted order. Return th...
{"functional": "def check(candidate):\n assert candidate(firstList = [[0,2],[5,10],[13,23],[24,25]], secondList = [[1,5],[8,12],[15,24],[25,26]]) == [[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]\n assert candidate(firstList = [[1,3],[5,9]], secondList = []) == []\n assert candidate(firstList = [], secondList = ...
198
183
coding
Solve the programming task below in a Python markdown code block. You need to write a function that reverses the words in a given string. A word can also fit an empty string. If this is not clear enough, here are some examples: As the input may have trailing spaces, you will also need to ignore unneccesary whitespace....
{"functional": "_inputs = [['I am an expert at this'], ['This is so easy'], ['no one cares']]\n_outputs = [['this at expert an am I'], ['easy so is This'], ['cares one no']]\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, ...
120
186
coding
Solve the programming task below in a Python markdown code block. You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. Input The first and the single line cont...
{"inputs": ["9 9 9\n", "1 9 9\n", "4 2 2\n", "2 1 2\n", "4 4 4\n", "8 4 2\n", "6 1 6\n", "2 2 1\n"], "outputs": ["36", "44\n", "20\n", "16\n", "24\n", "28\n", "32\n", "16\n"]}
204
109
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the binary representation of an integer as a string s, return the number of steps to reduce it to 1 under the following rules: If the current number is even, you have to divide it by 2. If the current number...
{"functional": "def check(candidate):\n assert candidate(s = \"1101\") == 6\n assert candidate(s = \"10\") == 1\n assert candidate(s = \"1\") == 0\n\n\ncheck(Solution().numSteps)"}
121
59
coding
Solve the programming task below in a Python markdown code block. Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the apartment, the friends want to play...
{"inputs": ["1\n1\n", "1\n2\n", "1\n5\n", "1\n5\n", "1\n4\n", "1\n3\n", "1\n2\n", "1\n1\n"], "outputs": ["3\n", "2\n", "3\n", "3\n", "2\n", "3\n", "2\n", "3\n"]}
447
86
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, return the length of the longest path, where each node in the path has the same value. This path may or may not pass through the root. The length of the path between two nodes is repre...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([5,4,5,1,1,5])) == 2\n assert candidate(root = tree_node([1,4,5,4,4,5])) == 2\n\n\ncheck(Solution().longestUnivaluePath)"}
159
71
coding
Solve the programming task below in a Python markdown code block. There is always an integer in Takahashi's mind. Initially, the integer in Takahashi's mind is 0. Takahashi is now going to eat four symbols, each of which is + or -. When he eats +, the integer in his mind increases by 1; when he eats -, the integer in h...
{"inputs": ["--+-", "++-+", "++++", "-+-+", "---+", "+---", "-+++", "+++-"], "outputs": ["-2\n", "2\n", "4\n", "0\n", "-2\n", "-2\n", "2\n", "2\n"]}
329
65
coding
Solve the programming task below in a Python markdown code block. A 3×3 grid with a integer written in each square, is called a magic square if and only if the integers in each row, the integers in each column, and the integers in each diagonal (from the top left corner to the bottom right corner, and from the top righ...
{"inputs": ["8\n0\n5", "1\n0\n1", "1\n0\n2", "1\n0\n4", "1\n1\n2", "1\n0\n3", "8\n0\n6", "1\n1\n4"], "outputs": ["8 0 7\n4 5 6\n3 10 2\n", "1 0 2\n2 1 0\n0 2 1\n", "1 0 5\n6 2 -2\n-1 4 3\n", "1 0 11\n14 4 -6\n-3 8 7\n", "1 1 4\n5 2 -1\n0 3 3\n", "1 0 8\n10 3 -4\n-2 6 5\n", "8 0 10\n8 6 4\n2 12 4\n", "1 1 10\n13 4 -5\n-...
360
234
coding
Solve the programming task below in a Python markdown code block. For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $S$, find the smallest sub-array size (smallest window length) where the sum of the sub-array is greater than or equal to $S$. If there is not such sub-array, report 0. Constrai...
{"inputs": ["3 6\n1 2 3", "3 3\n1 2 3", "3 7\n1 2 3", "3 10\n1 2 3", "3 10\n0 2 3", "3 15\n1 2 3", "3 10\n1 2 0", "6 4\n1 2 0 2 3 2"], "outputs": ["3\n", "1\n", "0", "0\n", "0\n", "0\n", "0\n", "2\n"]}
241
135
coding
Solve the programming task below in a Python markdown code block. Given an array of integers, where all elements but one occur twice, find the unique element. Example $a=[1,2,3,4,3,2,1]$ The unique element is $\begin{array}{c}4\end{array}$. Function Description Complete the lonelyinteger function in the e...
{"inputs": ["1\n1\n", "3\n1 1 2\n", "5\n0 0 1 2 1\n"], "outputs": ["1\n", "2\n", "2\n"]}
358
48
coding
Solve the programming task below in a Python markdown code block. The country Treeland consists of n cities, some pairs of them are connected with unidirectional roads. Overall there are n - 1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to ...
{"inputs": ["2\n1 2\n", "3\n2 1\n2 3\n", "4\n1 4\n2 4\n3 4\n", "8\n1 2\n3 2\n4 3\n4 5\n6 5\n6 7\n8 7\n", "8\n1 4\n3 2\n4 3\n4 5\n6 5\n6 7\n8 7\n", "8\n1 4\n3 2\n4 3\n4 5\n6 5\n6 7\n8 4\n", "8\n1 4\n3 2\n4 3\n4 5\n6 5\n6 7\n8 1\n", "8\n1 4\n3 2\n7 3\n4 5\n6 5\n6 7\n8 4\n"], "outputs": ["0\n1\n", "0\n2\n", "2\n1 2 3\n", ...
408
262
coding
Solve the programming task below in a Python markdown code block. There is a new attraction in Singapore Zoo: The Infinite Zoo. The Infinite Zoo can be represented by a graph with an infinite number of vertices labeled $1,2,3,\ldots$. There is a directed edge from vertex $u$ to vertex $u+v$ if and only if $u\&v=v$, wh...
{"inputs": ["5\n1 4\n3 6\n1 6\n6 2\n5 5\n", "5\n1 4\n3 7\n1 6\n6 2\n5 5\n", "5\n1 5\n3 6\n1 6\n6 2\n5 5\n", "5\n1 5\n3 6\n1 6\n6 2\n4 5\n", "5\n1 2\n3 7\n2 6\n3 2\n6 5\n", "5\n1 3\n3 7\n2 6\n3 2\n6 5\n", "5\n1 3\n3 7\n2 3\n1 2\n6 5\n", "5\n1 4\n3 6\n1 6\n6 3\n5 5\n"], "outputs": ["YES\nYES\nNO\nNO\nYES\n", "YES\nNO\nNO...
375
294