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. Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; numb...
{"inputs": ["1 1\n1\n", "1 2\n1\n", "1 3\n1\n", "1 4\n1\n", "1 5\n3\n", "1 6\n4\n", "1 7\n2\n", "1 8\n3\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
469
Solve the programming task below in a Python markdown code block. Zonal Computing Olympiad 2012, 26 Nov 2011 It's dinner time in Castle Camelot, and the fearsome Knights of the Round Table are clamouring for dessert. You, the chef, are in a soup. There are N knights, including King Arthur, each with a different prefe...
{"inputs": ["5\n1 2 1 2 2"], "outputs": ["4"]}
coding
496
Solve the programming task below in a Python markdown code block. You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j <...
{"inputs": ["1\n1\n", "1\n1\n", "3\n3 2 1\n", "3\n3 2 1\n", "5\n5 1 2 3 4\n", "5\n4 3 5 1 2\n", "5\n2 3 4 1 5\n", "5\n1 2 3 4 5\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "5\n", "1\n", "1\n", "1\n"]}
coding
246
Please solve the programming task below using a self-contained code snippet in a markdown code block. A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters ...
{"functional": "def check(candidate):\n assert candidate(s = \"race a car\") == False\n assert candidate(s = \" \") == True\n\n\ncheck(Solution().isPalindrome)"}
coding
103
Solve the programming task below in a Python markdown code block. Gerald has been selling state secrets at leisure. All the secrets cost the same: n marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 mar...
{"inputs": ["3\n", "2\n", "8\n", "9\n", "5\n", "7\n", "6\n", "1\n"], "outputs": [" 1\n", " 1\n", " 3\n", "1\n", "2\n", "3\n", "1\n", "...
coding
487
Solve the programming task below in a Python markdown code block. There is a building with n rooms, numbered 1 to n. We can move from any room to any other room in the building. Let us call the following event a move: a person in some room i goes to another room j~ (i \neq j). Initially, there was one person in each ro...
{"inputs": ["1 2", "4 2", "4 4", "5 4", "6 2", "9 2", "3 4", "3 2"], "outputs": ["1\n", "31\n", "35\n", "126\n", "181\n", "1081\n", "10\n", "10"]}
coding
458
Please solve the programming task below using a self-contained code snippet in a markdown code block. We call a positive integer special if all of its digits are distinct. Given a positive integer n, return the number of special integers that belong to the interval [1, n].   Please complete the following python code p...
{"functional": "def check(candidate):\n assert candidate(n = 20) == 19\n assert candidate(n = 5) == 5\n assert candidate(n = 135) == 110\n\n\ncheck(Solution().countSpecialNumbers)"}
coding
84
Solve the programming task below in a Python markdown code block. You have a grid with N rows and M columns. You have two types of tiles — one of dimensions 2 \times 2 and the other of dimensions 1 \times 1. You want to cover the grid using these two types of tiles in such a way that: Each cell of the grid is covered b...
{"inputs": ["4\n1 1\n4 5\n6 8\n3 2\n\n"], "outputs": ["1\n4\n0\n2\n"]}
coding
383
Solve the programming task below in a Python markdown code block. You are given a rectangular grid with $n$ rows and $m$ columns. The cell located on the $i$-th row from the top and the $j$-th column from the left has a value $a_{ij}$ written in it. You can perform the following operation any number of times (possibly...
{"inputs": ["1\n3 3\n-3 -2 -1\n0 -2 0\n-3 -2 -1\n", "1\n3 3\n0 -1 -2\n-8 -4 -3\n-3 0 -1\n", "1\n3 3\n0 -1 -4\n-8 -4 -3\n-3 0 -1\n", "1\n3 3\n0 -1 -4\n-8 -4 -3\n-1 0 -1\n", "1\n3 3\n-3 -2 -2\n0 -2 -1\n-3 -2 -1\n", "1\n3 3\n-1 -2 -2\n0 -2 -1\n-3 -2 -1\n", "1\n3 3\n-4 -4 -1\n-3 -4 -2\n-3 -2 0\n", "1\n3 3\n-6 -4 -1\n-3 -4 ...
coding
468
Solve the programming task below in a Python markdown code block. The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the t...
{"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n2\n", "1\n1\n", "1\n0\n", "1\n3\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "NO\n"]}
coding
601
Solve the programming task below in a Python markdown code block. Chef has to travel to another place. For this, he can avail any one of two cab services. The first cab service charges X rupees. The second cab service charges Y rupees. Chef wants to spend the minimum amount of money. Which cab service should Chef take...
{"inputs": ["3\n30 65\n42 42\n90 50\n"], "outputs": ["FIRST\nANY\nSECOND\n"]}
coding
313
Solve the programming task below in a Python markdown code block. *This is the advanced version of the [Minimum and Maximum Product of k Elements](https://www.codewars.com/kata/minimum-and-maximum-product-of-k-elements/) kata.* --- Given a list of **integers** and a positive integer `k` (> 0), find the minimum and m...
{"functional": "_inputs = [[[0, 1, 2, 3, 4], 2], [[0, -1, -2, -3, -4], 2], [[0, -1, -2, -3, -4], 3], [[-1, -2, -3, -4], 2], [[-1, -2, -3, -4], 3], [[], 2], [[-4, -10, -1], 2], [[0, 6, 3, 5, 4], 4], [[5, 4, 3, 3, 6], 2]]\n_outputs = [[[0, 12]], [[0, 12]], [[-24, 0]], [[2, 12]], [[-24, -6]], [None], [[4, 40]], [[0, 360]]...
coding
322
Solve the programming task below in a Python markdown code block. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests recei...
{"inputs": ["1\n1 1\n1\n1\n", "1\n2 1\n1\n1\n", "1\n2 1\n1\n1\n", "1\n1 1\n1\n1\n", "1\n0 1\n1\n1\n", "1\n0 1\n1\n2\n", "1\n0 1\n1\n3\n", "1\n0 1\n1\n5\n"], "outputs": ["1 1\n1 1\n", "0 0\n", "0 0\n", "1 1\n1 1\n", "1 1\n1 1\n", "1 1\n1 1\n", "1 1\n1 1\n", "1 1\n1 1\n"]}
coding
592
Solve the programming task below in a Python markdown code block. There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left ...
{"inputs": ["4\n1 4 4 2", "4\n1 8 4 2", "4\n2 8 4 2", "4\n4 8 4 1", "4\n1 0 4 2", "4\n1 4 4 0", "4\n2 8 0 1", "4\n1 3 4 2"], "outputs": ["22\n", "30\n", "32\n", "34\n", "15\n", "18\n", "23\n", "20"]}
coding
320
Solve the programming task below in a Python markdown code block. The sequence of $m$ integers is called the permutation if it contains all integers from $1$ to $m$ exactly once. The number $m$ is called the length of the permutation. Dreamoon has two permutations $p_1$ and $p_2$ of non-zero lengths $l_1$ and $l_2$. ...
{"inputs": ["6\n5\n1 4 3 2 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n", "6\n5\n1 4 3 1 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n", "6\n5\n1 4 3 2 1\n6\n2 4 1 3 3 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n", "6\n5...
coding
743
Solve the programming task below in a Python markdown code block. Given A, B, and C as the sides of a triangle, find whether the triangle is *scalene*. Note: A triangle is said to be *scalene* if all three sides of the triangle are distinct. It is guaranteed that the sides represent a valid triangle. ------ Input For...
{"inputs": ["4\n2 3 4\n1 2 2\n2 2 2\n3 5 6\n"], "outputs": ["YES\nNO\nNO\nYES"]}
coding
428
Solve the programming task below in a Python markdown code block. Eugeny loves listening to music. He has n songs in his play list. We know that song number i has the duration of t_{i} minutes. Eugeny listens to each song, perhaps more than once. He listens to song number i c_{i} times. Eugeny's play list is organized ...
{"inputs": ["1 2\n2 8\n1 16\n", "1 2\n2 8\n1 16\n", "3 1\n2 50\n1 50\n1 50\n160\n", "3 1\n2 50\n1 50\n1 50\n160\n", "3 1\n2 50\n1 50\n1 82\n160\n", "3 1\n2 74\n1 50\n1 82\n160\n", "3 1\n2 74\n1 32\n1 82\n160\n", "3 1\n2 50\n1 53\n1 82\n160\n"], "outputs": ["1\n1\n", "1\n1\n", "3\n", "3\n", "3\n", "2\n", "2\n", "3\n"]}
coding
555
Solve the programming task below in a Python markdown code block. # Task **_Given_** a **_list of digits_**, *return the **_smallest number_** that could be formed from these digits, using the digits only once (ignore duplicates).* ___ # Notes: * Only **_positive integers_** *will be passed to the function (> 0 ), ...
{"functional": "_inputs = [[[1, 3, 1]], [[4, 7, 5, 7]], [[4, 8, 1, 4]], [[5, 7, 9, 5, 7]], [[6, 7, 8, 7, 6, 6]], [[5, 6, 9, 9, 7, 6, 4]], [[1, 9, 1, 3, 7, 4, 6, 6, 7]], [[3, 6, 5, 5, 9, 8, 7, 6, 3, 5, 9]]]\n_outputs = [[13], [457], [148], [579], [678], [45679], [134679], [356789]]\nimport math\ndef _deep_eq(a, b, tol=1...
coding
472
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an 8 x 8 matrix representing a chessboard. There is exactly one white rook represented by 'R', some number of white bishops 'B', and some number of black pawns 'p'. Empty squares are represented by '.'. ...
{"functional": "def check(candidate):\n assert candidate([[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"p\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"R\",\".\",\".\",\".\",\"p\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\"...
coding
206
Solve the programming task below in a Python markdown code block. Every Friday and Saturday night, farmer counts amount of sheep returned back to his farm (sheep returned on Friday stay and don't leave for a weekend). Sheep return in groups each of the days -> you will be given two arrays with these numbers (one for F...
{"functional": "_inputs = [[[1, 2], [3, 4], 15], [[3, 1, 2], [4, 5], 21], [[5, 1, 4], [5, 4], 29], [[11, 23, 3, 4, 15], [7, 14, 9, 21, 15], 300], [[2, 7, 13, 17], [23, 56, 44, 12, 1, 2, 1], 255], [[2, 5, 8], [11, 23, 3, 4, 15, 112, 12, 4], 355], [[1, 1, 1, 2, 1, 2], [2, 1, 2, 1, 2, 1], 30], [[5, 10, 15], [11, 23, 3, 4,...
coding
209
Solve the programming task below in a Python markdown code block. Chef has N subordinates. In order to complete a very important order he will choose exactly K of them. He can't choose less than K since it will be not enough to complete the order in time. On the other hand if he chooses more than K subordinates he can'...
{"inputs": ["3\n5 2\n5 4\n9 3", "3\n5 2\n2 5\n9 3", "3\n5 1\n2 5\n9 3", "3\n9 1\n2 5\n9 3", "3\n9 1\n2 5\n8 3", "3\n9 1\n2 5\n7 3", "3\n9 0\n2 5\n7 3", "3\n9 0\n2 3\n5 4"], "outputs": ["10\n5\n84\n", "10\n0\n84\n", "5\n0\n84\n", "9\n0\n84\n", "9\n0\n56\n", "9\n0\n35\n", "1\n0\n35\n", "1\n0\n5\n"]}
coding
231
Solve the programming task below in a Python markdown code block. Spring is interesting season of year. Chef is thinking about different things, but last time he thinks about interesting game - "Strange Matrix". Chef has a matrix that consists of n rows, each contains m elements. Initially, the element aij of matrix e...
{"inputs": ["4 4 6\n2 2\n3 2\n3 2\n4 3\n4 4\n4 3"], "outputs": ["3\n3\n-1\n4"]}
coding
619
Solve the programming task below in a Python markdown code block. Ahmed Gafer failed to pass the test, but he got the job because of his friendship with Said and Shahhoud. After working in the kitchen for a while, he blew it. The customers didn't like the food anymore and one day he even burned the kitchen. Now the mas...
{"inputs": ["2\na\nabba"], "outputs": ["0\n2"]}
coding
461
Solve the programming task below in a Python markdown code block. You are given two positive integers `a` and `b` (`a < b <= 20000`). Complete the function which returns a list of all those numbers in the interval `[a, b)` whose digits are made up of prime numbers (`2, 3, 5, 7`) but which are not primes themselves. B...
{"functional": "_inputs = [[2, 222], [2, 77], [2700, 3000], [500, 999], [999, 2500]]\n_outputs = [[[22, 25, 27, 32, 33, 35, 52, 55, 57, 72, 75, 77]], [[22, 25, 27, 32, 33, 35, 52, 55, 57, 72, 75]], [[2722, 2723, 2725, 2727, 2732, 2733, 2735, 2737, 2752, 2755, 2757, 2772, 2773, 2775]], [[522, 525, 527, 532, 533, 535, 53...
coding
117
Solve the programming task below in a Python markdown code block. Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the sbegin and ending with the send ...
{"inputs": ["rmf\nrm\nf\n", "rmf\nrm\ng\n", "rmf\nrm\nh\n", "rmf\nqm\nh\n", "aabbc\na\nb\n", "aba\nba\nab\n", "aba\nba\nba\n", "aba\naa\nba\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "4\n", "0\n", "1\n", "0\n"]}
coding
311
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a binary string s and a positive integer k. You can apply the following operation on the string any number of times: Choose any substring of size k from s and flip all its characters, that is, turn all ...
{"functional": "def check(candidate):\n assert candidate(s = \"1001\", k = 3) == 4\n assert candidate(s = \"10110\", k = 5) == 2\n\n\ncheck(Solution().countDistinctStrings)"}
coding
176
Solve the programming task below in a Python markdown code block. Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation...
{"inputs": ["2\n", "4\n", "8\n", "8\n", "1\n", "4\n", "2\n", "110\n"], "outputs": ["1\n", "-1\n", "2\n", "2\n", "-1\n", "-1\n", "1\n", "10\n"]}
coding
329
Solve the programming task below in a Python markdown code block. Utkarsh is currently sitting for placements. He has applied to three companies named A, B, and C. You know Utkarsh's order of preference among these 3 companies, given to you as characters first, second, and third respectively (where first is the compan...
{"inputs": ["2\nA B C\nA B\nB C A\nA C"], "outputs": ["A\nC"]}
coding
499
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a string and your task will be to return a list of ints detailing the count of uppercase letters, lowercase, numbers and special characters, as follows. ```Haskell Solve("*'&ABCDabcde12345") = [4,5,5,3]. --the order is: ...
{"functional": "_inputs = [['Codewars@codewars123.com'], ['bgA5<1d-tOwUZTS8yQ'], ['P*K4%>mQUDaG$h=cx2?.Czt7!Zn16p@5H'], [\"RYT'>s&gO-.CM9AKeH?,5317tWGpS<*x2ukXZD\"], ['$Cnl)Sr<7bBW-&qLHI!mY41ODe'], ['@mw>0=QD-iAx!rp9TaG?o&M%l$34L.nbft']]\n_outputs = [[[1, 18, 3, 2]], [[7, 6, 3, 2]], [[9, 9, 6, 9]], [[15, 8, 6, 9]], [[1...
coding
129
Solve the programming task below in a Python markdown code block. ![](http://www.grindtv.com/wp-content/uploads/2015/08/drone.jpg) The other day I saw an amazing video where a guy hacked some wifi controlled lightbulbs by flying a drone past them. Brilliant. In this kata we will recreate that stunt... sort of. You w...
{"functional": "_inputs = [['xxxxxx', '====T'], ['xxxxxxxxx', '==T'], ['xxxxxxxxxxxxxxx', '=========T']]\n_outputs = [['ooooox'], ['oooxxxxxx'], ['ooooooooooxxxxx']]\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
242
Solve the programming task below in a Python markdown code block. Akash is feeling lonely.So he decided to visit his friend's house. His friend's house is located at the distance of K metres from his house.Now,he can take a step of one metre ,two metres or three metres at a time.Can you tell me number of ways of rea...
{"inputs": ["15\n1\n1\n9\n4\n10\n7\n2\n6\n6\n2\n12\n9\n8\n6\n6"], "outputs": ["1\n1\n149\n7\n274\n44\n2\n24\n24\n2\n927\n149\n81\n24\n24"]}
coding
173
Solve the programming task below in a Python markdown code block. Pupils Alice and Ibragim are best friends. It's Ibragim's birthday soon, so Alice decided to gift him a new puzzle. The puzzle can be represented as a matrix with $2$ rows and $n$ columns, every element of which is either $0$ or $1$. In one move you can ...
{"inputs": ["1\n0\n1\n1\n0\n", "3\n1 0 0\n0 0 0\n0 0 0\n0 0 0\n", "5\n0 1 0 1 0\n1 1 0 0 1\n1 0 1 0 1\n0 0 1 1 0\n", "7\n1 0 0 1 1 0 1\n1 0 0 0 1 1 1\n1 1 1 0 0 1 0\n0 1 1 1 0 0 0\n", "7\n0 0 1 0 1 0 1\n0 0 0 0 0 0 1\n0 1 0 1 0 1 0\n1 0 0 0 0 0 0\n", "7\n0 0 0 0 0 0 0\n1 0 0 0 0 0 0\n0 0 0 0 0 1 0\n0 0 0 0 0 0 0\n", "7...
coding
602
Solve the programming task below in a Python markdown code block. You're given a string containing a sequence of words separated with whitespaces. Let's say it is a sequence of patterns: a name and a corresponding number - like this: ```"red 1 yellow 2 black 3 white 4"``` You want to turn it into a different **string...
{"functional": "_inputs = [['red 1 yellow 2 black 3 white 4'], ['1 red 2 white 3 violet 4 green'], ['1 1 2 2 3 3 4 4'], ['#@&fhds 123F3f 2vn2# 2%y6D @%fd3 @!#4fs W@R^g WE56h%'], ['']]\n_outputs = [[\"[{name : 'red', id : '1'}, {name : 'yellow', id : '2'}, {name : 'black', id : '3'}, {name : 'white', id : '4'}]\"], [\"[...
coding
291
Solve the programming task below in a Python markdown code block. You are given three integers $a \le b \le c$. In one move, you can add $+1$ or $-1$ to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this op...
{"inputs": ["1\n3 6 10000\n", "1\n1 100 940\n", "1\n3 6 10000\n", "1\n1 100 940\n", "1\n1 6 10000\n", "1\n1 110 940\n", "1\n1 73 10000\n", "1\n5 76 10000\n"], "outputs": ["2\n3 6 10002\n", "6\n1 94 940\n", "2\n3 6 10002\n", "6\n1 94 940\n", "1\n1 5 10000\n", "10\n1 104 936\n", "1\n1 73 10001\n", "4\n5 80 10000\n"]}
coding
496
Solve the programming task below in a Python markdown code block. Consider the infinite x$x$ axis. There are N$N$ impacts on this X-axis at integral points (X1$X_1$,X2$X_2$,....XN$X_N$) (all distinct) . An impact at a point X$X$i propagates such that at a point X$X$0, the effect of the impact is K|Xi−X0|$K^{|X_i - X_0...
{"inputs": ["2\n4 3 10 10\n2 3 10 10"], "outputs": ["no\nyes"]}
coding
441
Solve the programming task below in a Python markdown code block. There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, an...
{"inputs": ["2 2\n", "1 7\n", "1 1\n", "2 8\n", "314 1592\n", "237891668 1\n", "1 1000000000\n", "17890722 23878637\n"], "outputs": ["0\n", "5\n", "1\n", "0\n", "496080\n", "237891666\n", "999999998\n", "427205972767200\n"]}
coding
263
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...
coding
73
Solve the programming task below in a Python markdown code block. My washing machine uses ```water``` amount of water to wash ```clothes``` amount of clothes. You are given a ```load``` amount of clothes to wash. For each single item of load above the standard amount of clothes, the washing machine will use 10% more w...
{"functional": "_inputs = [[10, 10, 21], [10, 10, 2], [10, 11, 20], [50, 15, 29], [50, 15, 15]]\n_outputs = [['Too much clothes'], ['Not enough clothes'], [23.58], [189.87], [50]]\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...
coding
337
Solve the programming task below in a Python markdown code block. You are given a string $s$, consisting of $n$ lowercase Latin letters. A substring of string $s$ is a continuous segment of letters from $s$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the num...
{"inputs": ["1\ng\n", "1\ng\n", "1\nh\n", "1\ni\n", "1\nf\n", "2\nab\n", "2\naz\n", "2\nqa\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\nab\n", "YES\naz\n", "YES\nqa\n"]}
coding
349
Solve the programming task below in a Python markdown code block. Do the following for a four-digit number N consisting of numbers 0-9. 1. Let L be the number obtained as a result of arranging the numerical values ​​of each of the N digits in descending order. 2. Let S be the number obtained as a result of arranging t...
{"inputs": ["6174\n3729\n90\n0000", "6174\n990\n3333\n0000", "6174\n503\n4924\n0000", "6174\n3985\n3333\n0000", "6174\n1779\n3333\n0000", "6174\n1779\n2211\n0000", "6174\n2012\n3078\n0000", "6174\n3985\n5889\n0000"], "outputs": ["0\n3\n4\n", "0\n4\nNA\n", "0\n5\n4\n", "0\n3\nNA\n", "0\n6\nNA\n", "0\n6\n4\n", "0\n3\n2\n...
coding
480
Solve the programming task below in a Python markdown code block. Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the beauty of the tower as follows: * The beauty of...
{"inputs": ["2 5 6 1", "2 9 7 0", "4 1 3 5", "4 1 1 5", "4 1 1 7", "1 2 2 2", "6 1 1 7", "4 2 2 5"], "outputs": ["0\n", "1\n", "24\n", "56\n", "8\n", "2\n", "792\n", "0\n"]}
coding
414
Solve the programming task below in a Python markdown code block. For a set $S$ of integers, perform a sequence of the following operations. Note that multiple elements can have equivalent values in $S$. * insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation. * find($x$): Report ...
{"inputs": ["10\n0 1\n0 1\n0 2\n0 3\n2 2\n1 1\n1 1\n1 3\n0 4\n3 1 4", "10\n0 1\n0 1\n0 2\n0 0\n2 2\n1 1\n1 2\n1 3\n0 4\n3 1 4", "10\n0 1\n0 1\n0 2\n0 3\n2 2\n1 1\n1 1\n1 3\n1 4\n3 1 4", "10\n0 1\n0 1\n0 2\n0 5\n2 2\n1 1\n1 1\n1 3\n1 4\n3 1 4", "10\n0 1\n0 1\n0 2\n0 0\n2 2\n1 1\n1 1\n1 3\n1 4\n0 1 1", "10\n0 0\n0 1\n0 2...
coding
448
Solve the programming task below in a Python markdown code block. Polycarp has recently got himself a new job. He now earns so much that his old wallet can't even store all the money he has. Berland bills somehow come in lots of different sizes. However, all of them are shaped as rectangles (possibly squares). All wal...
{"inputs": ["2\n+ 2 2\n? 2 2\n", "2\n+ 2 2\n? 2 2\n", "2\n+ 2 2\n? 4 2\n", "2\n+ 2 1\n? 2 2\n", "2\n+ 2 2\n? 8 2\n", "2\n+ 1 1\n? 2 2\n", "2\n+ 2 2\n? 6 2\n", "2\n+ 1 2\n? 6 2\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
coding
721
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese here City of Byteland can be described as a $2D$ grid of cells. Each cell may or may not contain a demon. You are given the list of cells that contain demons. In a single Kamehameha attack, Goku can kill all...
{"inputs": ["1\n3\n0 0\n1 0\n0 1"], "outputs": ["2"]}
coding
315
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"]}
coding
341
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integers, x and y, which represent your current location on a Cartesian grid: (x, y). You are also given an array points where each points[i] = [ai, bi] represents that a point exists at (ai, bi). A ...
{"functional": "def check(candidate):\n assert candidate(x = 3, y = 4, points = [[1,2],[3,1],[2,4],[2,3],[4,4]]) == 2\n assert candidate(x = 3, y = 4, points = [[3,4]]) == 0\n assert candidate(x = 3, y = 4, points = [[2,3]]) == -1\n\n\ncheck(Solution().nearestValidPoint)"}
coding
216
Solve the programming task below in a Python markdown code block. You are given $n$ words of equal length $m$, consisting of lowercase Latin alphabet letters. The $i$-th word is denoted $s_i$. In one move you can choose any position in any single word and change the letter at that position to the previous or next lett...
{"inputs": ["1\n2 7\nabcdefg\naaaaaaa\n", "6\n2 4\nbest\ncost\n6 3\nabb\nzba\nbef\ncdu\nooo\nzzz\n2 7\naaabbbc\nbbaezfe\n3 2\nab\nab\nab\n2 8\naaaaaaaa\nzzzzzzzz\n3 1\na\nu\ny\n"], "outputs": ["21\n", "11\n8\n35\n0\n200\n4\n"]}
coding
627
Solve the programming task below in a Python markdown code block. Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. Fo...
{"inputs": ["2\n2\n0", "2\n7\n0", "2\n0\n0", "2\n5\n0", "2\n1\n0", "2\n3\n0", "2\n8\n0", "2\n6\n0"], "outputs": ["5\n5\n", "5\n58\n", "5\n", "5\n28\n", "5\n2\n", "5\n10\n", "5\n77\n", "5\n41\n"]}
coding
231
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string num, representing a large integer. Return the largest-valued odd integer (as a string) that is a non-empty substring of num, or an empty string "" if no odd integer exists. A substring is a cont...
{"functional": "def check(candidate):\n assert candidate(num = \"52\") == \"5\"\n assert candidate(num = \"4206\") == \"\"\n assert candidate(num = \"35427\") == \"35427\"\n\n\ncheck(Solution().largestOddNumber)"}
coding
104
Solve the programming task below in a Python markdown code block. # Background My TV remote control has arrow buttons and an `OK` button. I can use these to move a "cursor" on a logical screen keyboard to type "words"... The screen "keyboard" layout looks like this #tvkb { width : 300px; border: 5px soli...
{"functional": "_inputs = [['codewars'], ['does'], ['your'], ['solution'], ['work'], ['for'], ['these'], ['words'], ['mississippi']]\n_outputs = [[36], [16], [23], [33], [20], [12], [27], [25], [35]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.i...
coding
575
Solve the programming task below in a Python markdown code block. There is Chef and Chef’s Crush who are playing a game of numbers. Chef’s crush has a number $A$ and Chef has a number $B$. Now, Chef wants Chef’s crush to win the game always, since she is his crush. The game ends when the greatest value of A^B is reac...
{"inputs": ["1\n4 5"], "outputs": ["2 7"]}
coding
590
Solve the programming task below in a Python markdown code block. Vasya has an array a_1, a_2, ..., a_n. You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≤ t_i ≤ 1, 1 ≤ l_i < r_i ≤ n) and it means: * if t_i=1 then subbarray a_{l_i}, a_{l_i...
{"inputs": ["2 1\n1 1 2\n", "5 1\n0 1 3\n", "2 1\n0 1 2\n", "4 1\n0 1 2\n", "4 1\n0 1 1\n", "124 1\n1 1 2\n", "124 1\n0 1 2\n", "152 1\n0 1 2\n"], "outputs": ["YES\n2 2 \n", "YES\n5 4 3 2 1 \n", "YES\n2 1 \n", "YES\n4 3 2 1 ", "NO\n", "YES\n124 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106...
coding
676
Solve the programming task below in a Python markdown code block. In this problem the input will consist of a number of lines of English text consisting of the letters of the English alphabet, the punctuation marks ' (apostrophe), . (full stop), , (comma), ; (semicolon), :(colon) and white space characters (blank, newl...
{"inputs": ["2\nThis is a sample piece of text to illustrate this\nproblem."], "outputs": ["10\na\nillustrate\nis\nof\npiece\nproblem\nsample\ntext\nthis\nto"]}
coding
374
Solve the programming task below in a Python markdown code block. There is an integer sequence of length 2^N: A_0, A_1, ..., A_{2^N-1}. (Note that the sequence is 0-indexed.) For every integer K satisfying 1 \leq K \leq 2^N-1, solve the following problem: - Let i and j be integers. Find the maximum value of A_i + A_j ...
{"inputs": ["2\n1 2 3 2", "2\n0 2 3 2", "2\n1 2 3 1", "2\n1 2 3 1\n", "3\n3 210 47 33 0 9 17 82", "3\n3 312 47 33 0 9 17 82", "3\n3 312 59 33 0 9 17 82", "3\n2 312 59 33 0 9 17 82"], "outputs": ["3\n4\n5\n", "2\n3\n5\n", "3\n4\n5", "3\n4\n5\n", "213\n213\n257\n257\n257\n257\n292\n", "315\n315\n359\n359\n359\n359\n394\n...
coding
432
Solve the programming task below in a Python markdown code block. Chef wants to organize a contest. Predicting difficulty levels of the problems can be a daunting task. Chef wants his contests to be balanced in terms of difficulty levels of the problems. Assume a contest had total P participants. A problem that was sol...
{"inputs": ["6\n3 100\n10 1 100\n3 100\n11 1 100\n3 100\n10 1 10\n3 100\n10 1 50\n4 100\n50 50 50 50\n4 100\n1 1 1 1"], "outputs": ["yes\nno\nno\nyes\nno\nno"]}
coding
626
Solve the programming task below in a Python markdown code block. Jzzhu has invented a kind of sequences, they meet the following property:$f_{1} = x ; f_{2} = y ; \forall i(i \geq 2), f_{i} = f_{i - 1} + f_{i + 1}$ You are given x and y, please calculate f_{n} modulo 1000000007 (10^9 + 7). -----Input----- The firs...
{"inputs": ["2 3\n3\n", "2 3\n6\n", "1 3\n6\n", "3 4\n6\n", "1 2\n6\n", "5 9\n6\n", "1 2\n6\n", "2 3\n6\n"], "outputs": ["1\n", "1000000006\n", "1000000005\n", "1000000006\n", "1000000006\n", "1000000003\n", "1000000006\n", "1000000006\n"]}
coding
300
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array arr, partition the array into (contiguous) subarrays of length at most k. After partitioning, each subarray has their values changed to become the maximum value of that subarray. Return the larg...
{"functional": "def check(candidate):\n assert candidate(arr = [1,15,7,9,2,5,10], k = 3) == 84\n assert candidate(arr = [1,4,1,5,7,3,6,1,9,9,3], k = 4) == 83\n assert candidate(arr = [1], k = 1) == 1\n\n\ncheck(Solution().maxSumAfterPartitioning)"}
coding
127
Please solve the programming task below using a self-contained code snippet in a markdown code block. Some robots are standing on an infinite number line with their initial coordinates given by a 0-indexed integer array nums and will start moving once given the command to move. The robots will move a unit distance eac...
{"functional": "def check(candidate):\n assert candidate(nums = [-2,0,2], s = \"RLL\", d = 3) == 8\n assert candidate(nums = [1,0], s = \"RL\", d = 2) == 5\n\n\ncheck(Solution().sumDistance)"}
coding
394
Solve the programming task below in a Python markdown code block. # Task You have two sorted arrays `a` and `b`, merge them to form new array of unique items. If an item is present in both arrays, it should be part of the resulting array if and only if it appears in both arrays the same number of times. # Example ...
{"functional": "_inputs = [[[10, 10, 10, 15, 20, 20, 25, 25, 30, 7000], [10, 15, 20, 20, 27, 7200]], [[500, 550, 1000, 1000, 1400, 3500], [2, 2, 2, 2, 3, 1500]], [[5], [5, 5, 7]]]\n_outputs = [[[15, 20, 25, 27, 30, 7000, 7200]], [[2, 3, 500, 550, 1000, 1400, 1500, 3500]], [[7]]]\nimport math\ndef _deep_eq(a, b, tol=1e-...
coding
318
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. You are given an array of N integers. Find the *minimum* number of integers you need to delete from the array such that the absolute difference between each pair of intege...
{"inputs": ["3\n2\n1 2\n5\n2 5 1 2 2\n4\n1 2 1 2"], "outputs": ["0\n2\n2"]}
coding
423
Solve the programming task below in a Python markdown code block. Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply this time machine to a well-known data structure: multiset. Artem wants to create a basic multiset of int...
{"inputs": ["3\n1 1 1\n2 2 1\n3 6 1\n", "3\n1 1 1\n3 2 1\n3 7 1\n", "3\n1 1 1\n3 2 0\n3 7 1\n", "3\n1 1 1\n1 2 1\n3 3 1\n", "3\n1 1 1\n2 2 1\n3 7 1\n", "3\n1 1 1\n2 2 1\n3 9 1\n", "3\n1 1 1\n1 2 1\n3 9 1\n", "3\n1 1 1\n3 2 2\n3 7 1\n"], "outputs": ["0\n", "1\n1\n", "0\n1\n", "2\n", "0\n", "0\n", "2\n", "0\n1\n"]}
coding
706
Solve the programming task below in a Python markdown code block. Today, puppy Tuzik is going to a new dog cinema. He has already left his home and just realised that he forgot his dog-collar! This is a real problem because the city is filled with catchers looking for stray dogs. A city where Tuzik lives in can be cons...
{"inputs": ["2 3\n1 2\n0 1\nRDL"], "outputs": ["4\n6\n6"]}
coding
681
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n binary matrix grid. A move consists of choosing any row or column and toggling each value in that row or column (i.e., changing all 0's to 1's, and all 1's to 0's). Every row of the matrix is in...
{"functional": "def check(candidate):\n assert candidate(grid = [[0,0,1,1],[1,0,1,0],[1,1,0,0]]) == 39\n assert candidate(grid = [[0]]) == 1\n\n\ncheck(Solution().matrixScore)"}
coding
144
Solve the programming task below in a Python markdown code block. For an array b of length m we define the function f as f(b) = \begin{cases} b[1] & if m = 1 \\\ f(b[1] ⊕ b[2],b[2] ⊕ b[3],...,b[m-1] ⊕ b[m]) & otherwise, \end{cases} where ⊕ is [bitwise exclusive OR](https://en.wikipedia.org/wiki/Bitwise_opera...
{"inputs": ["3\n5 4 1\n2\n2 3\n1 2\n", "3\n5 4 0\n2\n2 3\n1 2\n", "3\n2 4 0\n2\n2 3\n1 2\n", "3\n5 7 1\n2\n2 3\n1 2\n", "3\n2 4 1\n2\n2 3\n1 3\n", "3\n6 4 1\n2\n2 3\n1 3\n", "3\n8 8 1\n2\n2 3\n1 2\n", "3\n5 3 1\n2\n2 3\n1 2\n"], "outputs": ["5\n5\n", "4\n5\n", "4\n6\n", "7\n7\n", "5\n6\n", "5\n7\n", "9\n8\n", "3\n6\n"]...
coding
513
Solve the programming task below in a Python markdown code block. There are $N$ sabotages available in the game Among Us, initially all at level $0$. $N$ imposters are allotted the task to upgrade the level of the sabotages. The $i^{th}$ imposter $(1 \leq i \leq N)$ increases the level of $x^{th}$ sabotage $(1 \leq x...
{"inputs": ["1\n6"], "outputs": ["0"]}
coding
335
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed binary arrays nums1 and nums2. Find the widest pair of indices (i, j) such that i <= j and nums1[i] + nums1[i+1] + ... + nums1[j] == nums2[i] + nums2[i+1] + ... + nums2[j]. The widest pair ...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,1,0,1], nums2 = [0,1,1,0]) == 3\n assert candidate(nums1 = [0,1], nums2 = [1,1]) == 1\n assert candidate(nums1 = [0], nums2 = [1]) == 0\n\n\ncheck(Solution().widestPairOfIndices)"}
coding
184
Solve the programming task below in a Python markdown code block. Jack loved his house very much, because his lovely cats take a nap on the wall of his house almost every day. Jack loved cats very much. Jack decided to keep an observation diary of the cats as a free study during the summer vacation. After observing fo...
{"inputs": ["4 6\ns 0 2\ns 1 2\ns 2 1\nw 0\ns 3 3\ns 4 2\n3 3\ns 0 1\ns 1 1\ns 2 1\n0 0", "4 6\ns 0 2\ns 1 3\ns 2 1\nw 0\ns 3 3\ns 4 2\n3 3\ns 0 1\ns 0 1\ns 2 1\n0 0", "4 6\ns 0 2\ns 1 2\ns 2 1\nw 0\ns 3 3\ns 4 2\n4 3\ns 0 1\ns 1 2\ns 2 1\n0 0", "4 6\ns 0 3\ns 1 3\ns 2 1\nw 0\ns 3 3\ns 4 2\n3 3\ns 0 1\ns 1 1\ns 2 1\n0 ...
coding
653
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n employees, each with a unique id from 0 to n - 1. You are given a 2D integer array logs where logs[i] = [idi, leaveTimei] where: idi is the id of the employee that worked on the ith task, and leaveTimei i...
{"functional": "def check(candidate):\n assert candidate(n = 10, logs = [[0,3],[2,5],[0,9],[1,15]]) == 1\n assert candidate(n = 26, logs = [[1,1],[3,7],[2,12],[7,17]]) == 3\n assert candidate(n = 2, logs = [[0,10],[1,20]]) == 0\n\n\ncheck(Solution().hardestWorker)"}
coding
202
Solve the programming task below in a Python markdown code block. Chef and his girlfriend go on a date. Chef took X dollars with him, and was quite sure that this would be enough to pay the bill. At the end, the waiter brought a bill of Y dollars. Print "YES" if Chef has enough money to pay the bill, or "NO" if he has ...
{"inputs": ["4\n1 1\n1 2\n2 1\n50 100\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
coding
399
Solve the programming task below in a Python markdown code block. Sheldon Cooper, Leonard Hofstadter and Penny decide to go for drinks at Cheese cake factory. Sheldon proposes to make a game out of this. Sheldon proposes as follows, To decide the amount of beverage they plan to consume, say X. Then order for a random...
{"inputs": ["4\n4 3 25 5\n33", "4\n55 45 2 23\n58", "7\n2 5 4 9 7 33 6\n44", "6\n45 55 5 7 23 4\n107", "8\n4 8 9 7 45 6 3 27\n56", "8\n4 8 9 7 45 6 3 27\n156"], "outputs": ["True", "False", "True", "True", "True", "False"]}
coding
370
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of non-negative integers arr, you are initially positioned at start index of the array. When you are at index i, you can jump to i + arr[i] or i - arr[i], check if you can reach any index with value 0. ...
{"functional": "def check(candidate):\n assert candidate(arr = [4,2,3,0,3,1,2], start = 5) == True\n assert candidate(arr = [4,2,3,0,3,1,2], start = 0) == True \n assert candidate(arr = [3,0,2,1,2], start = 2) == False\n\n\ncheck(Solution().canReach)"}
coding
123
Solve the programming task below in a Python markdown code block. You are given two integers $a$ and $b$. You may perform any number of operations on them (possibly zero). During each operation you should choose any positive integer $x$ and set $a := a - x$, $b := b - 2x$ or $a := a - 2x$, $b := b - x$. Note that you ...
{"inputs": ["1\n29 2\n", "1\n24 2\n", "1\n24 1\n", "1\n21 2\n", "1\n16 0\n", "1\n20 0\n", "1\n31 0\n", "1\n35 0\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
438
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.   Please complete the following pyt...
{"functional": "def check(candidate):\n assert candidate(s = \"eleetminicoworoep\") == 13\n assert candidate(s = \"leetcodeisgreat\") == 5\n assert candidate(s = \"bcbcbc\") == 6\n\n\ncheck(Solution().findTheLongestSubstring)"}
coding
98
Solve the programming task below in a Python markdown code block. Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more a...
{"inputs": ["2\n1 0\n", "2\n0 1\n", "2\n0 1\n", "2\n1 0\n", "3\n0 1 0\n", "3\n0 0 1\n", "3\n0 1 1\n", "3\n1 0 0\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "1\n"]}
coding
564
Solve the programming task below in a Python markdown code block. Two friends like to pool their money and go to the ice cream parlor. They always choose two distinct flavors and they spend all of their money. Given a list of prices for the flavors of ice cream, select the two that will cost all of the money they hav...
{"inputs": ["2\n4\n5\n1 4 5 3 2\n4 \n4\n2 2 4 3\n"], "outputs": ["1 4\n1 2\n"]}
coding
668
Solve the programming task below in a Python markdown code block. Division of Big Integers Given two integers $A$ and $B$, compute the quotient, $\frac{A}{B}$. Round down to the nearest decimal. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the quotient in a line. ...
{"inputs": ["9 6", "2 1", "1 4", "2 4", "2 2", "5 3", "5 6", "9 8"], "outputs": ["1\n", "2\n", "0\n", "0\n", "1\n", "1\n", "0\n", "1\n"]}
coding
205
Solve the programming task below in a Python markdown code block. Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when represent...
{"inputs": ["1 3", "1 6", "3 2", "4 5", "1 2", "3 10", "3 14", "2 14"], "outputs": ["3\n", "6\n", "2\n", "5\n", "2", "10\n", "14\n", "7\n"]}
coding
295
Solve the programming task below in a Python markdown code block. The life goes up and down, just like nice sequences. Sequence t_1, t_2, ..., t_{n} is called nice if the following two conditions are satisfied: t_{i} < t_{i} + 1 for each odd i < n; t_{i} > t_{i} + 1 for each even i < n. For example, sequences (2, ...
{"inputs": ["2\n5 1\n", "2\n5 1\n", "2\n5 2\n", "2\n5 4\n", "2\n10 10\n", "2\n10 10\n", "5\n2 8 4 7 7\n", "5\n1 1 1 4 3\n"], "outputs": ["1\n", "1", "1\n", "1\n", "0\n", "0", "2\n", "1\n"]}
coding
559
Solve the programming task below in a Python markdown code block. A string S is called *Chef's favourite* if every substring chef in S must have a substring code before it. You are given a string S of size N that contains both code and chef as a substring. Please determine if S is Chef's favourite. Note: A substring ...
{"inputs": ["4\n8\ncodechef\n8\nchefcode\n14\nsxycodeghychef\n21\nsxychefvsvcodehghchef\n"], "outputs": ["AC\nWA\nAC\nWA\n"]}
coding
374
Solve the programming task below in a Python markdown code block. Cherry has a string S$S$ consisting of lowercase English letters. Using this string, he formed a pyramid of infinite length with certain rules: - N$N$-th row of pyramid contains N$N$ characters. - Each row of pyramid begins with the first character of th...
{"inputs": ["codechef\nchefcode\n3\n4\n12\n1455"], "outputs": ["0\n1\n181"]}
coding
619
Solve the programming task below in a Python markdown code block. Seven is a hungry number and its favourite food is number 9. Whenever it spots 9 through the hoops of 8, it eats it! Well, not anymore, because you are going to help the 9 by locating that particular sequence (7,8,9) in an array of digits and tell 7 to ...
{"functional": "_inputs = [[[7, 8, 9]], [[7, 7, 7, 8, 9]], [[8, 7, 8, 9, 8, 9, 7, 8]], [[8, 7, 8, 7, 9, 8]]]\n_outputs = [[[8, 9, 7]], [[8, 9, 7, 7, 7]], [[8, 8, 9, 8, 9, 7, 7, 8]], [[8, 7, 8, 7, 9, 8]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ma...
coding
134
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 consisting of an equal number of positive and negative integers. You should return the array of nums such that the the array follows the given conditions: E...
{"functional": "def check(candidate):\n assert candidate(nums = [3,1,-2,-5,2,-4]) == [3,-2,1,-5,2,-4]\n assert candidate(nums = [-1,1]) == [1,-1]\n\n\ncheck(Solution().rearrangeArray)"}
coding
146
Solve the programming task below in a Python markdown code block. When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1,...
{"inputs": ["2\n1 2\n", "4\n2 4 4 3\n", "6\n5 5 4 4 3 3\n"], "outputs": ["2\n1\n", "4\n3\n3\n4\n", "4\n4\n4\n4\n4\n4\n"]}
coding
396
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. You must implement a solution with a linear runtime complexity and use only constant extra space.   Please co...
{"functional": "def check(candidate):\n assert candidate(nums = [2,2,1]) == 1\n assert candidate(nums = [4,1,2,1,2]) == 4\n assert candidate(nums = [1]) == 1\n\n\ncheck(Solution().singleNumber)"}
coding
91
Solve the programming task below in a Python markdown code block. Given are two strings S and T consisting of lowercase English letters. Concatenate T and S in this order, without space in between, and print the resulting string. -----Constraints----- - S and T are strings consisting of lowercase English letters. - ...
{"inputs": ["c a\n", "oder atb", "redo atb", "redp atb", "redp bta", "redo bta", "redo bat", "redo b`t"], "outputs": ["ac\n", "atboder\n", "atbredo\n", "atbredp\n", "btaredp\n", "btaredo\n", "batredo\n", "b`tredo\n"]}
coding
145
Solve the programming task below in a Python markdown code block. You are given two positive integers $a$ and $b$. In one move, you can change $a$ in the following way: Choose any positive odd integer $x$ ($x > 0$) and replace $a$ with $a+x$; choose any positive even integer $y$ ($y > 0$) and replace $a$ with $a-y...
{"inputs": ["1\n164 94\n", "1\n224 94\n", "1\n80398 6\n", "1\n76711 6\n", "1\n76711 2\n", "1\n22528 2\n", "1\n22528 1\n", "1\n27854 1\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "2\n", "2\n"]}
coding
423
Solve the programming task below in a Python markdown code block. The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students. The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$...
{"inputs": ["3\n2 3 4\n1 2 3\n", "3\n2 3 4\n1 2 3\n", "3\n2 3 2\n0 2 3\n", "3\n2 3 2\n1 2 3\n", "3\n2 3 2\n0 0 3\n", "3\n2 3 1\n0 0 3\n", "3\n0 3 1\n0 0 3\n", "3\n0 3 1\n0 0 2\n"], "outputs": ["3\n", "3\n", "2\n", "1\n", "3\n", "2\n", "2\n", "2\n"]}
coding
347
Please solve the programming task below using a self-contained code snippet in a markdown code block. The k-beauty of an integer num is defined as the number of substrings of num when it is read as a string that meet the following conditions: It has a length of k. It is a divisor of num. Given integers num and k, re...
{"functional": "def check(candidate):\n assert candidate(num = 240, k = 2) == 2\n assert candidate(num = 430043, k = 2) == 2\n\n\ncheck(Solution().divisorSubstrings)"}
coding
139
Solve the programming task below in a Python markdown code block. Vasya plays the Need For Brake. He plays because he was presented with a new computer wheel for birthday! Now he is sure that he will win the first place in the championship in his favourite racing computer game! n racers take part in the championship,...
{"inputs": ["2\nteama 10\nteamb 10\n2\n10 10\nteamb\n", "3\nteama 10\nteamb 20\nteamc 40\n2\n10 20\nteama\n", "5\nteamc 8\nteamd 7\nteame 15\nteama 3\nteamb 21\n3\n1 2 3\nteamb\n", "5\nteamc 4\nteamd 7\nteame 15\nteama 3\nteamb 21\n3\n1 2 3\nteamb\n", "5\ntaemc 4\nteamd 7\nteame 15\nteama 3\nteamb 21\n3\n1 2 3\nteamb\n...
coding
464
Solve the programming task below in a Python markdown code block. Some new cashiers started to work at your restaurant. They are good at taking orders, but they don't know how to capitalize words, or use a space bar! All the orders they create look something like this: `"milkshakepizzachickenfriescokeburgerpizzasa...
{"functional": "_inputs = [['burgerfriesfriesfriesfriesfriespizzasandwichcokefriesburger']]\n_outputs = [['Burger Burger Fries Fries Fries Fries Fries Fries Pizza Sandwich Coke']]\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...
coding
237
Please solve the programming task below using a self-contained code snippet in a markdown code block. In LeetCode Store, there are n items to sell. Each item has a price. However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price. You are given an int...
{"functional": "def check(candidate):\n assert candidate(price = [2,5], special = [[3,0,5],[1,2,10]], needs = [3,2]) == 14\n assert candidate(price = [2,3,4], special = [[1,1,0,4],[2,2,1,9]], needs = [1,2,1]) == 11\n\n\ncheck(Solution().shoppingOffers)"}
coding
270
Solve the programming task below in a Python markdown code block. Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year... $n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $...
{"inputs": ["1\n1\n", "1\n1\n", "2\n1 1\n", "2\n1 2\n", "2\n1 2\n", "2\n1 1\n", "2\n2 2\n", "2\n2 1\n"], "outputs": ["1 1\n", "1 1\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n"]}
coding
663
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s of even length. Split this string into two halves of equal lengths, and let a be the first half and b be the second half. Two strings are alike if they have the same number of vowels ('a', 'e'...
{"functional": "def check(candidate):\n assert candidate(s = \"book\") == True\n assert candidate(s = \"textbook\") == False\n\n\ncheck(Solution().halvesAreAlike)"}
coding
148
Solve the programming task below in a Python markdown code block. # Task John won the championship of a TV show. He can get some bonuses. He needs to play a game to determine the amount of his bonus. Here are `n` rows and `m` columns of cards were placed on the ground. A non-negative number is written on each card. ...
{"functional": "_inputs = [[[[1, 3, 9], [2, 8, 5], [5, 7, 4]]], [[[11, 72, 38], [80, 69, 65], [68, 96, 99]]], [[[1, 5, 1, 1], [1, 5, 5, 1], [5, 5, 5, 1], [1, 1, 5, 1]]], [[[0, 0, 2, 3, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 4, 0, 0], [0, 0, 0, 0, 4, 0, 0], [0, 0, 2, ...
coding
434
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of intervals, where intervals[i] = [starti, endi] and each starti is unique. The right interval for an interval i is an interval j such that startj >= endi and startj is minimized. Note that i m...
{"functional": "def check(candidate):\n assert candidate(intervals = [[1,2]]) == [-1]\n assert candidate(intervals = [[3,4],[2,3],[1,2]]) == [-1,0,1]\n assert candidate(intervals = [[1,4],[2,3],[3,4]]) == [-1,2,-1]\n\n\ncheck(Solution().findRightInterval)"}
coding
138
Solve the programming task below in a Python markdown code block. Given an array $a$ of length $n$ and an integer $k$, you are tasked to find any two numbers $l$ and $r$ ($l \leq r$) such that: For each $x$ $(l \leq x \leq r)$, $x$ appears in $a$ at least $k$ times (i.e. $k$ or more array elements are equal to $x$). ...
{"inputs": ["1\n1 1\n114514\n", "4\n7 2\n11 11 12 13 13 14 14\n5 1\n6 3 5 2 1\n6 4\n4 3 4 3 3 4\n14 2\n1 1 2 2 2 3 3 3 3 4 4 4 4 4\n"], "outputs": ["114514 114514\n", "13 14\n1 3\n-1\n1 4\n"]}
coding
679
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array nums consisting of positive integers. You can choose two indices i and j, such that i != j, and the sum of digits of the number nums[i] is equal to that of nums[j]. Return the maximum v...
{"functional": "def check(candidate):\n assert candidate(nums = [18,43,36,13,7]) == 54\n assert candidate(nums = [10,12,19,14]) == -1\n\n\ncheck(Solution().maximumSum)"}
coding
125
Solve the programming task below in a Python markdown code block. You are given a permutation$^\dagger$ $p$ of length $n$. In one operation, you can choose two indices $1 \le i < j \le n$ and swap $p_i$ with $p_j$. Find the minimum number of operations needed to have exactly one inversion$^\ddagger$ in the permutatio...
{"inputs": ["1\n10\n9 6 7 10 3 2 1 4 5 8\n", "4\n2\n2 1\n2\n1 2\n4\n3 4 1 2\n4\n2 4 3 1\n"], "outputs": ["8\n", "0\n1\n3\n1\n"]}
coding
650
Solve the programming task below in a Python markdown code block. Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applicati...
{"inputs": ["300000 1\n2 44767\n", "300000 1\n1 300000\n", "300000 1\n2 300000\n", "3 4\n1 3\n1 1\n1 3\n2 3\n", "3 4\n2 3\n1 1\n1 3\n2 3\n", "3 4\n2 3\n2 1\n1 3\n2 3\n", "3 4\n2 3\n2 1\n2 3\n2 3\n", "3 4\n1 3\n1 2\n1 2\n2 3\n"], "outputs": ["0\n", "1\n", "0\n", "1\n2\n3\n1\n", "0\n1\n2\n1\n", "0\n0\n1\n0\n", "0\n0\n0\n...
coding
672
Solve the programming task below in a Python markdown code block. Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a ...
{"inputs": ["4 7\n", "4 9\n", "1 1\n", "4 6\n", "1 1\n", "1 2\n", "1 3\n", "1 4\n"], "outputs": ["2\n", "3\n", "1\n", "2\n", "1\n", "2\n", "3\n", "4\n"]}
coding
418