task_type
stringclasses
1 value
problem
stringlengths
261
3.34k
answer
stringlengths
35
6.15k
problem_tokens
int64
62
774
answer_tokens
int64
12
2.04k
coding
Solve the programming task below in a Python markdown code block. There are N squares aligned in a row. The i-th square from the left contains an integer a_i. Initially, all the squares are white. Snuke will perform the following operation some number of times: * Select K consecutive squares. Then, paint all of them ...
{"inputs": ["1 1\n1", "1 1\n0", "1 1\n-2", "1 1\n-3", "1 1\n-9", "1 1\n-16", "1 1\n-20", "1 1\n-25"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
290
103
coding
Solve the programming task below in a Python markdown code block. The alphabetized kata --------------------- Re-order the characters of a string, so that they are concatenated into a new string in "case-insensitively-alphabetical-order-of-appearance" order. Whitespace and punctuation shall simply be removed! The inp...
{"functional": "_inputs = [[''], [' '], [' a'], ['a '], [' a '], ['A b B a'], [' a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z'], ['!@$%^&*()_+=-`,'], ['The Holy Bible'], [\"CodeWars can't Load Today\"]]\n_outputs = [[''], [''], ['a'], ['a'], ['a'], ['AabB'], ['...
153
335
coding
Solve the programming task below in a Python markdown code block. The previous challenges covered Insertion Sort, which is a simple and intuitive sorting algorithm with a running time of $unrecognized$. In these next few challenges, we're covering a divide-and-conquer algorithm called Quicksort (also known as Partition...
{"inputs": ["5 \n4 5 3 7 2 \n"], "outputs": ["3 2 4 5 7\n"]}
726
36
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i][j] == 1. Some nodes initial are initially infected by malware. Wh...
{"functional": "def check(candidate):\n assert candidate(graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]) == 0\n assert candidate(graph = [[1,0,0],[0,1,0],[0,0,1]], initial = [0,2]) == 0\n assert candidate(graph = [[1,1,1],[1,1,1],[1,1,1]], initial = [1,2]) == 1\n\n\ncheck(Solution().minMalwareSpread)"}
244
126
coding
Solve the programming task below in a Python markdown code block. After his wife's tragic death, Eurydice, Orpheus descended to the realm of death to see her. Reaching its gates was uneasy, but passing through them proved to be even more challenging. Mostly because of Cerberus, the three-headed hound of Hades. Orpheus...
{"inputs": ["7\nbabba\nabaac\ncodeforces\nzeroorez\nabcdcba\nbbbbbbb\na\n", "7\nabbab\nabaac\ncodeforces\nzeroorez\nabcdcba\nbbbbbbb\na\n", "7\nabbab\nabaac\ncodeforces\nzeroorez\nabadcbc\nbbbbbbb\na\n", "7\nabbab\nabaac\ncodeforces\nzeroorez\nabadcbc\nbbbbabb\na\n", "7\nbbbaa\nabaac\ncodeforces\nyeroorez\nabadcbc\nbba...
619
351
coding
Solve the programming task below in a Python markdown code block. A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular (shortly, RBS) if it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this ...
{"inputs": ["2\n()\n", "2\n()\n", "2\n()\n", "4\n(())\n", "4\n(())\n", "4\n()()\n", "4\n(())\n", "8\n((()))()\n"], "outputs": ["00\n", "00\n", "00\n", "0110\n", "0110\n", "0000", "0110\n", "01001000\n"]}
692
116
coding
Solve the programming task below in a Python markdown code block. Polycarp has $x$ of red and $y$ of blue candies. Using them, he wants to make gift sets. Each gift set contains either $a$ red candies and $b$ blue candies, or $a$ blue candies and $b$ red candies. Any candy can belong to at most one gift set. Help Poly...
{"inputs": ["9\n8 9 2 8\n0 0 2 2\n38 204 6 13\n1010010010 0000000000 6 2\n1000000000 2 1 0100001000\n1 1000100110 1000011100 1\n1 0 1 1\n6 8 2 2\n4 1 2 5\n", "9\n10 8 2 5\n1 1 2 2\n52 311 22 9\n1000000000 1000000000 1 1\n1000000000 1 1 1000000000\n1 1000000000 1000000000 1\n1 1 1 1\n7 8 1 2\n4 1 2 3\n", "9\n10 8 2 5\n1...
492
1,303
coding
Solve the programming task below in a Python markdown code block. Valera is a lazy student. He has m clean bowls and k clean plates. Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. W...
{"inputs": ["1 1 1\n2\n", "1 2 1\n2\n", "1 1 2\n2\n", "1 2 2\n2\n", "1 0 1\n2\n", "1 0 0\n2\n", "1 1 0\n2\n", "1 4 1\n2\n"], "outputs": ["0", "0", "0", "0", "0\n", "1\n", "0\n", "0\n"]}
501
114
coding
Solve the programming task below in a Python markdown code block. You are given a three-digit positive integer N. Determine whether N is a palindromic number. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation. -----Constraints----- - 100≤N≤999 - N is an integer. ...
{"inputs": ["559", "676", "665", "179", "129", "371", "344", "158"], "outputs": ["No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
160
78
coding
Solve the programming task below in a Python markdown code block. Write function ```wordsToSentence``` which will create a string from a list of strings, separated by space. Example: ```["hello", "world"] -> "hello world"``` Also feel free to reuse/extend the following starter code: ```python def words_to_sentence(wo...
{"functional": "_inputs = [[['bacon', 'is', 'delicious']]]\n_outputs = [['bacon is delicious']]\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...
73
168
coding
Solve the programming task below in a Python markdown code block. The [half-life](https://en.wikipedia.org/wiki/Half-life) of a radioactive substance is the time it takes (on average) for one-half of its atoms to undergo radioactive decay. # Task Overview Given the initial quantity of a radioactive substance, the quan...
{"functional": "_inputs = [[10, 5, 1], [8, 4, 2], [12, 3, 2]]\n_outputs = [[1], [2], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): ret...
264
187
coding
Solve the programming task below in a Python markdown code block. Calculate the number of ways to color an N * M grid using K colors. Adjacent squares in the grid should have different colors. Squares are considered adjacent if they share an edge. Input Format The first line contains an integer T denoting the number...
{"inputs": ["3\n3 3 2\n3 4 3\n1 1 1\n"], "outputs": ["2\n1122\n1\n"]}
231
39
coding
Solve the programming task below in a Python markdown code block. Permutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as p_{i}. We'll call number n the size or the length of permuta...
{"inputs": ["3\n", "5\n", "1\n", "2\n", "4\n", "6\n", "7\n", "8\n"], "outputs": ["18\n", "1800\n", "1\n", "0\n", "0\n", "0\n", "670320\n", "0\n"]}
455
79
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Sereja have an array that consist of n integers a[1], a[2], ..., a[n]. Now Sereja want to delete some(possible none, but not all) elements from the array, such that arithmetical mean of all rema...
{"inputs": ["2\n1\n1\n4\n1 2 1 2"], "outputs": ["1\n3"]}
291
28
coding
Solve the programming task below in a Python markdown code block. The chef likes to play with numbers. He takes some integer number x, writes it down on his iPad, and then performs with it n−1 operations of the two kinds: - divide the number x by 3 (x must be divisible by 3); - multiply the number x by 2. After each it...
{"inputs": ["6\n4 8 6 3 12 9"], "outputs": ["9 3 6 12 4 8"]}
447
36
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums of size n. Consider a non-empty subarray from nums that has the maximum possible bitwise AND. In other words, let k be the maximum value of the bitwise AND of any subarray of nums....
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,3,2,2]) == 2\n assert candidate(nums = [1,2,3,4]) == 1\n\n\ncheck(Solution().longestSubarray)"}
153
61
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer n representing the number of nodes in an undirected graph. The nodes are labeled from 1 to n. You are also given a 2D integer array edges, where edges[i] = [ai, bi] indicates that ther...
{"functional": "def check(candidate):\n assert candidate(n = 6, edges = [[1,2],[1,4],[1,5],[2,6],[2,3],[4,6]]) == 4\n assert candidate(n = 3, edges = [[1,2],[2,3],[3,1]]) == -1\n\n\ncheck(Solution().magnificentSets)"}
241
87
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integers, n and k. An array of distinct positive integers is called a k-avoiding array if there does not exist any pair of distinct elements that sum to k. Return the minimum possible sum of a k-avoi...
{"functional": "def check(candidate):\n assert candidate(n = 5, k = 4) == 18\n assert candidate(n = 2, k = 6) == 3\n\n\ncheck(Solution().minimumSum)"}
107
54
coding
Solve the programming task below in a Python markdown code block. You are given an integer N. You have to find a [permutation] P of the integers \{1, 2, \ldots, N\} that satisfies M conditions of the following form: (X_{i}, Y_{i}), denoting that the element X_{i}\;(1≤ X_{i} ≤ N) must appear in the prefix of length Y_{i...
{"inputs": ["4\n3 2\n2 1\n1 2\n4 3\n1 2\n4 1\n3 2\n4 1\n2 3\n5 2\n5 4\n3 2\n"], "outputs": ["2 1 3\n-1\n1 2 3 4\n1 3 2 5 4\n"]}
751
87
coding
Solve the programming task below in a Python markdown code block. Problem Given the string S, which consists of lowercase letters and numbers. Follow the steps below to compress the length of string S. 1. Change the order of the characters in the character string to any order. Example: "0ig3he12fz99"-> "efghiz012399"...
{"inputs": ["2", "90", "111", "011", "010", "001", "101", "000"], "outputs": ["1\n", "2\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n"]}
337
75
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of positive integers nums, return the maximum possible sum of an ascending subarray in nums. A subarray is defined as a contiguous sequence of numbers in an array. A subarray [numsl, numsl+1, ..., numsr...
{"functional": "def check(candidate):\n assert candidate(nums = [10,20,30,5,10,50]) == 65\n assert candidate(nums = [10,20,30,40,50]) == 150\n assert candidate(nums = [12,17,15,13,10,11,12]) == 33\n assert candidate(nums = [100,10,1]) == 100\n\n\ncheck(Solution().maxAscendingSum)"}
140
128
coding
Solve the programming task below in a Python markdown code block. You are given a string s consisting of `A`, `B` and `C`. Snuke wants to perform the following operation on s as many times as possible: * Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`. Find the maximum possible number...
{"inputs": ["B", "D", "E", "F", "A", "G", "H", "I"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
173
62
coding
Solve the programming task below in a Python markdown code block. Santa has to send presents to the kids. He has a large stack of $n$ presents, numbered from $1$ to $n$; the topmost present has number $a_1$, the next present is $a_2$, and so on; the bottom present has number $a_n$. All numbers are distinct. Santa has ...
{"inputs": ["2\n3 3\n3 1 2\n3 2 1\n7 2\n2 1 7 3 4 5 6\n3 1\n", "2\n3 3\n3 1 2\n3 2 1\n7 2\n4 1 7 3 4 5 6\n3 1\n", "2\n3 3\n3 1 2\n3 2 1\n7 2\n2 1 7 3 4 5 6\n6 1\n", "2\n3 3\n3 1 2\n3 2 1\n7 2\n2 1 7 3 4 5 6\n4 1\n", "2\n3 3\n3 1 2\n3 2 1\n7 2\n2 1 7 3 5 7 6\n2 1\n", "2\n3 3\n3 1 2\n3 2 1\n7 2\n2 1 7 3 5 5 6\n1 2\n", "2...
611
393
coding
Solve the programming task below in a Python markdown code block. Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible. String s consists only of lowercase Latin letters, and it is allowed to change characters on...
{"inputs": ["a\n1\n", "z\n2\n", "a\n3\n", "a\n1\n", "z\n2\n", "a\n3\n", "y\n2\n", "b\n3\n"], "outputs": ["0\n", "impossible\n", "impossible\n", "0\n", "impossible\n", "impossible\n", "impossible\n", "impossible\n"]}
298
92
coding
Solve the programming task below in a Python markdown code block. Serval is fighting with a monster. The health of the monster is H. In one attack, Serval can decrease the monster's health by A. There is no other way to decrease the monster's health. Serval wins when the monster's health becomes 0 or below. Find the nu...
{"inputs": ["4 3", "1 1\n", "14 4", "14 3", "11 2", "14 5", "26 4", "20 2"], "outputs": ["2\n", "1\n", "4\n", "5\n", "6\n", "3\n", "7\n", "10\n"]}
228
86
coding
Solve the programming task below in a Python markdown code block. Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation a +...
{"inputs": ["5\n4\n", "1\n1\n", "6\n4\n", "1\n6\n", "5\n1\n", "6\n3\n", "5\n2\n", "1\n10\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n"]}
339
87
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. The staff of one of the most famous ChefLand's restaurants have just received the news! A delegation from the neighbouring country is going to visit the restaurant. The staff want to make this v...
{"inputs": ["aba\n4"], "outputs": ["21"]}
540
15
coding
Solve the programming task below in a Python markdown code block. The USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of $n$ haybale piles on the farm. The $i$-th pile contains $a_i$ haybales. However, Farmer John has just left for vacation, leaving Bessie all on her own. Every day, B...
{"inputs": ["3\n4 5\n1 0 3 2\n2 2\n100 1\n1 8\n0\n", "3\n4 5\n1 0 1 2\n2 2\n100 1\n1 8\n0\n", "3\n4 5\n1 0 1 2\n2 2\n100 2\n1 8\n0\n", "3\n4 5\n0 0 1 2\n2 2\n100 2\n1 7\n0\n", "3\n4 5\n0 0 1 2\n2 2\n000 2\n1 7\n0\n", "3\n4 5\n1 0 3 2\n2 2\n100 0\n1 8\n0\n", "3\n4 5\n2 0 1 2\n2 2\n100 2\n1 8\n0\n", "3\n4 1\n1 0 1 2\n2 2...
670
340
coding
Solve the programming task below in a Python markdown code block. You are at your grandparents' house and you are playing an old video game on a strange console. Your controller has only two buttons and each button has a number written on it. Initially, your score is $0$. The game is composed of $n$ rounds. For each $...
{"inputs": ["6\n+-++--\n2\n9 7\n1 1\n", "1\n-\n1\n427470105 744658699\n", "8\n+-+---+-\n5\n2 1\n10 3\n7 9\n10 10\n5 3\n", "20\n+-----+--+--------+-\n2\n1000000000 99999997\n250000000 1000000000\n"], "outputs": ["YES\nYES\n", "NO\n", "YES\nNO\nNO\nNO\nYES\n", "NO\nYES\n"]}
706
172
coding
Solve the programming task below in a Python markdown code block. In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of $n$ students doing yet another trick. Let's assume that all these students are numbered from $1$ to $n$. ...
{"inputs": ["1\n1\n", "1\n1\n", "2\n2 1\n", "2\n2 1\n", "3\n2 3 2\n", "3\n1 2 3\n", "3\n2 3 1\n", "3\n2 3 1\n"], "outputs": ["1 \n", "1\n", "1 2 \n", "1 2\n", "2 2 3 \n", "1 2 3 \n", "1 2 3 \n", "1 2 3\n"]}
603
131
coding
Solve the programming task below in a Python markdown code block. There are 3N participants in AtCoder Group Contest. The strength of the i-th participant is represented by an integer a_i. They will form N teams, each consisting of three participants. No participant may belong to multiple teams. The strength of a team...
{"inputs": ["2\n2 2 8 5 1 5", "2\n0 4 8 5 1 5", "2\n0 7 8 5 1 5", "2\n0 7 8 9 1 5", "2\n1 4 8 9 1 2", "2\n1 4 8 4 1 2", "2\n5 2 8 5 1 5", "2\n0 4 10 4 1 0"], "outputs": ["7\n", "9\n", "12\n", "13\n", "10\n", "6\n", "10", "5\n"]}
570
162
coding
Solve the programming task below in a Python markdown code block. General primality test are often computationally expensive, so in the biggest prime number race the idea is to study special sub-families of prime number and develop more effective tests for them. [Mersenne Primes](https://en.wikipedia.org/wiki/Mersenn...
{"functional": "_inputs = [[2], [3], [4], [5], [7], [10], [33], [101], [11213], [11215]]\n_outputs = [[True], [True], [False], [True], [True], [False], [False], [False], [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, ...
657
223
coding
Solve the programming task below in a Python markdown code block. Things are heated up between the Finance team and the Marketing team, and they decide to have one-on-one fifa matches to settle it once and for all. Jha, being an intern, won’t play (it’s a battle of legends, after all) and has been given one job: to fi...
{"inputs": ["4\n1 10 7 4\n15 3 8 7"], "outputs": ["250"]}
373
32
coding
Solve the programming task below in a Python markdown code block. Given an `array` of digital numbers, return a new array of length `number` containing the last even numbers from the original array (in the same order). The original array will be not empty and will contain at least "number" even numbers. For example: `...
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8, 9], 3], [[-22, 5, 3, 11, 26, -6, -7, -8, -9, -8, 26], 2], [[6, -25, 3, 7, 5, 5, 7, -3, 23], 1]]\n_outputs = [[[4, 6, 8]], [[-8, 26]], [[6]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose...
217
272
coding
Solve the programming task below in a Python markdown code block. There are $n$ seats in the train's car and there is exactly one passenger occupying every seat. The seats are numbered from $1$ to $n$ from left to right. The trip is long, so each passenger will become hungry at some moment of time and will go to take b...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "1 0\n1\n", "1 0\n0\n", "1 2\n1\n", "5 314\n0 310 942 628 0\n", "5 314\n0 310 942 628 1\n", "5 314\n1 310 942 628 1\n"], "outputs": ["2 \n", "2 ", "1\n", "0\n", "3\n", "314 628 1256 942 1570 \n", "314 628 1256 942 1570\n", "315 629 1257 943 1571\n"]}
700
211
coding
Solve the programming task below in a Python markdown code block. Julius Caesar protected his confidential information by encrypting it using a cipher. Caesar's cipher shifts each letter by a number of letters. If the shift takes you past the end of the alphabet, just rotate back to the front of the alphabet. In the ...
{"inputs": ["11\nmiddle-Outz\n2\n"], "outputs": ["okffng-Qwvb\n"]}
464
26
coding
Solve the programming task below in a Python markdown code block. A policeman wants to catch a thief. Both the policeman and the thief can only move on a line on integer coordinates between $0$ and $N$ (inclusive). Initially, the policeman is at a coordinate $x$ and the thief is at a coordinate $y$. During each second,...
{"inputs": ["5\n0 1 1 1\n1 4 1 5\n4 2 1 7\n3 7 2 10\n8 2 3 15"], "outputs": ["No\nNo\nYes\nYes\nYes"]}
488
62
coding
Solve the programming task below in a Python markdown code block. Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is #, and a "road" square if S_{ij} is .. From a road squa...
{"inputs": ["1 2\n..\n", "3 3\n...\n../\n...", "3 3\n...\n...\n...", "3 3\n...\n...\n...\n", "0 5\n...#.\n.#.#.\n.#...", "0 5\n.#...\n.#.#.\n.#...", "0 5\n.#...\n.#.#.\n.$...", "0 5\n.#..-\n.#.#.\n.$..."], "outputs": ["1\n", "4\n", "4", "4\n", "0\n", "0\n", "0\n", "0\n"]}
341
137
coding
Solve the programming task below in a Python markdown code block. The number ```89``` is the first integer with more than one digit that fulfills the property partially introduced in the title of this kata. What's the use of saying "Eureka"? Because this sum gives the same number. In effect: ```89 = 8^1 + 9^2``` Th...
{"functional": "_inputs = [[1, 100], [10, 89], [10, 100], [90, 100], [90, 150], [50, 150], [10, 150], [89, 135]]\n_outputs = [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 89]], [[89]], [[89]], [[]], [[135]], [[89, 135]], [[89, 135]], [[89, 135]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b,...
339
293
coding
Solve the programming task below in a Python markdown code block. A (1-indexed) string S of length N is said to be anti-palindrome if, for each 1 ≤ i ≤ N, S_{i} \ne S_{(N + 1 - i)}. You are given a string S of length N (consisting of lowercase Latin letters only). Rearrange the string to convert it into an anti-palind...
{"inputs": ["4\n3\nabc\n8\nabccccdd\n4\nxyyx\n6\nppppqr\n"], "outputs": ["NO\nYES\nabddcccc\nYES\nxxyy\nNO\n"]}
562
49
coding
Solve the programming task below in a Python markdown code block. Let's call the following process a transformation of a sequence of length $n$. If the sequence is empty, the process ends. Otherwise, append the greatest common divisor (GCD) of all the elements of the sequence to the result and remove one arbitrary ele...
{"inputs": ["3\n", "2\n", "1\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["1 1 3 ", "1 2 ", "1 ", "1 1 2 4 ", "1 1 1 2 4 ", "1 1 1 2 2 6 ", "1 1 1 1 2 2 6 ", "1 1 1 1 2 2 4 8 "]}
378
119
coding
Solve the programming task below in a Python markdown code block. Quick sort is based on the Divide-and-conquer approach. In QuickSort(A, p, r), first, a procedure Partition(A, p, r) divides an array A[p..r] into two subarrays A[p..q-1] and A[q+1..r] such that each element of A[p..q-1] is less than or equal to A[q], wh...
{"inputs": ["12\n13 19 9 5 12 8 7 4 13 0 6 3", "12\n13 19 9 5 12 8 7 4 21 0 2 18", "12\n13 19 9 5 12 8 7 4 13 0 6 18", "12\n8 19 9 5 12 8 7 4 21 4 10 18", "12\n13 19 9 5 12 8 7 4 40 0 10 1", "12\n40 19 9 1 12 8 8 6 21 0 10 1", "12\n40 19 6 1 12 8 0 2 21 2 4 22", "12\n13 19 9 5 12 8 7 4 21 2 6 11"], "outputs": ["0 [3] 9...
486
523
coding
Solve the programming task below in a Python markdown code block. There are n cities numbered from 1 to n in Berland. Some of them are connected by two-way roads. Each road has its own length — an integer number from 1 to 1000. It is known that from each city it is possible to get to any other city by existing roads. A...
{"inputs": ["2\n0 5\n5 0\n1\n1 2 5\n", "2\n0 5\n5 0\n1\n1 2 3\n", "3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1\n", "3\n0 983 173\n983 0 810\n173 810 0\n3\n3 2 567\n2 3 767\n1 2 763\n", "3\n0 983 173\n983 0 810\n173 810 0\n3\n2 2 567\n2 3 767\n1 2 763\n", "3\n0 983 173\n983 0 810\n173 810 0\n3\n2 3 567\n2 3 767\n1 2 763\n",...
589
477
coding
Solve the programming task below in a Python markdown code block. Alex decided to go on a touristic trip over the country. For simplicity let's assume that the country has $n$ cities and $m$ bidirectional roads connecting them. Alex lives in city $s$ and initially located in it. To compare different cities Alex assign...
{"inputs": ["1 0\n1000000000\n1\n", "1 0\n1000000000\n1\n", "1 0\n1000000000\n1\n", "1 0\n1000010000\n1\n", "2 1\n999999999 2\n1 2\n2\n", "2 1\n999999999 2\n1 2\n2\n", "2 1\n999999999 2\n1 2\n2\n", "2 1\n999999999 4\n1 2\n2\n"], "outputs": ["1000000000\n", "1000000000\n", "1000000000\n", "1000010000\n", "1000000001\n",...
586
282
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integers memory1 and memory2 representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second. At ...
{"functional": "def check(candidate):\n assert candidate(memory1 = 2, memory2 = 2) == [3,1,0]\n assert candidate(memory1 = 8, memory2 = 11) == [6,0,4]\n\n\ncheck(Solution().memLeak)"}
204
69
coding
Solve the programming task below in a Python markdown code block. Taro Aizu's company has a boss who hates being indivisible. When Taro goes out to eat with his boss, he pays by splitting the bill, but when the payment amount is not divisible by the number of participants, his boss always pays for it. One day, Taro be...
{"inputs": ["4 15000\n305\n24\n129\n500\n3 349\n9\n20\n30\n3 5016\n5\n9\n12\n0 0", "4 15000\n305\n24\n129\n949\n3 568\n9\n20\n30\n3 5016\n5\n9\n12\n0 0", "4 1512\n305\n17\n129\n129\n3 709\n6\n20\n52\n3 200909\n8\n6\n9\n0 0", "4 1512\n305\n17\n129\n129\n3 709\n6\n20\n52\n3 319036\n8\n6\n9\n0 0", "4 7955\n305\n24\n129\n1...
516
587
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s of '(' , ')' and lowercase English characters. Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return an...
{"functional": "def check(candidate):\n assert candidate(s = \"lee(t(c)o)de)\") == \"lee(t(c)o)de\"\n assert candidate(s = \"a)b(c)d\") == \"ab(c)d\"\n assert candidate(s = \"))((\") == \"\"\n\n\ncheck(Solution().minRemoveToMakeValid)"}
159
77
coding
Solve the programming task below in a Python markdown code block. You are given strings $S$ and $T$, consisting of lowercase English letters. It is guaranteed that $T$ is a permutation of the string abc. Find string $S'$, the lexicographically smallest permutation of $S$ such that $T$ is not a subsequence of $S'$. St...
{"inputs": ["7\nabacaba\nabc\ncccba\nacb\ndbsic\nbac\nabracadabra\nabc\ndddddddddddd\ncba\nbbc\nabc\nac\nabc\n", "7\nabacaba\nabc\ncccba\nacb\ndbsic\nbac\nabracadabra\nabc\ndddddddddddd\ncba\nbbc\nabd\nac\nabc\n", "7\nabacaba\nabc\ncccba\nacb\nebsic\nbac\nabracadabra\nabc\ndddddddddddd\ncba\nbbc\nabc\nac\nabc\n", "7\na...
559
587
coding
Solve the programming task below in a Python markdown code block. Patrick likes to play baseball, but sometimes he will spend so many hours hitting home runs that his mind starts to get foggy! Patrick is sure that his scores across $n$ sessions follow the identity permutation (ie. in the first game he scores $1$ point,...
{"inputs": ["1\n2\n1 2\n", "1\n2\n1 2\n", "1\n4\n2 1 3 4\n", "1\n4\n2 1 3 4\n", "1\n3\n2 1 3 4\n", "1\n4\n2 1 2 4\n", "1\n3\n2 0 3 4\n", "1\n5\n1 3 4 2 5\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
647
144
coding
Solve the programming task below in a Python markdown code block. Takahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who is in charge of making the scoreboard, is struggling to write the program that manages the players' scores in a game, which proceeds as follows. A game is played by N players, n...
{"inputs": ["6 1 4\n3\n1\n3\n2", "6 3 4\n3\n1\n3\n4", "6 5 4\n3\n0\n3\n2", "8 1 4\n3\n1\n0\n2", "6 3 4\n6\n1\n3\n1", "8 1 1\n4\n1\n0\n2", "8 5 3\n3\n0\n4\n2", "9 1 0\n6\n1\n3\n4"], "outputs": ["No\nNo\nNo\nNo\nNo\nNo\n", "No\nNo\nYes\nNo\nNo\nNo\n", "Yes\nYes\nYes\nYes\nYes\nYes\n", "No\nNo\nNo\nNo\nNo\nNo\nNo\nNo\n", ...
565
256
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The set [1, 2, 3, ..., n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, we get the following sequence for n = 3: "123" "132" "213" "231" "312" "321" Given n an...
{"functional": "def check(candidate):\n assert candidate(n = 3, k = 3) == \"213\"\n assert candidate(n = 4, k = 9) == \"2314\"\n assert candidate(n = 3, k = 1) == \"123\"\n\n\ncheck(Solution().getPermutation)"}
140
81
coding
Solve the programming task below in a Python markdown code block. We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3, S(114514) = 6. You want to make a consecutive integer sequence starting from number m (m, m + 1, ...). But you need to pay S(...
{"inputs": ["9 1 1\n", "1 1 2\n", "3 1 4\n", "1 1 1\n", "3 1 4\n", "1 1 1\n", "3 1 5\n", "2 1 2\n"], "outputs": ["9\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n"]}
295
102
coding
Solve the programming task below in a Python markdown code block. itertools.combinations_with_replacement(iterable, r) This tool returns $\textbf{r}$ length subsequences of elements from the input iterable allowing individual elements to be repeated more than once. Combinations are emitted in lexicographic sorted or...
{"inputs": ["HACK 2\n"], "outputs": ["AA\nAC\nAH\nAK\nCC\nCH\nCK\nHH\nHK\nKK\n"]}
440
35
coding
Solve the programming task below in a Python markdown code block. Arthur defines a function, $f(k)$, to be the number of $(p,q)$ pairs such that: $1<p\leq q\leq k$ ${p}$ and $q}$ are coprime. $p\cdot q=k$ Given an integer, $n$, help Arthur find and print the result of: $\sum_{k=1}^{n}f(k)$ Input Format The first l...
{"inputs": ["12\n"], "outputs": ["3\n"]}
390
15
coding
Solve the programming task below in a Python markdown code block. Find the difference of two sets $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$, $A - B$. Constraints * $1 \leq n, m \leq 200,000$ * $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$ * $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$ ...
{"inputs": ["5\n1 2 3 5 8\n2\n4 5", "5\n1 2 3 5 8\n0\n4 5", "5\n0 2 3 5 8\n0\n0 5", "5\n0 2 3 5 8\n2\n4 5", "5\n0 2 3 5 7\n2\n4 9", "5\n0 2 3 5 6\n3\n4 9", "5\n1 2 4 5 8\n0\n0 2", "5\n1 2 4 6 8\n0\n2 5"], "outputs": ["1\n2\n3\n8\n", "1\n2\n3\n5\n8\n", "0\n2\n3\n5\n8\n", "0\n2\n3\n8\n", "0\n2\n3\n5\n7\n", "0\n2\n3\n5\n6...
280
250
coding
Solve the programming task below in a Python markdown code block. Chef is given a sequence of prime numbers $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. A subsequence of $A$ is good if it does not contain any two identical numbers; in particular, the empty sequence is good. Chef has to find th...
{"inputs": ["5 3\n2 2 3 3 5"], "outputs": ["18"]}
393
25
coding
Solve the programming task below in a Python markdown code block. n people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins k ...
{"inputs": ["2 2\n1 2\n", "2 2\n1 2\n", "3 2\n1 3 2\n", "3 3\n1 2 3\n", "3 3\n1 2 3\n", "3 2\n1 3 2\n", "3 2\n2 3 2\n", "3 2\n2 3 0\n"], "outputs": ["2 ", "2", "3 ", "3 ", "3", "3", "3\n", "3\n"]}
374
124
coding
Solve the programming task below in a Python markdown code block. A sum of p rubles is charged from Arkady's mobile phone account every day in the morning. Among the following m days, there are n days when Arkady will top up the account: in the day d_{i} he will deposit t_{i} rubles on his mobile phone account. Arkady ...
{"inputs": ["1 1 1\n1 1\n", "1 2 1\n1 1\n", "1 2 1\n1 3\n", "1 1 1\n1 1\n", "1 2 1\n1 1\n", "1 2 1\n1 3\n", "1 2 1\n1 0\n", "1 4 1\n1 3\n"], "outputs": ["0\n", "1\n", "0\n", " 0", " 1", " ...
723
137
coding
Solve the programming task below in a Python markdown code block. Takahashi is playing with N cards. The i-th card has an integer X_i on it. Takahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions: * The integers on the two cards are the same. * The sum of the inte...
{"inputs": ["7 5\n3 1 4 1 5 9 3", "7 5\n3 1 4 1 5 8 3", "7 8\n4 2 5 1 5 9 3", "7 5\n3 1 4 1 5 4 3", "7 1\n3 1 4 1 5 4 3", "7 1\n4 1 4 1 5 4 3", "7 1\n6 1 4 1 5 4 3", "7 1\n6 0 4 1 5 4 3"], "outputs": ["3\n", "2\n", "1\n", "3\n", "3\n", "3\n", "3\n", "3\n"]}
261
190
coding
Solve the programming task below in a Python markdown code block. # Task Sorting is one of the most basic computational devices used in Computer Science. Given a sequence (length ≤ 1000) of 3 different key values (7, 8, 9), your task is to find the minimum number of exchange operations necessary to make the sequen...
{"functional": "_inputs = [[[7, 7, 8, 8, 9, 9]], [[9, 7, 8, 8, 9, 7]], [[8, 8, 7, 9, 9, 9, 8, 9, 7]], [[9, 9, 9, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7]], [[9, 9, 9, 7, 7, 8, 9, 7, 8, 9, 7, 9]], [[9, 9, 7, 7, 8, 8]], [[9, 7, 9]], [[8, 7, 8]], [[7, 8, 7, 8]], [[8, 8, 7, 8]], [[8, 8, 7, 7, 8]]]\n_outputs = [[0], [1], [4], [6...
480
401
coding
Solve the programming task below in a Python markdown code block. Boy Valera likes strings. And even more he likes them, when they are identical. That's why in his spare time Valera plays the following game. He takes any two strings, consisting of lower case Latin letters, and tries to make them identical. According to...
{"inputs": ["habege\necjecg\n0\n", "habege\ngcejce\n0\n", "habege\ngceice\n0\n", "habfge\ngceice\n0\n", "habfge\ngdeice\n0\n", "habfge\nedeicg\n0\n", "a\nb\n3\na b 2\na b 3\nb a 5\n", "uayd\nuxxd\n3\na x 8\nx y 13\nd c 2\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "2\nb\n", "21\nuxyd\n"]}
426
167
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return the largest integer that only occurs once. If no integer occurs once, return -1.   Please complete the following python code precisely: ```python class Solution: def largestUniq...
{"functional": "def check(candidate):\n assert candidate([5,7,3,9,4,9,8,3,1]) == 8\n assert candidate([9,9,8,8]) == -1\n\n\ncheck(Solution().largestUniqueNumber)"}
74
63
coding
Solve the programming task below in a Python markdown code block. Integral numbers can be even or odd. Even numbers satisfy `n = 2m` ( with `m` also integral ) and we will ( completely arbitrarily ) think of odd numbers as `n = 2m + 1`. Now, some odd numbers can be more odd than others: when for some `n`, `m` is mor...
{"functional": "_inputs = [[[1, 2]], [[1, 3]], [[1, 5]], [[]], [[0]], [[0, 1]], [[1, 3, 5, 7]], [[2, 4]], [[-1]], [[-1, -1]], [[-1, 0, 1]], [[-3, 3]], [[-5, 3]]]\n_outputs = [[1], [3], [None], [None], [0], [1], [7], [None], [-1], [None], [-1], [3], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(...
240
269
coding
Solve the programming task below in a Python markdown code block. Grandma Capa has decided to knit a scarf and asked Grandpa Sher to make a pattern for it, a pattern is a string consisting of lowercase English letters. Grandpa Sher wrote a string $s$ of length $n$. Grandma Capa wants to knit a beautiful scarf, and in ...
{"inputs": ["5\n8\nabcaacab\n6\nxyzxyz\n4\nabba\n8\nrprarlap\n10\nkhyyhhyhky\n", "5\n8\nabcaacab\n6\nxyzxyz\n4\nabba\n8\nrpqarlap\n10\nkhyyhhyhky\n", "5\n8\nabcaacab\n6\nxyzxyy\n4\nabba\n8\nrpqarlap\n10\nkhyyhhyhky\n", "5\n8\nabcaacab\n6\nxyzxyz\n4\nabab\n8\nrpqarlap\n10\nkhyyhhyhky\n", "5\n8\nabcaacab\n6\nxyzxyy\n4\na...
622
415
coding
Solve the programming task below in a Python markdown code block. Given an array of integers, find the sum of its elements. For example, if the array $ar=[1,2,3]$, $1+2+3=6$, so return $6$. Function Description Complete the simpleArraySum function in the editor below. It must return the sum of the array elements ...
{"inputs": ["6\n1 2 3 4 10 11\n"], "outputs": ["31\n"]}
231
29
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, find the subarray with the largest sum, and return its sum.   Please complete the following python code precisely: ```python class Solution: def maxSubArray(self, nums: List[int]) -> i...
{"functional": "def check(candidate):\n assert candidate(nums = [-2,1,-3,4,-1,2,1,-5,4]) == 6\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [5,4,-1,7,8]) == 23\n\n\ncheck(Solution().maxSubArray)"}
69
81
coding
Solve the programming task below in a Python markdown code block. The chef was busy in solving algebra, he found some interesting results, that there are many numbers which can be formed by the sum of the factorial of the digits, he wrote all those interesting numbers in the diary(in increasing order) and went to sleep...
{"inputs": ["2\n2\n10"], "outputs": ["1\n0"]}
302
19
coding
Solve the programming task below in a Python markdown code block. Given a set of numbers, return the additive inverse of each. Each positive becomes negatives, and the negatives become positives. ~~~if-not:racket ``` invert([1,2,3,4,5]) == [-1,-2,-3,-4,-5] invert([1,-2,3,-4,5]) == [-1,2,-3,4,-5] invert([]) == [] ``` ~...
{"functional": "_inputs = [[[1, 2, 3, 4, 5]], [[1, -2, 3, -4, 5]], [[]], [[0]]]\n_outputs = [[[-1, -2, -3, -4, -5]], [[-1, 2, -3, 4, -5]], [[]], [[0]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if i...
262
220
coding
Solve the programming task below in a Python markdown code block. Given are N positive integers A_1,...,A_N. Consider positive integers B_1, ..., B_N that satisfy the following condition. Condition: For any i, j such that 1 \leq i < j \leq N, A_i B_i = A_j B_j holds. Find the minimum possible value of B_1 + ... + B_N f...
{"inputs": ["1\n1\n", "1\n12\n", "3\n2 3 2", "3\n2 6 2", "3\n1 6 2", "3\n3 3 4", "3\n2 5 2", "3\n3 6 2"], "outputs": ["1\n", "1\n", "8\n", "7\n", "10\n", "11\n", "12\n", "6\n"]}
270
108
coding
Solve the programming task below in a Python markdown code block. Some numbers have funny properties. For example: > 89 --> 8¹ + 9² = 89 * 1 > 695 --> 6² + 9³ + 5⁴= 1390 = 695 * 2 > 46288 --> 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51 Given a positive integer n written as abcd... (a, b, c, d... being digits) and ...
{"functional": "_inputs = [[89, 1], [92, 1], [46288, 3], [114, 3], [46288, 5], [135, 1], [175, 1], [518, 1], [598, 1], [1306, 1], [2427, 1], [2646798, 1], [3456789, 1], [3456789, 5], [198, 1], [249, 1], [1377, 1], [1676, 1], [695, 2], [1878, 2], [7388, 2], [47016, 2], [542186, 2], [261, 3], [1385, 3], [2697, 3], [6376,...
470
548
coding
Solve the programming task below in a Python markdown code block. Find the intersection of two sets $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$. Constraints * $1 \leq n, m \leq 200,000$ * $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$ * $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$ Input ...
{"inputs": ["4\n1 3 5 8\n5\n1 3 5 9 7", "4\n1 2 5 8\n5\n2 3 5 9 7", "4\n1 2 5 8\n7\n0 3 5 9 9", "4\n1 2 0 8\n9\n1 3 5 9 6", "4\n1 2 5 8\n5\n4 3 5 9 11", "4\n1 2 5 8\n9\n2 3 5 9 11", "4\n1 2 9 8\n5\n4 3 5 9 11", "4\n1 2 5 8\n9\n1 3 5 9 11"], "outputs": ["1\n3\n5\n", "2\n5\n", "5\n", "1\n", "5\n", "2\n5\n", "9\n", "1\n5\...
278
236
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a circular integer array nums of length n, return the maximum possible sum of a non-empty subarray of nums. A circular array means the end of the array connects to the beginning of the array. Formally, the next ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,-2,3,-2]) == 3\n assert candidate(nums = [5,-3,5]) == 10\n assert candidate(nums = [3,-2,2,-3]) == 3\n\n\ncheck(Solution().maxSubarraySumCircular)"}
195
75
coding
Solve the programming task below in a Python markdown code block. Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following...
{"inputs": ["1\n2\n0\n", "1\n3\n0\n", "1\n6\n0\n", "1\n10\n0\n", "1\n13\n0\n", "2\n10 5\n0\n", "2\n11 5\n0\n", "2\n14 5\n0\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "-1\n", "-1\n", "-1\n"]}
463
113
coding
Solve the programming task below in a Python markdown code block. You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become d...
{"inputs": ["1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n5\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0", "0", "0", "0"]}
298
82
coding
Solve the programming task below in a Python markdown code block. You are given two strings A and B representing essays of two students who are suspected cheaters. For any two strings C, D we define their similarity score S(C,D) as 4⋅ LCS(C,D) - |C| - |D|, where LCS(C,D) denotes the length of the Longest Common Subsequ...
{"inputs": ["1 1\na\nb\n", "4 5\nabca\nbaaab\n", "4 5\nabca\nbabab\n", "4 5\nabca\naabab\n", "4 5\nabba\nbabab\n", "6 6\nooojjj\nooookj\n", "7 7\nuiibwws\nqhtkxcn\n", "6 9\nvvvkvv\nvgkkvvvgg\n"], "outputs": ["0\n", "4\n", "5\n", "5\n", "5\n", "7\n", "0\n", "6\n"]}
538
143
coding
Solve the programming task below in a Python markdown code block. You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied: * Let R, G and B be the sums of the integers painted red, green ...
{"inputs": ["4\n1\n1\n0\n2", "4\n1\n1\n0\n3", "4\n2\n1\n1\n2", "4\n2\n1\n2\n2", "4\n1\n1\n1\n2", "6\n1\n3\n0\n3\n5\n2", "6\n1\n3\n0\n3\n5\n0", "6\n1\n3\n0\n4\n1\n0"], "outputs": ["998244347\n", "0\n", "6\n", "18\n", "18", "138\n", "78\n", "162\n"]}
312
152
coding
Solve the programming task below in a Python markdown code block. problem Given the sequence $ A $ of length $ N $. Find the maximum value of $ \ sum B_i $, where $ B $ is one of the longest increasing subsequences of the sequence $ A $. The longest increasing subsequence of the sequence $ A $ is the longest subseque...
{"inputs": ["4\n7 4 7 8", "4\n7 4 1 8", "4\n7 4 2 9", "4\n7 4 2 6", "4\n6 4 3 8", "4\n7 5 7 8", "4\n6 4 3 3", "4\n6 1 3 3"], "outputs": ["19\n", "15\n", "16\n", "10\n", "14\n", "20\n", "6\n", "4\n"]}
150
132
coding
Solve the programming task below in a Python markdown code block. # Kata Task You are given a list of cogs in a gear train Each element represents the number of teeth of that cog e.g. `[100, 50, 25]` means * 1st cog has 100 teeth * 2nd cog has 50 teeth * 3rd cog has 25 teeth If the ``nth`` cog rotates clockwise a...
{"functional": "_inputs = [[[100], 0], [[100, 100, 100, 100], 0], [[100, 100, 100, 100], 1], [[100, 100, 100, 100], 2], [[100, 100, 100, 100], 3]]\n_outputs = [[[1, 1]], [[1, -1]], [[-1, 1]], [[1, -1]], [[-1, 1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
232
282
coding
Solve the programming task below in a Python markdown code block. Related to MrZizoScream's Product Array kata. You might want to solve that one first :) ```if:javascript **Note:** Node 10 has now been enabled, and you can now use its BigInt capabilities if you wish, though your resulting array must still contain stri...
{"functional": "_inputs = [[[1, 1, 1]], [[0, -99, 0]], [[9, 0, -2]], [[1, 2, 3, 4]], [[2, 3, 4, 5]], [[-8, 1, 5, 13, -1]], [[3, 14, 9, 11, 11]], [[4, 7, 3, 6, 2, 11, 14, 4, 7, 5]]]\n_outputs = [[[1, 1, 1]], [[0, 0, 0]], [[0, -18, 0]], [[24, 12, 8, 6]], [[60, 40, 30, 24]], [[-65, 520, 104, 40, -520]], [[15246, 3267, 508...
298
473
coding
Solve the programming task below in a Python markdown code block. You are given a function $f(X)=X^2$. You are also given $\mbox{K}$ lists. The $i^{\mbox{th}}$ list consists of $N_i$ elements. You have to pick one element from each list so that the value from the equation below is maximized: $S=(f(X_1)~+f(X_2)+~.......
{"inputs": ["3 1000\n2 5 4\n3 7 8 9 \n5 5 7 8 9 10 \n"], "outputs": ["206\n"]}
512
50
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order. ...
{"functional": "def check(candidate):\n assert candidate(candidates = [2,3,6,7], target = 7) == [[2,2,3],[7]]\n\n\ncheck(Solution().combinationSum)"}
155
51
coding
Solve the programming task below in a Python markdown code block. Write a function `titleToNumber(title) or title_to_number(title) or titleToNb title ...` (depending on the language) that given a column title as it appears in an Excel sheet, returns its corresponding column number. All column titles will be upperca...
{"functional": "_inputs = [['A'], ['Z'], ['AA'], ['AZ'], ['BA'], ['CODEWARS'], ['ZZZTOP'], ['OYAJI'], ['LONELINESS'], ['UNFORGIVABLE']]\n_outputs = [[1], [26], [27], [52], [53], [28779382963], [321268054], [7294985], [68400586976949], [79089429845931757]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a...
128
280
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A certain bug's home is on the x-axis at position x. Help them get there from position 0. The bug jumps according to the following rules: It can jump exactly a positions forward (to the right). It can jump exactly b ...
{"functional": "def check(candidate):\n assert candidate(forbidden = [14,4,18,1,15], a = 3, b = 15, x = 9) == 3\n assert candidate(forbidden = [8,3,16,6,12,20], a = 15, b = 13, x = 11) == -1\n assert candidate(forbidden = [1,6,2,14,5,17,4], a = 16, b = 9, x = 7) == 2\n\n\ncheck(Solution().minimumJumps)"}
221
147
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of strings strs, return the length of the longest uncommon subsequence between them. If the longest uncommon subsequence does not exist, return -1. An uncommon subsequence between an array of strings is...
{"functional": "def check(candidate):\n assert candidate(strs = [\"aba\",\"cdc\",\"eae\"]) == 3\n assert candidate(strs = [\"aaa\",\"aaa\",\"aa\"]) == -1\n\n\ncheck(Solution().findLUSlength)"}
191
60
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums of even length. As long as nums is not empty, you must repetitively: Find the minimum number in nums and remove it. Find the maximum number in nums and remove it. Calculat...
{"functional": "def check(candidate):\n assert candidate(nums = [4,1,4,0,3,5]) == 2\n assert candidate(nums = [1,100]) == 1\n\n\ncheck(Solution().distinctAverages)"}
183
58
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A swap is defined as taking two distinct positions in an array and swapping the values in them. A circular array is defined as an array where we consider the first element and the last element to be adjacent. Given a ...
{"functional": "def check(candidate):\n assert candidate(nums = [0,1,0,1,1,0,0]) == 1\n assert candidate(nums = [0,1,1,1,0,0,1,1,0]) == 2\n assert candidate(nums = [1,1,0,0,1]) == 0\n\n\ncheck(Solution().minSwaps)"}
119
92
coding
Solve the programming task below in a Python markdown code block. You have two arrays A and B of size N and M respectively. You have to merge both the arrays to form a new array C of size N + M (the relative order of elements in the original arrays A and B should not change in the array C). For e.g. if A = [{\color{bl...
{"inputs": ["2\n3 2\n6 4 5\n1 3\n2 3\n1 3\n2 2 4\n"], "outputs": ["4\n5\n"]}
715
44
coding
Solve the programming task below in a Python markdown code block. Since most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and their own games! Since you are so curious about Bitland, I'll gi...
{"inputs": ["1\n6\n", "1\n0\n", "1\n2\n", "1\n1\n", "1\n1\n", "1\n6\n", "1\n2\n", "1\n0\n"], "outputs": ["BitLGM\n", "BitAryo\n", "BitLGM\n", "BitLGM\n", "BitLGM\n", "BitLGM\n", "BitLGM\n", "BitAryo\n"]}
465
102
coding
Solve the programming task below in a Python markdown code block. Tired of the overpopulated world, Miu - The introverted cat visits a new continent in search for a new house. There are $N$ houses lying on the X-axis. Their positions are given by $X$$i$ , where $i$ refers to the $i$th house. ( $1 <= i <= N$ ) Each ...
{"inputs": ["2\n6\n7 -1 2 13 -5 15\n4\n6 10 3 12"], "outputs": ["5\n3"]}
460
42
coding
Solve the programming task below in a Python markdown code block. Write a function that takes a positive integer n, sums all the cubed values from 1 to n, and returns that sum. Assume that the input n will always be a positive integer. Examples: ```python sum_cubes(2) > 9 # sum of the cubes of 1 and 2 is 1 + 8 ``` ...
{"functional": "_inputs = [[1], [2], [3], [4], [10], [123]]\n_outputs = [[1], [9], [36], [100], [3025], [58155876]]\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 ...
110
201
coding
Solve the programming task below in a Python markdown code block. Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented...
{"inputs": ["a\nz\n", "b\ng\n", "a\ng\n", "a\nza\n", "ba\na\n", "a\naa\n", "a\nab\n", "`\nza\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
339
86
coding
Solve the programming task below in a Python markdown code block. ## Description Your job is to create a simple password validation function, as seen on many websites. The rules for a valid password are as follows: - There needs to be at least 1 uppercase letter. - There needs to be at least 1 lowercase letter. - The...
{"functional": "_inputs = [['Abcd1234'], ['Abcd123'], ['abcd1234'], ['AbcdefGhijKlmnopQRsTuvwxyZ1234567890'], ['ABCD1234'], ['Ab1!@#$%^&*()-_+={}[]|\\\\:;?/>.<,'], ['!@#$%^&*()-_+={}[]|\\\\:;?/>.<,'], [''], [' aA1----'], ['4aA1----']]\n_outputs = [[True], [False], [False], [True], [False], [True], [False], [False], [Tr...
168
293
coding
Solve the programming task below in a Python markdown code block. You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the c...
{"inputs": ["6\ncodeforces\naezakmi\nabacaba\nconvexhull\nswflldjgpaxs\nmyneeocktxpqjpz\n", "6\nsecrofedoc\naezakmi\nabacaba\nconvexhull\nswflldjgpaxs\nmyneeocktxpqjpz\n", "6\nsecrofedoc\naezakmi\nabacaba\nconvexhull\nswflldagpjxs\nmyneeocktxpqjpz\n", "6\ncodeforces\naezakmi\nabacabb\nconvexhull\nswflldjgpaxs\nmyneeock...
612
587
coding
Solve the programming task below in a Python markdown code block. A priority queue is a data structure which maintains a set $S$ of elements, each of with an associated value (key), and supports the following operations: * $insert(S, k)$: insert an element $k$ into the set $S$ * $extractMax(S)$: remove and return the ...
{"inputs": ["insert 8\ninsert 0\nextract\ninsert 4\nextract\ninsert 9\nextract\nextract\nend", "insert 8\ninsert 0\nextract\ninsert 5\nextract\ninsert 2\nextract\nextract\nend", "insert 8\ninsert 0\nextract\ninsert 7\nextract\ninsert 9\nextract\nextract\nend", "insert 8\ninsert 1\nextract\ninsert 5\nextract\ninsert 2\n...
303
302
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words. Note that the same word in the dictionary may be reused multipl...
{"functional": "def check(candidate):\n assert candidate(s = \"leetcode\", wordDict = [\"leet\",\"code\"]) == True\n assert candidate(s = \"applepenapple\", wordDict = [\"apple\",\"pen\"]) == True\n assert candidate(s = \"catsandog\", wordDict = [\"cats\",\"dog\",\"sand\",\"and\",\"cat\"]) == False\n\n\ncheck(...
101
92
coding
Solve the programming task below in a Python markdown code block. When provided with a String, capitalize all vowels For example: Input : "Hello World!" Output : "HEllO WOrld!" Note: Y is not a vowel in this kata. Also feel free to reuse/extend the following starter code: ```python def swap(st): ```
{"functional": "_inputs = [['HelloWorld!'], ['Sunday'], ['Codewars'], ['Monday'], ['Friday'], ['abracadabra']]\n_outputs = [['HEllOWOrld!'], ['SUndAy'], ['COdEwArs'], ['MOndAy'], ['FrIdAy'], ['AbrAcAdAbrA']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retur...
73
210
coding
Solve the programming task below in a Python markdown code block. Nuske has a grid with N rows and M columns of squares. The rows are numbered 1 through N from top to bottom, and the columns are numbered 1 through M from left to right. Each square in the grid is painted in either blue or white. If S_{i,j} is 1, the squ...
{"inputs": ["3 4 4\n1101\n0110\n1101\n1 1 3 4\n1 1 3 1\n2 2 3 4\n1 2 3 4", "3 4 4\n1101\n0110\n1101\n1 1 3 4\n2 1 3 1\n2 2 3 4\n1 2 2 4", "3 4 4\n1101\n0110\n1101\n1 1 3 4\n1 1 3 1\n2 2 3 4\n2 2 3 4", "3 4 4\n1101\n0110\n1101\n2 1 3 4\n2 1 3 1\n2 2 3 4\n1 2 2 4", "3 4 4\n1101\n1110\n1101\n1 1 3 4\n1 1 3 1\n2 2 3 4\n2 2...
676
519
coding
Solve the programming task below in a Python markdown code block. How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? - 0 \leq A_i \leq 9 - There exists some i such that A_i=0 holds. - There exists some i such that A_i=9 holds. The answer can be very large, so output it...
{"inputs": ["0", "3", "5", "7", "4", "6", "9", "8"], "outputs": ["0\n", "54\n", "14670\n", "2531214\n", "974\n", "199262\n", "359376750\n", "30683774\n"]}
188
95
coding
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"]}
262
24
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have two fruit baskets containing n fruits each. You are given two 0-indexed integer arrays basket1 and basket2 representing the cost of fruit in each basket. You want to make both baskets equal. To do so, you can...
{"functional": "def check(candidate):\n assert candidate(basket1 = [4,2,2,2], basket2 = [1,4,1,2]) == 1\n assert candidate(basket1 = [2,3,4,1], basket2 = [3,2,5,1]) == -1\n\n\ncheck(Solution().minCost)"}
194
83