problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Solve the programming task below in a Python markdown code block. "Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of n participants took part in the conte...
{"inputs": ["1 1\n0\n", "1 1\n10\n", "1 1\n16\n", "1 1\n100\n", "2 2\n9 0\n", "2 1\n3 2\n", "2 1\n3 0\n", "1 1\n110\n"], "outputs": ["0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
311
Solve the programming task below in a Python markdown code block. Coders is about to start and Ram has not done dinner yet. So, he quickly goes to hostel mess and finds a long queue in front of food counter. But somehow he manages to take the food plate and reaches in front of the queue. The plates are divided into se...
{"inputs": ["19\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19"], "outputs": ["4\n9\n25\n64\n169\n441\n1156\n3025\n7921\n20736\n54289\n142129\n372100\n974169\n2550409\n6677056\n17480761\n45765225\n119814916"]}
coding
367
Solve the programming task below in a Python markdown code block. Chef has $N$ points (numbered $1$ through $N$) in a 2D Cartesian coordinate system. For each valid $i$, the $i$-th point is $(x_i, y_i)$. He also has a fixed integer $c$ and he may perform operations of the following type: choose a point $(x_i, y_i)$ and...
{"inputs": ["1\n3 1\n1 1\n1 0\n3 2"], "outputs": ["2 2"]}
coding
589
Solve the programming task below in a Python markdown code block. Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from 1 to n. We say that this permutation maps value 1 into the value p1, value 2 into the value p2 and so on. Kyota Ootori has just ...
{"inputs": ["1 1\n", "5 8\n", "5 1\n", "2 2\n", "3 3\n", "9 1\n", "4 2\n", "2 1\n"], "outputs": ["1 ", "2 1 4 3 5 ", "1 2 3 4 5 ", "2 1 ", "2 1 3 ", "1 2 3 4 5 6 7 8 9 ", "1 2 4 3 ", "1 2\n"]}
coding
647
Solve the programming task below in a Python markdown code block. Sam is an avid collector of numbers. Every time he finds a new number he throws it on the top of his number-pile. Help Sam organise his collection so he can take it to the International Number Collectors Conference in Cologne. Given an array of numbers...
{"functional": "_inputs = [[[3, 2, 6, 2, 1, 3]], [[3, 2, 6, 2]], [[]], [[1, 100, 4, 2, 4]], [[-1, 1, -1]]]\n_outputs = [[[[3, 3], [2, 2], [6], [1]]], [[[3], [2, 2], [6]]], [[]], [[[1], [100], [4, 4], [2]]], [[[-1, -1], [1]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, floa...
coding
157
Solve the programming task below in a Python markdown code block. Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND ope...
{"inputs": ["1\n0 1\n", "5\n10 8\n10 10\n10 42\n20 16\n1000000000000000000 0\n"], "outputs": ["-1\n", "12\n10\n-1\n24\n1152921504606846976\n"]}
coding
496
Solve the programming task below in a Python markdown code block. # Introduction and Warm-up (Highly recommended) # [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays) ___ # Task **_Given_** an *array/list [] of integers* , **_Find_** *the Nth smallest element in...
{"functional": "_inputs = [[[3, 1, 2], 2], [[15, 20, 7, 10, 4, 3], 3], [[-5, -1, -6, -18], 4], [[-102, -16, -1, -2, -367, -9], 5], [[2, 169, 13, -5, 0, -1], 4]]\n_outputs = [[2], [7], [-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....
coding
584
Solve the programming task below in a Python markdown code block. Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more. Paul has found a tolerable string s ...
{"inputs": ["1 2\na\n", "1 2\nb\n", "1 1\na\n", "1 2\nb\n", "1 2\na\n", "1 2\nb\n", "1 1\na\n", "1 4\na\n"], "outputs": ["b\n", "NO\n", "NO\n", "NO\n", "b\n", "NO\n", "NO\n", "b\n"]}
coding
336
Solve the programming task below in a Python markdown code block. Two deer, AtCoDeer and TopCoDeer, are playing a game called Honest or Dishonest. In this game, an honest player always tells the truth, and an dishonest player always tell lies. You are given two characters a and b as the input. Each of them is either H ...
{"inputs": ["H I", "E H", "I H", "F H", "G H", "J H", "H J", "H G"], "outputs": ["D\n", "D\n", "D\n", "D\n", "D\n", "D\n", "D\n", "D\n"]}
coding
252
Solve the programming task below in a Python markdown code block. B: Periodic Sequence- problem Dr. Period, a professor at H University, is studying a property called the cycle that is supposed to be hidden in all things. As a generally known basic cycle, a cycle hidden in a sequence may be considered. That is, if th...
{"inputs": ["6\n1 2 3 1 1 3", "6\n1 2 3 1 0 3", "6\n2 2 3 1 0 3", "6\n2 2 3 2 0 3", "6\n4 2 3 2 0 3", "6\n4 2 3 2 0 4", "6\n4 4 3 2 0 4", "6\n7 4 3 2 0 4"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
530
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a strictly convex polygon with $N$ vertices (numbered $1$ through $N$). For each valid $i$, the coordinates of the $i$-th vertex are $...
{"inputs": ["2\n4\n-100 1\n0 2\n0 0\n100 1\n7\n-4 0\n-3 -2\n-3 2\n0 -4\n2 -3\n2 3\n3 2"], "outputs": ["4\n10"]}
coding
586
Solve the programming task below in a Python markdown code block. Frog Gorf is traveling through Swamp kingdom. Unfortunately, after a poor jump, he fell into a well of $n$ meters depth. Now Gorf is on the bottom of the well and has a long way up. The surface of the well's walls vary in quality: somewhere they are sli...
{"inputs": ["1\n1\n0\n", "1\n1\n0\n", "2\n1 1\n1 0\n", "2\n1 1\n0 0\n", "2\n1 2\n1 0\n", "2\n0 2\n1 0\n", "2\n1 1\n1 0\n", "3\n0 2 2\n1 1 0\n"], "outputs": ["1\n0 \n", "1\n0 ", "-1\n", "2\n1 0\n", "1\n0\n", "1\n0\n", "-1\n", "2\n1 0 \n"]}
coding
736
Solve the programming task below in a Python markdown code block. You had $n$ positive integers $a_1, a_2, \dots, a_n$ arranged in a circle. For each pair of neighboring numbers ($a_1$ and $a_2$, $a_2$ and $a_3$, ..., $a_{n - 1}$ and $a_n$, and $a_n$ and $a_1$), you wrote down: are the numbers in the pair equal or not....
{"inputs": ["2\nEEEEEN\nEE\n", "2\nEEEEEN\nEE\n", "2\nEENEEE\nEE\n", "2\nEEEEEN\nEEEEEN\n", "2\nEEEEEN\nEEEEEN\n", "2\nNEEEEE\nEEEEEN\n", "2\nEEEEEEN\nEEEEEEEN\n", "2\nEEEEEEN\nEEEEEEEN\n"], "outputs": ["NO\nYES\n", "NO\nYES\n", "NO\nYES\n", "NO\nNO\n", "NO\nNO\n", "NO\nNO\n", "NO\nNO\n", "NO\nNO\n"]}
coding
624
Solve the programming task below in a Python markdown code block. Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly a_{i} each hour. Luba can't water any parts ...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "1 88\n1\n", "1 89\n1\n", "1 88\n1\n", "1 89\n1\n", "1 73\n1\n", "2 6\n5 3\n"], "outputs": ["1\n", "1\n", "88\n", "89\n", "88\n", "89\n", "73\n", "2\n"]}
coding
431
Solve the programming task below in a Python markdown code block. It's tricky keeping track of who is owed what when spending money in a group. Write a function to balance the books. * The function should take one parameter: an object/dict with two or more name-value pairs which represent the members of the group and ...
{"functional": "_inputs = [[{'A': 20, 'B': 15, 'C': 10}], [{'A': 40, 'B': 25, 'X': 10}], [{'A': 40, 'B': 25, 'C': 10, 'D': 153, 'E': 58}], [{'A': 475, 'B': 384, 'C': 223, 'D': 111, 'E': 19}], [{'A': 20348, 'B': 493045, 'C': 2948, 'D': 139847, 'E': 48937534, 'F': 1938724, 'G': 4, 'H': 2084}]]\n_outputs = [[{'A': 5.0, 'B...
coding
231
Solve the programming task below in a Python markdown code block. There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "YES" and if not pri...
{"inputs": ["2\n0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0\n3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0", "2\n0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0\n3.0 2.0 9.680227793087974 6.0 13.0 5.0 7.0 9.0", "2\n0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0\n3.0 2.0 9.680227793087974 6.0 13.541356008746918 5.0 7.0 9.0", "2\n0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0\n3.0 2.0 9.680...
coding
364
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a series of times at which an alarm goes off. Your task will be to determine the maximum time interval between alarms. Each alarm starts ringing at the beginning of the corresponding minute and rings for exactly one minute...
{"functional": "_inputs = [[['14:51']], [['23:00', '04:22', '18:05', '06:24']], [['21:14', '15:34', '14:51', '06:25', '15:30']]]\n_outputs = [['23:59'], ['11:40'], ['09:10']]\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,...
coding
231
Solve the programming task below in a Python markdown code block. You have recently discovered that horses travel in a unique pattern - they're either running (at top speed) or resting (standing still). Here's an example of how one particular horse might travel: ``` The horse Blaze can run at 14 metres/second for 60 ...
{"functional": "_inputs = [[1000, 10, 127, 14], [1000, 10, 0, 10], [25, 50, 120, 18], [35869784, 90, 100, 5], [1234567, 4, 3, 11], [100000000, 21, 5, 14], [0, 100, 10, 14], [250, 0, 5, 14], [100, 10, 0, 14], [500, 100, 10, 0]]\n_outputs = [[1120], [10000], [450], [84954920], [7760148], [1130769276], [0], [0], [1400], [...
coding
221
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed integer arrays nums1 and nums2 of the same length. A pair of indices (i,j) is called beautiful if|nums1[i] - nums1[j]| + |nums2[i] - nums2[j]| is the smallest amongst all possible indices p...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3,2,4], nums2 = [2,3,1,2,3]) == [0,3]\n assert candidate(nums1 = [1,2,4,3,2,5], nums2 = [1,4,2,3,5,1]) == [1,4]\n\n\ncheck(Solution().beautifulPair)"}
coding
200
Solve the programming task below in a Python markdown code block. You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text. Calculate the volume of the...
{"inputs": ["1\ne\n", "1\nA\n", "1\ne\n", "1\nA\n", "1\nf\n", "1\ng\n", "1\nd\n", "1\nc\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n"]}
coding
217
Solve the programming task below in a Python markdown code block. Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elem...
{"inputs": ["2\n2 2\n2 3\n"], "outputs": ["3\n12"]}
coding
611
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an algorithm with O(log n)...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,5,6], target = 5) == 2\n assert candidate(nums = [1,3,5,6], target = 2) == 1\n assert candidate(nums = [1,3,5,6], target = 7) == 4\n\n\ncheck(Solution().searchInsert)"}
coding
105
Solve the programming task below in a Python markdown code block. In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your...
{"inputs": ["####\n.#..\n####\n....\n", "####\n....\n####\n....\n", "....\n....\n....\n....\n", "###.\n...#\n###.\n...#\n", ".##.\n#..#\n.##.\n#..#\n", ".#.#\n#.#.\n.#.#\n#.#.\n", "##..\n..##\n##..\n..##\n", "#.#.\n#.#.\n.#.#\n.#.#\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
345
Solve the programming task below in a Python markdown code block. You all know the Dirichlet principle, the point of which is that if n boxes have no less than n + 1 items, that leads to the existence of a box in which there are at least two items. Having heard of that principle, but having not mastered the technique ...
{"inputs": ["2 2 5\n", "5 1 7\n", "1 5 2\n", "1 1 2\n", "1 1 3\n", "1 5 4\n", "1 2 3\n", "3 1 5\n"], "outputs": ["Stas\n\n", "Masha\n\n", "Missing\n\n", "Missing\n\n", "Masha\n\n", "Missing\n", "Missing\n", "Masha\n"]}
coding
435
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a test that has n types of questions. You are given an integer target and a 0-indexed 2D integer array types where types[i] = [counti, marksi] indicates that there are counti questions of the ith type, and ea...
{"functional": "def check(candidate):\n assert candidate(target = 6, types = [[6,1],[3,2],[2,3]]) == 7\n assert candidate(target = 5, types = [[50,1],[50,2],[50,5]]) == 4\n assert candidate(target = 18, types = [[6,1],[3,2],[2,3]]) == 1\n\n\ncheck(Solution().waysToReachTarget)"}
coding
216
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. A...
{"inputs": ["2\n33\n", "2\n77\n", "2\n99\n", "2\n55\n", "2\n88\n", "2\n22\n", "2\n44\n", "2\n66\n"], "outputs": ["NO", "YES", "NO", "NO", "NO", "NO", "YES", "NO"]}
coding
342
Solve the programming task below in a Python markdown code block. Chef changed the password of his laptop a few days ago, but he can't remember it today. Luckily, he wrote the encrypted password on a piece of paper, along with the rules for decryption. The encrypted password is a string S consists of ASCII printable ch...
{"inputs": ["4\n2\n5 3\n3 1\n5\n0\n01800.00\n0\n0.00100\n3\nx 0\nd 3\n# .\n0xd21#xd098d", "4\n2\n5 3\n3 1\n5\n0\n01800.00\n0\n0.00100\n3\nx 0\nd 3\n# .\n0xd21#dd098x", "4\n2\n5 3\n3 1\n5\n-1\n01800.00\n0\n0.00100\n3\nx 0\nd 3\n# /\n0xd21#xd098d", "4\n2\n5 3\n3 1\n5\n-1\n01800.00\n0\n0.00100\n3\nx 0\nd 3\n# .\n0xd21#dd0...
coding
555
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, consider all duplicated substrings: (contiguous) substrings of s that occur 2 or more times. The occurrences may overlap. Return any duplicated substring that has the longest possible length. If s do...
{"functional": "def check(candidate):\n assert candidate(s = \"banana\") == \"ana\"\n assert candidate(s = \"abcd\") == \"\"\n\n\ncheck(Solution().longestDupSubstring)"}
coding
109
Solve the programming task below in a Python markdown code block. Failed Sort - Bug Fixing #4 Oh no, Timmy's Sort doesn't seem to be working? Your task is to fix the sortArray function to sort all numbers in ascending order Also feel free to reuse/extend the following starter code: ```python def sort_array(value): ```
{"functional": "_inputs = [['12345'], ['54321'], ['34251'], ['11111'], ['10101']]\n_outputs = [['12345'], ['12345'], ['12345'], ['11111'], ['00111']]\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 isi...
coding
74
Solve the programming task below in a Python markdown code block. Your task is to find the number couple with the greatest difference from a given array of number-couples. All number couples will be given as strings and all numbers in them will be positive integers. For instance: ['56-23','1-100']; in this case, y...
{"functional": "_inputs = [[['43-45', '1021-55', '000-18888', '92-34', '76-32', '99-1', '1020-54']], [['1-2', '2-4', '5-7', '8-9', '44-45']], [['1-1000', '2-1000', '100-67', '98-45', '8-9']], [['33-33', '77-77']], [['23-67', '67-23', '88-88', '45-46']], [['45896-2354', '4654-556767', '2455-423522', '3455-355', '34-34',...
coding
184
Solve the programming task below in a Python markdown code block. The chef has a recipe he wishes to use for his guests, but the recipe will make far more food than he can serve to the guests. The chef therefore would like to make a reduced version of the recipe which has the same ratios of ingredients, but makes less ...
{"inputs": ["3\n2 4 4\n3 2 3 4\n4 3 15 9 6", "3\n2 4 4\n3 2 3 4\n4 3 20 9 6", "3\n2 4 4\n3 2 1 4\n4 3 15 9 6", "3\n2 4 4\n3 2 3 4\n4 3 20 9 8", "3\n2 4 7\n3 2 1 4\n4 3 15 9 6", "3\n2 4 4\n3 2 3 6\n4 3 20 9 8", "3\n2 4 4\n3 2 3 8\n4 3 15 9 6", "3\n2 4 8\n3 2 3 4\n4 3 20 9 6"], "outputs": ["1 1\n2 3 4\n1 5 3 2", "1 1\n2 ...
coding
317
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...
coding
375
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a weighted tree consisting of n nodes numbered from 0 to n - 1. The tree is rooted at node 0 and represented with a 2D array edges of size n where edges[i] = [pari, weighti] indicates that node pari is t...
{"functional": "def check(candidate):\n assert candidate(edges = [[-1,-1],[0,5],[0,10],[2,6],[2,4]]) == 11\n assert candidate(edges = [[-1,-1],[0,5],[0,-6],[0,7]]) == 7\n\n\ncheck(Solution().maxScore)"}
coding
254
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer num. Rearrange the digits of num such that its value is minimized and it does not contain any leading zeros. Return the rearranged number with minimal value. Note that the sign of the number d...
{"functional": "def check(candidate):\n assert candidate(num = 310) == 103\n assert candidate(num = -7605) == -7650\n\n\ncheck(Solution().smallestNumber)"}
coding
100
Solve the programming task below in a Python markdown code block. Prof. Twotwo as the name suggests is very fond powers of 2. Moreover he also has special affinity to number 800. He is known for carrying quirky experiments on powers of 2. One day he played a game in his class. He brought some number plates on each of ...
{"inputs": ["5\n2222222\n24256\n65536\n023223\n33579\n"], "outputs": ["7\n4\n1\n4\n0\n"]}
coding
647
Solve the programming task below in a Python markdown code block. Assume you are creating a webshop and you would like to help the user in the search. You have products with brands, prices and name. You have the history of opened products (the most recently opened being the first item). Your task is to create a list o...
{"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...
coding
184
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. There are N chairs placed in circular order. Some of the chairs are empty while others have a child sitting in it. You are required to change the places of the children so th...
{"inputs": ["1\n8\n10001010"], "outputs": ["2"]}
coding
531
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 of length n. You are initially standing at index 0. You can jump from index i to index j where i < j if: nums[i] <= nums[j] and nums[k] < nums[i] for all indexes k in the ...
{"functional": "def check(candidate):\n assert candidate(nums = [3,2,4,4,1], costs = [3,7,6,4,2]) == 8\n assert candidate(nums = [0,1,2], costs = [1,1,1]) == 2\n\n\ncheck(Solution().minCost)"}
coding
188
Solve the programming task below in a Python markdown code block. Your company, [Congo Pizza](http://interesting-africa-facts.com/Africa-Landforms/Congo-Rainforest-Facts.html), is the second-largest online frozen pizza retailer. You own a number of international warehouses that you use to store your frozen pizzas, and ...
{"functional": "_inputs = [[32, 64, 16], [20, 20, 20], [80, 40, 20], [70, 60, 15], [90, 7, 5], [53, 21, 13]]\n_outputs = [[13824], [3375], [27000], [25740], [1005], [5265]]\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, a...
coding
294
Solve the programming task below in a Python markdown code block. Tokitsukaze has a sequence $a$ of length $n$. For each operation, she selects two numbers $a_i$ and $a_j$ ($i \ne j$; $1 \leq i,j \leq n$). If $a_i = a_j$, change one of them to $0$. Otherwise change both of them to $\min(a_i, a_j)$. Tokitsukaze wants...
{"inputs": ["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0\n"], "outputs": ["4\n3\n2\n"]}
coding
550
Solve the programming task below in a Python markdown code block. There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that 1. 1 ≤ i, j ≤ N 2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th. Input The single input line co...
{"inputs": ["w\n", "v\n", "u\n", "x\n", "t\n", "s\n", "r\n", "q\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
183
Solve the programming task below in a Python markdown code block. Implement function which will return sum of roots of a quadratic equation rounded to 2 decimal places, if there are any possible roots, else return **None/null/nil/nothing**. If you use discriminant,when discriminant = 0, x1 = x2 = root => return sum of ...
{"functional": "_inputs = [[1, -35, -23], [6, 0, -24], [-5, 21, 0], [6, 4, 8], [1, 5, -24], [3, 11, 6], [2, 2, 9], [1, -1.6666666666666667, -26], [1, 6, 10], [7, -2, -5], [1, 8, 20], [2, 3, -2], [1, 4, 12], [3, -2, -5], [3, 4, 9], [5, 4, 0], [4, -5, 0], [1, 4, 9], [1, 0, -49], [2, 8, 8], [1, 0, -0.16], [1, 6, 12], [1, ...
coding
123
Solve the programming task below in a Python markdown code block. Chef has a sequence $A$ of $N$ integers such that $|A_{i}| ≤ 1$. For each $x$ such that $-N ≤ x ≤ N$, find the number of non-empty subsequences of $A$ whose sum of elements is $x$. Since that answer may be too large, print this modulo $163,577,857$. --...
{"inputs": ["2\n2\n1 0\n3\n-1 1 -1\n"], "outputs": ["0 0 1 2 0\n0 1 3 2 1 0 0\n"]}
coding
422
Solve the programming task below in a Python markdown code block. Write a program to find the remainder when an integer A is divided by an integer B. -----Input----- The first line contains an integer T, the total number of test cases. Then T lines follow, each line contains two Integers A and B. -----Output----- F...
{"inputs": ["3 \n0 3\n100 43\n1 3", "3 \n0 3\n101 43\n1 3", "3 \n0 2\n100 79\n1 40", "3 \n0 2\n100 75\n1 40", "3 \n0 2\n000 75\n1 40", "3 \n0 2\n100 79\n0 40", "3 \n0 2\n001 75\n1 40", "3 \n2 4\n100 465\n0 3"], "outputs": ["0\n14\n1\n", "0\n15\n1\n", "0\n21\n1\n", "0\n25\n1\n", "0\n0\n1\n", "0\n21\n0\n", "0\n1\n1\n", "...
coding
156
Solve the programming task below in a Python markdown code block. You are given an undirected graph consisting of N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. In addition, each vertex has a label, `A` or `B`. The label of Vertex i is s_i. Edge i bidirectionally connects v...
{"inputs": ["2 3\nAA\n1 1\n1 2\n2 2", "2 3\nAA\n1 2\n1 2\n2 2", "2 3\nBA\n1 1\n1 2\n2 2", "2 3\nBA\n2 1\n1 2\n2 2", "2 3\nBA\n1 1\n1 2\n2 1", "2 3\nBA\n2 2\n1 2\n2 2", "2 3\nAB\n1 1\n1 2\n2 2", "4 3\nABAB\n1 1\n2 3\n3 1"], "outputs": ["No\n", "No\n", "Yes\n", "No\n", "No\n", "No\n", "Yes", "No\n"]}
coding
644
Please solve the programming task below using a self-contained code snippet in a markdown code block. An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic. Given an integer n, return true if n is strictly palindro...
{"functional": "def check(candidate):\n assert candidate(n = 9) == False\n assert candidate(n = 4) == False\n\n\ncheck(Solution().isStrictlyPalindromic)"}
coding
129
Solve the programming task below in a Python markdown code block. We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb. The sand dr...
{"inputs": ["180\n3\n60 120 180\n3\n30 16\n61 1\n7 282", "180\n3\n85 120 180\n3\n2 9\n74 1\n238 180", "180\n3\n60 74 180\n3\n30 16\n61 1\n180 180", "180\n3\n60 74 173\n3\n30 16\n61 1\n180 316", "180\n3\n60 140 180\n3\n30 16\n61 1\n74 316", "180\n3\n30 32 180\n3\n30 16\n34 1\n180 316", "180\n3\n85 45 180\n3\n30 90\n45 1...
coding
545
Solve the programming task below in a Python markdown code block. Naman has two binary strings $s$ and $t$ of length $n$ (a binary string is a string which only consists of the characters "0" and "1"). He wants to convert $s$ into $t$ using the following operation as few times as possible. In one operation, he can cho...
{"inputs": ["3\n000\n000\n", "3\n000\n000\n", "3\n000\n001\n", "3\n100\n000\n", "3\n010\n000\n", "3\n010\n001\n", "3\n010\n100\n", "3\n010\n101\n"], "outputs": ["0", "0\n", "-1\n", "-1\n", "-1\n", "1\n", "1\n", "-1\n"]}
coding
619
Solve the programming task below in a Python markdown code block. zeros The zeros tool returns a new array with a given shape and type filled with $\mbox{o}$'s. import numpy print numpy.zeros((1,2)) #Default type is float #Output : [[ 0. 0.]] print numpy.zeros((1,2), dtype = numpy.int) #Type ch...
{"inputs": ["3 3 3\n"], "outputs": ["[[[0 0 0]\n [0 0 0]\n [0 0 0]]\n\n [[0 0 0]\n [0 0 0]\n [0 0 0]]\n\n [[0 0 0]\n [0 0 0]\n [0 0 0]]]\n[[[1 1 1]\n [1 1 1]\n [1 1 1]]\n\n [[1 1 1]\n [1 1 1]\n [1 1 1]]\n\n [[1 1 1]\n [1 1 1]\n [1 1 1]]]\n"]}
coding
466
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array arr, remove a subarray (can be empty) from arr such that the remaining elements in arr are non-decreasing. Return the length of the shortest subarray to remove. A subarray is a contiguous subseq...
{"functional": "def check(candidate):\n assert candidate(arr = [1,2,3,10,4,2,3,5]) == 3\n assert candidate(arr = [5,4,3,2,1]) == 4\n assert candidate(arr = [1,2,3]) == 0\n assert candidate(arr = [1]) == 0\n\n\ncheck(Solution().findLengthOfShortestSubarray)"}
coding
105
Solve the programming task below in a Python markdown code block. # Task Your task is to sort the characters in a string according to the following rules: ``` - Rule1: English alphabets are arranged from A to Z, case insensitive. ie. "Type" --> "epTy" - Rule2: If the uppercase and lowercase of an English alphabet ex...
{"functional": "_inputs = [['a'], ['cba'], ['Cba'], ['cCBbAa'], ['!'], ['c b a'], ['-c--b--a-'], ['cbaCcC'], ['Codewars'], [' MkWD{RB=//k-^ J@,xH Vfi uAz+$ kV _[ }a!}%pSBwn !kKB (b q PQF +}wS .kfU r wFNEs#NsR UVMdG']]\n_outputs = [['a'], ['abc'], ['abC'], ['AaBbcC'], ['!'], ['a b c'], ['-a--b--c-'], ['abcCcC'], ['aCd...
coding
338
Solve the programming task below in a Python markdown code block. INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence of characters to print, using t...
{"inputs": ["N\n", "M\n", "o2^\"t\n", "t\"^2o\n", "\\Pk|a\\'\n", "'\\a|kP\\\n", "s3=MS8%X\n", "X%8SM=3s\n"], "outputs": ["142\n", "78\n", "10\n170\n210\n54\n22\n", "210\n234\n202\n46\n86\n", "198\n48\n52\n152\n184\n76\n86\n", "28\n170\n180\n72\n104\n204\n208\n", "50\n2\n16\n10\n232\n174\n120\n138\n", "230\n118\n136\n82...
coding
475
Solve the programming task below in a Python markdown code block. There are only 2 type of denominations in Chefland: Coins worth 1 rupee each Notes worth 10 rupees each Chef wants to pay his friend exactly X rupees. What is the minimum number of coins Chef needs to pay exactly X rupees? ------ Input Format ------ ...
{"inputs": ["4\n53\n100\n9\n11\n"], "outputs": ["3\n0\n9\n1\n"]}
coding
293
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 array of strings words. You should add a closed pair of bold tag <b> and </b> to wrap the substrings in s that exist in words. If two such substrings overlap, you should wrap them toge...
{"functional": "def check(candidate):\n assert candidate(s = \"abcxyz123\", words = [\"abc\",\"123\"]) == \"<b>abc</b>xyz<b>123</b>\"\n assert candidate(s = \"aaabbb\", words = [\"aa\",\"b\"]) == \"<b>aaabbb</b>\"\n\n\ncheck(Solution().addBoldTag)"}
coding
139
Solve the programming task below in a Python markdown code block. `{a, e, i, o, u, A, E, I, O, U}` Natural Language Understanding is the subdomain of Natural Language Processing where people used to design AI based applications have ability to understand the human languages. HashInclude Speech Processing team has a pr...
{"functional": "_inputs = [['bbbb'], ['baceb'], ['aeiou'], ['aeiouAEIOU']]\n_outputs = [[0], [16], [35], [220]]\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...
coding
310
Solve the programming task below in a Python markdown code block. The penultimate task involved the calculation of the typical Fibonacci sequence up to the nth term. Input – single integer n Output – Fibonacci sequence up to the nth term, all terms on a new line SAMPLE INPUT 5 SAMPLE OUTPUT 1 1 2 3 5
{"inputs": ["5"], "outputs": ["1\n1\n2\n3\n5"]}
coding
71
Solve the programming task below in a Python markdown code block. One day, Delta, the dog, got very angry. He has $N$ items with different values, and he decided to destroy a few of them. However, Delta loves his hooman as well. So he only destroyed those items whose Least Significant Bit in binary representation is 0....
{"inputs": ["1\n5\n1 2 3 4 5"], "outputs": ["6"]}
coding
262
Solve the programming task below in a Python markdown code block. Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together. He cannot do any other calculation. Given are two integers A and B. If Takahashi can calculate A \times B, print the result; if he cannot, ...
{"inputs": ["2 8", "9 5", "3 8", "9 8", "7 7", "6 8", "7 9", "7 8"], "outputs": ["16\n", "45\n", "24\n", "72\n", "49\n", "48\n", "63\n", "56\n"]}
coding
183
Solve the programming task below in a Python markdown code block. Given the number n, return a string which shows the minimum number of moves to complete the tower of Hanoi consisting of n layers. Tower of Hanoi : https://en.wikipedia.org/wiki/Tower_of_Hanoi Example - 2 layered Tower of Hanoi Input: n=2 Start [[2, ...
{"functional": "_inputs = [[2], [3]]\n_outputs = [['[[2, 1], [], []]\\n[[2], [1], []]\\n[[], [1], [2]]\\n[[], [], [2, 1]]'], ['[[3, 2, 1], [], []]\\n[[3, 2], [], [1]]\\n[[3], [2], [1]]\\n[[3], [2, 1], []]\\n[[], [2, 1], [3]]\\n[[1], [2], [3]]\\n[[1], [], [3, 2]]\\n[[], [], [3, 2, 1]]']]\nimport math\ndef _deep_eq(a, b,...
coding
160
Solve the programming task below in a Python markdown code block. DO YOU EXPECT ME TO FIND THIS OUT? WHAT BASE AND/XOR LANGUAGE INCLUDES string? DON'T BYTE OF MORE THAN YOU CAN CHEW YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD THE LAST STACK ...
{"inputs": ["1\n8\n", "1\n8\n", "1\n11\n", "1\n22\n", "1\n26\n", "2\n1 5\n", "2\n4 8\n", "2\n5 9\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
201
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef aims to be the richest person in Chefland by his new restaurant franchise. Currently, his assets are worth $A$ billion dollars and have no liabilities. He aims t...
{"inputs": ["3\n100 200 10\n111 199 11\n190 200 10"], "outputs": ["10\n8\n1"]}
coding
552
Solve the programming task below in a Python markdown code block. A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs. Catacombs consist of several rooms and bidirectional passages between some pairs of them. ...
{"inputs": ["1\n0\n", "1\n0\n", "2\n0 0\n", "2\n0 1\n", "2\n0 1\n", "2\n0 0\n", "5\n0 1 0 1 3\n", "5\n0 1 0 1 0\n"], "outputs": ["1\n", "1\n", "2\n", "1\n", "1\n", "2\n", "3\n", "4\n"]}
coding
490
Solve the programming task below in a Python markdown code block. Limak is a little polar bear. He has n balls, the i-th ball has size t_{i}. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: No two friends can get balls of ...
{"inputs": ["3\n3 1 2\n", "3\n1 1 2\n", "3\n2 3 2\n", "3\n1 2 1\n", "3\n1 2 3\n", "3\n1 1 1\n", "3\n2 2 3\n", "3\n1 2 2\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
coding
537
Solve the programming task below in a Python markdown code block. Given an integer N, find the number of tuples (w, x, y, z) such that 1 ≤ w, x, y, z ≤ N and \frac{w}{x} + \frac{y}{z} is an integer. For example, if N = 2, the tuple (1,2,1,2) satisfies both conditions, i.e. \frac{1}{2} + \frac{1}{2} = 1 is an integer, ...
{"inputs": ["3\n2\n3\n7"], "outputs": ["10\n31\n355\n"]}
coding
567
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a group of n people labeled from 0 to n - 1 where each person has a different amount of money and a different level of quietness. You are given an array richer where richer[i] = [ai, bi] indicates that ai has...
{"functional": "def check(candidate):\n assert candidate(richer = [[1,0],[2,1],[3,1],[3,7],[4,3],[5,3],[6,3]], quiet = [3,2,5,4,6,1,7,0]) == [5,5,2,5,4,5,6,7]\n assert candidate(richer = [], quiet = [0]) == [0]\n\n\ncheck(Solution().loudAndRich)"}
coding
219
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, find a subarray that has the largest product, and return the product. The test cases are generated so that the answer will fit in a 32-bit integer.   Please complete the following python c...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,-2,4]) == 6\n assert candidate(nums = [-2,0,-1]) == 0\n\n\ncheck(Solution().maxProduct)"}
coding
88
Solve the programming task below in a Python markdown code block. Let $f_{x} = c^{2x-6} \cdot f_{x-1} \cdot f_{x-2} \cdot f_{x-3}$ for $x \ge 4$. You have given integers $n$, $f_{1}$, $f_{2}$, $f_{3}$, and $c$. Find $f_{n} \bmod (10^{9}+7)$. -----Input----- The only line contains five integers $n$, $f_{1}$, $f_{2}$...
{"inputs": ["5 1 2 5 3\n", "4 1 1 1 1\n", "4 1 1 1 1\n", "5 2 2 5 3\n", "5 1 2 5 3\n", "17 97 41 37 11\n", "24 97 41 37 11\n", "17 97 41 37 11\n"], "outputs": ["72900\n", "1\n", "1", "145800\n", "72900", "317451037\n", "303925722\n", "317451037"]}
coding
327
Solve the programming task below in a Python markdown code block. > If you've finished this kata, you can try the [more difficult version](https://www.codewars.com/kata/5b256145a454c8a6990000b5). ## Taking a walk A promenade is a way of uniquely representing a fraction by a succession of “left or right” choices. Fo...
{"functional": "_inputs = [[''], ['L'], ['R'], ['LRLL'], ['LLRLR'], ['RRRLRRR'], ['LLLLRLLLL'], ['LLLLLLLLLL'], ['RLRLRLRRLRLL'], ['LLRRLRRLRLLL'], ['LRRLLRLLRLRR'], ['LRRLRLLLLRLL'], ['LLLRRRLLLRLL'], ['RRLRRRLLRLRR'], ['RRRRLLRLLRLR'], ['LLRLRLLRLLRL'], ['LRLLRRRRLLRR'], ['RLRRLRRRRRRR']]\n_outputs = [[[1, 1]], [[1, ...
coding
641
Solve the programming task below in a Python markdown code block. Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the ave...
{"inputs": ["0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2\n", "0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n", "1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n", "0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n", "0 0\n1 0\n0 1\n1 1\n0 2\n1 2\n0 3\n1 3\n", "0 0\n2 1\n1 0\n0 2\n2 2\n1 0\n2 1\n0 2\n", "0 0\n2 1\n1 0\n0 2\n2 2\n1 0\n2 1\n0 2\n", ...
coding
388
Solve the programming task below in a Python markdown code block. We have two bottles for holding water. Bottle 1 can hold up to A milliliters of water, and now it contains B milliliters of water. Bottle 2 contains C milliliters of water. We will transfer water from Bottle 2 to Bottle 1 as much as possible. How much am...
{"inputs": ["0 2 0", "0 4 0", "0 6 4", "1 4 0", "1 7 0", "6 4 0", "6 2 0", "9 0 7"], "outputs": ["2\n", "4\n", "10\n", "3\n", "6\n", "0\n", "0\n", "0\n"]}
coding
222
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n, the number of teams in a tournament that has strange rules: If the current number of teams is even, each team gets paired with another team. A total of n / 2 matches are played, and n / 2 ...
{"functional": "def check(candidate):\n assert candidate(n = 7) == 6\n assert candidate(n = 14) == 13\n\n\ncheck(Solution().numberOfMatches)"}
coding
180
Solve the programming task below in a Python markdown code block. You are given a dataset consisting of $N$ items. Each item is a pair of a word and a boolean denoting whether the given word is a spam word or not. We want to use this dataset for training our latest machine learning model. Thus we want to choose some su...
{"inputs": ["3\n3\nabc 0\nabc 1\nefg 1\n7\nfck 1\nfck 0\nfck 1\nbody 0\nbody 0\nbody 0\nram 0\n5\nvv 1\nvv 0\nvv 0\nvv 1\nvv 1\n"], "outputs": ["2\n6\n3"]}
coding
583
Solve the programming task below in a Python markdown code block. A chess tournament will be held soon, where $n$ chess players will take part. Every participant will play one game against every other participant. Each game ends in either a win for one player and a loss for another player, or a draw for both players. ...
{"inputs": ["3\n3\n111\n1\n1\n4\n2122\n", "3\n3\n111\n2\n21\n4\n2122\n", "3\n3\n111\n2\n21\n4\n2122\n", "3\n3\n111\n2\n12\n4\n2122\n", "3\n3\n111\n2\n11\n4\n2122\n", "3\n3\n111\n2\n22\n4\n2122\n", "3\n3\n111\n2\n21\n4\n2122\n"], "outputs": ["YES\nX==\n=X=\n==X\nYES\nX\nYES\nX=+-\n=X==\n-=X+\n+=-X\n", "YES\nX==\n=X=\n==...
coding
500
Solve the programming task below in a Python markdown code block. Chef is buying sweet things to prepare for Halloween! The shop sells both chocolate and candy. Each bar of chocolate has a tastiness of X. Each piece of candy has a tastiness of Y. One packet of chocolate contains 2 bars, while one packet of candy cont...
{"inputs": ["4\n5 1\n5 2\n5 3\n3 10\n"], "outputs": ["Chocolate\nEither\nCandy\nCandy\n"]}
coding
569
Solve the programming task below in a Python markdown code block. Two strings ```a``` and b are called isomorphic if there is a one to one mapping possible for every character of ```a``` to every character of ```b```. And all occurrences of every character in ```a``` map to same character in ```b```. ## Task In this ...
{"functional": "_inputs = [['ESTATE', 'DUELED'], ['XXX', 'YYY'], ['CBAABC', 'DEFFED'], ['RAMBUNCTIOUSLY', 'THERMODYNAMICS'], ['DISCRIMINATIVE', 'SIMPLIFICATION'], ['SEE', 'SAW'], ['BANANA', 'SENSE'], ['AB', 'CC'], ['XXY', 'XYY'], ['ABCBACCBA', 'ABCBACCAB'], ['AA', 'BBB'], ['abcdefghijk', 'abcdefghijba']]\n_outputs = [[...
coding
197
Solve the programming task below in a Python markdown code block. Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of n small Latin letters; the task was to learn the way the letters that the string contains are written...
{"inputs": ["a\n1\n", "a\n0\n", "a\n2\n", "aa\n2\n", "aa\n3\n", "cky\n79\n", "aaaa\n4\n", "aaaa\n1\n"], "outputs": ["0\n", "1\na", "0\n", "0\n", "0\n", "0\n", "0\n", "1\naaaa"]}
coding
524
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string num representing the digits of a very large integer and an integer k. You are allowed to swap any two adjacent digits of the integer at most k times. Return the minimum integer you can obtain al...
{"functional": "def check(candidate):\n assert candidate(num = \"4321\", k = 4) == \"1342\"\n assert candidate(num = \"100\", k = 1) == \"010\"\n assert candidate(num = \"36789\", k = 1000) == \"36789\"\n assert candidate(num = \"22\", k = 22) == \"22\"\n assert candidate(num = \"9438957234785635408\", k...
coding
99
Solve the programming task below in a Python markdown code block. This challenge extends the previous [repeater()](https://www.codewars.com/kata/thinkful-string-drills-repeater) challenge. Just like last time, your job is to write a function that accepts a string and a number as arguments. This time, however, you shoul...
{"functional": "_inputs = [['yo', 3], ['WuB', 6], ['code, eat, code, sleep... ', 2]]\n_outputs = [['\"yo\" repeated 3 times is: \"yoyoyo\"'], ['\"WuB\" repeated 6 times is: \"WuBWuBWuBWuBWuBWuB\"'], ['\"code, eat, code, sleep... \" repeated 2 times is: \"code, eat, code, sleep... code, eat, code, sleep... \"']]\nimport...
coding
168
Solve the programming task below in a Python markdown code block. ## Task Complete the function that receives an array of strings (`arr`) as an argument and returns all the valid Roman numerals. Basic Roman numerals are denoted as: ``` I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1000 ``` For the purposes of this k...
{"functional": "_inputs = [[['MMMCDLXVL', 'MDLXXXVI', 'DCLXII', 'MMMMCLL', 'MMDCCCLXXXIVCD']], [['MMMMCCCXXXII', 'MMDCCCXXVCD', 'MMCCCXLV', 'DCCLXVIIICD', 'MMMMCXII']], [['DCCLIVI', 'MDCCXXXVVI', 'MDLXXVI', 'MDVIL', 'MCCLXIII']], [['DV', '', 'CLVIII', 'MDCCCXXCD', 'MDCLXVI', 'MMMDCCCLXXXVI']], [['MMCDXVIII', '', 'MMMCC...
coding
630
Solve the programming task below in a Python markdown code block. Hint * One grid may be filled more than once * Even if it can be represented by one line segment such as '1', it may be represented by two or more line segments. Sample Input 1 Formula for Sample Input 1. Sample Input 2 Sample Input 2 formula. Anoth...
{"inputs": ["4\n1 1 1 5\n3 3 5 3\n4 2 4 4\n7 1 7 5", "23\n1 1 3 1\n3 1 3 3\n3 3 1 3\n1 3 1 5\n1 5 3 5\n5 2 7 2\n7 2 7 4\n6 4 5 4\n5 6 5 5\n5 6 7 6\n11 4 9 4\n13 0 15 0\n15 1 15 4\n20 2 18 2\n21 5 23 5\n21 5 21 7\n21 7 23 7\n23 7 23 9\n23 9 21 9\n24 0 26 0\n24 0 24 4\n24 4 26 4\n26 0 26 4", "23\n1 1 3 1\n3 1 3 3\n3 3 1 ...
coding
591
Solve the programming task below in a Python markdown code block. Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the cod...
{"inputs": ["0 0 2 4\n1 2\n1 2\n", "0 0 2 3\n1 1\n1 3\n", "0 0 2 4\n1 1\n1 2\n", "0 0 2 3\n1 1\n1 2\n", "-140 -140 2 200\n1 0\n0 1\n", "-12 -34 5 200\n1 0\n2 0\n3 1\n10 3\n11 4\n", "0 0 5 101\n21 38\n43 42\n5 29\n69 3\n84 52\n", "0 0 5 100\n12 105\n15 59\n21 1\n27 6\n27 76\n"], "outputs": ["Anton\n", "Dasha\n", "Dasha\...
coding
498
Solve the programming task below in a Python markdown code block. Vasya has recently finished writing a book. Now he faces the problem of giving it the title. Vasya wants the title to be vague and mysterious for his book to be noticeable among others. That's why the title should be represented by a single word containi...
{"inputs": ["2\n?\n", "1\na\n", "1\n?\n", "1\n?a\n", "3\nb?c\n", "3\na?c\n", "2\n????\n", "3\n????\n"], "outputs": ["IMPOSSIBLE\n", "a\n", "a\n", "aa\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n", "abba\n", "IMPOSSIBLE\n"]}
coding
499
Solve the programming task below in a Python markdown code block. You are given a integer $n$ ($n > 0$). Find any integer $s$ which satisfies these conditions, or report that there are no such numbers: In the decimal representation of $s$: $s > 0$, $s$ consists of $n$ digits, no digit in $s$ equals $0$, $s$ is no...
{"inputs": ["1\n31\n", "1\n28\n", "1\n7628\n", "1\n6538\n", "1\n90010\n", "1\n99999\n", "1\n99996\n", "1\n99997\n"], "outputs": ["2333333333333333333333333333333\n", "2333333333333333333333333333\n", "23333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...
coding
503
Solve the programming task below in a Python markdown code block. You task is to implement an simple interpreter for the notorious esoteric language [HQ9+](https://esolangs.org/wiki/HQ9+) that will work for a single character input: - If the input is `'H'`, return `'Hello World!'` - If the input is `'Q'`, return the i...
{"functional": "_inputs = [['X'], ['H'], ['Q']]\n_outputs = [[None], ['Hello World!'], ['Q']]\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):...
coding
412
Solve the programming task below in a Python markdown code block. Given is a number sequence A of length N. Find the number of integers i \left(1 \leq i \leq N\right) with the following property: - For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i. -----Constraints----- - ...
{"inputs": ["4\n6 8 5 5", "4\n5 8 5 5", "4\n6 8 2 5", "4\n7 8 5 5", "4\n8 8 5 5", "4\n3 8 2 5", "4\n7 9 5 5", "4\n7 9 8 5"], "outputs": ["2\n", "1\n", "2\n", "2\n", "0\n", "3\n", "2\n", "4\n"]}
coding
209
Solve the programming task below in a Python markdown code block. FizzBuzz is often one of the first programming puzzles people learn. Now undo it with reverse FizzBuzz! Write a function that accepts a string, which will always be a valid section of FizzBuzz. Your function must return an array that contains the number...
{"functional": "_inputs = [['1 2 Fizz 4 Buzz'], ['Fizz 688 689 FizzBuzz'], ['Fizz Buzz'], ['Fizz'], ['Buzz'], ['Buzz Fizz'], ['FizzBuzz']]\n_outputs = [[[1, 2, 3, 4, 5]], [[687, 688, 689, 690]], [[9, 10]], [[3]], [[5]], [[5, 6]], [[15]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinst...
coding
246
Solve the programming task below in a Python markdown code block. Given a square matrix of size N×N, calculate the absolute difference between the sums of its diagonals. -----Input----- The first line contains a single integer N. The next N lines denote the matrix's rows, with each line containing N space-separated i...
{"inputs": ["3\n11 2 4\n4 5 6\n10 8 -12"], "outputs": ["15"]}
coding
218
Solve the programming task below in a Python markdown code block. Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else. For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not ...
{"inputs": ["2 0\n1\n9\n", "5 5\n5\n5\n", "2 4\n1\n9\n", "7 7\n7\n7\n", "1 4\n1\n9\n", "2 0\n2\n9\n", "2 6\n7\n9\n", "6 0\n1\n6\n"], "outputs": ["4\n", "0\n", "3\n", "0\n", "8\n", "4\n", "1\n", "1\n"]}
coding
511
Solve the programming task below in a Python markdown code block. # Task Mirko has been moving up in the world of basketball. He started as a mere spectator, but has already reached the coveted position of the national team coach! Mirco is now facing a difficult task: selecting five primary players for the upcoming ...
{"functional": "_inputs = [[['michael', 'jordan', 'lebron', 'james', 'kobe', 'bryant']], [['babic', 'keksic', 'boric', 'bukic', 'sarmic', 'balic', 'kruzic', 'hrenovkic', 'beslic', 'boksic', 'krafnic', 'pecivic', 'klavirkovic', 'kukumaric', 'sunkic', 'kolacic', 'kovacic', 'prijestolonasljednikovic']], [['jgztazpytubijfs...
coding
408
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return true if there exists a triple of indices (i, j, k) such that i < j < k and nums[i] < nums[j] < nums[k]. If no such indices exists, return false.   Please complete the following pyth...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4,5]) == True\n assert candidate(nums = [5,4,3,2,1]) == False\n assert candidate(nums = [2,1,5,0,4,6]) == True\n\n\ncheck(Solution().increasingTriplet)"}
coding
99
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that : p[0] = start p[i] and p[i+1] differ by only one bit in their binary representation. p[0] and p[2^n -1] must also ...
{"functional": "def check(candidate):\n assert candidate(n = 2, start = 3) == [3,2,0,1]\n assert candidate(n = 3, start = 2) == [2,6,7,5,4,0,1,3]\n\n\ncheck(Solution().circularPermutation)"}
coding
139
Solve the programming task below in a Python markdown code block. Linear Kingdom has exactly one tram line. It has `n` stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. ## Your ...
{"functional": "_inputs = [[4, [0, 2, 4, 4], [3, 5, 2, 0]], [2, [0, 2, 4, 4], [3, 5, 2, 0]], [1, [0, 2, 4, 4], [3, 5, 2, 0]], [10, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]], [5, [0, 2, 4, 14, 2], [3, 5, 14, 0, 0]]]\n_outputs = [[6], [6], [3], [25], [16]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):...
coding
376
Solve the programming task below in a Python markdown code block. I bought food at the store to make a lunch box to eat at lunch. At the store, I only got an elongated bag to put food in, so I had to stack all the food vertically and put it in the bag. I want to pack the bag with the heavy ones down so that it won't fa...
{"inputs": ["4\nsandwich 80 120\napple 50 200\ncheese 20 40\ncake 100 100\n9\nonigiri 66 300\nonigiri 80 300\nanpan 70 85\nmikan 50 80\nkenyuma 100 500\nchocolaud 50 350\ncookie 30 80\npusni 40 400\ncracker 40 275\n0", "4\ntandwich 80 120\napple 50 200\ncheese 14 5\ncake 100 100\n9\nonigiri 80 300\nonigiri 80 300\nnapn...
coding
664
Solve the programming task below in a Python markdown code block. You are the best freelancer in the city. Everybody knows you, but what they don't know, is that you are actually offloading your work to other freelancers and and you rarely need to do any work. You're living the life! To make this process easier you ne...
{"functional": "_inputs = [[60, [[1, 0]]], [60, [[0, 0]]]]\n_outputs = [['Easy Money!'], ['I need to work 1 hour(s) and 0 minute(s)']]\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, (lis...
coding
244
Solve the programming task below in a Python markdown code block. ### Problem Context The [Fibonacci](http://en.wikipedia.org/wiki/Fibonacci_number) sequence is traditionally used to explain tree recursion. ```python def fibonacci(n): if n in [0, 1]: return n return fibonacci(n - 1) + fibonacci(n - ...
{"functional": "_inputs = [[70], [60], [50]]\n_outputs = [[190392490709135], [1548008755920], [12586269025]]\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...
coding
429
Solve the programming task below in a Python markdown code block. *** No Loops Allowed *** You will be given an array (a) and a value (x). All you need to do is check whether the provided array contains the value, without using a loop. Array can contain numbers or strings. X can be either. Return true if the array co...
{"functional": "_inputs = [[[66, 101], 66], [[80, 117, 115, 104, 45, 85, 112, 115], 45], [['t', 'e', 's', 't'], 'e'], [['what', 'a', 'great', 'kata'], 'kat'], [[66, 'codewars', 11, 'alex loves pushups'], 'alex loves pushups'], [['come', 'on', 110, '2500', 10, '!', 7, 15], 'Come'], [[\"when's\", 'the', 'next', 'Katathon...
coding
166
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of intervals intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping. Note that intervals which only to...
{"functional": "def check(candidate):\n assert candidate(intervals = [[1,2],[2,3],[3,4],[1,3]]) == 1\n assert candidate(intervals = [[1,2],[1,2],[1,2]]) == 2\n assert candidate(intervals = [[1,2],[2,3]]) == 0\n\n\ncheck(Solution().eraseOverlapIntervals)"}
coding
125
Solve the programming task below in a Python markdown code block. Consider creating the following number pattern. 4 8 2 3 1 0 8 3 7 6 2 0 5 4 1 8 1 0 3 2 5 9 5 9 9 1 3 7 4 4 4 8 0 4 1 8 8 2 8 4 9 6 0 0 2 5 6 0 2 1 6 2 7 8 Five This pattern follows the rules below. A B C In the sequence of numbers, C is the ones...
{"inputs": ["4823108376\n2273064329\n0123456789", "4823108376\n2314825047\n0123456789", "4823108376\n1842094049\n0123456789", "4823108376\n2704372300\n0123456789", "4823108376\n2811474872\n0123456789", "4823108376\n1472363412\n0123456789", "4823108376\n5495669921\n0123456789", "4823108376\n2337446006\n0123456789"], "ou...
coding
356
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. The concatenation of two numbers is the number formed by concatenating their numerals. For example, the concatenation of 15, 49 is 1549. The concatenation value of nums ...
{"functional": "def check(candidate):\n assert candidate(nums = [7,52,2,4]) == 596\n assert candidate(nums = [5,14,13,8,12]) == 673\n\n\ncheck(Solution().findTheArrayConcVal)"}
coding
198
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, an integer modulo, and an integer k. Your task is to find the count of subarrays that are interesting. A subarray nums[l..r] is interesting if the following condition hold...
{"functional": "def check(candidate):\n assert candidate(nums = [3,2,4], modulo = 2, k = 1) == 3\n assert candidate(nums = [3,1,9,6], modulo = 3, k = 0) == 2\n\n\ncheck(Solution().countInterestingSubarrays)"}
coding
173