task_type
stringclasses
4 values
problem
stringlengths
14
5.23k
solution
stringlengths
1
8.29k
problem_tokens
int64
9
1.02k
solution_tokens
int64
1
1.98k
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed arrays of strings startWords and targetWords. Each string consists of lowercase English letters only. For each string in targetWords, check if it is possible to choose a string from startWo...
{"functional": "def check(candidate):\n assert candidate(startWords = [\"ant\",\"act\",\"tack\"], targetWords = [\"tack\",\"act\",\"acti\"]) == 2\n assert candidate(startWords = [\"ab\",\"a\"], targetWords = [\"abc\",\"abcd\"]) == 1\n\n\ncheck(Solution().wordCount)"}
311
80
coding
Solve the programming task below in a Python markdown code block. You are given N non-negative integers A_1, A_2, ..., A_N and another non-negative integer K. For a integer X between 0 and K (inclusive), let f(X) = (X XOR A_1) + (X XOR A_2) + ... + (X XOR A_N). Here, for non-negative integers a and b, a XOR b denotes t...
{"inputs": ["3 7\n1 6 3\n", "4 9\n7 4 0 3\n", "1 0\n1000000000000\n"], "outputs": ["14\n", "46\n", "1000000000000\n"]}
388
78
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, return the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through th...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,4,5])) == 3\n assert candidate(root = tree_node([1,2])) == 1\n\n\ncheck(Solution().diameterOfBinaryTree)"}
170
60
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Suppose we have a file system that stores both files and directories. An example of one system is represented in the following picture: Here, we have dir as the only directory in the root. dir contains two subdirecto...
{"functional": "def check(candidate):\n assert candidate(input = \"dir\\n\\tsubdir1\\n\\tsubdir2\\n\\t\\tfile.ext\") == 20\n assert candidate(input = \"dir\\n\\tsubdir1\\n\\t\\tfile1.ext\\n\\t\\tsubsubdir1\\n\\tsubdir2\\n\\t\\tsubsubdir2\\n\\t\\t\\tfile2.ext\") == 32\n assert candidate(input = \"a\") == 0\n ...
438
160
coding
Solve the programming task below in a Python markdown code block. Polycarp has $n$ friends, the $i$-th of his friends has $a_i$ candies. Polycarp's friends do not like when they have different numbers of candies. In other words they want all $a_i$ to be the same. To solve this, Polycarp performs the following set of ac...
{"inputs": ["1\n2\n1 691\n", "1\n2\n1 691\n", "1\n3\n1 1 67\n", "1\n3\n1 1 67\n", "1\n3\n1 1 65\n", "1\n3\n0 1 65\n", "1\n3\n0 1 91\n", "1\n3\n0 0 91\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "-1\n", "1\n", "-1\n", "-1\n"]}
712
140
coding
Solve the programming task below in a Python markdown code block. Given an integer $n$. Consider all pairs of integer arrays $a$ and $p$ of the same length such that $n = \prod a_i^{p_i}$ (i.e. $a_1^{p_1}\cdot a_2^{p_2}\cdot\ldots$) ($a_i>1;p_i>0$) and $a_i$ is the product of some (possibly one) distinct prime numbers...
{"inputs": ["7\n100\n10\n864\n130056192\n1000000000\n2\n999999018\n"], "outputs": ["20\n10\n22\n118\n90\n2\n333333009\n"]}
615
84
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Alice and Bob, both have to drink water. But they both don't want to go, so they will play a game to decide who will fetch water for both of them. Alice will choose a number randomly between 1 ...
{"inputs": ["3\n1 1\n1 2\n2 3", "3\n1 1\n1 3\n2 3", "3\n1 2\n1 3\n2 3", "3\n1 1\n1 1\n2 3", "3\n1 1\n2 1\n2 3", "3\n1 3\n1 3\n2 2", "3\n1 1\n2 1\n1 3", "3\n1 2\n2 1\n2 3"], "outputs": ["0/1\n1/2\n1/2", "0/1\n1/3\n1/2\n", "1/2\n1/3\n1/2\n", "0/1\n0/1\n1/2\n", "0/1\n1/2\n1/2\n", "1/3\n1/3\n1/2\n", "0/1\n1/2\n1/3\n", "1/2...
428
237
coding
Solve the programming task below in a Python markdown code block. Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome. Examples: Non-string inputs should be converted to strings. Return an array...
{"functional": "_inputs = [[['bat', 'tab', 'cat']], [['dog', 'cow', 'tap', 'god', 'pat']], [['abcd', 'dcba', 'lls', 's', 'sssll']], [[]], [['adgdfsh', 'wertewry', 'zxcbxcb', 'efveyn']], [[5, 2, 'abc', True, [False]]], [[5777, 'dog', 'god', True, 75]]]\n_outputs = [[[[0, 1], [1, 0]]], [[[0, 3], [2, 4], [3, 0], [4, 2]]],...
123
338
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Russian] and [Mandarin Chinese]. Given the time control of a chess match as a + b, determine which format of chess out of the given 4 it belongs to. 1) Bullet if a + b < 3 2) Blitz if 3 ≤ a + b ≤ 10 3) Rapid if 11 ≤ a +...
{"inputs": ["4\n1 0\n4 1\n100 0\n20 5\n"], "outputs": ["1\n2\n4\n3"]}
319
38
coding
Solve the programming task below in a Python markdown code block. You're given an array $a$. You should repeat the following operation $k$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. -----I...
{"inputs": ["2 5\n2 3\n", "2 5\n2 3\n", "2 5\n4 3\n", "2 1\n4 3\n", "3 5\n1 2 3\n", "3 7\n1 2 3\n", "3 1\n6 1 7\n", "3 1\n6 6 7\n"], "outputs": ["2\n1\n0\n0\n0\n", "2\n1\n0\n0\n0\n", "3\n1\n0\n0\n0\n", "3\n", "1\n1\n1\n0\n0\n", "1\n1\n1\n0\n0\n0\n0\n", "1\n", "6\n"]}
407
170
coding
Solve the programming task below in a Python markdown code block. For encrypting strings this region of chars is given (in this order!): * all letters (ascending, first all UpperCase, then all LowerCase) * all digits (ascending) * the following chars: `.,:;-?! '()$%&"` These are 77 chars! (This region is zero-based....
{"functional": "_inputs = [[\"$-Wy,dM79H'i'o$n0C&I.ZTcMJw5vPlZc Hn!krhlaa:khV mkL;gvtP-S7Rt1Vp2RV:wV9VuhO Iz3dqb.U0w\"], ['5MyQa9p0riYplZc'], [\"5MyQa79H'ijQaw!Ns6jVtpmnlZ.V6p\"], [''], [None]]\n_outputs = [['Do the kata \"Kobayashi-Maru-Test!\" Endless fun and excitement when finding a solution!'], ['This is a test!']...
508
307
coding
Solve the programming task below in a Python markdown code block. Your task is to write an update for a lottery machine. Its current version produces a sequence of random letters and integers (passed as a string to the function). Your code must filter out all letters and return **unique** integers as a string, in their...
{"functional": "_inputs = [['wQ8Hy0y5m5oshQPeRCkG'], ['ffaQtaRFKeGIIBIcSJtg'], ['555'], ['HappyNewYear2020'], ['20191224isXmas'], ['']]\n_outputs = [['805'], ['One more run!'], ['5'], ['20'], ['20194'], ['One more run!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\...
168
239
coding
Solve the programming task below in a Python markdown code block. You already know that Valery's favorite sport is biathlon. Due to your help, he learned to shoot without missing, and his skills are unmatched at the shooting range. But now a smaller task is to be performed, he should learn to complete the path fastest....
{"inputs": ["1 2 4\nST\n", "1 2 1\nST\n", "2 1 4\nS\nT\n", "1 3 3\nSaT\n", "2 1 1\nS\nT\n", "1 3 3\nTyS\n", "1 4 1\nSxyT\n", "3 3 1\naaa\naaa\nTSa\n"], "outputs": ["\n", "\n", "\n", "a\n", "\n", "y\n", "-1\n", "\n"]}
592
127
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A truck has two fuel tanks. You are given two integers, mainTank representing the fuel present in the main tank in liters and additionalTank representing the fuel present in the additional tank in liters. The truck ha...
{"functional": "def check(candidate):\n assert candidate(mainTank = 5, additionalTank = 10) == 60\n assert candidate(mainTank = 1, additionalTank = 2) == 10\n\n\ncheck(Solution().distanceTraveled)"}
184
61
coding
Solve the programming task below in a Python markdown code block. A string of length 6 consisting of lowercase English letters is said to be coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th and 6-th characters are also equal. Given a string S, determine whether it is coffee-like. -----Co...
{"inputs": ["cofgee", "sjppvv", "uuppis", "ephoni", "cofgef", "uvppis", "eohoni", "fegfoc"], "outputs": ["No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
169
78
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums of even length. As long as nums is not empty, you must repetitively: Find the minimum number in nums and remove it. Find the maximum number in nums and remove it. Calculat...
{"functional": "def check(candidate):\n assert candidate(nums = [4,1,4,0,3,5]) == 2\n assert candidate(nums = [1,100]) == 1\n\n\ncheck(Solution().distinctAverages)"}
183
58
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed 1-dimensional (1D) integer array original, and two integers, m and n. You are tasked with creating a 2-dimensional (2D) array with m rows and n columns using all the elements from original. ...
{"functional": "def check(candidate):\n assert candidate(original = [1,2,3,4], m = 2, n = 2) == [[1,2],[3,4]]\n assert candidate(original = [1,2,3], m = 1, n = 3) == [[1,2,3]]\n assert candidate(original = [1,2], m = 1, n = 1) == []\n assert candidate(original = [3], m = 1, n = 2) == []\n\n\ncheck(Solution(...
205
135
coding
Solve the programming task below in a Python markdown code block. Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than $a$ and screen height not greater than $b$. Monocarp is also used to TV sets with...
{"inputs": ["4 2 6 4\n", "1 1 1 1\n", "3 3 2 4\n", "3 3 2 6\n", "4 2 4 3\n", "5 5 1 1\n", "3 3 2 4\n", "4 2 4 3\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "0\n", "5\n", "1\n", "0\n"]}
628
118
coding
Solve the programming task below in a Python markdown code block. Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To in...
{"inputs": ["1 1 1\n1 1\n", "1 2 1\n2 2\n", "1 1 1\n1 1\n", "1 2 1\n2 2\n", "1 3 1\n2 2\n", "1 1 1\n0 1\n", "1 5 1\n2 2\n", "1 5 1\n2 4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "0\n", "0\n"]}
373
134
coding
Solve the programming task below in a Python markdown code block. Given a square grid of characters in the range ascii[a-z], rearrange elements of each row alphabetically, ascending. Determine if the columns are also in ascending alphabetical order, top to bottom. Return YES if they are or NO if they are not. Exampl...
{"inputs": ["1\n5\nebacd\nfghij\nolmkn\ntrpqs\nxywuv\n"], "outputs": ["YES\n"]}
519
36
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation. Note: You are not allowed to use any built-in function which evaluates strings as...
{"functional": "def check(candidate):\n assert candidate(s = \"1 + 1\") == 2\n assert candidate(s = \" 2-1 + 2 \") == 3\n assert candidate(s = \"(1+(4+5+2)-3)+(6+8)\") == 23\n\n\ncheck(Solution().calculate)"}
94
79
coding
Solve the programming task below in a Python markdown code block. While Alice was drinking sugarcane juice, she started wondering about the following facts: The juicer sells each glass of sugarcane juice for 50 coins. He spends 20\% of his total income on buying sugarcane. He spends 20\% of his total income on buying s...
{"inputs": ["4\n2\n4\n5\n10\n"], "outputs": ["30\n60\n75\n150\n"]}
624
34
coding
Solve the programming task below in a Python markdown code block. A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly $n$ minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by ...
{"inputs": ["1 1\n-1\n", "1 1\n-1\n", "1 2\n1 -1\n", "1 2\n-1 1\n", "1 2\n-1 1\n", "1 2\n1 -1\n", "2 2\n1 -1\n", "1 1\n-1000000\n"], "outputs": ["1\n", "1\n", "-1\n", "1\n", "1\n", "-1\n", "-1\n", "1\n"]}
510
123
coding
Solve the programming task below in a Python markdown code block. There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Eac...
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n6\n", "3\n1\n2\n4\n", "3\n1\n2\n4\n", "4\n1\n1\n1\n2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "3\n"]}
268
100
coding
Solve the programming task below in a Python markdown code block. Given the coordinates (x, y) of a point in 2-D plane. Find if it is possible to reach (x, y) from (0, 0). The only possible moves from any coordinate (i, j) are as follows: Go to the point with coordinates (i + 1, j + 1). Go to the point with coordina...
{"inputs": ["6\n0 2\n1 2\n-1 -3\n-1 0\n-3 1\n2 -1\n"], "outputs": ["YES\nNO\nYES\nNO\nYES\nNO\n"]}
457
51
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will write a function `doubles` that will remove double string characters that are adjacent to each other. For example: `doubles('abbcccdddda') = 'aca'`, because, from left to right: ```Haskell a) There is only one 'a' on the left han...
{"functional": "_inputs = [['abbbzz'], ['zzzzykkkd'], ['abbcccdddda'], ['vvvvvoiiiiin'], ['rrrmooomqqqqj'], ['xxbnnnnnyaaaaam'], ['qqqqqqnpppgooooonpppppqmmmmmc'], ['qqqqqwwwx'], ['jjjfzzzzzzsddgrrrrru'], ['jjjjjfuuuutgggggqppdaaas'], ['iiiiibllllllyqqqqqbiiiiiituuf'], ['mmmmmmuzzqllllmqqqp']]\n_outputs = [['ab'], ['yk...
265
332
coding
Solve the programming task below in a Python markdown code block. To protect people from evil, a long and tall wall was constructed a few years ago. But just a wall is not safe, there should also be soldiers on it, always keeping vigil. The wall is very long and connects the left and the right towers. There are ex...
{"inputs": ["4\n3 8\n3 9\n2 4\n5 25"], "outputs": ["0\n0\n-1\n5"]}
603
36
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integers m and n representing a 0-indexed m x n grid. You are also given two 2D integer arrays guards and walls where guards[i] = [rowi, coli] and walls[j] = [rowj, colj] represent the positions of t...
{"functional": "def check(candidate):\n assert candidate(m = 4, n = 6, guards = [[0,0],[1,1],[2,3]], walls = [[0,1],[2,2],[1,4]]) == 7\n assert candidate(m = 3, n = 3, guards = [[1,1]], walls = [[0,1],[1,0],[2,1],[1,2]]) == 4\n\n\ncheck(Solution().countUnguarded)"}
197
112
coding
Solve the programming task below in a Python markdown code block. Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food. Iahu...
{"inputs": ["1\n1\n", "2\n1 2\n", "2\n2 2\n", "2\n2 3\n", "2\n2 1\n", "4\n1 1 1 3\n", "4\n1 2 1 4\n", "4\n1 1 1 2\n"], "outputs": ["YES", "NO", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
318
110
coding
Solve the programming task below in a Python markdown code block. Vasya commutes by train every day. There are n train stations in the city, and at the i-th station it's possible to buy only tickets to stations from i + 1 to a_{i} inclusive. No tickets are sold at the last station. Let ρ_{i}, j be the minimum number o...
{"inputs": ["2\n2\n", "2\n2\n", "3\n3 3\n", "3\n3 3\n", "3\n2 3\n", "4\n4 4 4\n", "4\n3 3 4\n", "4\n3 3 4\n"], "outputs": ["1\n", "1\n", "3\n", "3\n", "4\n", "6\n", "8\n", "8\n"]}
495
104
coding
Solve the programming task below in a Python markdown code block. Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau". To play Mau-Mau, you need a pack of $52$ c...
{"inputs": ["AS\n2H 4C TH JH AD\n", "2H\n3D 4C AC KD AS\n", "4D\nAS AC AD AH 5H\n", "3D\n8S 4S 2C AS 6H\n", "7H\nTC 4C KC AD 9S\n", "KH\n3C QD 9S KS 8D\n", "4H\nJH QC 5H 9H KD\n", "9H\nKC 6D KD 4C 2S\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n"]}
578
161
coding
Solve the programming task below in a Python markdown code block. [Haikus](https://en.wikipedia.org/wiki/Haiku_in_English) are short poems in a three-line format, with 17 syllables arranged in a 5–7–5 pattern. Your task is to check if the supplied text is a haiku or not. ### About syllables [Syllables](https://en.wi...
{"functional": "_inputs = [['An old silent pond...\\nA frog jumps into the pond,\\nsplash! Silence again.'], ['An old silent pond...\\nA frog jumps into the pond, splash!\\nSilence again.'], ['An old silent pond...\\nA frog jumps into the pond,\\nsplash!\\nSilence again.'], ['An old silent pond... A frog jumps into the...
571
370
coding
Solve the programming task below in a Python markdown code block. Let $s$ be some string consisting of symbols "0" or "1". Let's call a string $t$ a substring of string $s$, if there exists such number $1 \leq l \leq |s| - |t| + 1$ that $t = s_l s_{l+1} \ldots s_{l + |t| - 1}$. Let's call a substring $t$ of string $s$ ...
{"inputs": ["4 4\n", "5 3\n", "7 3\n", "1 1\n", "2 2\n", "3 3\n", "3 1\n", "4 2\n"], "outputs": ["1111", "01010", "0010010", "1", "11", "111", "010", "0101"]}
673
99
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell. The distance between two adjacent cells is 1.   Please complete the following python code precisely: ```python class Solution: ...
{"functional": "def check(candidate):\n assert candidate(mat = [[0,0,0],[0,1,0],[0,0,0]]) == [[0,0,0],[0,1,0],[0,0,0]]\n assert candidate(mat = [[0,0,0],[0,1,0],[1,1,1]]) == [[0,0,0],[0,1,0],[1,2,1]]\n\n\ncheck(Solution().updateMatrix)"}
82
111
coding
Solve the programming task below in a Python markdown code block. Chef has started developing interest in playing chess, and was learning how the [Queen] moves. Chef has an empty N \times N chessboard. He places a Queen at (X, Y) and wonders - What are the number of cells that are under attack by the Queen? Notes: ...
{"inputs": ["5\n1 1 1\n3 2 2\n3 2 1\n2 2 2\n150 62 41\n"], "outputs": ["0\n8\n6\n3\n527\n"]}
529
58
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef likes problems related to numbers a lot. He is generally quite good at solving these kinds of problems, but today he got stuck at one number theory problem, and so he ask...
{"inputs": ["6", "9939"], "outputs": ["1", "4"]}
495
21
coding
Solve the programming task below in a Python markdown code block. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are: 2332 110011 54322345 For a given number ```num```, write a function which returns the number of nu...
{"functional": "_inputs = [[2], [141221001], [1551], [13598], ['ACCDDCCA'], ['1551'], [-4505]]\n_outputs = [[0], [5], [2], [0], ['Not valid'], ['Not valid'], ['Not valid']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, a...
294
217
coding
Solve the programming task below in a Python markdown code block. group() A group() expression returns one or more subgroups of the match. Code >>> import re >>> m = re.match(r'(\w+)@(\w+)\.(\w+)','username@hackerrank.com') >>> m.group(0) # The entire match 'username@hackerrank.com' >>> m.group(1) # Th...
{"inputs": ["..12345678910111213141516171820212223\n"], "outputs": ["1\n"]}
510
49
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col). You are situated in the top-left cell, (0, 0)...
{"functional": "def check(candidate):\n assert candidate(heights = [[1,2,2],[3,8,2],[5,3,5]]) == 2\n assert candidate(heights = [[1,2,3],[3,8,4],[5,3,5]]) == 1\n assert candidate(heights = [[1,2,1,1,1],[1,2,1,2,1],[1,2,1,2,1],[1,2,1,2,1],[1,1,1,2,1]]) == 0\n\n\ncheck(Solution().minimumEffortPath)"}
200
140
coding
Solve the programming task below in a Python markdown code block. A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not. You are given string s consisting of ...
{"inputs": ["u\n", "u\n", "v\n", "w\n", "zza\n", "abb\n", "zaz\n", "acc\n"], "outputs": ["u\n", "u\n", "v\n", "w\n", "zaz\n", "bab\n", "zaz\n", "cac\n"]}
281
73
coding
Solve the programming task below in a Python markdown code block. Guy-Manuel and Thomas have an array $a$ of $n$ integers [$a_1, a_2, \dots, a_n$]. In one step they can add $1$ to any element of the array. Formally, in one step they can choose any integer index $i$ ($1 \le i \le n$) and do $a_i := a_i + 1$. If either ...
{"inputs": ["1\n1\n0\n", "1\n1\n0\n", "4\n3\n2 -1 -1\n4\n-1 0 0 1\n2\n-1 2\n3\n0 -2 1\n", "4\n3\n2 -1 -1\n4\n-2 0 0 1\n2\n-1 2\n3\n0 -2 1\n", "4\n3\n2 -1 -1\n4\n-1 0 0 1\n2\n-1 2\n3\n0 -2 1\n", "1\n50\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 -98\n", "1\n50\n2 2 ...
635
510
coding
Solve the programming task below in a Python markdown code block. There are $b$ boys and $g$ girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and $n$ participants have accepted the invitation. The organizers do not know how many boys and girls are among them. Organ...
{"inputs": ["5\n6\n3\n", "5\n3\n5\n", "1\n1\n1\n", "1\n1\n2\n", "3\n3\n4\n", "4\n4\n5\n", "4\n4\n7\n", "3\n3\n5\n"], "outputs": ["4\n", "4\n", "2\n", "1\n", "3\n", "4\n", "2\n", "2\n"]}
445
102
coding
Solve the programming task below in a Python markdown code block. Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] fo...
{"inputs": ["2"], "outputs": ["1 2\n2 1"]}
400
18
coding
Solve the programming task below in a Python markdown code block. Inna and Dima bought a table of size n × m in the shop. Each cell of the table contains a single letter: "D", "I", "M", "A". Inna loves Dima, so she wants to go through his name as many times as possible as she moves through the table. For that, Inna ac...
{"inputs": ["1 1\nI\n", "1 1\nD\n", "1 1\nM\n", "1 1\nA\n", "1 1\nD\n", "1 1\nM\n", "1 1\nA\n", "1 1\nI\n"], "outputs": ["Poor Dima!\n", "Poor Dima!\n", "Poor Dima!\n", "Poor Dima!\n", "Poor Dima!\n", "Poor Dima!\n", "Poor Dima!\n", "Poor Dima!\n"]}
675
126
coding
Solve the programming task below in a Python markdown code block. Chef's dog Snuffles has so many things to play with! This time around, Snuffles has an array A containing N integers: A1, A2, ..., AN. Bad news: Snuffles only loves to play with an array in which all the elements are equal. Good news: We have a mover of ...
{"inputs": ["3\n5 2\n1 4 5 2 3\n3 1\n1 4 1\n4 2\n3 4 3 5"], "outputs": ["3\n2\n-1"]}
660
53
coding
Solve the programming task below in a Python markdown code block. There are N hills in a row numbered 1 through N from left to right. Each hill has a height; for each valid i, the height of the i-th hill is Hi. Chef is initially on the leftmost hill (hill number 1). He can make an arbitrary number of jumps (including z...
{"inputs": ["3\n5 3 2\n2 5 2 6 3\n5 2 3\n4 4 4 4 4\n5 2 7\n1 4 3 2 1"], "outputs": ["3\n5\n1"]}
616
64
coding
Solve the programming task below in a Python markdown code block. Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l_1 to minute r_1 inclusive. Also, during the minute k she prinks and...
{"inputs": ["6 6 5 8 9\n", "1 1 1 1 1\n", "1 2 3 4 5\n", "1 3 3 5 3\n", "1 2 2 3 5\n", "2 4 3 7 3\n", "2 4 1 2 5\n", "4 6 6 8 9\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "1\n", "1\n", "1\n", "1\n"]}
338
134
coding
Solve the programming task below in a Python markdown code block. This kata focuses on the Numpy python package and you can read up on the Numpy array manipulation functions here: https://docs.scipy.org/doc/numpy-1.13.0/reference/routines.array-manipulation.html You will get two integers `N` and `M`. You must return a...
{"functional": "_inputs = [[10, 1], [10, 3], [10, 97]]\n_outputs = [[[[4, 0, 1, 2, 3], [9, 5, 6, 7, 8]]], [[[2, 3, 4, 0, 1], [7, 8, 9, 5, 6]]], [[[3, 4, 0, 1, 2], [8, 9, 5, 6, 7]]]]\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_t...
269
264
coding
Solve the programming task below in a Python markdown code block. The Story: Aliens from Kepler 27b have immigrated to Earth! They have learned English and go to our stores, eat our food, dress like us, ride Ubers, use Google, etc. However, they speak English a little differently. Can you write a program that converts ...
{"functional": "_inputs = [['codewars'], ['hello']]\n_outputs = [['cudewors'], ['hellu']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): ret...
160
165
coding
Solve the programming task below in a Python markdown code block. You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and s...
{"inputs": ["1\n0 2\n", "1\n0 0\n", "1\n1 0\n", "1\n1 1\n", "1\n1 2\n", "1\n0 79\n", "1\n0 10\n", "1\n0 -1\n"], "outputs": ["3\n", "0\n", "1\n", "0\n", "1\n", "13\n", "4\n", "1\n"]}
413
105
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of strings words and a string chars. A string is good if it can be formed by characters from chars (each character can only be used once). Return the sum of lengths of all good strings in words....
{"functional": "def check(candidate):\n assert candidate(words = [\"cat\",\"bt\",\"hat\",\"tree\"], chars = \"atach\") == 6\n assert candidate(words = [\"hello\",\"world\",\"leetcode\"], chars = \"welldonehoneyr\") == 10\n\n\ncheck(Solution().countCharacters)"}
99
74
coding
Solve the programming task below in a Python markdown code block. Late last night in the Tanner household, ALF was repairing his spaceship so he might get back to Melmac. Unfortunately for him, he forgot to put on the parking brake, and the spaceship took off during repair. Now it's hovering in space. ALF has the tech...
{"functional": "_inputs = [['X'], ['X\\n.'], ['.X\\n..'], ['..\\n.X'], ['..\\nX.'], ['.......\\nX.......'], ['..........\\n..........\\n.......X..\\n..........\\n..........'], ['..........\\n..........\\n..........\\n........X.\\n..........'], ['........................'], ['\\n\\n\\n\\n']]\n_outputs = [[[0, 0]], [[0, ...
351
292
coding
Solve the programming task below in a Python markdown code block. After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions. Before the ...
{"inputs": ["2\n5\n5\n", "2\n3\n5\n", "2\n6\n5\n", "2\n7\n5\n", "2\n7\n6\n", "2\n7\n9\n", "2\n5\n5\n", "2\n7\n12\n"], "outputs": ["0\n1 0\n", "0\n0\n", "0\n0\n", "0\n0\n", "0\n0\n", "0\n0\n", "0\n1 0\n", "0\n0\n"]}
464
123
coding
Solve the programming task below in a Python markdown code block. Permutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as p_{i}. We'll call number n the size or the length of permuta...
{"inputs": ["3\n", "5\n", "1\n", "2\n", "4\n", "6\n", "7\n", "8\n"], "outputs": ["18\n", "1800\n", "1\n", "0\n", "0\n", "0\n", "670320\n", "0\n"]}
455
79
coding
Solve the programming task below in a Python markdown code block. Kevin Sun wants to move his precious collection of n cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into k boxes of a fixed size. In order to keep his collection safe during tr...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "1 2\n10\n", "1 2\n10\n", "1 1\n10\n", "2 1\n2 5\n", "2 2\n2 3\n", "2 2\n2 3\n"], "outputs": ["1\n", "1\n", "10\n", "10\n", "10\n", "7\n", "3\n", "3\n"]}
527
114
coding
Solve the programming task below in a Python markdown code block. # It's too hot, and they can't even… One hot summer day Pete and his friend Billy decided to buy watermelons. They chose the biggest crate. They rushed home, dying of thirst, and decided to divide their loot, however they faced a hard problem. Pete and...
{"functional": "_inputs = [[4], [2], [5], [88], [100], [67], [90], [10], [99], [32]]\n_outputs = [[True], [False], [False], [True], [True], [False], [True], [True], [False], [True]]\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_t...
295
216
coding
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, ...
434
448
coding
Solve the programming task below in a Python markdown code block. Given two integers $n$ and $\textbf{r}$. In how many ways can $\textbf{r}$ items be chosen from $n$ items? Input Format The first line contains the number of test cases $\mathbf{T}$. Each of the next $\mathbf{T}$ lines contains two integers $n$ and $\t...
{"inputs": ["4\n2 1\n4 0\n5 2\n10 3\n"], "outputs": ["2\n1\n10\n120\n"]}
201
40
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. There are N chairs placed in circular order. Some of the chairs are empty while others have a child sitting in it. You are required to change the places of the children so th...
{"inputs": ["1\n8\n10001010"], "outputs": ["2"]}
531
23
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an binary array nums and an integer k, return true if all 1's are at least k places away from each other, otherwise return false.   Please complete the following python code precisely: ```python class Solution: ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,0,0,0,1,0,0,1], k = 2) == True\n assert candidate(nums = [1,0,0,1,0,1], k = 2) == False\n assert candidate(nums = [1,1,1,1,1], k = 0) == True\n assert candidate(nums = [0,1,0,1], k = 1) == True\n\n\ncheck(Solution().kLengthApart)"}
84
122
coding
Solve the programming task below in a Python markdown code block. Write a program that extracts n different numbers from the numbers 0 to 100 and outputs the number of combinations that add up to s. Each n number is from 0 to 100, and the same number cannot be used in one combination. For example, if n is 3 and s is 6,...
{"inputs": ["6 6\n3 1\n0 0", "2 8\n4 3\n0 0", "3 4\n1 3\n0 0", "3 4\n2 3\n0 0", "3 0\n2 3\n0 0", "3 1\n2 9\n0 0", "3 6\n3 1\n0 0", "3 12\n3 1\n0 0"], "outputs": ["0\n0\n", "4\n0\n", "1\n1\n", "1\n2\n", "0\n2\n", "0\n5\n", "3\n0", "12\n0\n"]}
260
159
coding
Solve the programming task below in a Python markdown code block. The [Sharkovsky's Theorem](https://en.wikipedia.org/wiki/Sharkovskii%27s_theorem) involves the following ordering of the natural numbers: ```math 3≺5≺7≺9≺ ...\\ ≺2·3≺2·5≺2·7≺2·9≺...\\ ≺2^n·3≺2^n·5≺2^n·7≺2^n·9≺...\\ ≺2^{(n+1)}·3≺2^{(n+1)}·5≺2^{(n+1)}·7≺2^...
{"functional": "_inputs = [[18, 12], [3, 9], [10, 16], [1, 22], [32, 1024], [17, 17]]\n_outputs = [[True], [True], [True], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isi...
250
214
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given two strings $S$ and $R$. You may reorder the characters in the string $R$ in any way; let's denote the resulting string by $R_{r}$. Thi...
{"inputs": ["4\naa\nababab\naaa\nramialsadaka\nsaid\nsryhieni\ncode\ncodeisfun"], "outputs": ["aaabbb\naaaaadiklmrs\nImpossible\ncodefinsu"]}
506
56
coding
Solve the programming task below in a Python markdown code block. Sherlock is given an array of $N$ integers ($A_0,A_1...A_{N-1}$ by Watson. Now Watson asks Sherlock how many different pairs of indices $\boldsymbol{i}$ and $j$ exist such that $\boldsymbol{i}$ is not equal to $j$ but $A_i$ is equal to $A_j$. That ...
{"inputs": ["2\n3\n1 2 3\n3\n1 1 2\n"], "outputs": ["0\n2\n"]}
342
32
coding
Solve the programming task below in a Python markdown code block. If I give you a date, can you tell me what day that date is? For example, december 8th, 2015 is a tuesday. Your job is to write the function ```day(d)``` which takes a string representation of a date as input, in the format YYYYMMDD. The example would b...
{"functional": "_inputs = [['20151208'], ['20140728'], ['20160229'], ['20160301'], ['19000228'], ['19000301']]\n_outputs = [['Tuesday'], ['Monday'], ['Monday'], ['Tuesday'], ['Wednesday'], ['Thursday']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return mat...
192
225
coding
Solve the programming task below in a Python markdown code block. An n × n table a is defined as follows: The first row and the first column contain ones, that is: a_{i}, 1 = a_{1, }i = 1 for all i = 1, 2, ..., n. Each of the remaining numbers in the table is equal to the sum of the number above it and the number t...
{"inputs": ["1\n", "5\n", "2\n", "3\n", "4\n", "6\n", "7\n", "9\n"], "outputs": ["1", "70", "2", "6", "20", "252", "924", "12870"]}
345
72
coding
Solve the programming task below in a Python markdown code block. Adam is standing at point $(a,b)$ in an infinite 2D grid. He wants to know if he can reach point $(x,y)$ or not. The only operation he can do is to move to point $(a+b,b),(a,a+b),(a-b,b),\text{or}(a,b-a)$ from some point $(a,b)$. It is given that he can ...
{"inputs": ["3\n1 1 2 3\n2 1 2 3\n3 3 1 1\n"], "outputs": ["YES\nYES\nNO\n"]}
325
42
coding
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"]}
721
166
coding
Solve the programming task below in a Python markdown code block. I have the `par` value for each hole on a golf course and my stroke `score` on each hole. I have them stored as strings, because I wrote them down on a sheet of paper. Right now, I'm using those strings to calculate my golf score by hand: take the diffe...
{"functional": "_inputs = [['443454444344544443', '353445334534445344'], ['123456123456123456', '123456123456123456']]\n_outputs = [[-1], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance...
258
238
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s that consists of the digits '1' to '9' and two integers k and minLength. A partition of s is called beautiful if: s is partitioned into k non-intersecting substrings. Each substring has a len...
{"functional": "def check(candidate):\n assert candidate(s = \"23542185131\", k = 3, minLength = 2) == 3\n assert candidate(s = \"23542185131\", k = 3, minLength = 3) == 1\n assert candidate(s = \"3312958\", k = 3, minLength = 1) == 1\n\n\ncheck(Solution().beautifulPartitions)"}
196
112
coding
Solve the programming task below in a Python markdown code block. Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an h × w field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only s...
{"inputs": ["2 2 2\n2 1\n1 2\n", "3 4 2\n2 2\n2 4\n", "3 4 2\n3 2\n2 4\n", "3 7 2\n3 2\n2 4\n", "2 4 2\n2 2\n2 3\n", "3 4 2\n2 2\n2 3\n", "100000 100000 2\n1 2\n2 1\n", "100 100 3\n15 7\n16 15\n15 88\n"], "outputs": ["0\n", "2", "3", "9", "1", "2\n", "0\n", "950251154"]}
461
192
coding
Solve the programming task below in a Python markdown code block. For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_...
{"inputs": ["2\n2\n3"], "outputs": ["NO\nYES\n1 3 2"]}
645
24
coding
Solve the programming task below in a Python markdown code block. Mountaineers Mr. Takahashi and Mr. Aoki recently trekked across a certain famous mountain range. The mountain range consists of N mountains, extending from west to east in a straight line as Mt. 1, Mt. 2, ..., Mt. N. Mr. Takahashi traversed the range fro...
{"inputs": ["1\n17\n17", "5\n2 3 3 3 3\n3 3 2 2 2", "5\n1 1 1 2 2\n6 2 1 1 1", "5\n1 1 1 4 2\n6 2 1 1 1", "5\n1 1 1 4 2\n6 2 1 1 0", "5\n1 1 1 4 2\n6 0 1 1 0", "5\n1 1 1 4 2\n6 1 1 1 0", "5\n1 1 1 4 2\n6 2 1 2 0"], "outputs": ["1", "4\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
562
207
coding
Solve the programming task below in a Python markdown code block. We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally. Takahashi is standing at Vertex u, and Aoki is standing at Vertex v. Now, they will play a game of tag as follows: - 1. If Takahashi and Aoki are standing at the ...
{"inputs": ["2 1 2\n1 2", "2 1 2\n1 2\n", "5 4 5\n1 2\n1 3\n2 4\n1 5", "5 4 1\n1 2\n1 3\n3 4\n3 5", "5 4 1\n1 2\n2 3\n1 4\n3 5", "5 4 5\n1 2\n1 5\n2 4\n1 5", "5 4 5\n2 2\n1 3\n1 4\n1 5", "5 5 1\n1 2\n2 3\n1 4\n3 5"], "outputs": ["0", "0\n", "2\n", "1\n", "0\n", "2\n", "1\n", "2\n"]}
473
198
coding
Solve the programming task below in a Python markdown code block. The only difference between the easy and the hard versions is the maximum value of $k$. You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first...
{"inputs": ["1\n9124\n", "1\n9124\n", "1\n3621\n", "1\n4320\n", "1\n2836\n", "1\n6961\n", "1\n3722\n", "1\n6297\n"], "outputs": ["4\n", "4\n", "1\n", "2\n", "7\n", "3\n", "5\n", "2\n"]}
587
110
coding
Solve the programming task below in a Python markdown code block. Our fruit guy has a bag of fruit (represented as an array of strings) where some fruits are rotten. He wants to replace all the rotten pieces of fruit with fresh ones. For example, given `["apple","rottenBanana","apple"]` the replaced array should be `["...
{"functional": "_inputs = [[['apple', 'banana', 'kiwi', 'melone', 'orange']], [['rottenApple', 'rottenBanana', 'rottenApple', 'rottenPineapple', 'rottenKiwi']], [[]], [None], [['apple', 'rottenBanana', 'rottenApple', 'pineapple', 'kiwi']]]\n_outputs = [[['apple', 'banana', 'kiwi', 'melone', 'orange']], [['apple', 'bana...
189
281
coding
Solve the programming task below in a Python markdown code block. Mihai has an $8 \times 8$ chessboard whose rows are numbered from $1$ to $8$ from top to bottom and whose columns are numbered from $1$ to $8$ from left to right. Mihai has placed exactly one bishop on the chessboard. The bishop is not placed on the edg...
{"inputs": ["3\n\n.....#..\n#...#...\n.#.#....\n..#.....\n.#.#....\n#...#...\n.....#..\n......#.\n\n#.#.....\n.#......\n#.#.....\n...#....\n....#...\n.....#..\n......#.\n.......#\n\n.#.....#\n..#...#.\n...#.#..\n....#...\n...#.#..\n..#...#.\n.#.....#\n#.......\n"], "outputs": ["4 3\n2 2\n4 5\n"]}
502
136
coding
Solve the programming task below in a Python markdown code block. Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the ave...
{"inputs": ["0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2\n", "0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n", "1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n", "0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n", "0 0\n1 0\n0 1\n1 1\n0 2\n1 2\n0 3\n1 3\n", "0 0\n2 1\n1 0\n0 2\n2 2\n1 0\n2 1\n0 2\n", "0 0\n2 1\n1 0\n0 2\n2 2\n1 0\n2 1\n0 2\n", ...
388
318
coding
Solve the programming task below in a Python markdown code block. A hostel has N rooms in a straight line. It has to accommodate X people. Unfortunately, out of these X people, Y of them are infected with chickenpox. Due to safety norms, the following precaution must be taken: No person should occupy a room directly a...
{"inputs": ["3\n4 0\n5 3\n3 3\n"], "outputs": ["4\n8\n5\n"]}
497
30
coding
Solve the programming task below in a Python markdown code block. Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all wat...
{"inputs": ["2 4\n4 4\n", "2 1\n1 1\n", "2 1\n2 2\n", "2 1\n1 1\n", "2 4\n4 4\n", "2 1\n2 2\n", "2 1\n3 2\n", "2 1\n3 4\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
366
118
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. In English, we have a concept called root, which can be followed by some other word to form another longer word - let's call this word derivative. For example, when the root "help" is followed by the word "ful", we ca...
{"functional": "def check(candidate):\n assert candidate(dictionary = [\"cat\",\"bat\",\"rat\"], sentence = \"the cattle was rattled by the battery\") == \"the cat was rat by the bat\"\n assert candidate(dictionary = [\"a\",\"b\",\"c\"], sentence = \"aadsfasf absbs bbab cadsfafs\") == \"a a b c\"\n\n\ncheck(Solut...
169
94
coding
Solve the programming task below in a Python markdown code block. Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_...
{"inputs": ["10\n1 1000000000\n2 146085669\n9 805629\n4 9999997\n5 999996\n6 99995\n9 18320\n8 993\n9 157\n7 2\n", "10\n1 1000000000\n2 999999999\n3 99999998\n4 9999997\n5 56682\n9 99995\n5 18320\n8 993\n9 92\n7 1\n", "10\n1 1000000000\n2 146085669\n6 805629\n4 9999997\n5 999996\n6 99995\n9 18320\n8 993\n9 157\n7 2\n",...
404
955
coding
Solve the programming task below in a Python markdown code block. ## Problem There are `n` apples that need to be divided into four piles. We need two mysterious number `x` and `y`. Let The number of first pile equals to `x+y`, the number of second pile equals to `x-y`, the number of third pile equals to `x*y`, the nu...
{"functional": "_inputs = [[48, 3], [100, 4], [25, 4], [24, 4]]\n_outputs = [[[12, 6, 27, 3]], [[20, 12, 64, 4]], [[]], [[]]]\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)...
539
212
coding
Solve the programming task below in a Python markdown code block. Hands that shed innocent blood! There are n guilty people in a line, the i-th of them holds a claw with length L_{i}. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person ...
{"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n0\n", "1\n2\n", "1\n3\n", "1\n4\n", "2\n0 0\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n"]}
291
88
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1. Return the size of the largest island in grid after applying this operation. An island is a 4-directionally connected group o...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,0],[0,1]]) == 3\n assert candidate(grid = [[1,1],[1,0]]) == 4\n assert candidate(grid = [[1,1],[1,1]]) == 4\n\n\ncheck(Solution().largestIsland)"}
105
75
coding
Solve the programming task below in a Python markdown code block. Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last n days. Assume that the average air temperature for each day is integral. Vasya believes that if the average temperatu...
{"inputs": ["2\n1 2\n", "2\n1 2\n", "2\n2 2\n", "2\n8 2\n", "2\n4 2\n", "2\n16 2\n", "3\n2 5 8\n", "3\n2 4 8\n"], "outputs": ["3\n", "3", "2\n", "-4\n", "0\n", "-12\n", "11\n", "8\n"]}
610
108
coding
Solve the programming task below in a Python markdown code block. Find out the maximum sub-array of non negative numbers from an array. The sub-array should be continuous. That is, a sub-array created by choosing the second and fourth element and skipping the third element is invalid. Maximum sub-array is defined in...
{"inputs": ["1\n6\n1 2 5 -7 2 3"], "outputs": ["1 2 5"]}
262
30
coding
Solve the programming task below in a Python markdown code block. Let's denote the $f(x)$ function for a string $x$ as the number of distinct characters that the string contains. For example $f({abc}) = 3$, $f({bbbbb}) = 1$, and $f({babacaba}) = 3$. Given a string $s$, split it into two non-empty strings $a$ and $b$ s...
{"inputs": ["5\n2\naa\n7\nabcabcd\n5\naaaaa\n10\npaiumoment\n4\naazz\n"], "outputs": ["2\n7\n2\n10\n3\n"]}
505
49
coding
Solve the programming task below in a Python markdown code block. You are given the sequence of Nucleotides of one strand of DNA through a string S of length N. S contains the character A, T, C, and G only. Chef knows that: A is complementary to T. T is complementary to A. C is complementary to G. G is complementary t...
{"inputs": ["4\n4\nATCG\n4\nGTCC\n5\nAAAAA\n3\nTAC\n"], "outputs": ["TAGC\nCAGG\nTTTTT\nATG\n"]}
440
46
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s of lower and upper case English letters. A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where: 0 <= i <= s.length - 2 s[i] is a lower-case letter and s[i + 1] ...
{"functional": "def check(candidate):\n assert candidate(s = \"leEeetcode\") == \"leetcode\"\n assert candidate(s = \"abBAcC\") == \"\"\n assert candidate(s = \"s\") == \"s\"\n\n\ncheck(Solution().makeGood)"}
183
63
coding
Solve the programming task below in a Python markdown code block. Share price =========== You spent all your saved money to buy some shares. You bought it for `invested`, and want to know how much it's worth, but all the info you can quickly get are just the change the shares price made in percentages. Your task: --...
{"functional": "_inputs = [[100, []], [100, [-50, 50]], [100, [-50, 100]], [100, [-20, 30]], [1000, [0, 2, 3, 6]]]\n_outputs = [['100.00'], ['75.00'], ['100.00'], ['104.00'], ['1113.64']]\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,...
194
254
coding
Solve the programming task below in a Python markdown code block. The `depth` of an integer `n` is defined to be how many multiples of `n` it is necessary to compute before all `10` digits have appeared at least once in some multiple. example: ``` let see n=42 Multiple value digits comment 42*1 ...
{"functional": "_inputs = [[8], [13], [7], [25], [42], [1]]\n_outputs = [[12], [8], [10], [36], [9], [10]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(...
337
192
coding
Solve the programming task below in a Python markdown code block. ## Your Story "A *piano* in the home meant something." - *Fried Green Tomatoes at the Whistle Stop Cafe* You've just realized a childhood dream by getting a beautiful and beautiful-sounding upright piano from a friend who was leaving the country. You im...
{"functional": "_inputs = [[1], [5], [12], [42], [88], [89], [92], [100], [111], [200], [2017]]\n_outputs = [['white'], ['black'], ['black'], ['white'], ['white'], ['white'], ['white'], ['black'], ['white'], ['black'], ['white']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, ...
769
231
coding
Solve the programming task below in a Python markdown code block. Madoka wants to enter to "Novosibirsk State University", but in the entrance exam she came across a very difficult task: Given an integer $n$, it is required to calculate $\sum{\operatorname{lcm}(c, \gcd(a, b))}$, for all triples of positive integers $(...
{"inputs": ["3\n", "5\n", "4\n", "6\n", "7\n", "8\n", "9\n", "47\n"], "outputs": ["1\n", "11\n", "4\n", "20\n", "42\n", "60\n", "100\n", "32596\n"]}
539
81
coding
Solve the programming task below in a Python markdown code block. Joisino is about to compete in the final round of a certain programming competition. In this contest, there are N problems, numbered 1 through N. Joisino knows that it takes her T_i seconds to solve problem i(1≦i≦N). Also, there are M kinds of drinks off...
{"inputs": ["3\n2 1 4\n2\n1 1\n0 3", "3\n2 1 4\n2\n1 1\n0 6", "3\n2 1 4\n2\n1 0\n2 3", "3\n2 1 4\n2\n1 0\n0 3", "3\n1 1 4\n2\n1 1\n0 6", "3\n2 0 4\n2\n1 0\n0 3", "3\n1 1 0\n2\n1 1\n0 6", "3\n1 1 0\n2\n1 1\n0 8"], "outputs": ["6\n6\n", "6\n9\n", "5\n9\n", "5\n6\n", "6\n8\n", "4\n5\n", "2\n8\n", "2\n10\n"]}
477
207
coding
Solve the programming task below in a Python markdown code block. You are teaching students to generate strings consisting of unique lowercase latin characters (a-z). You give an example reference string $s$ to the students. You notice that your students just copy paste the reference string instead of creating their ow...
{"inputs": ["4\nhelowrd 0\nbackground 0\nabcdefghijklmnopqrstuvwxyz 0\nb 1"], "outputs": ["abcfgij\nefhijlmpqs\nNOPE\na"]}
456
44
coding
Solve the programming task below in a Python markdown code block. [BasE91](http://base91.sourceforge.net/) is a method for encoding binary as ASCII characters. It is more efficient than Base64 and needs 91 characters to represent the encoded data. The following ASCII charakters are used: 'ABCDEFGHIJKLMNOPQRSTUVWX...
{"functional": "_inputs = [['fPNKd'], ['>OwJh>Io0Tv!8PE']]\n_outputs = [['test'], ['Hello World!']]\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) != l...
232
178
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?   Please complete the following python code precisely: ...
{"functional": "def check(candidate):\n assert candidate(n = 2) == 2\n assert candidate(n = 3) == 3\n\n\ncheck(Solution().climbStairs)"}
88
45
coding
Solve the programming task below in a Python markdown code block. You are given an array $a_{1}, a_{2}, \ldots, a_{n}$. You can remove at most one subsegment from it. The remaining elements should be pairwise distinct. In other words, at most one time you can choose two integers $l$ and $r$ ($1 \leq l \leq r \leq n$) ...
{"inputs": ["2\n2 1\n", "2\n2 1\n", "2\n3 1\n", "2\n6 1\n", "3\n1 2 3\n", "3\n1 2 1\n", "3\n1 2 0\n", "3\n1 2 3\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "1\n", "0\n", "0"]}
412
108
coding
Solve the programming task below in a Python markdown code block. You are given two integers $n$ and $k$. Your task is to find if $n$ can be represented as a sum of $k$ distinct positive odd (not divisible by $2$) integers or not. You have to answer $t$ independent test cases. -----Input----- The first line of the ...
{"inputs": ["1\n707 44\n", "1\n2 65536\n", "1\n2 65536\n", "1\n2 15317\n", "1\n3 15317\n", "1\n1 15317\n", "1\n0 15317\n", "1\n0 26405\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
382
133