problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Solve the programming task below in a Python markdown code block. "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (Diamond i...
{"inputs": ["W\n", "Q\n", "A\n", "W\n", "Q\n", "A\n", "V\n", "R\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
290
Solve the programming task below in a Python markdown code block. Today at the lesson Vitya learned a very interesting function — mex. Mex of a sequence of numbers is the minimum non-negative number that is not present in the sequence as element. For example, mex([4, 33, 0, 1, 1, 5]) = 2 and mex([1, 2, 3]) = 0. Vitya ...
{"inputs": ["2 2\n1 6\n1\n3\n", "2 2\n2 5\n1\n1\n", "2 2\n1 3\n2\n3\n", "2 2\n1 6\n1\n0\n", "2 2\n1 6\n1\n1\n", "2 2\n1 3\n1\n1\n", "2 2\n1 5\n1\n1\n", "2 2\n2 5\n2\n1\n"], "outputs": ["1\n0\n", "0\n0\n", "0\n1\n", "1\n1\n", "1\n0\n", "1\n0\n", "1\n0\n", "1\n0\n"]}
coding
364
Solve the programming task below in a Python markdown code block. Implement a function called makeAcronym that returns the first letters of each word in a passed in string. Make sure the letters returned are uppercase. If the value passed in is not a string return 'Not a string'. If the value passed in is a string w...
{"functional": "_inputs = [['My aunt sally'], ['Please excuse my dear aunt Sally'], ['How much wood would a woodchuck chuck if a woodchuck could chuck wood'], ['Unique New York'], ['a42'], ['1111'], [64], [[]], [{}], ['']]\n_outputs = [['MAS'], ['PEMDAS'], ['HMWWAWCIAWCCW'], ['UNY'], ['Not letters'], ['Not letters'], [...
coding
178
Solve the programming task below in a Python markdown code block. There are N children, numbered 1, 2, ..., N. Snuke has decided to distribute x sweets among them. He needs to give out all the x sweets, but some of the children may get zero sweets. For each i (1 \leq i \leq N), Child i will be happy if he/she gets ex...
{"inputs": ["2 1\n30 1", "2 0\n30 20", "2 1\n30 20", "2 1\n30 26", "2 0\n30 26", "2 10\n20 2", "2 0\n30 17", "2 0\n20 26"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "1\n", "0\n", "0\n"]}
coding
296
Solve the programming task below in a Python markdown code block. We have a grid with H rows and W columns. At first, all cells were painted white. Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column. Compute the following: - For each integer j (...
{"inputs": ["1000000000 1000000001 0", "1000000000 1000001000 0", "1000000000 1001001000 0", "1000000000 1001001010 0", "1000100000 1001001010 0", "1000000000 1000000000 0", "1000000000 1000000000 0\n", "4 5 8\n1 1\n1 4\n0 5\n2 3\n3 1\n3 2\n3 4\n4 4"], "outputs": ["999999997000000002\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "100...
coding
436
Solve the programming task below in a Python markdown code block. Given an array of arguments, representing system call arguments keys and values, join it into a single, space-delimited string. You don't need to care about the application name -- your task is only about parameters. Each element of the given array can ...
{"functional": "_inputs = [[['foo']], [['f']], [[['f']]], [[['foo', 'bar']]], [[['f', 'bar']]], [[['foo', 'bar'], ['baz', 'qux']]], [[['foo'], 'bar', ['baz', 'qux'], ['xyzzy', 'a'], 'a', ['a'], ['a', 'plugh']]], [[]], [[['---'], '---', ['---', '---'], ['-----', '-'], '-', ['-'], ['-', '-----']]]]\n_outputs = [['foo'], ...
coding
284
Solve the programming task below in a Python markdown code block. Chef has a number N, Cheffina challenges the chef to check the divisibility of all the permutation of N by 5. If any of the permutations is divisible by 5 then print 1 else print 0. -----Input:----- - First-line will contain $T$, the number of test case...
{"inputs": ["2\n19\n385"], "outputs": ["0\n1"]}
coding
176
Solve the programming task below in a Python markdown code block. In Programmers Army Land, people have started preparation as sports day is scheduled next week. You are given a task to form 1 team of $k$ consecutive players, from a list of sports player whose powers are given to you. You want your team to win this cha...
{"inputs": ["1\n5 3\n1 2 3 4 5"], "outputs": ["12"]}
coding
368
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n.   Please complete the following python code precisely: ```python class Solution: def smallestEvenMultiple(self, ...
{"functional": "def check(candidate):\n assert candidate(n = 5) == 10\n assert candidate(n = 6) == 6\n\n\ncheck(Solution().smallestEvenMultiple)"}
coding
70
Solve the programming task below in a Python markdown code block. Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers? Constraints * All values in input are integers. * 1 \leq K \leq N \leq 50 Input Input is given from S...
{"inputs": ["6 2", "2 1", "2 0", "0 0", "0 1", "6 1", "9 0", "6 0"], "outputs": ["5\n", "2\n", "3\n", "1\n", "0\n", "6\n", "10\n", "7\n"]}
coding
127
Solve the programming task below in a Python markdown code block. Given are two sequences a=\{a_0,\ldots,a_{N-1}\} and b=\{b_0,\ldots,b_{N-1}\} of N non-negative integers each. Snuke will choose an integer k such that 0 \leq k < N and an integer x not less than 0, to make a new sequence of length N, a'=\{a_0',\ldots,a_...
{"inputs": ["2\n1 2\n0 0\n", "3\n0 2 1\n2 0 3", "3\n0 2 1\n2 1 0", "3\n0 2 0\n1 3 3", "3\n1 0 1\n2 2 3", "3\n0 2 1\n0 1 3", "3\n0 0 1\n2 3 2", "3\n1 0 1\n2 3 2"], "outputs": ["", "0 2\n", "1 0\n", "1 3\n", "2 3\n", "2 1\n", "1 2\n", "0 3\n"]}
coding
528
Solve the programming task below in a Python markdown code block. Bob and Alice are having a lockout match between them. There are three problems in the contest worth A, B, and C points respectively. Only the first player to solve a problem gets points for that problem. It is impossible for Bob and Alice to solve a pro...
{"inputs": ["3\n2 5 2\n4 2 2\n3 5 5"], "outputs": ["NO\nYES\nNO"]}
coding
390
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef Anup is making dishes. Each dish consists of N ingredients, and quantity of each ingredient is an integer between 1 and K inclusive. Relative quality of 2 dishes is determined by their lex...
{"inputs": ["4\n3 3 1\n3 3 2\n3 3 3\n3 3 4", "4\n4 3 1\n4 3 2\n4 3 3\n4 3 4"], "outputs": ["1 1 1\n1 1 2\n1 1 3\n1 2 1", "1 1 1 1\n1 1 1 2\n1 1 1 3\n1 1 2 1"]}
coding
631
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 1-indexed m x n integer matrix mat, you can select any cell in the matrix as your starting cell. From the starting cell, you can move to any other cell in the same row or column, but only if the value of the d...
{"functional": "def check(candidate):\n assert candidate(mat = [[3,1],[3,4]]) == 2\n assert candidate(mat = [[1,1],[1,1]]) == 1\n assert candidate(mat = [[3,1,6],[-9,5,7]]) == 4\n\n\ncheck(Solution().maxIncreasingCells)"}
coding
179
Solve the programming task below in a Python markdown code block. Mash 2 arrays together so that the returning array has alternating elements of the 2 arrays . Both arrays will always be the same length. eg. [1,2,3] + ['a','b','c'] = [1, 'a', 2, 'b', 3, 'c'] Also feel free to reuse/extend the following starter code: ...
{"functional": "_inputs = [[[1, 2, 3], ['a', 'b', 'c']], [[1, 2, 3, 4, 5], ['a', 'b', 'c', 'd', 'e']], [[1, 1, 1, 1], [2, 2, 2, 2]], [[1, 8, 'hello', 'dog'], ['fish', '2', 9, 10]], [[None, 4], [None, 'hello']], [[1], [2]], [['h', 'l', 'o', 'o', 'l'], ['e', 'l', 'w', 'r', 'd']]]\n_outputs = [[[1, 'a', 2, 'b', 3, 'c']], ...
coding
103
Solve the programming task below in a Python markdown code block. Simon: On the fountain, there should be 2 jugs - a 5 gallon and a 3 gallon. Do you see them? Fill one of the jugs with exactly 4 gallons of water and place it on the scale and the timer will stop. You must be precise; one ounce more or less will result i...
{"inputs": ["2\n5 3 4\n3 6 4\n"], "outputs": ["YES\nNO\n"]}
coding
684
Solve the programming task below in a Python markdown code block. Snuke has decided to use a robot to clean his room. There are N pieces of trash on a number line. The i-th piece from the left is at position x_i. We would like to put all of them in a trash bin at position 0. For the positions of the pieces of trash, ...
{"inputs": ["2 100\n1 13", "2 100\n1 25", "2 101\n1 25", "2 101\n1 42", "2 101\n1 10", "2 100\n0 13", "2 001\n1 25", "2 101\n0 10"], "outputs": ["370\n", "430\n", "433\n", "518\n", "358\n", "365\n", "133\n", "353\n"]}
coding
656
Solve the programming task below in a Python markdown code block. Prefix function of string $t = t_1 t_2 \ldots t_n$ and position $i$ in it is defined as the length $k$ of the longest proper (not equal to the whole substring) prefix of substring $t_1 t_2 \ldots t_i$ which is also a suffix of the same substring. For ex...
{"inputs": ["3\nvkcup\nabababa\nzzzzzz\n"], "outputs": ["ckpuv\naababab\nzzzzzz\n"]}
coding
708
Solve the programming task below in a Python markdown code block. Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a n by m table. Denote c-th cell of r-th row as (r, c). The tai...
{"inputs": ["3 3\n", "3 4\n", "5 3\n", "9 9\n", "3 5\n", "3 6\n", "7 3\n", "7 4\n"], "outputs": ["###\n..#\n###\n", "####\n...#\n####\n", "###\n..#\n###\n#..\n###\n", "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n", "#####\n....#\n#####\n", "######\n.....#\n######\n...
coding
302
Solve the programming task below in a Python markdown code block. One way to create a task is to learn from life. You can choose some experience in real life, formalize it and then you will get a new task. Let's think about a scene in real life: there are lots of people waiting in front of the elevator, each person wa...
{"inputs": ["1 1\n2\n", "1 1\n2\n", "2 1\n2 2\n", "2 2\n2 2\n", "2 2\n2 2\n", "2 1\n2 2\n", "2 2\n3 2\n", "2 3\n6 2\n"], "outputs": ["2\n", "2\n", "4\n", "2\n", "2\n", "4\n", "4\n", "10\n"]}
coding
530
Solve the programming task below in a Python markdown code block. # Don't give me five! In this kata you get the start number and the end number of a region and should return the count of all numbers except numbers with a 5 in it. The start and the end number are both inclusive! Examples: ``` 1,9 -> 1,2,3,4,6,7,8,9 ...
{"functional": "_inputs = [[1, 9], [4, 17], [1, 90], [-4, 17], [-4, 37], [-14, -1], [-14, -6]]\n_outputs = [[8], [12], [72], [20], [38], [13], [9]]\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 isins...
coding
249
Solve the programming task below in a Python markdown code block. You are given an array $a$ consisting of $n$ non-negative integers. It is guaranteed that $a$ is sorted from small to large. For each operation, we generate a new array $b_i=a_{i+1}-a_{i}$ for $1 \le i < n$. Then we sort $b$ from small to large, replace...
{"inputs": ["1\n4\n1 145 10441 497785\n", "1\n4\n1 143 10297 497785\n", "5\n3\n1 10 100\n4\n4 8 9 13\n5\n0 0 0 8 13\n6\n2 4 8 16 32 64\n7\n0 0 0 0 0 0 0\n", "1\n104\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
coding
666
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. There is a haunted town called HauntedLand. The structure of HauntedLand can be thought of as a grid of size n * m. There is a house in each cell of the grid. Some people hav...
{"inputs": ["2\n2 2\n*.\n..\n3 4\n.*..\n***.\n.*..", "2\n2 2\n*.\n..\n3 4\n.*..\n***.\n.*.."], "outputs": ["1\n2", "1\n2"]}
coding
581
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a party where n friends numbered from 0 to n - 1 are attending. There is an infinite number of chairs in this party that are numbered from 0 to infinity. When a friend arrives at the party, they sit on the un...
{"functional": "def check(candidate):\n assert candidate(times = [[1,4],[2,3],[4,6]], targetFriend = 1) == 1\n assert candidate(times = [[3,10],[1,5],[2,6]], targetFriend = 0) == 2\n\n\ncheck(Solution().smallestChair)"}
coding
240
Solve the programming task below in a Python markdown code block. Yurii is sure he can do everything. Can he solve this task, though? He has an array $a$ consisting of $n$ positive integers. Let's call a subarray $a[l...r]$ good if the following conditions are simultaneously satisfied: $l+1 \leq r-1$, i. e. the suba...
{"inputs": ["8\n3 1 2 3 1 2 3 3\n", "8\n3 1 2 2 1 4 3 1\n", "8\n3 1 2 3 1 4 3 3\n", "8\n3 2 2 2 1 4 3 1\n", "8\n3 2 2 2 2 4 3 1\n", "8\n3 1 2 3 1 2 3 15\n", "8\n3 1 2 3 1 4 3 15\n", "8\n3 1 2 2 1 4 3 15\n"], "outputs": ["5\n", "2\n", "4\n", "1\n", "1\n", "6", "4\n", "2\n"]}
coding
629
Solve the programming task below in a Python markdown code block. In this kata you're expected to sort an array of 32-bit integers in ascending order of the number of **on** bits they have. E.g Given the array **[7, 6, 15, 8]** - 7 has **3 on** bits (000...0**111**) - 6 has **2 on** bits (000...00**11**) - 15 has *...
{"functional": "_inputs = [[[3, 8, 3, 6, 5, 7, 9, 1]], [[9, 4, 5, 3, 5, 7, 2, 56, 8, 2, 6, 8, 0]]]\n_outputs = [[[1, 8, 3, 3, 5, 6, 9, 7]], [[0, 2, 2, 4, 8, 8, 3, 5, 5, 6, 9, 7, 56]]]\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...
coding
321
Solve the programming task below in a Python markdown code block. Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry. He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1. Watson g...
{"inputs": ["3\n", "4\n", "1\n", "2\n", "1\n", "2\n", "1\n", "4\n"], "outputs": ["2\n1 1 2 \n", "2\n1 1 2 1 \n", "1\n1 \n", "1\n1 1 \n", "1\n1 \n", "1\n1 1 \n", "1\n1 ", "2\n1 1 2 1 "]}
coding
362
Solve the programming task below in a Python markdown code block. The capital of Berland looks like a rectangle of size n × m of the square blocks of same size. Fire! It is known that k + 1 blocks got caught on fire (k + 1 ≤ n·m). Those blocks are centers of ignition. Moreover positions of k of these centers are know...
{"inputs": ["8 5 1\n3 3\n", "10 5 1\n3 3\n", "10 5 1\n3 5\n", "10 5 1\n3 3\n", "5 1 2\n4 1\n5 1\n", "5 1 2\n4 1\n5 1\n", "5 1 2\n4 1\n1 1\n", "5 1 2\n4 1\n2 1\n"], "outputs": ["2\n", "2\n", "4\n", "2\n", "1\n", "1\n", "1\n", "1\n"]}
coding
445
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, encode the string such that its encoded length is the shortest. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. k shoul...
{"functional": "def check(candidate):\n assert candidate(s = \"aaa\") == \"aaa\"\n assert candidate(s = \"aaaaa\") == \"5[a]\"\n assert candidate(s = \"aaaaaaaaaa\") == \"10[a]\"\n assert candidate(s = \"aabcaabcd\") == \"2[aabc]d\"\n assert candidate(s = \"abbbabbbcabbbabbbc\") == \"2[2[abbb]c]\"\n\n\nc...
coding
123
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n tasks assigned to you. The task times are represented as an integer array tasks of length n, where the ith task takes tasks[i] hours to finish. A work session is when you work for at most sessionTime conse...
{"functional": "def check(candidate):\n assert candidate(tasks = [1,2,3], sessionTime = 3) == 2\n assert candidate(tasks = [3,1,3,1,1], sessionTime = 8) == 2\n assert candidate(tasks = [1,2,3,4,5], sessionTime = 15) == 1\n\n\ncheck(Solution().minSessions)"}
coding
209
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 (e.g.,"waterbottle" is a rotation of"erbottlewat"). Can you use only one call to the method that checks if one word is a substring of another...
{"functional": "def check(candidate):\n assert candidate(s1 = \"waterbottle\", s2 = \"erbottlewat\") == True\n assert candidate(s1 = \"aa\", s2 = \"aba\") == False\n\n\ncheck(Solution().isFlipedString)"}
coding
119
Solve the programming task below in a Python markdown code block. Hint In solving this problem, the following may be referred to. Shows how to convert an integer value to a string. Assign value as a string to str. For C include <stdio.h> int main () { int value = 123; // Convert this value to a string char str [6]...
{"inputs": ["1 10\n1 2 3 4 7 6 7 8 9 10", "5 7\n8 4 5 3 1 6 9 10 11 2", "5 7\n8 3 5 3 1 6 9 10 11 2", "5 7\n8 1 5 3 1 6 9 10 11 2", "6 7\n8 1 5 3 1 6 9 10 11 2", "6 7\n3 2 5 3 1 6 18 10 8 2", "3 4\n3 4 5 3 5 11 17 2 5 1", "3 6\n3 4 5 3 5 11 17 2 5 1"], "outputs": ["0\n", "34444\n", "14444\n", "11111\n", "111111\n", "14...
coding
609
Solve the programming task below in a Python markdown code block. Pankhuri hates Algebra. Doesn't matter how hard she tries, she always fails to get good marks in her assessments. One of her marked assessments has been recently returned. She noticed that this time, the professor has only given per question marks and fi...
{"inputs": ["3 \n3 \n8 - 1 - 25\n2\n38 + 20\n4\n40 - 8 - 1 + 25"], "outputs": ["32\n58\n58"]}
coding
616
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n cars traveling at different speeds in the same direction along a one-lane road. You are given an array cars of length n, where cars[i] = [positioni, speedi] represents: positioni is the distance between t...
{"functional": "def check(candidate):\n assert candidate(cars = [[1,2],[2,1],[4,3],[7,2]]) == [1.00000,-1.00000,3.00000,-1.00000]\n assert candidate(cars = [[3,4],[5,4],[6,3],[9,1]]) == [2.00000,1.00000,1.50000,-1.00000]\n\n\ncheck(Solution().getCollisionTimes)"}
coding
268
Solve the programming task below in a Python markdown code block. There are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S. Adjacent ...
{"inputs": ["1\nq\n", "5\naaaab", "5\naa`ab", "5\naa``b", "5\nba_`a", "5\nbaaaa", "5\naa_`b", "5\nca_`a"], "outputs": ["1\n", "2\n", "4\n", "3\n", "5\n", "2\n", "4\n", "5\n"]}
coding
213
Solve the programming task below in a Python markdown code block. Implement a function which behaves like the 'uniq -c' command in UNIX. It takes as input a sequence and returns a sequence in which all duplicate elements following each other have been reduced to one instance together with the number of times a duplic...
{"functional": "_inputs = [[['a', 'a', 'b', 'b', 'c', 'a', 'b', 'c']], [['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c']], [[None, 'a', 'a']], [['foo']], [['']], [[]]]\n_outputs = [[[['a', 2], ['b', 2], ['c', 1], ['a', 1], ['b', 1], ['c', 1]]], [[['a', 3], ['b', 3], ['c', 3]]], [[[None, 1], ['a', 2]]], [[['foo', 1]]], [[[...
coding
145
Solve the programming task below in a Python markdown code block. You have two strings A = A_1 A_2 ... A_n and B = B_1 B_2 ... B_n of the same length consisting of 0 and 1. You can transform A using the following operations in any order and as many times as you want: * Shift A by one character to the left (i.e., if A...
{"inputs": ["1\n1", "1\n0", "1010\n1110", "1010\n1111", "1010\n0000", "1010\n1010", "1010\n1011", "1010\n1001"], "outputs": ["0\n", "-1", "1\n", "2\n", "-1\n", "0\n", "1\n", "3\n"]}
coding
366
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Alexey is trying to develop a program for a very simple microcontroller. It makes readings from various sensors over time, and these readings must happen at specific regular ...
{"inputs": ["3\n3\n2 3 5\n4\n1 8 7 11\n4\n4 4 5 6"], "outputs": ["6\n7\n4"]}
coding
585
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 2D grid of size m x n and an integer k. You need to shift the grid k times. In one shift operation: Element at grid[i][j] moves to grid[i][j + 1]. Element at grid[i][n - 1] moves to grid[i + 1][0]. Element at...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,2,3],[4,5,6],[7,8,9]], k = 1) == [[9,1,2],[3,4,5],[6,7,8]]\n assert candidate(grid = [[3,8,1,9],[19,7,2,5],[4,6,11,10],[12,0,21,13]], k = 4) == [[12,0,21,13],[3,8,1,9],[19,7,2,5],[4,6,11,10]]\n assert candidate(grid = [[1,2,3],[4,5,6],[7,8,9]]...
coding
159
Solve the programming task below in a Python markdown code block. You are given a set of $n$ segments on the axis $Ox$, each segment has integer endpoints between $1$ and $m$ inclusive. Segments may intersect, overlap or even coincide with each other. Each segment is characterized by two integers $l_i$ and $r_i$ ($1 \l...
{"inputs": ["1 7\n1 7\n", "1 7\n5 5\n", "1 2\n1 1\n", "1 7\n5 5\n", "1 2\n1 1\n", "1 9\n5 5\n", "1 3\n1 1\n", "1 7\n1 7\n"], "outputs": ["0\n\n", "6\n1 2 3 4 6 7 \n", "1\n2 \n", "6\n1 2 3 4 6 7\n", "1\n2\n", "8\n1 2 3 4 6 7 8 9\n", "2\n2 3\n", "0\n\n"]}
coding
505
Please solve the programming task below using a self-contained code snippet in a markdown code block. A string is considered beautiful if it satisfies the following conditions: Each of the 5 English vowels ('a', 'e', 'i', 'o', 'u') must appear at least once in it. The letters must be sorted in alphabetical order (i.e...
{"functional": "def check(candidate):\n assert candidate(word = \"aeiaaioaaaaeiiiiouuuooaauuaeiu\") == 13\n assert candidate(word = \"aeeeiiiioooauuuaeiou\") == 5\n assert candidate(word = \"a\") == 0\n\n\ncheck(Solution().longestBeautifulSubstring)"}
coding
205
Solve the programming task below in a Python markdown code block. Chef and Chefina are best friends. Chefina wants to test the Problem Solving skills of chef so she provides Chef 2 integer number $X$ and $Y$ The task of chef is to take the two numbers $X$ and $Y$ and return their SUM. Identify whether Chef can solve ...
{"inputs": ["6 70"], "outputs": ["76"]}
coding
181
Solve the programming task below in a Python markdown code block. You are currently in the United States of America. The main currency here is known as the United States Dollar (USD). You are planning to travel to another country for vacation, so you make it today's goal to convert your USD (all bills, no cents) into t...
{"functional": "_inputs = [[7, 'Armenian Dram'], [322, 'Armenian Dram'], [25, 'Bangladeshi Taka'], [730, 'Bangladeshi Taka'], [37, 'Croatian Kuna'], [40, 'Croatian Kuna'], [197, 'Czech Koruna'], [333, 'Czech Koruna'], [768, 'Dominican Peso'], [983, 'Dominican Peso']]\n_outputs = [['You now have 3346 of Armenian Dram.']...
coding
531
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the number of combinations that make up that amount. If that amount...
{"functional": "def check(candidate):\n assert candidate(amount = 5, coins = [1, 2, 5]) == 4\n assert candidate(amount = 3, coins = [2]) == 0\n assert candidate(amount = 10, coins = [10] ) == 1\n\n\ncheck(Solution().change)"}
coding
136
Solve the programming task below in a Python markdown code block. ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but **exactly** 4 digits or exactly 6 digits. If the function is passed a valid PIN string, return `true`, else return `false`. ## Examples ``` "1234" --> true "12345"...
{"functional": "_inputs = [['1'], ['12'], ['123'], ['12345'], ['1234567'], ['-1234'], ['-12345'], ['1.234'], ['00000000'], ['a234'], ['.234'], ['1234'], ['0000'], ['1111'], ['123456'], ['098765'], ['000000'], ['090909']]\n_outputs = [[False], [False], [False], [False], [False], [False], [False], [False], [False], [Fals...
coding
126
Solve the programming task below in a Python markdown code block. In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After pr...
{"inputs": ["1 3 2 1 2 1\n", "0 0 0 0 0 0\n", "4 4 4 4 5 4\n", "2 2 2 2 2 1\n", "1 1 1 1 1 5\n", "8 1 1 3 3 0\n", "1 1 2 2 3 3\n", "1 2 2 5 2 5\n"], "outputs": ["YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n"]}
coding
340
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an integer array perm that is a permutation of the first n positive integers, where n is always odd. It was encoded into another integer array encoded of length n - 1, such that encoded[i] = perm[i] XOR perm[...
{"functional": "def check(candidate):\n assert candidate(encoded = [3,1]) == [1,2,3]\n assert candidate(encoded = [6,5,4,6]) == [2,4,1,5,3]\n\n\ncheck(Solution().decode)"}
coding
145
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Guddu likes a girl that loves playing with numbers. She agreed to go on a date with Guddu, but only if he can solve the following problem: An intege...
{"inputs": ["1\n2"], "outputs": ["28"]}
coding
383
Solve the programming task below in a Python markdown code block. You need to play around with the provided string (s). Move consonants forward 9 places through the alphabet. If they pass 'z', start again at 'a'. Move vowels back 5 places through the alphabet. If they pass 'a', start again at 'z'. For our Polish frie...
{"functional": "_inputs = [['testcase'], ['codewars'], ['exampletesthere'], ['returnofthespacecamel'], ['bringonthebootcamp'], ['weneedanofficedog']]\n_outputs = [['tabtbvba'], ['bnaafvab'], ['agvvyuatabtqaaa'], ['aatpawnftqabyvbabvvau'], ['kaiwpnwtqaknntbvvy'], ['fawaaavwnffibaanp']]\nimport math\ndef _deep_eq(a, b, t...
coding
195
Solve the programming task below in a Python markdown code block. A binary gap within a positive number ```num``` is any sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of ```num```. For example: ```9``` has binary representation ```1001``` and contains a bin...
{"functional": "_inputs = [[9]]\n_outputs = [[2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x...
coding
233
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given n item's value and label as two integer arrays values and labels. You are also given two integers numWanted and useLimit. Your task is to find a subset of items with the maximum sum of their values such ...
{"functional": "def check(candidate):\n assert candidate(values = [5,4,3,2,1], labels = [1,1,2,2,3], numWanted = 3, useLimit = 1) == 9\n assert candidate(values = [5,4,3,2,1], labels = [1,3,3,3,2], numWanted = 3, useLimit = 2) == 12\n assert candidate(values = [9,8,8,7,6], labels = [0,0,0,1,1], numWanted = 3, ...
coding
145
Solve the programming task below in a Python markdown code block. A Narcissistic Number is a number of length n in which the sum of its digits to the power of n is equal to the original number. If this seems confusing, refer to the example below. Ex: 153, where n = 3 (number of digits in 153) 1^(3) + 5^(3) + 3^(3) = 1...
{"functional": "_inputs = [[153], [370], [371], [407], [1634], [8208], [9474], [54748], [92727], [93084], [548834], [1741725], [4210818], [9800817], [9926315], [24678050], [88593477], [146511208], [472335975], [534494836], [912985153], [4679307774], [115132219018763992565095597973971522401]]\n_outputs = [[True], [True]...
coding
159
Solve the programming task below in a Python markdown code block. You must have tried to solve the Rubik’s cube. You might even have succeeded at it. Rubik’s cube is a 3x3x3 cube which has 6 different color for each face.The Rubik’s cube is made from 26 smaller pieces which are called cubies. There are 6 cubies at the ...
{"inputs": ["1\n3\n3\n3"], "outputs": ["12"]}
coding
403
Solve the programming task below in a Python markdown code block. You went to the store, selling $n$ types of chocolates. There are $a_i$ chocolates of type $i$ in stock. You have unlimited amount of cash (so you are not restricted by any prices) and want to buy as many chocolates as possible. However if you buy $x_i$...
{"inputs": ["2\n1 7\n", "2\n0 6\n", "2\n4 9\n", "2\n5 2\n", "2\n6 16\n", "2\n6 16\n", "2\n5 16\n", "2\n1 12\n"], "outputs": ["8\n", "6\n", "13\n", "3\n", "22", "22", "21\n", "13\n"]}
coding
482
Solve the programming task below in a Python markdown code block. Define n!! as n!! = 1 \* 3 \* 5 \* ... \* n if n is odd, n!! = 2 \* 4 \* 6 \* ... \* n if n is even. Hence 8!! = 2 \* 4 \* 6 \* 8 = 384, there is no zero at the end. 30!! has 3 zeros at the end. For a positive integer n, please count how many z...
{"functional": "_inputs = [[8], [30], [487], [500]]\n_outputs = [[0], [3], [0], [62]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return ...
coding
183
Solve the programming task below in a Python markdown code block. There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You ...
{"inputs": ["3\n2 5 -1", "3\n2 5 -2", "3\n3 5 -2", "3\n3 2 -2", "3\n0 2 -2", "3\n0 3 -2", "3\n0 3 -4", "3\n0 6 -5"], "outputs": ["12\n6\n10\n", "14\n8\n10\n", "14\n10\n10\n", "8\n10\n6\n", "8\n4\n4\n", "10\n4\n6\n", "14\n8\n6\n", "22\n10\n12\n"]}
coding
460
Solve the programming task below in a Python markdown code block. Currently, people's entertainment is limited to programming contests. The activity of the entertainment club of a junior high school to which she belongs is to plan and run a programming contest. Her job is not to create problems. It's a behind-the-scene...
{"inputs": ["1 1 1 1 1 1\n1 1 1 0 0 0\n1 0 0 0 1 0\n3 0 0 3 0 0\n3 1 0 1 3 1\n1 2 0 2 0 1\n0 0 1 1 0 3\n1 0 0 1 1 0\n0 0 0 0 0 0", "1 1 1 1 1 1\n1 1 1 0 0 0\n1 0 0 0 1 0\n3 0 0 0 0 0\n3 1 0 1 3 1\n1 2 0 2 0 1\n0 0 1 1 0 3\n1 0 0 1 1 0\n0 0 0 0 0 0", "1 1 1 1 1 1\n1 1 1 0 0 0\n1 0 0 0 1 1\n2 0 0 3 0 0\n3 1 0 1 3 1\n1 2 ...
coding
625
Solve the programming task below in a Python markdown code block. You need to write a function, that returns the first non-repeated character in the given string. For example for string `"test"` function should return `'e'`. For string `"teeter"` function should return `'r'`. If a string contains all unique cha...
{"functional": "_inputs = [['test'], ['teeter'], ['1122321235121222'], ['rend']]\n_outputs = [['e'], ['r'], ['5'], ['r']]\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...
coding
157
Solve the programming task below in a Python markdown code block. *After getting lost in Hollywood, ibti decided to give you yet another problem related to permutations.* Consider a permutation P of length 2\cdot N. An array A of size N is generated using the permutation P, such that the i^{th} element of the array ...
{"inputs": ["8 269696969"], "outputs": ["2 16 576 34560 3110400 142258231 78756849 13872609"]}
coding
663
Solve the programming task below in a Python markdown code block. Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water. The only dry land there is an archipelago of n narrow islands located in a row. For more comfort let'...
{"inputs": ["2 1\n1 2\n5 6\n1\n", "2 1\n1 1\n100 100\n5\n", "2 2\n11 14\n15 18\n2 9\n", "2 2\n11 14\n17 18\n2 9\n", "4 4\n1 4\n7 8\n9 10\n12 14\n4 5 3 8\n", "3 2\n1 5\n6 12\n14 100000000000\n10000000000 4\n", "5 9\n1 2\n3 3\n5 7\n11 13\n14 20\n2 3 4 10 6 2 6 9 5\n", "5 9\n1 2\n3 3\n5 7\n11 13\n14 20\n2 3 4 20 6 2 6 9 5...
coding
685
Solve the programming task below in a Python markdown code block. You are given an integer $N$ and a string consisting of '+' and digits. You are asked to transform the string into a valid formula whose calculation result is smaller than or equal to $N$ by modifying some characters. Here, you replace one character with...
{"inputs": ["1\n5", "1\n4", "1\n0", "1\n6", "1\n2", "1\n3", "1\n7", "1\n1"], "outputs": ["1\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n", "0\n"]}
coding
428
Solve the programming task below in a Python markdown code block. You are given a string $a$, consisting of $n$ characters, $n$ is even. For each $i$ from $1$ to $n$ $a_i$ is one of 'A', 'B' or 'C'. A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence ...
{"inputs": ["3\nAABB\nCAAB\nABCA\n", "3\nAABB\nCAAB\nABCA\n", "3\nAABB\nBAAC\nABCA\n", "3\nAAAB\nBAAC\nABCA\n", "3\nBAAA\nAABC\nABCA\n", "3\nAABB\nACAB\nABCA\n", "3\nBAAA\nAABB\nBACA\n", "3\nBAAA\nBAAC\nABCA\n"], "outputs": ["YES\nNO\nNO\n", "YES\nNO\nNO\n", "YES\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nYES\nNO\n", "YES\nYES\n...
coding
556
Solve the programming task below in a Python markdown code block. One day, Chef found a cube which has each of its sides painted in some color out of black, blue, red, green, yellow and orange. Now he asks you to check if he can choose three sides such that they are pairwise adjacent and painted in the same color. ---...
{"inputs": ["2\nblue yellow green orange black green\ngreen yellow green orange black green", "2\nblue yellow green orange black green\ngreen yellow green orange black green"], "outputs": ["NO\nYES", "NO\nYES\n"]}
coding
328
Solve the programming task below in a Python markdown code block. Devu is a disastrous oracle: his predictions about various events of your life are horrifying. Instead of providing good luck, he "blesses" you with bad luck. The secret behind his wickedness is a hidden omen which is a string of length m. On your visit ...
{"inputs": ["3\n2\nab\nba\n2\naa\nbb\n3\naabb\nabab\nbaab"], "outputs": ["1\n0\n2"]}
coding
488
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two arrays nums1 and nums2. Return the maximum dot product between non-empty subsequences of nums1 and nums2 with the same length. A subsequence of a array is a new array which is formed from the original array ...
{"functional": "def check(candidate):\n assert candidate(nums1 = [2,1,-2,5], nums2 = [3,0,-6]) == 18\n assert candidate(nums1 = [3,-2], nums2 = [2,-6,7]) == 21\n assert candidate(nums1 = [-1,-1], nums2 = [1,1]) == -1\n\n\ncheck(Solution().maxDotProduct)"}
coding
169
Solve the programming task below in a Python markdown code block. Lеt's create function to play cards. Our rules: We have the preloaded `deck`: ``` deck = ['joker','2♣','3♣','4♣','5♣','6♣','7♣','8♣','9♣','10♣','J♣','Q♣','K♣','A♣', '2♦','3♦','4♦','5♦','6♦','7♦','8♦','9♦','10♦','J♦','Q♦','K♦','A♦', ...
{"functional": "_inputs = [['Q\u2663', '3\u2663', '\u2666'], ['3\u2663', 'Q\u2663', '\u2666'], ['5\u2665', 'A\u2663', '\u2666'], ['8\u2660', '8\u2660', '\u2663'], ['2\u2666', 'A\u2660', '\u2666'], ['A\u2660', '2\u2666', '\u2666'], ['joker', 'joker', '\u2666'], ['joker', '10\u2663', '\u2660'], ['10\u2663', 'joker', '\u2...
coding
494
Solve the programming task below in a Python markdown code block. Alice and Bob are playing a game on a line with n cells. There are n cells labeled from 1 through n. For each i from 1 to n-1, cells i and i+1 are adjacent. Alice initially has a token on some cell on the line, and Bob tries to guess where it is. Bob ...
{"inputs": ["1 2\n1 1\n", "6 3\n5 1 4\n", "6 3\n4 2 3\n", "9 3\n5 1 4\n", "6 3\n5 2 4\n", "6 3\n5 2 3\n", "6 3\n5 2 1\n", "6 3\n5 4 3\n"], "outputs": ["0\n", "12\n", "11\n", "21\n", "12\n", "12\n", "12\n", "11\n"]}
coding
722
Solve the programming task below in a Python markdown code block. Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will...
{"inputs": ["4\n3 10\n3 4 5\n2 4 2\n3 8\n3 4 5\n2 4 2\n5 20\n23 54 124 54 83\n2 9 5 2 10\n5 20\n4 7 12 34 13\n30 4 3 0 9\n"], "outputs": ["2\n1\n0\n2\n"]}
coding
736
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array arr of positive integers sorted in a strictly increasing order, and an integer k. Return the kth positive integer that is missing from this array.   Please complete the following python code precisely: ...
{"functional": "def check(candidate):\n assert candidate(arr = [2,3,4,7,11], k = 5) == 9\n assert candidate(arr = [1,2,3,4], k = 2) == 6\n\n\ncheck(Solution().findKthPositive)"}
coding
86
Solve the programming task below in a Python markdown code block. This is an easier version of the next problem. In this version, $q = 0$. A sequence of integers is called nice if its elements are arranged in blocks like in $[3, 3, 3, 4, 1, 1]$. Formally, if two elements are equal, everything in between must also be e...
{"inputs": ["5 0\n3 7 3 7 3\n", "5 0\n1 2 1 2 1\n", "5 0\n2 3 2 3 3\n", "5 0\n1 2 1 2 1\n", "5 0\n2 3 2 3 3\n", "5 0\n2 3 4 3 3\n", "5 0\n1 4 1 2 1\n", "5 0\n1 2 2 2 1\n"], "outputs": ["2\n", "2\n", "2\n", "2", "2", "1\n", "2\n", "2\n"]}
coding
572
Solve the programming task below in a Python markdown code block. Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the ...
{"inputs": ["1 3\n1 2\n", "1 3\n0 2\n", "1 0\n1 9\n", "1 6\n0 2\n", "1 0\n1 7\n", "1 10\n1 9\n", "1 1\n0 10\n", "1 22\n22 33\n"], "outputs": ["1\n", "1\n", "1\n", "4\n", "1\n", "1\n", "0\n", "0\n"]}
coding
310
Solve the programming task below in a Python markdown code block. You are given a grid with $R$ rows (numbered $1$ through $R$) and $C$ columns (numbered $1$ through $C$). Initially, each cell of this grid is either empty, contains an ant or an anteater. Each ant is moving in a fixed direction: up, down, left or right....
{"inputs": ["10\n3 3\nR--\n---\n--U\n1 4\nR--R\n2 2\n--\n--\n1 4\nR--L\n1 4\n-R-L\n1 4\n-R#L\n3 3\nR-D\n-#-\nR-U\n3 3\nR-D\n---\nR#U\n3 3\n-D-\nR-L\n-U-\n1 7\nRLLLLLL\n"], "outputs": ["1\n0\n0\n0\n1\n0\n3\n2\n6\n3"]}
coding
645
Solve the programming task below in a Python markdown code block. You are given four integers $n$, $c_0$, $c_1$ and $h$ and a binary string $s$ of length $n$. A binary string is a string consisting of characters $0$ and $1$. You can change any character of the string $s$ (the string should be still binary after the c...
{"inputs": ["6\n3 1 1 1\n100\n5 10 100 1\n01010\n5 2 1 1\n11101\n5 1 10 1\n11111\n12 2 1 9\n101110110101\n2 100 1 0\n00\n", "6\n3 1 1 0\n110\n5 5 100 1\n01000\n5 3 1 1\n11111\n5 1 10 2\n11111\n12 2 1 10\n101110110101\n2 100 0 10\n00\n", "6\n3 1 1 1\n100\n5 10 100 1\n01000\n5 3 0 1\n11111\n5 1 10 1\n10111\n12 4 1 10\n10...
coding
574
Solve the programming task below in a Python markdown code block. Joisino the magical girl has decided to turn every single digit that exists on this world into 1. Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points). She is now standing before a wall. The wall is divided into HW squares in H rows and W...
{"inputs": ["2 4\n0 9 9 9 9 9 9 9 9 9\n9 0 9 9 9 9 9 9 9 9\n9 9 0 9 9 9 9 9 9 9\n9 9 9 0 2 9 9 9 9 9\n9 9 9 9 0 9 9 9 9 2\n9 9 9 9 9 0 9 9 9 9\n9 9 9 9 9 9 0 9 9 9\n9 9 9 9 9 9 9 0 9 9\n9 9 9 9 2 9 9 9 0 9\n9 2 9 9 9 9 9 9 9 0\n-1 -1 -1 -1\n8 1 1 8", "2 4\n0 9 9 9 9 9 9 9 9 9\n9 0 9 9 9 9 9 9 9 9\n9 9 0 9 9 9 9 9 9 9\n...
coding
659
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, return the length of the longest repeating substrings. If no repeating substring exists, return 0.   Please complete the following python code precisely: ```python class Solution: def longestRepe...
{"functional": "def check(candidate):\n assert candidate(\"abcd\") == 0\n assert candidate(\"abbaba\") == 2\n assert candidate(\"aabcaabdaab\") == 3\n assert candidate(\"aaaaa\") == 4\n\n\ncheck(Solution().longestRepeatingSubstring)"}
coding
74
Solve the programming task below in a Python markdown code block. Don't Drink the Water Given a two-dimensional array representation of a glass of mixed liquids, sort the array such that the liquids appear in the glass based on their density. (Lower density floats to the top) The width of the glass will not change fro...
{"functional": "_inputs = [[[['H', 'H', 'W', 'O'], ['W', 'W', 'O', 'W'], ['H', 'H', 'O', 'O']]], [[['A', 'A', 'O', 'H'], ['A', 'H', 'W', 'O'], ['W', 'W', 'A', 'W'], ['H', 'H', 'O', 'O']]], [[['A', 'H', 'W', 'O']]], [[['A'], ['H'], ['W'], ['O']]], [[]]]\n_outputs = [[[['O', 'O', 'O', 'O'], ['W', 'W', 'W', 'W'], ['H', 'H...
coding
259
Solve the programming task below in a Python markdown code block. I'm traveling to a country with a rabbit. There are n cities in this country numbered from 1 to n, and the rabbit is now in city 1. City i is a point on the coordinate plane (xi, yi) ). Rabbits travel to meet the following conditions. * The travel path...
{"inputs": ["5\n100.1 90.1\n0 0\n0 10\n5 5\n10 0\n10 4", "5\n100.1 90.1\n0 0\n0 10\n7 5\n10 0\n10 10", "5\n100.1 90.1\n0 0\n0 10\n5 5\n10 0\n10 10", "5\n100.2380070184939 90.1\n0 0\n0 10\n5 9\n10 0\n9 4", "5\n100.2380070184939 90.1\n0 0\n0 10\n4 9\n7 0\n17 0", "5\n101.055831370051 90.1\n0 0\n1 10\n4 9\n7 0\n17 -1", "5\...
coding
400
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 "]}
coding
378
Solve the programming task below in a Python markdown code block. Takahashi is taking exams on N subjects. The score on each subject will be an integer between 0 and K (inclusive). He has already taken exams on N-1 subjects and scored A_i points on the i-th subject. His goal is to achieve the average score of M points ...
{"inputs": ["2 1 1\n0\n", "4 100 60\n0 0 0\n", "5 10 7\n8 10 3 6\n", "5 20 10\n7 7 8 8\n", "5 20 10\n7 7 7 8\n", "5 20 10\n12 12 12 13\n", "5 20 10\n12 12 13 13\n", "4 100 60\n100 100 100\n"], "outputs": ["-1\n", "-1\n", "8\n", "20\n", "-1\n", "1\n", "0\n", "0\n"]}
coding
292
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums and an integer k, modify the array in the following way: choose an index i and replace nums[i] with -nums[i]. You should apply this process exactly k times. You may choose the same index ...
{"functional": "def check(candidate):\n assert candidate(nums = [4,2,3], k = 1) == 5\n assert candidate(nums = [3,-1,0,2], k = 3) == 6\n assert candidate(nums = [2,-3,-1,5,-4], k = 2) == 13\n\n\ncheck(Solution().largestSumAfterKNegations)"}
coding
122
Solve the programming task below in a Python markdown code block. Monisha likes to paint. She has painted $N$ paintings (numbered $1$ through $N$) and wants to choose some subset of these paintings for an exhibition. For each valid $i$, the $i$-th painting has beauty $b_i$ and the probability that it will be displayed ...
{"inputs": ["2\n3\n5 6 2\n1.0 0.0 0.5\n4\n2 2 2 2\n0.5 0.5 0.5 0.5"], "outputs": ["6.000000000000000\n1.000000000000000"]}
coding
682
Solve the programming task below in a Python markdown code block. You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. F...
{"inputs": ["3\n2 2 3", "3\n4 2 3", "3\n6 2 3", "3\n6 2 5", "3\n6 4 5", "3\n2 4 5", "3\n2 2 5", "3\n2 2 4"], "outputs": ["3 2 2\n", "3 4 2\n", "3 6 2\n", "5 6 2\n", "5 6 4\n", "5 2 4\n", "5 2 2\n", "4 2 2\n"]}
coding
278
Solve the programming task below in a Python markdown code block. Hongcow likes solving puzzles. One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle a...
{"inputs": ["1 1\nX\n", "1 1\nX\n", "1 2\nXX\n", "1 2\nXX\n", "2 1\nX\nX\n", "2 1\nX\nX\n", "2 2\n.X\nXX\n", "2 2\nX.\nX.\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n"]}
coding
513
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s and an integer k. You can choose one of the first k letters of s and append it at the end of the string. Return the lexicographically smallest string you could have after applying the mentione...
{"functional": "def check(candidate):\n assert candidate(s = \"cba\", k = 1) == \"acb\"\n assert candidate(s = \"baaca\", k = 3) == \"aaabc\"\n\n\ncheck(Solution().orderlyQueue)"}
coding
103
Solve the programming task below in a Python markdown code block. Problem Let $ f (x) $ be the sum of each digit when the non-negative integer $ x $ is expressed in binary. Given a positive integer $ N $, output the largest of $ f (0) $, $ f (1) $, ..., $ f (N) $. Example of calculating the function $ f (5) $: When ...
{"inputs": ["6", "1", "5", "4", "3", "8", "7", "2"], "outputs": ["2\n", "1\n", "2\n", "2\n", "2\n", "3\n", "3\n", "1"]}
coding
245
Solve the programming task below in a Python markdown code block. You have an empty sequence, and you will be given $N$ queries. Each query is one of these three types: 1 x -Push the element x into the stack. 2 -Delete the element present at the top of the stack. 3 -Print the maximum element in the stack. Func...
{"inputs": ["STDIN Function\n----- --------\n10 operations[] size n = 10\n1 97 operations = ['1 97', '2', '1 20', ....]\n2\n1 20\n2\n1 26\n1 20\n2\n3\n1 91\n3\n"], "outputs": ["26\n91\n"]}
coding
286
Solve the programming task below in a Python markdown code block. Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls ar...
{"inputs": ["1 1\n1 1\n", "3 2\n1 2\n2 1 3\n", "3 2\n2 1 2\n1 3\n", "5 3\n1 4\n3 1 2 3\n1 5\n", "7 3\n3 1 3 7\n2 2 5\n2 4 6\n", "8 5\n2 1 2\n2 3 4\n1 5\n2 6 7\n1 8\n", "10 10\n1 5\n1 4\n1 10\n1 3\n1 7\n1 1\n1 8\n1 6\n1 9\n1 2\n", "13 8\n1 5\n2 8 10\n1 13\n4 1 2 3 11\n1 7\n2 6 12\n1 4\n1 9\n"], "outputs": ["0\n", "3\n",...
coding
702
Solve the programming task below in a Python markdown code block. Ilya lives in a beautiful city of Chordalsk. There are $n$ houses on the street Ilya lives, they are numerated from $1$ to $n$ from left to right; the distance between every two neighboring houses is equal to $1$ unit. The neighboring houses are $1$ and...
{"inputs": ["3\n1 2 1\n", "3\n1 1 3\n", "3\n1 1 3\n", "3\n1 0 3\n", "3\n1 2 2\n", "3\n0 0 3\n", "3\n1 3 2\n", "3\n1 2 1\n"], "outputs": ["1\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "1\n"]}
coding
601
Solve the programming task below in a Python markdown code block. Variation of this nice kata, the war has expanded and become dirtier and meaner; both even and odd numbers will fight with their pointy `1`s. And negative integers are coming into play as well, with, ça va sans dire, a negative contribution (think of the...
{"functional": "_inputs = [[[1, 5, 12]], [[7, -3, 20]], [[7, -3, -2, 6]], [[-3, -5]], [[]]]\n_outputs = [['odds win'], ['evens win'], ['tie'], ['evens win'], ['tie']]\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...
coding
240
Solve the programming task below in a Python markdown code block. Ronald's uncle left him 3 fertile chickens in his will. When life gives you chickens, you start a business selling chicken eggs which is exactly what Ronald decided to do. A chicken lays 300 eggs in its first year. However, each chicken's egg productio...
{"functional": "_inputs = [[0, 5], [2, 1], [4, 8], [74, 10], [1, 15]]\n_outputs = [['No chickens yet!'], [900], [2655], [3984], [900]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (lis...
coding
315
Solve the programming task below in a Python markdown code block. In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses ...
{"inputs": ["1 1 0\n1 3\n", "2 2 13\n1 13\n2 12\n", "1 1 1000000\n1 1000000\n", "4 2 4\n1 9\n1 0\n1 4\n2 6\n", "4 2 4\n1 9\n1 1\n1 4\n2 6\n", "4 2 4\n1 4\n1 1\n1 4\n2 6\n", "4 2 8\n1 9\n1 10\n1 4\n2 6\n", "4 2 4\n1 9\n1 10\n1 4\n2 6\n"], "outputs": ["0\n", "13\n", "1000000\n", "4\n", "4\n", "4\n", "8\n", "4\n"]}
coding
590
Solve the programming task below in a Python markdown code block. JJ gives you a number N and challenges you to construct a permutation P of length N such that: |P_{i + 1} - P_{i}| ≥ 2 for all 1 ≤ i ≤ N - 1 (Here |x| denotes the absolute value of x) Can you complete JJ's challenge? As a reminder, a permutation of len...
{"inputs": ["2\n2\n6\n"], "outputs": ["-1\n1 4 2 5 3 6\n"]}
coding
393
Solve the programming task below in a Python markdown code block. At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, n groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. I...
{"inputs": ["3\n1 5\n2 6\n4 7\n", "3\n1 5\n2 6\n3 7\n", "3\n1 5\n2 6\n3 12\n", "3\n3 9\n20 30\n1 3\n", "3\n3 9\n20 30\n0 3\n", "3\n3 9\n20 55\n0 3\n", "3\n3 13\n20 55\n0 3\n", "3\n3 10\n20 30\n0 3\n"], "outputs": ["0\n\n", "0\n", "0\n\n", "3\n1 2 3\n", "3\n1 2 3\n", "3\n1 2 3\n", "3\n1 2 3\n", "3\n1 2 3\n"]}
coding
394
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s consisting only of lowercase English letters. We call a substring special if it contains no character which has occurred at least twice (in other words, it does not contain a repeating charact...
{"functional": "def check(candidate):\n assert candidate(s = \"abcd\") == 10\n assert candidate(s = \"ooo\") == 3\n assert candidate(s = \"abab\") == 7\n\n\ncheck(Solution().numberOfSpecialSubstrings)"}
coding
179
Solve the programming task below in a Python markdown code block. JJ loves playing with medians. He has an array A of length N (N is odd). He wants to partition the array A into two non-empty subsets P and Q such that the value of |median(P) - median(Q)| is as small as possible. (Note that each A_{i} must belong to eit...
{"inputs": ["3\n5\n2 7 4 8 2\n3\n1 2 3\n5\n1 1 1 1 1\n"], "outputs": ["2\n1\n0"]}
coding
591
Solve the programming task below in a Python markdown code block. We define a function f on a binary string S of length N as follows: f(S) = \sum_{i = 1}^{N - 1} |S_{i+1} - S_{i}|. JJ and Uttu have a binary string S of length N and they decide to play a game using it. The rules of the game are as follows: JJ starts ...
{"inputs": ["3\n5\n10011\n2\n00\n5\n10101"], "outputs": ["JJ\nJJ\nUttu"]}
coding
502
Solve the programming task below in a Python markdown code block. AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or gr...
{"inputs": ["3 6\n1 7 3", "3 6\n1 5 2", "3 7\n1 5 0", "3 6\n1 7 2", "3 6\n1 5 0", "3 7\n0 5 0", "2 7\n0 6 0", "2 7\n0 3 0"], "outputs": ["2\n", "0\n", "3\n", "2\n", "1\n", "3\n", "2\n", "2\n"]}
coding
418
Solve the programming task below in a Python markdown code block. Chef loves saving money and he trusts none other bank than State Bank of Chefland. Unsurprisingly, the employees like giving a hard time to their customers. But instead of asking them to stand them in long queues, they have weird way of accepting money. ...
{"inputs": ["4\n1\n2\n3\n4"], "outputs": ["1\n1\n1 2\n3\n1 2 4\n7\n1 2 4 8\n15"]}
coding
632
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X ...
{"inputs": ["5 3\n20 11 18 2 13\n1 3\n3 5\n2 4"], "outputs": ["2147483629\n2147483645\n2147483645"]}
coding
417
Solve the programming task below in a Python markdown code block. Who's interested in football? Rayne Wooney has been one of the top players for his football club for the last few years. But unfortunately, he got injured during a game a few months back and has been out of play ever since. He's got proper treatment and ...
{"inputs": ["3\n6\n3 7 1 4 2 4\n5\n5 4 3 2 1\n5\n4 3 2 2 3"], "outputs": ["4\nUNFIT\n1"]}
coding
640