task_type
stringclasses
4 values
problem
stringlengths
14
5.23k
solution
stringlengths
1
8.29k
problem_tokens
int64
9
1.02k
solution_tokens
int64
1
1.98k
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed binary string s and two integers minJump and maxJump. In the beginning, you are standing at index 0, which is equal to '0'. You can move from index i to index j if the following conditions ar...
{"functional": "def check(candidate):\n assert candidate(s = \"011010\", minJump = 2, maxJump = 3) == True\n assert candidate(s = \"01101110\", minJump = 2, maxJump = 3) == False\n\n\ncheck(Solution().canReach)"}
159
77
coding
Solve the programming task below in a Python markdown code block. problem There is a mysterious device $ M $, and if you put Tanuki and Fox in this device, one animal will come out from the device (hereinafter, Tanuki will be $ T $ and Fox will be $ F $). $ M (x, y) $ represents an animal that came out by putting ani...
{"inputs": ["3\nF S T", "3\nF R T", "3\nG S T", "3\nG R T", "3\nH R T", "3\nF U T", "3\nE S T", "3\nE T T"], "outputs": ["T\n", "T\n", "T\n", "T\n", "T\n", "T\n", "T\n", "T\n"]}
245
94
coding
Solve the programming task below in a Python markdown code block. Given: an array containing hashes of names Return: a string formatted as a list of names separated by commas except for the last two names, which should be separated by an ampersand. Example: ``` ruby list([ {name: 'Bart'}, {name: 'Lisa'}, {name: 'Mag...
{"functional": "_inputs = [[[{'name': 'Bart'}, {'name': 'Lisa'}, {'name': 'Maggie'}, {'name': 'Homer'}, {'name': 'Marge'}]], [[{'name': 'Bart'}, {'name': 'Lisa'}, {'name': 'Maggie'}]], [[{'name': 'Bart'}, {'name': 'Lisa'}]], [[{'name': 'Bart'}]], [[]]]\n_outputs = [['Bart, Lisa, Maggie, Homer & Marge'], ['Bart, Lisa & ...
440
268
coding
Solve the programming task below in a Python markdown code block. You are given an array of integers $a_1, a_2, \ldots, a_n$ and an integer $x$. You need to select the maximum number of elements in the array, such that for every subsegment $a_l, a_{l + 1}, \ldots, a_r$ containing strictly more than one element $(l < r...
{"inputs": ["1\n10\n5 -9 -1 6 -6 5 -6 -8 5 3\n0\n", "4\n5\n1 2 3 4 5\n2\n10\n2 4 2 4 2 4 2 4 2 4\n3\n3\n-10 -5 -10\n-8\n3\n9 9 -3\n5\n", "10\n1\n62169\n62169\n1\n49900\n49900\n1\n-45220\n-45220\n1\n45734\n45734\n1\n-77581\n-77581\n1\n-48287\n-48287\n1\n53304\n53304\n1\n13558\n13558\n1\n18202\n18202\n1\n33613\n33613\n",...
714
811
coding
Solve the programming task below in a Python markdown code block. A number $a_2$ is said to be the arithmetic mean of two numbers $a_1$ and $a_3$, if the following condition holds: $a_1 + a_3 = 2\cdot a_2$. We define an arithmetic mean deviation of three numbers $a_1$, $a_2$ and $a_3$ as follows: $d(a_1, a_2, a_3) = |...
{"inputs": ["3\n3 4 5\n2 2 6\n1 6 5\n"], "outputs": ["0\n1\n0\n"]}
746
36
coding
Solve the programming task below in a Python markdown code block. Ohana Matsumae is trying to clean a room, which is divided up into an n by n grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square...
{"inputs": ["1\n1\n", "1\n0\n", "1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "2\n10\n01\n", "2\n10\n01\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1", "1", "1\n", "1"]}
378
91
coding
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"]}
410
22
coding
Solve the programming task below in a Python markdown code block. There are N children and Chef wants to give them 1 candy each. Chef already has X candies with him. To buy the rest, he visits a candy shop. In the shop, packets containing exactly 4 candies are available. Determine the minimum number of candy packets C...
{"inputs": ["4\n20 12\n10 100\n10 9\n20 9\n"], "outputs": ["2\n0\n1\n3\n"]}
432
43
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. The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems. Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to fi...
{"inputs": ["0\n", "1\n", "1\n", "0\n", "110\n", "010\n", "000\n", "100\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "010\n", "010\n", "000\n", "100\n"]}
680
86
coding
Solve the programming task below in a Python markdown code block. Ash is on his way to becoming the Pokemon Master. His pokemon can perform the following moves: - Tackle - Deal damage worth $X$ points - Grow - Increase damage by $Y$ points i.e. $X$ = $X$ + $Y$ But, it can only perform Grow first (0 or more times) ...
{"inputs": ["2\n101 10 10\n11 3 3"], "outputs": ["6\n-1"]}
525
32
coding
Solve the programming task below in a Python markdown code block. There were $N$ students (numbered $1$ through $N$) participating in the Indian Programming Camp (IPC) and they watched a total of $K$ lectures (numbered $1$ through $K$). For each student $i$ and each lecture $j$, the $i$-th student watched the $j$-th le...
{"inputs": ["4 8 4\n1 2 1 2 5\n3 5 1 3 4\n1 2 4 5 11\n1 1 1 3 12"], "outputs": ["1"]}
663
58
coding
Solve the programming task below in a Python markdown code block. The Duck song For simplicity, we'll assume that there are only three types of grapes: green grapes, purple grapes and black grapes. Andrew, Dmitry and Michal are all grapes' lovers, however their preferences of grapes are different. To make all of them...
{"inputs": ["1 6 2\n4 3 3\n", "5 1 1\n4 3 2\n", "1 2 3\n3 2 1\n", "1 8 4\n3 1 9\n", "6 1 2\n4 9 6\n", "3 2 1\n1 2 3\n", "1 7 9\n4 5 7\n", "4 6 4\n4 5 6\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
547
150
coding
Solve the programming task below in a Python markdown code block. George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t. Help George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George could have go...
{"inputs": ["05:50\n05:44\n", "00:00\n01:00\n", "00:01\n00:00\n", "23:59\n23:59\n", "23:44\n23:55\n", "00:00\n13:12\n", "12:00\n23:59\n", "12:44\n12:44\n"], "outputs": ["00:06\n", "23:00\n", "00:01\n", "00:00\n", "23:49\n", "10:48\n", "12:01\n", "00:00\n"]}
355
182
coding
Solve the programming task below in a Python markdown code block. There is an ice cream shop named Ten Ice Cream. At this store, we always have 10 types of ice cream on the shelves. The store manager creates a daily graph showing how well ice cream is selling for reference in product development. For such a store mana...
{"inputs": ["15\n2\n6\n7\n0\n1\n9\n8\n7\n3\n8\n9\n4\n8\n4\n2\n3\n9\n1\n5\n0", "15\n2\n6\n7\n0\n0\n9\n8\n7\n3\n8\n9\n4\n8\n2\n2\n3\n9\n1\n5\n0", "15\n2\n6\n7\n0\n1\n9\n8\n7\n3\n8\n9\n4\n8\n4\n2\n3\n9\n1\n2\n0", "15\n2\n6\n7\n0\n0\n9\n8\n7\n3\n8\n9\n8\n8\n2\n2\n3\n9\n1\n5\n0", "15\n2\n6\n7\n0\n1\n9\n8\n7\n3\n8\n9\n4\n8\n...
366
731
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array intervals where intervals[i] = [li, ri] represent the interval [li, ri), remove all intervals that are covered by another interval in the list. The interval [a, b) is covered by the interval [c, d) if a...
{"functional": "def check(candidate):\n assert candidate(intervals = [[1,4],[3,6],[2,8]]) == 2\n\n\ncheck(Solution().removeCoveredIntervals)"}
123
45
coding
Solve the programming task below in a Python markdown code block. Make a function that returns the value multiplied by 50 and increased by 6. If the value entered is a string it should return "Error". Note: in `C#`, you'll always get the input as a string, so the above applies if the string isn't representing a double...
{"functional": "_inputs = [['hello'], [1], [5], [0], [1.2], [3], ['RyanIsCool']]\n_outputs = [['Error'], [56], [256], [6], [66], [156], ['Error']]\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 isinst...
95
199
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. We define the *goodness* of any array B of length M as: \sum_{i = 1}^{M - 1} |B_{i + 1} - B_{i}| (Here |X| denotes the absolute value of X). In particular, *goodness* of any array of length 1 is 0. Alice and Bob have an array A containing N distinct ele...
{"inputs": ["2\n3\n1 3 2\n4\n1 2 3 4\n"], "outputs": ["Bob\nAlice\n"]}
759
34
coding
Solve the programming task below in a Python markdown code block. Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b. Constraints * 0 < a, b ≤ 2,000,000,000 * LCM(a, b) ≤ 2,000,000,000 * The number of data sets ≤ 50 Input Input consists of several d...
{"inputs": ["13 1\n183 188468232", "13 1\n183 218395056", "13 1\n183 158763340", "13 2\n183 158763340", "11 2\n183 158763340", "8 1\n21473 188468232", "8 1\n32366 188468232", "0 8\n3041947 11770363"], "outputs": ["1 13\n3 11496562152\n", "1 13\n3 13322098416\n", "1 13\n1 29053691220\n", "1 26\n1 29053691220\n", "1 22\n...
204
342
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are standing at position 0 on an infinite number line. There is a destination at position target. You can make some number of moves numMoves so that: On each move, you can either go left or right. During the ith ...
{"functional": "def check(candidate):\n assert candidate(target = 2) == 3\n assert candidate(target = 3) == 2\n\n\ncheck(Solution().reachNumber)"}
144
43
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum.   Please complete the ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,4,3,2]) == 4\n assert candidate(nums = [6,2,6,5,1,2]) == 9\n\n\ncheck(Solution().arrayPairSum)"}
109
60
coding
Solve the programming task below in a Python markdown code block. Chef owns an icecream shop in Chefland named scoORZ. There are only three types of coins in Chefland: Rs. 5, Rs. 10 and Rs. 15. An icecream costs Rs. 5. There are $N$ people (numbered $1$ through $N$) standing in a queue to buy icecream from scoORZ. Each...
{"inputs": ["3\n2\n5 10\n2\n10 5\n2\n5 15\n"], "outputs": ["YES\nNO\nNO"]}
615
38
coding
Solve the programming task below in a Python markdown code block. Iroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectiv...
{"inputs": ["2 7 5", "2 7 3", "2 4 3", "2 4 1", "2 4 0", "3 4 0", "4 4 0", "1 0 1"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
206
94
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer k, return the minimum number of Fibonacci numbers whose sum is equal to k. The same Fibonacci number can be used multiple times. The Fibonacci numbers are defined as: F1 = 1 F2 = 1 Fn = Fn-1 + Fn-2 f...
{"functional": "def check(candidate):\n assert candidate(k = 7) == 2 \n assert candidate(k = 10) == 2 \n assert candidate(k = 19) == 3 \n\n\ncheck(Solution().findMinFibonacciNumbers)"}
136
64
coding
Solve the programming task below in a Python markdown code block. You are using at most A number of 1s and at most B number of 2s. How many different evaluation results are possible when they are formed in an expression containing only addition + sign and multiplication * sign are allowed? Note that, multiplication ta...
{"inputs": ["4\n0 0\n2 2\n0 2\n2 0\n"], "outputs": ["0\n6\n2\n2\n"]}
496
36
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a weighted undirected connected graph with n vertices numbered from 0 to n - 1, and an array edges where edges[i] = [ai, bi, weighti] represents a bidirectional and weighted edge between nodes ai and bi. A minim...
{"functional": "def check(candidate):\n assert candidate(n = 5, edges = [[0,1,1],[1,2,1],[2,3,2],[0,3,2],[0,4,3],[3,4,3],[1,4,6]]) == [[0,1],[2,3,4,5]]\n assert candidate(n = 4, edges = [[0,1,1],[1,2,1],[2,3,1],[0,3,1]]) == [[],[0,1,2,3]]\n\n\ncheck(Solution().findCriticalAndPseudoCriticalEdges)"}
228
141
coding
Solve the programming task below in a Python markdown code block. # Task: Based on the received dimensions, `a` and `b`, of an ellipse, calculare its area and perimeter. ## Example: ```python Input: ellipse(5,2) Output: "Area: 31.4, perimeter: 23.1" ``` **Note:** The perimeter approximation formula you should use: ...
{"functional": "_inputs = [[5, 2], [6, 8], [13, 1]]\n_outputs = [['Area: 31.4, perimeter: 23.1'], ['Area: 150.8, perimeter: 44.2'], ['Area: 40.8, perimeter: 54.6']]\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=t...
128
219
coding
Solve the programming task below in a Python markdown code block. Takahashi has a string S of length N consisting of lowercase English letters. On this string, he will perform the following operation K times: * Let T be the string obtained by reversing S, and U be the string obtained by concatenating S and T in this o...
{"inputs": ["5 2\nbacba", "5 2\nbacaa", "5 1\nbabba", "5 1\nbabbb", "5 1\nbabbc", "5 2\nbabbc", "5 2\ncabab", "5 1\nbacaa"], "outputs": ["aaaab\n", "aaaaa\n", "aabba\n", "abbbb\n", "abbcc\n", "aabbc\n", "aabab\n", "aaaac\n"]}
235
111
coding
Solve the programming task below in a Python markdown code block. The educational program (AHK Education) of the Aiz Broadcasting Association broadcasts a handicraft program for children, "Play with Tsukuro". This time I will make a box with sticks, but I would like to see if I can make a rectangular parallelepiped usi...
{"inputs": ["1 1 2 2 3 1 1 3 3 3 1 2", "1 1 3 4 8 9 7 3 3 5 5 5", "1 0 2 2 3 1 1 3 3 3 1 2", "1 1 3 7 8 9 7 3 3 5 5 5", "0 0 2 2 3 1 1 3 3 3 1 2", "1 1 2 2 5 1 2 3 3 3 1 2", "1 1 3 4 8 9 3 3 4 5 5 5", "1 1 2 2 3 1 2 3 2 3 1 2"], "outputs": ["no\n", "no\n", "no\n", "no\n", "no\n", "no\n", "no\n", "no\n"]}
283
238
coding
Solve the programming task below in a Python markdown code block. Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as fo...
{"inputs": ["aaac\n3\n1\n2\n1\nvwxyz\n2\n3\n4\n-", "caaa\n3\n1\n2\n1\nvwxyz\n2\n3\n4\n-", "caaa\n3\n1\n2\n2\nvxxyz\n2\n3\n4\n-", "ca`a\n3\n1\n2\n2\nvwxyz\n2\n3\n4\n-", "caaa\n3\n1\n0\n2\nvwxyz\n2\n3\n4\n-", "aaac\n3\n1\n2\n1\nvwxyz\n2\n2\n4\n-", "ca`a\n3\n1\n2\n1\nvwxyz\n2\n3\n4\n-", "ca`a\n3\n1\n2\n2\nvwxyz\n2\n2\n4\n...
335
255
coding
Solve the programming task below in a Python markdown code block. The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could hav...
{"inputs": ["2\n1 1\n", "2\n2 1\n", "2\n1 0\n", "2\n2 0\n", "2\n2 2\n", "2\n0 0\n", "2\n1 2\n", "3\n1 3 2\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
388
104
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, return the number of homogenous substrings of s. Since the answer may be too large, return it modulo 109 + 7. A string is homogenous if all the characters of the string are the same. A substring is a...
{"functional": "def check(candidate):\n assert candidate(s = \"abbcccaa\") == 13\n assert candidate(s = \"xy\") == 2\n assert candidate(s = \"zzzzz\") == 15\n\n\ncheck(Solution().countHomogenous)"}
111
62
coding
Solve the programming task below in a Python markdown code block. ## Task Write a method `remainder` which takes two integer arguments, `dividend` and `divisor`, and returns the remainder when dividend is divided by divisor. Do NOT use the modulus operator (%) to calculate the remainder! #### Assumption Dividend wil...
{"functional": "_inputs = [[3, 2], [19, 2], [10, 2], [34, 7], [27, 5]]\n_outputs = [[1], [1], [0], [6], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if le...
208
197
coding
Solve the programming task below in a Python markdown code block. A little girl loves problems on bitwise operations very much. Here's one of them. You are given two integers l and r. Let's consider the values of $a \oplus b$ for all pairs of integers a and b (l ≤ a ≤ b ≤ r). Your task is to find the maximum value amo...
{"inputs": ["1 2\n", "1 1\n", "1 1\n", "1 3\n", "1 3\n", "1 2\n", "1 1\n", "8 16\n"], "outputs": ["3\n", "0\n", "0\n", "3\n", "3\n", "3\n", "0\n", "31\n"]}
276
88
coding
Solve the programming task below in a Python markdown code block. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are: 2332 110011 54322345 For this kata, single digit numbers will not be considered numerical palindro...
{"functional": "_inputs = [[868], [1321], [1215], [2], [123322367], [1551], [13598], ['ACCDDCCA'], ['1551'], [-4505], [22.22]]\n_outputs = [[True], [False], [True], [False], [True], [True], [False], ['Not valid'], ['Not valid'], ['Not valid'], ['Not valid']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstanc...
256
254
coding
Solve the programming task below in a Python markdown code block. Harish has decided to go to Arya's hotel this morning. We all know he is crazy for masala dosas. And as usual he is always hungry. He decided to order all the masala dosas at once. But then he realised that he did not have enough money to buy all of them...
{"inputs": ["2\n16\n27"], "outputs": ["YES\nNO"]}
353
20
coding
Solve the programming task below in a Python markdown code block. Given n and m, calculate 1^{1} + 2^{2} + 3^{3} + ... + n^{n} modulo m. ------ Input ------ The first line contains 1 ≤ t ≤ 10, the number of test cases. Then the test case definitions follow. Each test case is of the form: 1 ≤ n 10^{18}, 1 ≤ m ≤ 2000...
{"inputs": ["6\n1 100000\n2 100000\n3 100000\n4 100000\n5 100000\n6 100000"], "outputs": ["1\n5\n32\n288\n3413\n50069"]}
220
86
coding
Solve the programming task below in a Python markdown code block. Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a large queue of n Berland residents lined up in front of the ice cream stall. We know that each of them has a certain amount of berl...
{"inputs": ["1\n1\n", "1\n0\n", "1\n1\n", "1\n0\n", "1\n2\n", "2\n2 1\n", "2\n2 1\n", "2\n2 0\n"], "outputs": ["1 ", "0 ", "1 ", "0 ", "2 ", ":(\n", ":(", "1 1 "]}
623
88
coding
Solve the programming task below in a Python markdown code block. Your team is writing a fancy new text editor and you've been tasked with implementing the line numbering. Write a function which takes a list of strings and returns each line prepended by the correct number. The numbering starts at 1. The format is `n:...
{"functional": "_inputs = [[[]], [['a', 'b', 'c']], [['', '', '', '', '']], [['', 'b', '', '', '']]]\n_outputs = [[[]], [['1: a', '2: b', '3: c']], [['1: ', '2: ', '3: ', '4: ', '5: ']], [['1: ', '2: b', '3: ', '4: ', '5: ']]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, flo...
138
237
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array forts of length n representing the positions of several forts. forts[i] can be -1, 0, or 1 where: -1 represents there is no fort at the ith position. 0 indicates there is an en...
{"functional": "def check(candidate):\n assert candidate(forts = [1,0,0,-1,0,0,0,0,1]) == 4\n assert candidate(forts = [0,0,1,-1]) == 0\n\n\ncheck(Solution().captureForts)"}
246
68
coding
Solve the programming task below in a Python markdown code block. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. -----Constraints----- - The length of S is 4. - S consists of uppercase English lett...
{"inputs": ["EEFF", "FQEE", "SPOT", "ASRA", "EEQF", "SPNT", "ARSA", "EEQG"], "outputs": ["Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
135
73
coding
Solve the programming task below in a Python markdown code block. Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she ...
{"inputs": ["1\n2\n", "1\n4\n", "1\n0\n", "1\n-3\n", "2\n0 3\n", "2\n0 0\n", "1\n7500\n", "1\n5507\n"], "outputs": ["2\n", "4\n", "0\n", "3\n", "3\n", "0\n", "7500\n", "5507\n"]}
374
103
coding
Solve the programming task below in a Python markdown code block. The problem is quite simple. You're given a number N and a positive integer K. Tell if N can be represented as a sum of K prime numbers (not necessarily distinct). Input Format The first line contains a single integer T, denoting the number of test c...
{"inputs": ["2\n10 2\n1 6\n"], "outputs": ["Yes\nNo\n"]}
226
25
coding
Solve the programming task below in a Python markdown code block. collections.deque() A deque is a double-ended queue. It can be used to add or remove elements from both ends. Deques support thread safe, memory efficient appends and pops from either side of the deque with approximately the same $O(1)$ performance i...
{"inputs": ["6\nappend 1\nappend 2\nappend 3\nappendleft 4\npop\npopleft\n"], "outputs": ["1 2\n"]}
479
38
coding
Solve the programming task below in a Python markdown code block. Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many ...
{"inputs": ["8\n", "1\n", "9\n", "5\n", "2\n", "6\n", "4\n", "3\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
275
70
coding
Solve the programming task below in a Python markdown code block. Given an array A consisting of N non-negative integers. You need to perform the following operation (N - 1) times: Sort the array A in ascending order. Let M be the current size of the array A. Replace the array A by [(A_{2} - A_{1}), (A_{3} - A_{2}), ...
{"inputs": ["2\n4\n29 19 0 3\n1\n777"], "outputs": ["1\n777"]}
578
34
coding
Solve the programming task below in a Python markdown code block. A problem setter is called an *expert* if at least 50 \% of their problems are approved by Chef. Munchy submitted X problems for approval. If Y problems out of those were approved, find whether Munchy is an *expert* or not. ------ Input Format ------ ...
{"inputs": ["4\n5 3\n1 1\n4 1\n2 1\n"], "outputs": ["YES\nYES\nNO\nYES"]}
487
35
coding
Solve the programming task below in a Python markdown code block. You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$. In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is...
{"inputs": ["1\n6\n1 0 -3 1 0 1\n", "1\n6\n5 -5 -3 1 1 1\n", "1\n6\n5 -6 -3 2 1 1\n", "1\n6\n5 -4 -4 1 1 1\n", "1\n6\n5 -6 -4 2 2 1\n", "1\n6\n6 -5 -3 1 0 1\n", "1\n6\n3 -6 -4 4 2 1\n", "1\n6\n6 -4 -3 1 0 0\n"], "outputs": ["2\n", "3\n", "4\n", "3\n", "5\n", "2\n", "7\n", "1\n"]}
596
182
coding
Solve the programming task below in a Python markdown code block. Chef’s girlfriend is angry with him because he forgot her birthday. Chef decided to please her by gifting her a Love Graph. Chef has $N$ vertices: $V_1, V_2, \dots, V_N$. Love Graph is an undirected multigraph with no self-loops and can be constructed b...
{"inputs": ["1\n2 1"], "outputs": ["2"]}
494
16
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. Eugeny loves listening to music. He has n songs in his play list. We know that song number i has the duration of t_{i} minutes. Eugeny listens to each song, perhaps more than once. He listens to song number i c_{i} times. Eugeny's play list is organized ...
{"inputs": ["1 2\n2 8\n1 16\n", "1 2\n2 8\n1 16\n", "3 1\n2 50\n1 50\n1 50\n160\n", "3 1\n2 50\n1 50\n1 50\n160\n", "3 1\n2 50\n1 50\n1 82\n160\n", "3 1\n2 74\n1 50\n1 82\n160\n", "3 1\n2 74\n1 32\n1 82\n160\n", "3 1\n2 50\n1 53\n1 82\n160\n"], "outputs": ["1\n1\n", "1\n1\n", "3\n", "3\n", "3\n", "2\n", "2\n", "3\n"]}
555
222
coding
Solve the programming task below in a Python markdown code block. You are a skier (marked below by the `X`). You have made it to the Olympics! Well done. ``` \_\_\_X\_ \*\*\*\*\*\ \*\*\*\*\*\*\ \*\*\*\*\*\*\*\ \*\*\*\*\*\*\*\*\ \*\*\*\*\*\*\*\*\*\\.\_\_\_\_/ ``` Your job in this kata is to calculate the maximum speed...
{"functional": "_inputs = [[['*']], [['*', '**', '***']], [['*', '**', '***', '****', '*****', '******']], [['*', '**', '***', '****', '*****', '******', '*******', '********']]]\n_outputs = [[\"1.35 metres: He's crap!\"], [\"12.15 metres: He's ok!\"], [\"48.60 metres: He's flying!\"], ['86.40 metres: Gold!!']]\nimport...
449
254
coding
Solve the programming task below in a Python markdown code block. JJ has an array A of length N. He can perform the following operation on A: Select any L, R (1 ≤ L ≤ R ≤ N) and for each i such that L ≤ i ≤ R, set A_{i} := A_{i} + 1. JJ wants to make A palindromic. Find the minimum number of moves to do so. Note: An ...
{"inputs": ["3\n6\n2 6 4 3 4 1\n2\n1 10\n3\n1 10 1\n"], "outputs": ["2\n9\n0\n"]}
544
48
coding
Solve the programming task below in a Python markdown code block. You are given a binary string S. In one second, the following scenario happens simultaneously and independently for all the bits which are set to 1 in the string: Change the bit from 1 to 0. If the left neighbour exists and is 0, change it to 1. If the...
{"inputs": ["3\n3 1\n101\n5 2\n10001\n14 3\n10011010111000"], "outputs": ["010\n10101\n01100101010101"]}
532
73
coding
Solve the programming task below in a Python markdown code block. You're looking through different hex codes, and having trouble telling the difference between #000001 and #100000 We need a way to tell which is red, and which is blue! That's where you create ```hex_color()```! It should read an RGB input, and re...
{"functional": "_inputs = [[''], ['000 000 000'], ['121 245 255'], ['027 100 100'], ['021 021 021'], ['255 000 000'], ['000 147 000'], ['212 103 212'], ['101 101 092']]\n_outputs = [['black'], ['black'], ['blue'], ['cyan'], ['white'], ['red'], ['green'], ['magenta'], ['yellow']]\nimport math\ndef _deep_eq(a, b, tol=1e-...
271
282
coding
Solve the programming task below in a Python markdown code block. Step through my `green glass door`. You can take the `moon`, but not the `sun`. You can take your `slippers`, but not your `sandals`. You can go through `yelling`, but not `shouting`. You can't run through `fast`, but you can run with `speed`. You c...
{"functional": "_inputs = [['moon'], ['test'], ['glasses'], ['airplane'], ['free'], ['branch'], ['aardvark']]\n_outputs = [[True], [False], [True], [False], [True], [False], [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_t...
149
196
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a positive integer num, return the number of positive integers less than or equal to num whose digit sums are even. The digit sum of a positive integer is the sum of all its digits.   Please complete the followi...
{"functional": "def check(candidate):\n assert candidate(num = 4) == 2\n assert candidate(num = 30) == 14\n\n\ncheck(Solution().countEven)"}
86
45
coding
Solve the programming task below in a Python markdown code block. In the speed skating badge test, grades are awarded when the time specified for two distances is exceeded. For example, to reach Class A, 500 M requires less than 40.0 seconds and 1000 M requires less than 1 minute and 23 seconds. Create a program that ...
{"inputs": ["40.0 70.0\n72.5 140.51", "40.0 70.15273874709118\n72.5 140.51", "40.0 70.15273874709118\n73.39358812211353 140.51", "40.0 70.26540141125885\n73.39358812211353 140.51", "40.991466890252646 70.26540141125885\n73.39358812211353 140.51", "40.991466890252646 70.71729331330802\n73.39358812211353 140.51", "40.991...
473
471
coding
Solve the programming task below in a Python markdown code block. Your algorithm is so good at predicting the market that you now know what the share price of Mahindra & Mahindra. (M&M) will be for the next N days. Each day, you can either buy one share of M&M, sell any number of shares of M&M that you own, or not mak...
{"inputs": ["3\n3\n5 3 2\n3\n1 2 100\n4\n1 3 1 2"], "outputs": ["0\n197\n3"]}
341
46
coding
Solve the programming task below in a Python markdown code block. You are given an integer array $a_1, a_2, \ldots, a_n$. The array $b$ is called to be a subsequence of $a$ if it is possible to remove some elements from $a$ to get $b$. Array $b_1, b_2, \ldots, b_k$ is called to be good if it is not empty and for ever...
{"inputs": ["1\n7\n", "1\n32\n", "2\n1 2\n", "1\n688\n", "2\n1 2\n", "1\n1469\n", "1\n2185\n", "1\n89751\n"], "outputs": ["1\n", "1\n", "3", "1\n", "3\n", "1\n", "1\n", "1\n"]}
535
102
coding
Solve the programming task below in a Python markdown code block. One very important person has a piece of paper in the form of a rectangle a × b. Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size x_{i} × y_{i}. Each impression must be parallel to the sides of the...
{"inputs": ["2 2 2\n1 2\n2 1\n", "2 1 1\n1 1\n1 1\n", "2 1 2\n1 1\n1 1\n", "1 100 50\n4 20\n", "2 2 4\n3 1\n2 2\n", "2 2 4\n2 3\n2 1\n", "2 4 2\n1 2\n2 3\n", "2 1 4\n1 2\n1 2\n"], "outputs": ["4\n", "0\n", "2\n", "0\n", "0\n", "8\n", "8\n", "4\n"]}
422
166
coding
Solve the programming task below in a Python markdown code block. The chef is trying to decode 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 ...
{"inputs": ["4\n1\n2\n3\n4"], "outputs": ["2\n23\n34\n234\n345\n456\n2345\n3456\n4567\n5678"]}
216
58
coding
Solve the programming task below in a Python markdown code block. In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model soluti...
{"inputs": ["2\n0 1\n", "2\n8 37\n", "2\n6 37\n", "2\n6 43\n", "2\n1 43\n", "2\n0 32\n", "2\n1 32\n", "2\n73 37\n"], "outputs": ["1", "29\n", "31\n", "37\n", "42\n", "32\n", "31\n", "36"]}
679
115
coding
Solve the programming task below in a Python markdown code block. Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of sum of digits of the num...
{"inputs": ["6\n", "4\n", "3\n", "5\n", "31\n", "28\n", "98\n", "88\n"], "outputs": ["9/4\n", "3/2\n", "2/1\n", "7/3\n", "222/29\n", "85/13\n", "317/16\n", "1529/86\n"]}
252
102
coding
Solve the programming task below in a Python markdown code block. Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive. Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after s...
{"inputs": ["1\n0 0\n", "1\n8 9\n", "1\n8 17\n", "1\n16 17\n", "2\n1 2\n1 3\n", "2\n1 3\n1 6\n", "2\n1 3\n2 4\n", "2\n2 2\n1 3\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "1\n", "1\n", "-1\n", "1\n"]}
431
122
coding
Solve the programming task below in a Python markdown code block. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the number of vertices an...
{"inputs": ["4 6\n0 1 1\n0 2 5\n1 2 3\n1 3 4\n2 3 1\n3 2 7", "4 6\n0 1 1\n0 2 5\n1 2 3\n0 3 4\n2 3 1\n3 2 7", "4 6\n0 1 1\n0 2 5\n1 2 3\n0 3 4\n2 3 1\n0 2 7", "4 6\n0 1 1\n0 2 5\n1 2 3\n0 2 4\n2 3 1\n0 2 7", "4 6\n0 1 1\n0 2 0\n1 2 2\n0 3 4\n2 3 1\n3 2 7", "4 6\n0 1 1\n0 2 5\n1 2 3\n0 3 3\n2 3 1\n3 2 7", "4 6\n0 1 1\n0...
555
586
coding
Solve the programming task below in a Python markdown code block. # Base64 Numeric Translator Our standard numbering system is (Base 10). That includes 0 through 9. Binary is (Base 2), only 1’s and 0’s. And Hexadecimal is (Base 16) (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F). A hexadecimal “F” has a (Base 10) va...
{"functional": "_inputs = [['WIN'], ['b64'], ['B64'], ['/+/'], ['HelloWorld']]\n_outputs = [[90637], [114360], [7864], [262079], [134710352538679645]]\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 is...
442
222
coding
Solve the programming task below in a Python markdown code block. Whereas humans nowadays read fewer and fewer books on paper, book readership among marmots has surged. Heidi has expanded the library and is now serving longer request sequences. -----Input----- Same as the easy version, but the limits have changed: 1...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "4 1\n1 2 2 1\n", "4 2\n1 2 3 1\n", "4 2\n1 2 3 2\n", "4 2\n1 2 3 2\n", "4 3\n1 1 1 1\n", "4 2\n2 2 3 1\n"], "outputs": ["1\n", "1\n", "3\n", "3\n", "3\n", "3\n", "1\n", "3\n"]}
146
138
coding
Solve the programming task below in a Python markdown code block. problem Given a sequence $ a_i $ of length $ N $. Output all integers $ K (1 \ le K \ le N) $ that satisfy the following conditions. Condition: Well sorted $ a_1, \ cdots, a_K $ matches $ a_ {N-K + 1}, \ cdots, a_N $. Example Input 8 5 2 4 9 4 9...
{"inputs": ["8\n5 2 4 4 4 9 2 5", "8\n6 2 7 4 2 7 2 0", "8\n5 2 4 9 4 9 2 5", "8\n5 2 4 4 4 14 2 0", "8\n5 2 4 4 4 14 2 5", "8\n5 2 4 4 4 11 2 0", "8\n5 2 6 4 4 11 2 0", "8\n6 2 6 4 4 11 2 0"], "outputs": ["1 2 6 7 8\n", "8\n", "1 2 4 6 7 8", "8\n", "1 2 6 7 8\n", "8\n", "8\n", "8\n"]}
118
220
coding
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"]}
624
157
coding
Solve the programming task below in a Python markdown code block. You have two variables a and b. Consider the following sequence of actions performed with these variables: If a = 0 or b = 0, end the process. Otherwise, go to step 2; If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to st...
{"inputs": ["1 4\n", "2 4\n", "2 1\n", "7 1\n", "4 8\n", "1 2\n", "2 3\n", "1 3\n"], "outputs": ["1 0\n", "2 0\n", "0 1\n", "1 1\n", "4 0\n", "1 0\n", "2 3\n", "1 1\n"]}
340
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. An n-bit gray code sequence is a sequence of 2n integers where: Every integer is in the inclusive range [0, 2n - 1], The first integer is 0, An integer appears no more than once in the sequence, The binary representa...
{"functional": "def check(candidate):\n assert candidate(n = 2) == [0,1,3,2]\n assert candidate(n = 1) == [0,1]\n\n\ncheck(Solution().grayCode)"}
145
53
coding
Solve the programming task below in a Python markdown code block. Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef...
{"inputs": ["1\n3 2", "1\n11 2"], "outputs": ["2", "6"]}
371
27
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums and an integer threshold. Find the length of the longest subarray of nums starting at index l and ending at index r (0 <= l <= r < nums.length) that satisfies the following...
{"functional": "def check(candidate):\n assert candidate(nums = [3,2,5,4], threshold = 5) == 3\n assert candidate(nums = [1,2], threshold = 2) == 1\n assert candidate(nums = [2,3,4,5], threshold = 4) == 3\n\n\ncheck(Solution().longestAlternatingSubarray)"}
197
88
coding
Solve the programming task below in a Python markdown code block. Indraneel's student has given him data from two sets of experiments that the student has performed. Indraneel wants to establish a correlation between the two sets of data. Each data set is a sequence of $N$ numbers. The two data sets do not match number...
{"inputs": ["7\n3 8 4 23 9 11 28\n2 3 22 26 8 16 12"], "outputs": ["4\n3 4 23 9\n2 3 22 8"]}
470
65
coding
Solve the programming task below in a Python markdown code block. The objective is to disambiguate two given names: the original with another This kata is slightly more evolved than the previous one: [Author Disambiguation: to the point!](https://www.codewars.com/kata/580a429e1cb4028481000019). The function ```could_...
{"functional": "_inputs = [['Carlos Ray Norris', 'Carlos Ray Norris'], ['Carlos Ray Norris', 'Carlos Ray'], ['Carlos Ray Norris', 'Ray Norris'], ['Carlos Ray Norris', 'Carlos Norris'], ['Carlos Ray Norris', 'Norris'], ['Carlos Ray Norris', 'Carlos'], ['Carlos Ray Norris', 'Norris Carlos'], ['Carlos Ray Norris', 'carlos...
536
438
coding
Solve the programming task below in a Python markdown code block. At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The leve...
{"inputs": ["4\n110 16 20\n98 86 19\n80 8 39\n65 79 65\n2\n99 81 9\n66 72 90\n0", "4\n010 163 20\n98 86 5\n80 34 33\n65 79 65\n2\n49 81 20\n97 1 4\n0", "4\n110 11 20\n98 86 19\n80 10 39\n65 0 65\n2\n99 81 9\n66 102 90\n0", "4\n100 64 20\n51 86 18\n80 39 36\n65 79 65\n2\n99 81 6\n76 72 90\n0", "4\n100 70 20\n98 86 55\n8...
465
608
coding
Solve the programming task below in a Python markdown code block. The Mormons are trying to find new followers and in order to do that they embark on missions. Each time they go on a mission, every Mormons converts a fixed number of people (reach) into followers. This continues and every freshly converted Mormon as we...
{"functional": "_inputs = [[40, 2, 120], [40, 2, 121]]\n_outputs = [[1], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ...
195
179
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. In an alien language, surprisingly, they also use English lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters. Given a sequence of words written in ...
{"functional": "def check(candidate):\n assert candidate(words = [\"hello\",\"leetcode\"], order = \"hlabcdefgijkmnopqrstuvwxyz\") == True\n assert candidate(words = [\"word\",\"world\",\"row\"], order = \"worldabcefghijkmnpqstuvxyz\") == False\n assert candidate(words = [\"apple\",\"app\"], order = \"abcdefgh...
124
99
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and an integer k. You may partition nums into one or more subsequences such that each element in nums appears in exactly one of the subsequences. Return the minimum number of subseq...
{"functional": "def check(candidate):\n assert candidate(nums = [3,6,1,2,5], k = 2) == 2\n assert candidate(nums = [1,2,3], k = 1) == 2\n assert candidate(nums = [2,2,4,5], k = 0) == 3\n\n\ncheck(Solution().partitionArray)"}
144
88
coding
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 repeatLimit. Construct a new string repeatLimitedString using the characters of s such that no letter appears more than repeatLimit times in a row. You do not have to use all ch...
{"functional": "def check(candidate):\n assert candidate(s = \"cczazcc\", repeatLimit = 3) == \"zzcccac\"\n assert candidate(s = \"aababab\", repeatLimit = 2) == \"bbabaa\"\n\n\ncheck(Solution().repeatLimitedString)"}
181
67
coding
Solve the programming task below in a Python markdown code block. Your task is to make function, which returns the sum of a sequence of integers. The sequence is defined by 3 non-negative values: **begin**, **end**, **step**. If **begin** value is greater than the **end**, function should returns **0** *Examples* ~...
{"functional": "_inputs = [[2, 6, 2], [1, 5, 1], [1, 5, 3], [0, 15, 3], [16, 15, 3], [2, 24, 22], [2, 2, 2], [2, 2, 1], [1, 15, 3], [15, 1, 3]]\n_outputs = [[12], [15], [5], [45], [0], [26], [2], [2], [35], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n r...
161
280
coding
Solve the programming task below in a Python markdown code block. You are given an array $a_1, a_2, \ldots, a_n$ of positive integers. A good pair is a pair of indices $(i, j)$ with $1 \leq i, j \leq n$ such that, for all $1 \leq k \leq n$, the following equality holds: $$ |a_i - a_k| + |a_k - a_j| = |a_i - a_j|, $$ w...
{"inputs": ["3\n3\n5 2 7\n5\n1 4 2 2 3\n1\n2\n"], "outputs": ["2 3\n1 2\n1 1\n"]}
636
48
coding
Solve the programming task below in a Python markdown code block. There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, ...
{"inputs": ["1 1 1\n1\n1\n", "1 1 1\n1\n1\n", "1 1 1\n1\n2\n", "1 1 3\n5\n15\n", "1 1 4\n5\n15\n", "1 1 2\n5\n15\n", "1 1 2\n5\n13\n", "1 1 10\n5\n15\n"], "outputs": ["0\n", "0", "2\n", "22\n", "21\n", "23\n", "19\n", "15\n"]}
517
144
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible. You can use each character in text at most once. Return the maximum number of instances that can...
{"functional": "def check(candidate):\n assert candidate(text = \"nlaebolko\") == 1\n assert candidate(text = \"loonbalxballpoon\") == 2\n assert candidate(text = \"leetcode\") == 0\n\n\ncheck(Solution().maxNumberOfBalloons)"}
100
66
coding
Solve the programming task below in a Python markdown code block. # Pythagorean Triples A Pythagorean triplet is a set of three numbers a, b, and c where `a^2 + b^2 = c^2`. In this Kata, you will be tasked with finding the Pythagorean triplets whose product is equal to `n`, the given argument to the function `pythagor...
{"functional": "_inputs = [[60], [780], [2040], [4200], [12180], [120120], [192720], [328860], [907200], [1440600]]\n_outputs = [[[3, 4, 5]], [[5, 12, 13]], [[8, 15, 17]], [[7, 24, 25]], [[20, 21, 29]], [[33, 56, 65]], [[48, 55, 73]], [[60, 63, 87]], [[42, 144, 150]], [[49, 168, 175]]]\nimport math\ndef _deep_eq(a, b, ...
349
338
coding
Solve the programming task below in a Python markdown code block. Chef wants to buy a new phone, but he is not willing to spend a lot of money. Instead, he checks the price of his chosen model everyday and waits for the price to drop to an acceptable value. So far, he has observed the price for $N$ days (numbere $1$ th...
{"inputs": ["1\n7\n375 750 723 662 647 656 619"], "outputs": ["2"]}
545
42
coding
Solve the programming task below in a Python markdown code block. You have N balls and K boxes. You want to divide the N balls into K boxes such that: Each box contains ≥ 1 balls. No two boxes contain the same number of balls. Determine if it is possible to do so. ------ Input Format ------ - The first line contai...
{"inputs": ["4\n3 4\n30 3\n2 2\n1 1\n"], "outputs": ["NO\nYES\nNO\nYES\n"]}
389
37
coding
Solve the programming task below in a Python markdown code block. For his computer science class, Jacob builds a model tree with sticks and balls containing n nodes in the shape of a tree. Jacob has spent a_{i} minutes building the i-th ball in the tree. Jacob's teacher will evaluate his model and grade Jacob based on...
{"inputs": ["2 1\n1 100000\n2 1\n", "2 1\n1 100000\n2 1\n", "2 1\n2 100000\n2 1\n", "2 2\n2 100000\n2 1\n", "2 1\n1 100100\n2 1\n", "2 1\n2 101000\n2 1\n", "2 1\n0 101001\n2 1\n", "2 1\n3 001000\n2 1\n"], "outputs": ["100000\n", "100000\n", "100000\n", "2\n", "100100\n", "101000\n", "101001\n", "1000\n"]}
659
223
coding
Solve the programming task below in a Python markdown code block. Calculate the power of an army of numbers from 1 to $N$, both included. -----Input:----- - First line will contain a single integer $N$. -----Output:----- For each testcase, output in a single line containing the answer. -----Constraints----- - $1 \le...
{"inputs": ["24"], "outputs": ["5"]}
97
13
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n binary matrix mat, return the number of special positions in mat. A position (i, j) is called special if mat[i][j] == 1 and all other elements in row i and column j are 0 (rows and columns are 0-indexed...
{"functional": "def check(candidate):\n assert candidate(mat = [[1,0,0],[0,0,1],[1,0,0]]) == 1\n assert candidate(mat = [[1,0,0],[0,1,0],[0,0,1]]) == 3\n\n\ncheck(Solution().numSpecial)"}
109
75
coding
Solve the programming task below in a Python markdown code block. You are given a sequence $a_1,a_2,\ldots,a_n$. The task is to perform the following queries on it: Type 1. Given two integers $\boldsymbol{l}$ and $\textbf{r}$ $(1\leq l\lt r\leq n;r-l+1\ is even)$. Reorder the elements of the sequence in such a way (ch...
{"inputs": ["6 4\n1 2 3 4 5 6\n1 2 5\n2 2 3\n2 3 4\n2 4 5\n"], "outputs": ["5\n7\n9\n"]}
553
56
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array cookies, where cookies[i] denotes the number of cookies in the ith bag. You are also given an integer k that denotes the number of children to distribute all the bags of cookies to. All ...
{"functional": "def check(candidate):\n assert candidate(cookies = [8,15,10,20,8], k = 2) == 31\n assert candidate(cookies = [6,1,3,2,2,4,1,2], k = 3) == 7\n\n\ncheck(Solution().distributeCookies)"}
146
82
coding
Solve the programming task below in a Python markdown code block. You are given an array $A$ of $N$ positive and pairwise distinct integers. You can permute the elements in any way you want. The cost of an ordering $(A_1, A_2, \ldots, A_N)$ is defined as $ (((A_1 \bmod A_2) \bmod A_3)......) \bmod A_N$ where $X \bmod...
{"inputs": ["1\n2\n7 12"], "outputs": ["7"]}
413
19
coding
Solve the programming task below in a Python markdown code block. Takahashi has come to an integer shop to buy an integer. The shop sells the integers from 1 through 10^9. The integer N is sold for A \times N + B \times d(N) yen (the currency of Japan), where d(N) is the number of digits in the decimal notation of N. F...
{"inputs": ["10 7 100\n", "2 1 100000000000\n", "1234 56789 314159265\n", "5 826766933 11100722310\n", "18 395432867 10840610026\n", "1000000000 1000000000 100\n", "384836991 191890310 91047313\n", "782177068 404011431 1793399970\n"], "outputs": ["9\n", "1000000000\n", "254309\n", "731963982\n", "404539679\n", "0\n", "...
373
266
coding
Solve the programming task below in a Python markdown code block. I'm traveling to a country with a rabbit. There are n cities in this country numbered from 1 to n, and the rabbit is now in city 1. City i is a point on the coordinate plane (xi, yi) ). Rabbits travel to meet the following conditions. * The travel path...
{"inputs": ["5\n100.1 90.1\n0 0\n0 10\n5 5\n10 0\n10 4", "5\n100.1 90.1\n0 0\n0 10\n7 5\n10 0\n10 10", "5\n100.1 90.1\n0 0\n0 10\n5 5\n10 0\n10 10", "5\n100.2380070184939 90.1\n0 0\n0 10\n5 9\n10 0\n9 4", "5\n100.2380070184939 90.1\n0 0\n0 10\n4 9\n7 0\n17 0", "5\n101.055831370051 90.1\n0 0\n1 10\n4 9\n7 0\n17 -1", "5\...
400
394
coding
Solve the programming task below in a Python markdown code block. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a i...
{"inputs": ["11\n", "11\n", "101\n", "111\n", "111\n", "110\n", "100\n", "101\n"], "outputs": ["1\n", "1\n", "11\n", "11\n", "11\n", "11\n", "10\n", "11\n"]}
306
90
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n grid. Each cell of grid represents a street. The street of grid[i][j] can be: 1 which means a street connecting the left cell and the right cell. 2 which means a street connecting the upper cel...
{"functional": "def check(candidate):\n assert candidate(grid = [[2,4,3],[6,5,2]]) == True\n assert candidate(grid = [[1,2,1],[1,2,1]]) == False\n assert candidate(grid = [[1,1,2]]) == False\n assert candidate(grid = [[1,1,1,1,1,1,3]]) == True\n assert candidate(grid = [[2],[2],[2],[2],[2],[2],[6]]) == T...
254
123
coding
Solve the programming task below in a Python markdown code block. Chef likes problems on geometry a lot. Please help him to solve one such problem. Find all possible triangles with integer sides which has the radius of inscribed circle (also known as incircle) equal to R. Two triangles are said to be different if they ...
{"inputs": ["2"], "outputs": ["5\n5 12 13\n6 8 10\n6 25 29\n7 15 20\n9 10 17"]}
367
51