problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and an integer k. Find the maximum subarray sum of all the subarrays of nums that meet the following conditions: The length of the subarray is k, and All the elements of the subarr...
{"functional": "def check(candidate):\n assert candidate(nums = [1,5,4,2,9,9,9], k = 3) == 15\n assert candidate(nums = [4,4,4], k = 3) == 0\n\n\ncheck(Solution().maximumSubarraySum)"}
coding
149
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two lists of closed intervals, firstList and secondList, where firstList[i] = [starti, endi] and secondList[j] = [startj, endj]. Each list of intervals is pairwise disjoint and in sorted order. Return th...
{"functional": "def check(candidate):\n assert candidate(firstList = [[0,2],[5,10],[13,23],[24,25]], secondList = [[1,5],[8,12],[15,24],[25,26]]) == [[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]\n assert candidate(firstList = [[1,3],[5,9]], secondList = []) == []\n assert candidate(firstList = [], secondList = ...
coding
198
Solve the programming task below in a Python markdown code block. **Debug** a function called calculate that takes 3 values. The first and third values are numbers. The second value is a character. If the character is "+" , "-", "\*", or "/", the function will return the result of the corresponding mathematical functio...
{"functional": "_inputs = [[2, '+', 4], [6, '-', 1.5], [-4, '*', 8], [49, '/', -7], [8, 'm', 2], [4, '/', 0], [3.2, '+', 8], [3.2, '-', 8], [3.2, '/', 8], [3.2, '*', 8], [-3, '+', 0], [-3, '-', 0], [-3, '/', 0], [-2, '/', -2], [-2, 'codewars', -2], [-3, '*', 0], [0, '*', 0], [0, '**', 0], [-3, 'w', 0], [0, '/', 0]]\n_o...
coding
277
Solve the programming task below in a Python markdown code block. Gerald has n younger brothers and their number happens to be even. One day he bought n^2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n^2 he has exactly one bag wit...
{"inputs": ["2\n", "4\n", "6\n", "8\n", "4\n", "6\n", "8\n", "2\n"], "outputs": ["1 4\n2 3\n", "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9\n", "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19\n", "1 64 2 63 3 62 4 61\n5 60 6 59 7 58 8 57\n9 56 10 55 11 54 12 53\n13...
coding
311
Solve the programming task below in a Python markdown code block. We consider two strings to be anagrams of each other if the first string's letters can be rearranged to form the second string. In other words, both strings must contain the same exact letters in the same exact frequency. For example, bacdc and dcbac are...
{"inputs": ["cde\nabc\n"], "outputs": ["4\n"]}
coding
491
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules: Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.len...
{"functional": "def check(candidate):\n assert candidate(nums1 = [7,4], nums2 = [5,2,8,9]) == 1\n assert candidate(nums1 = [1,1], nums2 = [1,1,1]) == 9\n assert candidate(nums1 = [7,7,8,3], nums2 = [1,2,9,7]) == 2\n assert candidate(nums1 = [4,7,9,11,23], nums2 = [3,5,1024,12,18]) == 0\n\n\ncheck(Solution()...
coding
188
Solve the programming task below in a Python markdown code block. ```if-not:ruby Create a function, that accepts an arbitrary number of arrays and returns a single array generated by alternately appending elements from the passed in arguments. If one of them is shorter than the others, the result should be padded with ...
{"functional": "_inputs = [[[1, 2, 3], ['c', 'd', 'e']], [[1, 2, 3], [4, 5]], [[1, 2], [3, 4, 5]], [[None], [None, None], [None, None, None]], [[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[]]]\n_outputs = [[[1, 'c', 2, 'd', 3, 'e']], [[1, 4, 2, 5, 3, None]], [[1, 3, 2, 4, None, 5]], [[None, None, None, None, None, None, None, N...
coding
289
Solve the programming task below in a Python markdown code block. Little Petya often visits his grandmother in the countryside. The grandmother has a large vertical garden, which can be represented as a set of `n` rectangles of varying height. Due to the newest irrigation system we can create artificial rain above them...
{"functional": "_inputs = [[[2]], [[1, 2, 1, 2, 1]], [[4, 2, 3, 3, 2]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]], [[1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]], [[1, 2, 3, 4, 5, 1, 5, 4, 3, 2, 1]], [[1, 1, 1, 2, 1, 2, 10, 2, 3, 3]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ...
coding
357
Solve the programming task below in a Python markdown code block. VK news recommendation system daily selects interesting publications of one of $n$ disjoint categories for each user. Each publication belongs to exactly one category. For each category $i$ batch algorithm selects $a_i$ publications. The latest A/B test...
{"inputs": ["1\n1\n7\n", "1\n2\n7\n", "1\n2\n4\n", "1\n1\n72\n", "1\n5\n16\n", "1\n3\n31\n", "1\n1\n72\n", "1\n3\n31\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
409
Solve the programming task below in a Python markdown code block. The absolute difference is the positive difference between two values $\boldsymbol{a}$ and $\boldsymbol{b}$, is written $\left|a-b\right|$ or $|b-a|$ and they are equal. If $\boldsymbol{a}=3$ and $b=2$, $|3-2|=|2-3|=1$. Given an array of integers, find ...
{"inputs": ["3\n3 -7 0\n", "5\n1 -3 71 68 17\n", "10\n-59 -36 -13 1 -53 -92 -2 -96 -54 75\n"], "outputs": ["3\n", "3\n", "1\n"]}
coding
592
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums that does not contain any zeros, find the largest positive integer k such that -k also exists in the array. Return the positive integer k. If there is no such integer, return -1.   Please c...
{"functional": "def check(candidate):\n assert candidate(nums = [-1,2,-3,3]) == 3\n assert candidate(nums = [-1,10,6,7,-7,1]) == 7\n assert candidate(nums = [-10,8,6,7,-2,-3]) == -1\n\n\ncheck(Solution().findMaxK)"}
coding
94
Solve the programming task below in a Python markdown code block. Vasya wants to climb up a stair of certain amount of steps (Input parameter 1). There are 2 simple rules that he has to stick to. 1. Vasya can climb 1 or 2 steps at each move. 2. Vasya wants the number of moves to be a multiple of a certain integer. (In...
{"functional": "_inputs = [[10, 2], [3, 5], [29, 7], [2, 2], [1, 2], [10000, 2], [10000, 3], [10000, 10], [9999, 3], [9999, 2], [9999, 10], [9999, 9], [18, 10], [19, 10], [20, 10], [7688, 5], [4608, 5], [3979, 2], [5, 2]]\n_outputs = [[6], [-1], [21], [2], [-1], [5000], [5001], [5000], [5001], [5000], [5000], [5004], [...
coding
395
Solve the programming task below in a Python markdown code block. Salmon has some hidden numbers that he wants you to find! Given an integer $N$, find and output any two integers A and B such that: * $1 ≤ A, B ≤ 10^{9}$, and * $A*B = N$. ------ Input: ------ The first line of input consists of a single integer $T$ ($...
{"inputs": ["5\n1\n3\n5\n8\n10"], "outputs": ["1 1\n1 3\n1 5\n1 8\n2 5\n"]}
coding
228
Solve the programming task below in a Python markdown code block. As you might know, cooking is the process of taking a food item and subjecting it to various processes(like heating, roasting, baking etc). A food item gets prepared after it has been subjected to exactly N processes. The order in which the processes are...
{"inputs": ["3\n2 2\n2 3\n1 3", "3\n0 2\n2 3\n1 3", "3\n0 2\n2 3\n1 5", "3\n0 2\n2 5\n1 5", "3\n2 2\n2 3\n2 3", "3\n0 2\n2 4\n1 5", "3\n0 1\n2 5\n1 5", "3\n0 2\n3 4\n1 5"], "outputs": ["2\n18\n6", "2\n18\n6\n", "2\n18\n20\n", "2\n260\n20\n", "2\n18\n18\n", "2\n84\n20\n", "0\n260\n20\n", "2\n588\n20\n"]}
coding
732
Solve the programming task below in a Python markdown code block. Karl is developing a key storage service. Each user has a positive integer key. Karl knows that storing keys in plain text is bad practice. So, instead of storing a key, he decided to store a fingerprint of a key. However, using some existing fingerprin...
{"inputs": ["3\n3\n1\n222880\n", "3\n3\n1\n339159\n", "3\n4\n1\n337517\n", "3\n3\n19\n45773\n", "3\n4\n1\n528334\n", "3\n2\n3\n223713\n", "3\n3\n3\n125981\n", "3\n1\n38\n45773\n"], "outputs": ["0\n0\n1070\n", "0\n0\n199\n", "0\n0\n107\n", "0\n1\n699\n", "0\n0\n2411\n", "0\n0\n95\n", "0\n0\n664\n", "0\n6\n699\n"]}
coding
571
Solve the programming task below in a Python markdown code block. AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set ...
{"inputs": ["4\n0224", "6\n123123", "19\n5546189040285140044", "19\n4753841743850076999", "19\n9039528710159876563", "19\n3616863455241776042", "19\n2785343766571511696", "19\n2922045480066417189"], "outputs": ["3", "17", "273\n", "311\n", "412\n", "322\n", "239\n", "281\n"]}
coding
227
Solve the programming task below in a Python markdown code block. -----General Statement:----- Given the actual high and low temperatures for the day and the normal high and low temperatures for that day, calculate the average difference from normal. -----Input:----- The first line of the data set for this problem is ...
{"inputs": ["3\n75 45 78 40\n50 32 45 30\n56 48 62 45"], "outputs": ["1.0 DEGREE(S) ABOVE NORMAL\n3.5 DEGREE(S) ABOVE NORMAL\n1.5 DEGREE(S) BELOW NORMAL"]}
coding
320
Solve the programming task below in a Python markdown code block. Kshitij has recently started solving problems on codechef. As he is real problem solving enthusiast, he wants continuous growth in number of problems solved per day. He started with $a$ problems on first day. He solves $d$ problems more than previous d...
{"inputs": ["1\n1 4 3 8 2"], "outputs": ["43"]}
coding
378
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a 3 lane road of length n that consists of n + 1 points labeled from 0 to n. A frog starts at point 0 in the second lane and wants to jump to point n. However, there could be obstacles along the way. You are ...
{"functional": "def check(candidate):\n assert candidate(obstacles = [0,1,2,3,0]) == 2 \n assert candidate(obstacles = [0,1,1,3,3,0]) == 0\n assert candidate(obstacles = [0,2,1,0,3,0]) == 2\n\n\ncheck(Solution().minSideJumps)"}
coding
340
Solve the programming task below in a Python markdown code block. # Task **_Given_** *a number* , **_Return_** **_The Maximum number _** *could be formed from the digits of the number given* . ___ # Notes * **_Only Natural numbers_** *passed to the function , numbers Contain digits [0:9] inclusive* * **_Digit ...
{"functional": "_inputs = [[213], [7389], [63792], [566797], [1000000]]\n_outputs = [[321], [9873], [97632], [977665], [1000000]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tu...
coding
606
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s of lowercase English letters and a 2D integer array shifts where shifts[i] = [starti, endi, directioni]. For every i, shift the characters in s from the index starti to the index endi (inclusi...
{"functional": "def check(candidate):\n assert candidate(s = \"abc\", shifts = [[0,1,0],[1,2,1],[0,2,1]]) == \"ace\"\n assert candidate(s = \"dztz\", shifts = [[0,0,0],[1,1,1]]) == \"catz\"\n\n\ncheck(Solution().shiftingLetters)"}
coding
198
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1. The edges in the graph are represented by a given 2D integer array edges, where edges[i] = [ui, vi] denotes an edge betwee...
{"functional": "def check(candidate):\n assert candidate(n = 7, edges = [[0,1],[1,2],[2,0],[3,4],[4,5],[5,6],[6,3]]) == 3\n assert candidate(n = 4, edges = [[0,1],[0,2]]) == -1\n\n\ncheck(Solution().findShortestCycle)"}
coding
182
Solve the programming task below in a Python markdown code block. Imagine that you have an array of 3 integers each representing a different person. Each number can be 0, 1, or 2 which represents the number of hands that person holds up. Now imagine there is a sequence which follows these rules: * None of the people h...
{"functional": "_inputs = [[54], [98], [3]]\n_outputs = [[[0, 0, 0]], [[2, 2, 1]], [[0, 1, 0]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b...
coding
340
Solve the programming task below in a Python markdown code block. This problem is a simplified version of D2, but it has significant differences, so read the whole statement. Polycarp has an array of $n$ ($n$ is even) integers $a_1, a_2, \dots, a_n$. Polycarp conceived of a positive integer $k$. After that, Polycarp b...
{"inputs": ["1\n4\n0 0 0 4\n", "1\n4\n1 2 3 4\n", "1\n4\n1 1 1 1\n", "1\n4\n-10 -10 -5 -5\n", "1\n4\n1000000 0 0 0\n", "1\n6\n8 128 -38 -39 19 119\n", "1\n4\n572894 617066 -274175 841676\n", "1\n4\n210452 -553585 -303337 -97565\n"], "outputs": ["4\n", "1\n", "-1\n", "5\n", "1000000\n", "1\n", "1\n", "1\n"]}
coding
452
Solve the programming task below in a Python markdown code block. There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate i...
{"inputs": ["1 1\n0\n0\n", "1 1\n1\n1\n", "1 1\n0\n1\n", "1 1\n5\n5\n", "1 1\n0\n-1\n", "2 2\n0 2\n0 1\n", "1 5\n1\n1 2 3 4 5\n", "3 3\n0 0 0\n0 0 0\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "4\n", "3\n", "6\n"]}
coding
582
Solve the programming task below in a Python markdown code block. Natasha's favourite numbers are $n$ and $1$, and Sasha's favourite numbers are $m$ and $-1$. One day Natasha and Sasha met and wrote down every possible array of length $n+m$ such that some $n$ of its elements are equal to $1$ and another $m$ elements ar...
{"inputs": ["0 2\n", "2 0\n", "2 2\n", "0 0\n", "1 4\n", "0 0\n", "1 4\n", "6 2\n"], "outputs": ["0\n", "2\n", "5\n", "0\n", "1\n", "0\n", "1\n", "121\n"]}
coding
610
Solve the programming task below in a Python markdown code block. You are given a string S consisting of 0 and 1. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into 0 by repeating the following operation some number of times. - Choose a contiguous segment [l,r] in S whos...
{"inputs": ["011", "111", "101", "001", "000", "110", "100", "010"], "outputs": ["2\n", "3\n", "2\n", "2\n", "3\n", "2\n", "2\n", "2"]}
coding
336
Solve the programming task below in a Python markdown code block. Let's call a non-empty sequence of positive integers a_1, a_2... a_{k} coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array a consisting of n positive integers, find the number of its coprime subsequences...
{"inputs": ["1\n1\n", "1\n1\n", "3\n1 2 3\n", "3\n1 2 5\n", "3\n1 1 5\n", "3\n1 1 1\n", "3\n1 2 3\n", "1\n100000\n"], "outputs": ["1\n", "1", "5\n", "5\n", "6\n", "7\n", "5", "0\n"]}
coding
346
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two binary trees root1 and root2. Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge the two trees into a new...
{"functional": "def check(candidate):\n assert is_same_tree(candidate(root1 = tree_node([1,3,2,5]), root2 = tree_node([2,1,3,None,4,None,7])), tree_node([3,4,5,5,4,None,7]))\n assert is_same_tree(candidate(root1 = tree_node([1]), root2 = tree_node([1,2])), tree_node([2,2]))\n\n\ncheck(Solution().mergeTrees)"}
coding
224
Solve the programming task below in a Python markdown code block. You are given $n$ rectangles, each of height $1$. Each rectangle's width is a power of $2$ (i. e. it can be represented as $2^x$ for some non-negative integer $x$). You are also given a two-dimensional box of width $W$. Note that $W$ may or may not be a...
{"inputs": ["2\n5 8\n1 2 8 2 8\n6 11\n4 8 8 2 2 8\n", "2\n5 9\n1 2 8 8 8\n6 10\n2 8 8 2 2 8\n", "2\n5 8\n1 2 8 2 8\n6 11\n4 2 8 2 2 8\n", "2\n5 8\n1 2 8 2 8\n6 11\n4 1 8 2 2 8\n", "2\n5 13\n2 2 8 2 8\n6 9\n2 8 8 2 2 1\n", "2\n5 8\n2 2 8 2 8\n6 11\n4 8 8 2 2 8\n", "2\n5 8\n4 2 8 2 8\n6 15\n2 8 8 2 2 1\n", "2\n5 13\n1 2 ...
coding
611
Solve the programming task below in a Python markdown code block. In this kata, you'll be given an integer of range `0 <= x <= 99` and have to return that number spelt out in English. A few examples: ```python name_that_number(4) # returns "four" name_that_number(19) # returns "nineteen" name_that_number(99) # ret...
{"functional": "_inputs = [[1], [52], [21], [99], [0], [53], [23], [76]]\n_outputs = [['one'], ['fifty two'], ['twenty one'], ['ninety nine'], ['zero'], ['fifty three'], ['twenty three'], ['seventy six']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return m...
coding
168
Solve the programming task below in a Python markdown code block. Rupsa really loves triangles. One day she came across an equilateral triangle having length of each side as an integer N. She started wondering if it was possible to transform the triangle keeping two sides fixed and alter the third side such that it sti...
{"inputs": ["2\n5\n3"], "outputs": ["YES\nNO"]}
coding
342
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integers m and n representing the dimensions of a 0-indexed m x n grid. You are also given a 0-indexed 2D integer matrix coordinates, where coordinates[i] = [x, y] indicates that the cell with coordi...
{"functional": "def check(candidate):\n assert candidate(m = 3, n = 3, coordinates = [[0,0]]) == [3,1,0,0,0]\n assert candidate(m = 3, n = 3, coordinates = [[0,0],[1,1],[0,2]]) == [0,2,2,0,0]\n\n\ncheck(Solution().countBlackBlocks)"}
coding
257
Solve the programming task below in a Python markdown code block. There are N towns numbered 1, 2, \cdots, N. Some roads are planned to be built so that each of them connects two distinct towns bidirectionally. Currently, there are no roads connecting towns. In the planning of construction, each town chooses one town...
{"inputs": ["2\n1 1", "2\n1 2", "2\n2 2", "2\n2 1", "2\n2 -1", "2\n-1 2", "2\n1 -1", "2\n-1 1"], "outputs": ["1\n", "0\n", "1\n", "1", "1\n", "1\n", "1\n", "1\n"]}
coding
428
Solve the programming task below in a Python markdown code block. There are a number of ways to shuffle a deck of cards. Riffle shuffle is one such example. The following is how to perform riffle shuffle. There is a deck of n cards. First, we divide it into two decks; deck A which consists of the top half of it and de...
{"inputs": ["9 1\n3\n9 4\n1 2 6 4", "9 1\n3\n9 4\n1 1 6 6", "9 1\n4\n5 4\n1 2 6 4", "2 1\n4\n5 4\n1 2 6 4", "9 1\n3\n9 4\n1 2 2 4", "5 1\n3\n9 4\n1 2 3 4", "9 1\n4\n5 4\n2 2 6 4", "5 1\n1\n9 4\n1 2 3 4"], "outputs": ["3\n0\n", "3\n1\n", "8\n0\n", "0\n0\n", "3\n8\n", "1\n0\n", "8\n3\n", "4\n0\n"]}
coding
662
Solve the programming task below in a Python markdown code block. The Kingdom of Kremland is a tree (a connected undirected graph without cycles) consisting of $n$ vertices. Each vertex $i$ has its own value $a_i$. All vertices are connected in series by edges. Formally, for every $1 \leq i < n$ there is an edge betwee...
{"inputs": ["1\n1\n", "1\n1\n", "3\n2 1 3\n", "3\n2 1 2\n", "3\n2 0 2\n", "3\n3 0 2\n", "3\n2 1 3\n", "4\n2 1 1 3\n"], "outputs": ["1", "1\n", "7", "7\n", "8\n", "7\n", "7\n", "11"]}
coding
674
Solve the programming task below in a Python markdown code block. Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For examp...
{"inputs": ["3\n", "2\n", "8\n", "9\n", "6\n", "7\n", "5\n", "4\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "2\n", "1\n", "1\n", "2\n"]}
coding
334
Solve the programming task below in a Python markdown code block. Let's call an array $a$ of $m$ integers $a_1, a_2, \ldots, a_m$ Decinc if $a$ can be made increasing by removing a decreasing subsequence (possibly empty) from it. For example, if $a = [3, 2, 4, 1, 5]$, we can remove the decreasing subsequence $[a_1, a_...
{"inputs": ["1\n1\n", "3\n2 3 1\n", "6\n4 5 2 6 1 3\n", "10\n7 10 1 8 3 9 2 4 6 5\n", "20\n2 1 13 10 12 18 15 19 5 14 16 9 3 8 17 11 7 20 6 4\n"], "outputs": ["1\n", "6\n", "19\n", "39\n", "90\n"]}
coding
472
Solve the programming task below in a Python markdown code block. You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of ma...
{"inputs": ["3 3 2 1\n1\n2\n3\n", "4 1000 2 1\n663\n663\n2\n1\n", "5 100 20 80\n79\n50\n9\n9\n80", "5 100 20 80\n79\n50\n9\n9\n157", "5 100 12 80\n80\n40\n42\n21\n62", "5 100 12 22\n80\n40\n42\n21\n62", "5 100 171 80\n68\n40\n9\n21\n80", "5 100 12 22\n80\n41\n42\n21\n62"], "outputs": ["0\n", "336\n", "32\n", "62\n", "2...
coding
598
Solve the programming task below in a Python markdown code block. The famous store "Second Food" sells groceries only two days a month. And the prices in each of days differ. You wanted to buy $n$ kilos of potatoes for a month. You know that on the first day of the month $1$ kilo of potatoes costs $a$ coins, and on the...
{"inputs": ["5\n5 4\n3 1\n5 4\n3 2\n3 4\n3 5\n20 15\n10 2\n1000000000 900000000\n1000000000 8\n"], "outputs": ["9\n10\n9\n135\n888888888900000000\n"]}
coding
587
Solve the programming task below in a Python markdown code block. A Madhav array has the following property: ```a[0] = a[1] + a[2] = a[3] + a[4] + a[5] = a[6] + a[7] + a[8] + a[9] = ...``` Complete the function/method that returns `true` if the given array is a Madhav array, otherwise it returns `false`. *Edge cases...
{"functional": "_inputs = [[[6, 2, 4, 2, 2, 2, 1, 5, 0, 0]], [[6, 2, 4, 2, 2, 2, 1, 5, 0, -100]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, -2, -1]], [[-6, -3, -3, 8, -5, -4]], [[-6, -3, -3, 8, -10, -4]], [[3, 1, 2, 3, 0]], [[3, 3]], [[]], [[1]], [[5, 2, 4, 1, 0, 3]], [[6, 2, 4, 2, 2, 2, 1, 5, 0, 0, -12, 13, -5, 4, 6]],...
coding
162
Solve the programming task below in a Python markdown code block. There are N people (with different names) and K clubs. For each club you know the list of members (so you have K unordered lists). Each person can be a member of many clubs (and also 0 clubs) and two different clubs might have exactly the same members. T...
{"inputs": ["5", "9", "7", "8", "6", "2", "4", "3"], "outputs": ["4\n", "334\n", "336\n", "384\n", "1\n", "1", "7", "1"]}
coding
628
Solve the programming task below in a Python markdown code block. On an $8 \times 8$ grid, some horizontal rows have been painted red, and some vertical columns have been painted blue, in some order. The stripes are drawn sequentially, one after the other. When the stripe is drawn, it repaints all the cells through whi...
{"inputs": ["4\n\n....B...\n....B...\n....B...\nRRRRRRRR\n....B...\n....B...\n....B...\n....B...\n\nRRRRRRRB\nB......B\nB......B\nB......B\nB......B\nB......B\nB......B\nRRRRRRRB\n\nRRRRRRBB\n.B.B..BB\nRRRRRRBB\n.B.B..BB\n.B.B..BB\nRRRRRRBB\n.B.B..BB\n.B.B..BB\n\n........\n........\n........\nRRRRRRRR\n........\n.........
coding
459
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array words of size n consisting of non-empty strings. We define the score of a string term as the number of strings words[i] such that term is a prefix of words[i]. For example, if words = ["a", "ab...
{"functional": "def check(candidate):\n assert candidate(words = [\"abc\",\"ab\",\"bc\",\"b\"]) == [5,4,3,2]\n assert candidate(words = [\"abcd\"]) == [4]\n\n\ncheck(Solution().sumPrefixScores)"}
coding
173
Solve the programming task below in a Python markdown code block. A pair of numbers has a unique LCM but a single number can be the LCM of more than one possible pairs. For example `12` is the LCM of `(1, 12), (2, 12), (3,4)` etc. For a given positive integer N, the number of different integer pairs with LCM is equal t...
{"functional": "_inputs = [[1], [12], [24], [25], [101101291], [12345676], [1251562], [625], [9801], [30858025]]\n_outputs = [[1], [8], [11], [3], [5], [68], [41], [5], [23], [63]]\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_to...
coding
144
Solve the programming task below in a Python markdown code block. Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-dimensional coordinate system on this sheet and drew n black horizontal and vertical segments parallel to the coordinate axes. All segments have width equa...
{"inputs": ["1\n1 1 1 1\n", "1\n1 1 1 0\n", "1\n1 1 1 -1\n", "3\n0 1 4 1\n1 4 1 2\n0 3 2 3\n", "3\n0 1 2 1\n1 6 1 2\n0 3 3 3\n", "3\n0 1 2 1\n1 2 1 2\n0 3 3 3\n", "3\n0 1 2 1\n1 6 1 2\n0 3 2 3\n", "3\n1 1 2 1\n1 6 1 2\n0 3 3 3\n"], "outputs": ["1", "2\n", "3\n", "10\n", "11\n", "8\n", "10\n", "10\n"]}
coding
395
Solve the programming task below in a Python markdown code block. There are three sticks with integer lengths $l_1, l_2$ and $l_3$. You are asked to break exactly one of them into two pieces in such a way that: both pieces have positive (strictly greater than $0$) integer length; the total length of the pieces is eq...
{"inputs": ["1\n1 98 99\n", "1\n1 98 99\n", "1\n1 98 186\n", "1\n2 98 186\n", "1\n2 98 239\n", "1\n1 98 239\n", "1\n1 98 108\n", "1\n2465 1 1\n"], "outputs": ["YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
530
Solve the programming task below in a Python markdown code block. Write a program which reverses a given string str. Input str (the size of str ≤ 20) is given in a line. Output Print the reversed str in a line. Example Input w32nimda Output admin23w
{"inputs": ["w32njmda", "admjn23w", "acmjn23w", "3cmjn2aw", "3dmjn2aw", "wa2njmd3", "xa2njmd3", "xa3njmd3"], "outputs": ["admjn23w\n", "w32njmda\n", "w32njmca\n", "wa2njmc3\n", "wa2njmd3\n", "3dmjn2aw\n", "3dmjn2ax\n", "3dmjn3ax\n"]}
coding
69
Solve the programming task below in a Python markdown code block. Given a string ``string`` that contains only letters, you have to find out the number of **unique** strings (including ``string`` itself) that can be produced by re-arranging the letters of the ``string``. Strings are case **insensitive**. HINT: Genera...
{"functional": "_inputs = [['AB'], ['ABC'], ['AbA'], ['ABBb'], ['AbcD'], ['AAA'], [''], ['ASTON'], ['BEST'], ['ABcDEFgHIJ'], ['ABcDEFgHIJbaslidbailsbdilasbdkanmsdklhkbHSJKHVDASH'], ['ABcDEFgHIJbaslidbailsbdilasbdkanmsdklhkbHSJKHVDASHVVYQVWKDVDWQUV']]\n_outputs = [[2], [6], [3], [4], [24], [1], [1], [120], [24], [362880...
coding
244
Solve the programming task below in a Python markdown code block. In this kata, you will be given a string of text and valid parentheses, such as `"h(el)lo"`. You must return the string, with only the text inside parentheses reversed, so `"h(el)lo"` becomes `"h(le)lo"`. However, if said parenthesized text contains pare...
{"functional": "_inputs = [['h(el)lo'], ['a ((d e) c b)'], ['one (two (three) four)'], ['one (ruof ((rht)ee) owt)'], [''], ['many (parens) on (top)'], ['( ( ) (()) )']]\n_outputs = [['h(le)lo'], ['a (b c (d e))'], ['one (ruof (three) owt)'], ['one (two ((thr)ee) four)'], [''], ['many (snerap) on (pot)'], ['( (()) ( ) )...
coding
327
Solve the programming task below in a Python markdown code block. You are given a string $S$. Find the number of ways to choose an unordered pair of non-overlapping non-empty substrings of this string (let's denote them by $s_1$ and $s_2$ in such a way that $s_2$ starts after $s_1$ ends) such that their concatenation $...
{"inputs": ["abba"], "outputs": ["7"]}
coding
335
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an n x n grid where you have placed some 1 x 1 x 1 cubes. Each value v = grid[i][j] represents a tower of v cubes placed on top of cell (i, j). After placing these cubes, you have decided to glue any dir...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,2],[3,4]]) == 34\n assert candidate(grid = [[1,1,1],[1,0,1],[1,1,1]]) == 32\n assert candidate(grid = [[2,2,2],[2,1,2],[2,2,2]]) == 46\n\n\ncheck(Solution().surfaceArea)"}
coding
147
Solve the programming task below in a Python markdown code block. AtCoDeer the deer has N square tiles. The tiles are numbered 1 through N, and the number given to each tile is written on one side of the tile. Also, each corner of each tile is painted in one of the 1000 colors, which are represented by the integers 0 b...
{"inputs": ["6\n0 1 2 3\n0 4 6 1\n1 6 9 2\n2 7 5 3\n6 4 5 7\n4 0 3 5", "6\n0 0 0 0\n0 0 1 0\n0 0 0 0\n0 0 0 0\n0 0 0 1\n0 1 0 0", "6\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n1 0 0 0", "6\n0 1 2 3\n0 4 6 1\n1 6 9 2\n3 7 5 3\n6 4 5 7\n4 0 3 5", "6\n0 1 2 3\n0 4 6 1\n1 6 9 2\n3 7 5 3\n6 4 6 7\n4 0 3 5", "6\n0 1 2 3\n...
coding
568
Solve the programming task below in a Python markdown code block. Taking into consideration the [3.5 edition rules](http://www.dandwiki.com/wiki/SRD:Ability_Scores#Table:_Ability_Modifiers_and_Bonus_Spells), your goal is to build a function that takes an ability score (worry not about validation: it is always going to ...
{"functional": "_inputs = [[0], [1], [5], [10], [20]]\n_outputs = [[{'modifier': 0, 'maximum_spell_level': -1, 'extra_spells': []}], [{'modifier': -5, 'maximum_spell_level': -1, 'extra_spells': []}], [{'modifier': -3, 'maximum_spell_level': -1, 'extra_spells': []}], [{'modifier': 0, 'maximum_spell_level': 0, 'extra_spe...
coding
520
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"]}
coding
615
Solve the programming task below in a Python markdown code block. Ori and Sein have overcome many difficult challenges. They finally lit the Shrouded Lantern and found Gumon Seal, the key to the Forlorn Ruins. When they tried to open the door to the ruins... nothing happened. Ori was very surprised, but Sein gave the ...
{"inputs": ["1 1\n1 1\n", "1 1\n1 1\n", "2 1\n1 1\n1 1\n", "2 2\n1 1\n1 1\n", "2 2\n1 1\n1 1\n", "2 1\n1 1\n1 1\n", "3 1\n1 1\n2 2\n3 3\n", "3 2\n1 1\n2 2\n3 3\n"], "outputs": ["1", "1\n", "2", "1", "1\n", "2\n", "3", "0"]}
coding
745
Solve the programming task below in a Python markdown code block. Write a function that accepts two square matrices (`N x N` two dimensional arrays), and return the sum of the two. Both matrices being passed into the function will be of size `N x N` (square), containing only integers. How to sum two matrices: Take ea...
{"functional": "_inputs = [[[[1, 2, 3], [3, 2, 1], [1, 1, 1]], [[2, 2, 1], [3, 2, 3], [1, 1, 3]]], [[[1, 2], [1, 2]], [[2, 3], [2, 3]]], [[[1]], [[2]]]]\n_outputs = [[[[3, 4, 4], [6, 4, 4], [2, 2, 4]]], [[[3, 5], [3, 5]]], [[[3]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b...
coding
265
Solve the programming task below in a Python markdown code block. Summer is at its peak in Chefland. Chef is planning to purchase a water cooler to keep his room cool. He has two options available: Rent a cooler at the cost of X coins per month. Purchase a cooler for Y coins. Given that the summer season will last fo...
{"inputs": ["3\n5 10 1\n5 10 2\n5 10 3"], "outputs": ["YES\nNO\nNO"]}
coding
549
Solve the programming task below in a Python markdown code block. You have to create a function named reverseIt. Write your function so that in the case a string or a number is passed in as the data , you will return the data in reverse order. If the data is any other type, return it as it is. Examples of inputs and...
{"functional": "_inputs = [['Hello'], [314159], ['314159'], [[]], [{}], [True], [[1, 2, 3]]]\n_outputs = [['olleH'], [951413], ['951413'], [[]], [{}], [True], [[1, 2, 3]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, ab...
coding
138
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. You are given a grid with size $N \times M$. Each cell of this grid contains either $0$ or $1$. We should perform the following operation until the size of t...
{"inputs": ["2\n1 2\n01\n3 3\n000\n111\n010"], "outputs": ["YES\nNO"]}
coding
692
Solve the programming task below in a Python markdown code block. Many cats live on the campus of a school. Natsume's daily routine is to pet those cats. However, the cats may be capricious and go for a walk off campus. The campus site is a rectangle with each side parallel to the x-axis or y-axis and is surrounded by...
{"inputs": ["2\n1 3 11 11\n4\n13 13\n2 15\n10 9\n5 10\n1 3 20 18\n4\n6 13\n2 15\n1 10\n25 4", "2\n1 3 20 16\n4\n13 13\n2 15\n10 10\n5 10\n0 3 20 0\n4\n1 8\n1 15\n10 10\n25 4", "2\n1 1 11 11\n4\n13 25\n2 15\n10 9\n5 14\n1 3 20 18\n4\n6 13\n2 15\n1 10\n25 4", "2\n1 3 6 10\n4\n21 13\n1 7\n10 10\n8 10\n1 0 20 10\n4\n21 6\n...
coding
510
Solve the programming task below in a Python markdown code block. Poker Nim is another $2$-player game that's a simple variation on a Nim game. The rules of the games are as follows: The game starts with $n$ piles of chips indexed from $\mbox{0}$ to $n-1$. Each pile $\boldsymbol{i}$ (where $0\leq i<n$) has $c_i$ chips...
{"inputs": ["2\n2 5\n1 2\n3 5\n2 1 3\n"], "outputs": ["First\nSecond\n"]}
coding
502
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, reverse the string according to the following rules: All the characters that are not English letters remain in the same position. All the English letters (lowercase or uppercase) should be reversed....
{"functional": "def check(candidate):\n assert candidate(s = \"ab-cd\") == \"dc-ba\"\n assert candidate(s = \"a-bC-dEf-ghIj\") == \"j-Ih-gfE-dCba\"\n assert candidate(s = \"Test1ng-Leet=code-Q!\") == \"Qedo1ct-eeLg=ntse-T!\"\n\n\ncheck(Solution().reverseOnlyLetters)"}
coding
96
Solve the programming task below in a Python markdown code block. After Fox Ciel won an onsite round of a programming contest, she took a bus to return to her castle. The fee of the bus was 220 yen. She met Rabbit Hanako in the bus. They decided to play the following game because they got bored in the bus. * Initial...
{"inputs": ["3 0\n", "7 2\n", "5 5\n", "3 5\n", "8 2\n", "4 1\n", "8 1\n", "0 0\n"], "outputs": ["Hanako", "Ciel", "Hanako", "Ciel", "Ciel", "Hanako", "Hanako", "Hanako"]}
coding
418
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array. A k-diff pair is an integer pair (nums[i], nums[j]), where the following are true: 0 <= i, j < nums.length i !=...
{"functional": "def check(candidate):\n assert candidate(nums = [3, 1, 4, 1, 5], k = 2) == 2\n assert candidate(nums = [1, 2, 3, 4, 5], k = 1) == 4\n assert candidate(nums = [1, 3, 1, 5, 4], k = 0) == 1\n\n\ncheck(Solution().findPairs)"}
coding
134
Solve the programming task below in a Python markdown code block. The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped k ×...
{"inputs": ["1 1 1\n\n.\n\n1 1\n", "2 1 1\n\n.\n\n#\n\n1 1\n", "1 1 10\n\n..........\n\n1 6\n", "2 2 2\n\n#.\n..\n\n.#\n#.\n\n2 1\n", "2 2 2\n\n#.\n..\n\n.#\n.#\n\n2 1\n", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1\n", "1 6 2\n\n##\n..\n##\n.#\n##\n#.\n\n6 2\n", "4 1 3\n\n...\n\n...\n\n...\n\n...\n\n1 1\n"], "outputs": ["1", "1...
coding
557
Solve the programming task below in a Python markdown code block. You are given three integers A, B and C. Determine if there exists an equilateral triangle whose sides have lengths A, B and C. Constraints * All values in input are integers. * 1 \leq A,B,C \leq 100 Input Input is given from Standard Input in the f...
{"inputs": ["2 4 2", "0 0 0", "3 4 2", "2 6 2", "3 4 1", "2 7 2", "3 0 1", "1 7 2"], "outputs": ["No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
141
Solve the programming task below in a Python markdown code block. Write a function getMean that takes as parameters an array (arr) and 2 integers (x and y). The function should return the mean between the mean of the the first x elements of the array and the mean of the last y elements of the array. The mean should be...
{"functional": "_inputs = [[[1, 3, 2, 4], 2, 3], [[1, 3, 2], 2, 2], [[1, 3, 2, 4], 1, 2], [[1, 3, 2, 4], 2, 8], [[1, -1, 2, -1], 2, 3]]\n_outputs = [[2.5], [2.25], [-1], [-1], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_to...
coding
274
Solve the programming task below in a Python markdown code block. ## Task: You have to create a function `isPronic` to check whether the argument passed is a Pronic Number and return true if it is & false otherwise. ### Description: `Pronic Number` -A pronic number, oblong number, rectangular number or heteromecic nu...
{"functional": "_inputs = [[2], [3], [4], [5], [6], [-3], [-27]]\n_outputs = [[True], [False], [False], [False], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, ...
coding
314
Solve the programming task below in a Python markdown code block. You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and s...
{"inputs": ["1\n0 2\n", "1\n0 0\n", "1\n1 0\n", "1\n1 1\n", "1\n1 2\n", "1\n0 79\n", "1\n0 10\n", "1\n0 -1\n"], "outputs": ["3\n", "0\n", "1\n", "0\n", "1\n", "13\n", "4\n", "1\n"]}
coding
413
Solve the programming task below in a Python markdown code block. An onion array is an array that satisfies the following condition for all values of `j` and `k`: If all of the following are `true`: * `j >= 0` * `k >= 0` * `j + k = array.length - 1` * `j != k` then: * `a[j] + a[k] <= 10` ### Examples: ``` [1, 2...
{"functional": "_inputs = [[[6, 0, 4]], [[1, 1, 15, 10, -1]]]\n_outputs = [[True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): r...
coding
274
Solve the programming task below in a Python markdown code block. You are given a string S of length 2N, containing N occurrences of `a` and N occurrences of `b`. You will choose some of the characters in S. Here, for each i = 1,2,...,N, it is not allowed to choose exactly one of the following two: the i-th occurrence...
{"inputs": ["3\nbabbaa", "3\naabbba", "3\nbababa", "3\naaabbb", "3\nbbaaba", "3\naabbab", "3\nababab", "3\nabbbaa"], "outputs": ["bbaa\n", "ba\n", "bababa\n", "ab\n", "bbaaba\n", "abab\n", "ababab\n", "bbaa\n"]}
coding
271
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have a list arr of all integers in the range [1, n] sorted in a strictly increasing order. Apply the following algorithm on arr: Starting from left to right, remove the first number and every other number afterwa...
{"functional": "def check(candidate):\n assert candidate(n = 9) == 6\n assert candidate(n = 1) == 1\n\n\ncheck(Solution().lastRemaining)"}
coding
164
Solve the programming task below in a Python markdown code block. collections.OrderedDict An OrderedDict is a dictionary that remembers the order of the keys that were inserted first. If a new entry overwrites an existing entry, the original insertion position is left unchanged. Example Code >>> from collections i...
{"inputs": ["9\nBANANA FRIES 12\nPOTATO CHIPS 30\nAPPLE JUICE 10\nCANDY 5\nAPPLE JUICE 10\nCANDY 5\nCANDY 5\nCANDY 5\nPOTATO CHIPS 30\n"], "outputs": ["BANANA FRIES 12\nPOTATO CHIPS 60\nAPPLE JUICE 20\nCANDY 20\n"]}
coding
632
Solve the programming task below in a Python markdown code block. Challenge: Given two null-terminated strings in the arguments "string" and "prefix", determine if "string" starts with the "prefix" string. Return 1 (or any other "truthy" value) if true, 0 if false. Example: ``` startsWith("hello world!", "hello"); // ...
{"functional": "_inputs = [['hello world!', 'hello'], ['hello world!', 'HELLO'], ['nowai', 'nowaisir'], ['', ''], ['abc', ''], ['', 'abc']]\n_outputs = [[True], [False], [False], [True], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ma...
coding
278
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer num. You may swap any two digits of num that have the same parity (i.e. both odd digits or both even digits). Return the largest possible value of num after any number of swaps.   Plea...
{"functional": "def check(candidate):\n assert candidate(num = 1234) == 3412\n assert candidate(num = 65875) == 87655\n\n\ncheck(Solution().largestInteger)"}
coding
93
Solve the programming task below in a Python markdown code block. Transpose means is to interchange rows and columns of a two-dimensional array matrix. [A^(T)]ij=[A]ji ie: Formally, the i th row, j th column element of AT is the j th row, i th column element of A: Example : ``` [[1,2,3],[4,5,6]].transpose() //sho...
{"functional": "_inputs = [[[]], [[[1]]], [[[0, 1]]], [[[1, 2, 3], [4, 5, 6]]], [[[1, 2, 3, 4, 5, 6]]], [[[1], [2], [3], [4], [5], [6]]], [[['a', 'b', 'c'], ['d', 'e', 'f']]], [[[True, False, True], [False, True, False]]], [[[]]], [[[], [], [], [], [], []]]]\n_outputs = [[[]], [[[1]]], [[[0], [1]]], [[[1, 4], [2, 5], [...
coding
175
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. In one operation, you can choose any index i where 0 <= i < nums.length and change nums[i] to nums[i] + x where x is an integer from the range [-k, k]. You can app...
{"functional": "def check(candidate):\n assert candidate(nums = [1], k = 0) == 0\n assert candidate(nums = [0,10], k = 2) == 6\n assert candidate(nums = [1,3,6], k = 3) == 0\n\n\ncheck(Solution().smallestRangeI)"}
coding
156
Solve the programming task below in a Python markdown code block. Chef and Chefina are playing a game. There are two piles numbered 1 and 2. Pile 1 contains X stones while Pile 2 contains Y stones. Chef starts the game. In his turn, Chef can either remove 1 stone each from both the piles or remove 2 stones from pile...
{"inputs": ["3\n1 10\n2 2\n4 2\n"], "outputs": ["CHEFINA\nCHEFINA\nCHEF\n"]}
coding
529
Solve the programming task below in a Python markdown code block. You are given four distinct integers $a$, $b$, $c$, $d$. Timur and three other people are running a marathon. The value $a$ is the distance that Timur has run and $b$, $c$, $d$ correspond to the distances the other three participants ran. Output the nu...
{"inputs": ["1\n2 9 10 1\n", "1\n4455 4 5 10\n", "4\n2 3 4 1\n10000 0 1 2\n500 600 400 300\n0 9999 10000 9998\n"], "outputs": ["2\n", "0\n", "2\n0\n1\n3\n"]}
coding
404
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef has defined a new type of rooted tree - divisor tree. In this tree, every node has a positive integer written on it. It follows some rules: The root can have any positiv...
{"inputs": ["11 12", "932451 935212"], "outputs": ["14", "101245"]}
coding
714
Solve the programming task below in a Python markdown code block. We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i). Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there? We remind you that the distance...
{"inputs": ["4 5\n0 5\n-2 4\n3 4\n4 -4\n", "12 3\n1 1\n1 1\n1 1\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n", "20 100000\n14309 -32939\n-56855 100340\n151364 25430\n103789 -113141\n147404 -136977\n-37006 -30929\n188810 -49557\n13419 70401\n-88280 165170\n-196399 137941\n-176527 -61904\n46659 115261\n-153551 114185\n...
coding
365
Solve the programming task below in a Python markdown code block. For given an integer $n$, print all permutations of $\\{1, 2, ..., n\\}$ in lexicographic order. Constraints * $1 \leq n \leq 9$ Input An integer $n$ is given in a line. Output Print each permutation in a line in order. Separate adjacency elements ...
{"inputs": ["1", "4", "5", "4", "1", "5", "3", "2"], "outputs": ["1\n", "1 2 3 4\n1 2 4 3\n1 3 2 4\n1 3 4 2\n1 4 2 3\n1 4 3 2\n2 1 3 4\n2 1 4 3\n2 3 1 4\n2 3 4 1\n2 4 1 3\n2 4 3 1\n3 1 2 4\n3 1 4 2\n3 2 1 4\n3 2 4 1\n3 4 1 2\n3 4 2 1\n4 1 2 3\n4 1 3 2\n4 2 1 3\n4 2 3 1\n4 3 1 2\n4 3 2 1\n", "1 2 3 4 5\n1 2 3 5 4\n1 2 4...
coding
146
Solve the programming task below in a Python markdown code block. CQXYM found a rectangle A of size n × m. There are n rows and m columns of blocks. Each block of the rectangle is an obsidian block or empty. CQXYM can change an obsidian block to an empty block or an empty block to an obsidian block in one operation. A...
{"inputs": ["1\n5 4\n1000\n0000\n0110\n0001\n0001\n", "1\n5 4\n1000\n0000\n1110\n0001\n0000\n", "1\n5 4\n1011\n0000\n1010\n0000\n1000\n", "1\n5 4\n1000\n0010\n0110\n0001\n0001\n", "1\n5 4\n1011\n0000\n1010\n0001\n1000\n", "1\n5 4\n1000\n0100\n0110\n0101\n0000\n", "1\n5 4\n1011\n0000\n1010\n1001\n1000\n", "1\n5 4\n0011\...
coding
639
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer array nums. The element sum is the sum of all the elements in nums. The digit sum is the sum of all the digits (not necessarily distinct) that appear in nums. Return the absolute dif...
{"functional": "def check(candidate):\n assert candidate(nums = [1,15,6,3]) == 9\n assert candidate(nums = [1,2,3,4]) == 0\n\n\ncheck(Solution().differenceOfSum)"}
coding
124
Solve the programming task below in a Python markdown code block. One of the built-in functions of Python is divmod, which takes two arguments $\boldsymbol{\alpha}$ and $\boldsymbol{b}$ and returns a tuple containing the quotient of $a/b$ first and then the remainder $\boldsymbol{a}$. For example: >>> print divmo...
{"inputs": ["177\n10\n"], "outputs": ["17\n7\n(17, 7)\n"]}
coding
291
Solve the programming task below in a Python markdown code block. There are N people living on a number line. The i-th person lives at coordinate X_i. You are going to hold a meeting that all N people have to attend. The meeting can be held at any integer coordinate. If you choose to hold the meeting at coordinate P, t...
{"inputs": ["1\n1\n", "2\n0 4", "2\n0 1", "2\n2 4", "2\n0 3", "2\n1 4", "2\n1 4\n", "7\n4 1 0 12 23 0 0"], "outputs": ["0\n", "8\n", "1\n", "2\n", "5\n", "5", "5\n", "462\n"]}
coding
292
Solve the programming task below in a Python markdown code block. Continuing from previous version of codeXplod series i.e. CodeXplod 1.0,Chandu and daspal are still fighting over a matter of MOMO's(they are very fond of Mo Mos of sector 3..:P).This time the fight became so savior that they want to kill each other.As w...
{"inputs": ["51\n8 10 Chandu\n2 2959 Daspal\n2903 6 Chandu\n9 2938 Daspal\n10 2907 Daspal\n8 2966 Daspal\n8 2938 Daspal\n4 2984 Daspal\n5 2939 Daspal\n2 2975 Daspal\n2925 10 Chandu\n4 2982 Daspal\n10 2959 Daspal\n3 2906 Daspal\n5 2904 Daspal\n2983 5 Chandu\n10 2998 Daspal\n10 2980 Daspal\n6 2913 Daspal\n9 2974 Daspal\n...
coding
478
Solve the programming task below in a Python markdown code block. Chef has a sequence of $N$ integers, $A_1, A_2, ... , A_N$. He likes this sequence if it contains a subsequence of $M$ integers, $B_1, B_2, ... , B_M$ within it. A subsequence is a sequence that can be derived from another sequence by deleting some or n...
{"inputs": ["2\n6\n0 2 2 4 7 6\n3\n2 3 4\n6\n5 5 3 19 1 4\n2\n5 9", "2\n6\n0 2 2 4 7 6\n3\n2 3 4\n6\n5 5 0 19 1 4\n2\n5 9", "2\n6\n0 2 2 4 7 6\n3\n2 5 4\n6\n5 5 0 19 1 4\n2\n5 9", "2\n6\n0 2 3 4 7 6\n3\n2 3 4\n6\n22 5 6 19 1 4\n2\n4 3", "2\n6\n0 2 2 4 7 6\n3\n2 3 4\n6\n41 5 3 19 1 4\n2\n5 9", "2\n6\n1 1 3 4 7 6\n3\n2 3...
coding
758
Solve the programming task below in a Python markdown code block. Given three numbers $n, a, b$. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to $a$, and the number of components in its complement is $b$. The matrix must be symmetric, and all digits on th...
{"inputs": ["3 1 2\n", "3 3 3\n", "5 1 1\n", "2 1 1\n", "1 1 1\n", "3 1 1\n", "5 2 2\n", "4 1 1\n"], "outputs": ["YES\n001\n001\n110\n", "NO\n", "YES\n01000\n10100\n01010\n00101\n00010\n", "NO\n", "YES\n0\n", "NO\n", "NO\n", "YES\n0100\n1010\n0101\n0010\n"]}
coding
561
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Given an array of size n, you have to answer queries of the form : L R k . For each query, you have to find an element which occurs consecutively in the subarray [L,R] more t...
{"inputs": ["5 1\n1 2 2 2 2\n1 5 3"], "outputs": ["2"]}
coding
390
Solve the programming task below in a Python markdown code block. Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters. Constraints * The number of characters in the sentence < 1200 Input A sentence in English is given in several lines. Output Prints the n...
{"inputs": ["This is ` pen.", "This si a pen.", "hTit si a pen.", "hTis ir a pen.", "hTis ri a pdn.", "hTis ri a odn.", "hTis ri a odo.", "hsiT rh a od.o"], "outputs": ["a : 0\nb : 0\nc : 0\nd : 0\ne : 1\nf : 0\ng : 0\nh : 1\ni : 2\nj : 0\nk : 0\nl : 0\nm : 0\nn : 1\no : 0\np : 1\nq : 0\nr : 0\ns : 2\nt : 1\nu : 0\nv :...
coding
250
Solve the programming task below in a Python markdown code block. Given a string of words (x), you need to return an array of the words, sorted alphabetically by the final character in each. If two words have the same last letter, they returned array should show them in the order they appeared in the given string. Al...
{"functional": "_inputs = [['man i need a taxi up to ubud'], ['what time are we climbing up the volcano'], ['take me to semynak'], ['massage yes massage yes massage'], ['take bintang and a dance please']]\n_outputs = [[['a', 'need', 'ubud', 'i', 'taxi', 'man', 'to', 'up']], [['time', 'are', 'we', 'the', 'climbing', 'vo...
coding
92
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Mike likes to invent new functions. The latest one he has invented is called SuperFunction. Let's consider how it can be calculated: You are given two integers N and K. SuperFunction of N and K...
{"inputs": ["5 2 100"], "outputs": ["30"]}
coding
509
Solve the programming task below in a Python markdown code block. Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find ...
{"inputs": ["3 6\n", "6 8\n", "5 5\n", "3 3\n", "2 2\n", "7 7\n", "3 8\n", "4 8\n"], "outputs": ["2\n", "2\n", "5\n", "3\n", "2\n", "7\n", "2\n", "2\n"]}
coding
276
Solve the programming task below in a Python markdown code block. #Unflatten a list (Easy) There are several katas like "Flatten a list". These katas are done by so many warriors, that the count of available list to flattin goes down! So you have to build a method, that creates new arrays, that can be flattened! #Sh...
{"functional": "_inputs = [[[3, 5, 2, 1]], [[1, 4, 5, 2, 1, 2, 4, 5, 2, 6, 2, 3, 3]], [[1, 1, 1, 1]], [[1]], [[99, 1, 1, 1]], [[3, 1, 1, 3, 1, 1]]]\n_outputs = [[[[3, 5, 2], 1]], [[1, [4, 5, 2, 1], 2, [4, 5, 2, 6], 2, [3, 3]]], [[1, 1, 1, 1]], [[1]], [[[99, 1, 1, 1]]], [[[3, 1, 1], [3, 1, 1]]]]\nimport math\ndef _deep_...
coding
512
Solve the programming task below in a Python markdown code block. These days, chef is very much interested in Mathematics. He has started attending Recitations too! His hunger for problems is increasing day by day! Today, chef was a given a crumpled maths problem, which he is stuck with . He needs your help to do it He...
{"inputs": ["2\n10 3\n20 2"], "outputs": ["Case #1: 43\nCase #2: 180"]}
coding
287
Solve the programming task below in a Python markdown code block. Let S be the sum of divisors of an integer N excluding the number itself. When N = S, N is called a perfect number, when N> S, N is called a defendant number, and when N <S, N is called an abundant number. Create a program that determines whether a given...
{"inputs": ["1\n1\n5\n4\n6\n12\n18\n4\n820514\n99999998\n699564\n100001100\n0", "1\n1\n5\n6\n6\n12\n18\n4\n820514\n99999998\n699564\n100001100\n0", "1\n1\n5\n4\n6\n1\n5\n5\n1356316\n171009028\n699564\n100001100\n0", "1\n1\n5\n6\n6\n12\n20\n4\n820514\n99999998\n206539\n100101100\n0", "1\n1\n9\n4\n6\n0\n5\n5\n1356316\n17...
coding
330
Solve the programming task below in a Python markdown code block. *** Nova polynomial from roots*** This kata is from a series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714041e8...
{"functional": "_inputs = [[[4]], [[0, 0, 0, 0]], [[1, 1, 1, 1]], [[-1, 1, 2, -2]], [[]]]\n_outputs = [[[-4, 1]], [[0, 0, 0, 0, 1]], [[1, -4, 6, -4, 1]], [[4, 0, -5, 0, 1]], [[1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_to...
coding
468
Solve the programming task below in a Python markdown code block. Take 2 strings `s1` and `s2` including only letters from `a`to `z`. Return a new **sorted** string, the longest possible, containing distinct letters, - each taken only once - coming from s1 or s2. # Examples: ``` a = "xyaabbbccccdefww" b = "xxxxyyyyabk...
{"functional": "_inputs = [['aretheyhere', 'yestheyarehere'], ['loopingisfunbutdangerous', 'lessdangerousthancoding'], ['inmanylanguages', 'theresapairoffunctions'], ['lordsofthefallen', 'gamekult'], ['codewars', 'codewars'], ['agenerationmustconfrontthelooming', 'codewarrs']]\n_outputs = [['aehrsty'], ['abcdefghilnopr...
coding
150