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. Chef wants you to distribute candies among $N$ kids who are sitting in a circle. However, he wants to make some kids jealous of others. Thus, he wants you to distribute candies in such a way that there is a difference of at least $K$ candies between two ...
{"inputs": ["1\n2 1"], "outputs": ["3"]}
coding
302
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.   Please complete the following python code precisely: ```python class...
{"functional": "def check(candidate):\n assert candidate(num = \"1432219\", k = 3) == \"1219\"\n assert candidate(num = \"10200\", k = 1) == \"200\"\n assert candidate(num = \"10\", k = 2) == \"0\"\n\n\ncheck(Solution().removeKdigits)"}
coding
79
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. In one operation, select any non-negative integer x and an index i, then update nums[i] to be equal to nums[i] AND (nums[i] XOR x). Note that AND is the bitwise AND operat...
{"functional": "def check(candidate):\n assert candidate(nums = [3,2,4,6]) == 7\n assert candidate(nums = [1,2,3,9,2]) == 11\n\n\ncheck(Solution().maximumXOR)"}
coding
132
Solve the programming task below in a Python markdown code block. In Byteland they have a very strange monetary system. Each Bytelandian gold coin has an integer number written on it. A coin n can be exchanged in a bank into three coins: n/2, n/3 and n/4. But these numbers are all rounded down (the banks have to make ...
{"inputs": ["12\n1", "12\n0", "12\n3", "12\n4", "12\n5", "12\n7", "12\n9", "12\n6"], "outputs": ["13\n1\n", "13\n0\n", "13\n3\n", "13\n4\n", "13\n5\n", "13\n7\n", "13\n9\n", "13\n6\n"]}
coding
350
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string sentence that consist of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to "Goat Latin" (a made-up language similar ...
{"functional": "def check(candidate):\n assert candidate(sentence = \"I speak Goat Latin\") == \"Imaa peaksmaaa oatGmaaaa atinLmaaaaa\"\n assert candidate(sentence = \"The quick brown fox jumped over the lazy dog\") == \"heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ...
coding
274
Solve the programming task below in a Python markdown code block. A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to ...
{"inputs": ["1 2\nA\n", "1 26\nZ\n", "2 2\nAA\n", "2 2\nBA\n", "2 3\nAA\n", "2 3\n@A\n", "2 3\n?A\n", "1 15\nZ\n"], "outputs": ["0\nA", "0\nZ", "1\nBA", "0\nBA", "1\nAB\n", "0\n@A", "0\n?A", "0\nZ"]}
coding
222
Solve the programming task below in a Python markdown code block. The Chef is sleeping now. He tries to cook new kind of meals in his dream. These meals are arranged in a row and numbered from 1 to N consecutively. For each meal i (1≤i≤N) there is given one integer f(i) which denotes the time needed to cook it. Init...
{"inputs": ["5 3\n40 30 40 30 40", "5 3\n40 30 40 30 40"], "outputs": ["3", "3"]}
coding
477
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 2D integer array nums, return all elements of nums in diagonal order as shown in the below images.   Please complete the following python code precisely: ```python class Solution: def findDiagonalOrder(sel...
{"functional": "def check(candidate):\n assert candidate(nums = [[1,2,3],[4,5,6],[7,8,9]]) == [1,4,2,7,5,3,8,6,9]\n assert candidate(nums = [[1,2,3,4,5],[6,7],[8],[9,10,11],[12,13,14,15,16]]) == [1,6,2,8,7,3,9,4,12,10,5,13,11,14,15,16]\n assert candidate(nums = [[1,2,3],[4],[5,6,7],[8],[9,10,11]]) == [1,4,2,5,...
coding
76
Solve the programming task below in a Python markdown code block. Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autoco...
{"inputs": ["find\n4\nfind\nfindfirstof\nfindit\nf", "fjnd\n4\nfind\nfindfirstof\nfindit\nf", "njfd\n4\nfind\nfotsqifdmig\nfindit\nf", "dfjn\n4\nfind\nfotsqifdmig\nfindit\nf", "dfjm\n4\nfinc\ngimdfiqstpf\nfiidnt\nf", "fjnd\n4\nfind\nfindfiqstof\nfindit\nf", "fjnd\n4\nfind\nfotsqifdnif\nfindit\nf", "fjnd\n4\nfind\nfotsq...
coding
356
Solve the programming task below in a Python markdown code block. The chef was busy in solving algebra, he found some interesting results, that there are many numbers which can be formed by sum of some numbers which are prime. Chef wrote those numbers in dairy. Cheffina came and saw what the chef was doing. Cheffina im...
{"inputs": ["2\n12 2\n11 2"], "outputs": ["1\n0"]}
coding
258
Solve the programming task below in a Python markdown code block. Write a program which reads a word W and a text T, and prints the number of word W which appears in text T T consists of string Ti separated by space characters and newlines. Count the number of Ti which equals to W. The word and text are case insensiti...
{"inputs": ["computer\nNurtures computer scientists and highly-skilled computer engineers\nwho will create and exploit \"knowledge\" for the enw era.\nProvides an outstanding computer environment.\nEND_OF_TEXT", "comquter\nNurtures computer scientists and highly-skilled computer engineers\nwho will create and tiolpxe \...
coding
203
Solve the programming task below in a Python markdown code block. Let us consider sets of positive integers less than or equal to n. Note that all elements of a set are different. Also note that the order of elements doesn't matter, that is, both {3, 5, 9} and {5, 9, 3} mean the same set. Specifying the number of set ...
{"inputs": ["9 1 31\n2 3 3\n3 3 19\n16 10 3\n20 3 45\n20 8 19\n20 20 155\n3 6 6\n3 3 15\n0 0 0", "9 3 31\n2 3 3\n10 3 28\n16 6 87\n20 3 102\n20 8 19\n20 20 155\n3 6 6\n3 3 15\n0 0 0", "9 3 5\n9 1 22\n10 3 28\n16 10 107\n26 1 102\n20 10 21\n20 10 2\n3 4 3\n4 2 6\n0 0 0", "9 6 23\n2 3 3\n8 3 41\n16 10 87\n20 3 102\n20 2 ...
coding
458
Solve the programming task below in a Python markdown code block. Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try ...
{"inputs": ["1\nZ\n", "1\nV\n", "1\nK\n", "1\nY\n", "1\nU\n", "2\nKV\n", "2\nVK\n", "2\nKU\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "0\n"]}
coding
499
Solve the programming task below in a Python markdown code block. In ordinary chess, the pieces are only of two colors, black and white. In our version of chess, we are including new pieces with unique movements. One of the most powerful pieces in this version is the red knight. The red knight can move to six differ...
{"inputs": ["7\n6 6 0 1\n", "6\n5 1 0 5\n", "7\n0 3 4 3\n"], "outputs": ["4\nUL UL UL L\n", "Impossible\n", "2\nLR LL\n"]}
coding
686
Solve the programming task below in a Python markdown code block. Professor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way. In total there are n piles of boxes, arranged in a line, from left to right, i-th pile (1 ≤ i ≤ n) containing ai boxes. Luckily, m student...
{"inputs": ["1 1\n1\n", "1 1\n2\n", "1 1\n3\n", "2 1\n2 1\n", "2 1\n1 1\n", "3 2\n1 0 4\n", "3 2\n1 0 3\n", "3 2\n1 0 2\n"], "outputs": [" 2", "3\n", "4\n", "5\n", " 4", "6\n", "5\n", " ...
coding
617
Solve the programming task below in a Python markdown code block. You will be given two numbers `m,n`. The numbers could span from `0` to `10000`. We can get their product by using binary reduction as show in the table below. Example (to understand the table please read the description below it) real value of m(r...
{"functional": "_inputs = [[100, 15], [15, 0], [0, 0]]\n_outputs = [[[960, 480, 60]], [[]], [[]]]\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...
coding
459
Solve the programming task below in a Python markdown code block. Implement a function that normalizes out of range sequence indexes (converts them to 'in range' indexes) by making them repeatedly 'loop' around the array. The function should then return the value at that index. Indexes that are not out of range should ...
{"functional": "_inputs = [[[], 10]]\n_outputs = [[None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_d...
coding
292
Solve the programming task below in a Python markdown code block. Janmansh and Jay are playing a game. They start with a number X and they play a total of Y moves. Janmansh plays the first move of the game, after which both the players make moves alternatingly. In one move, a player can increment or decrement X by 1....
{"inputs": ["2\n2 2\n4 3\n"], "outputs": ["Janmansh\nJay\n"]}
coding
433
Solve the programming task below in a Python markdown code block. >When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said # Description: Given two array of integers(`arr1`,`arr2`). Your task is going to find a pair of numbers(...
{"functional": "_inputs = [[[3, 10, 5], [20, 7, 15, 8]], [[3], [20]], [[3, 10, 5], [3, 10, 5]], [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]]\n_outputs = [[[17, 2]], [[17, 17]], [[7, 0]], [[9, 1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b...
coding
436
Solve the programming task below in a Python markdown code block. Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed h and the processor smashes k centimeters of potato each second. If there are less than k centimeters remaining, than durin...
{"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 1 2\n1\n", "5 6 3\n5 4 3 2 1\n", "5 6 3\n5 5 5 5 5\n", "5 6 3\n1 2 1 1 1\n", "5 6 3\n1 2 2 1 1\n", "5 6 3\n5 4 6 2 1\n"], "outputs": ["1\n", "1\n", "1\n", "5\n", "10\n", "2\n", "3\n", "6\n"]}
coding
641
Solve the programming task below in a Python markdown code block. Let's consider all integers in the range from $1$ to $n$ (inclusive). Among all pairs of distinct integers in this range, find the maximum possible greatest common divisor of integers in pair. Formally, find the maximum value of $\mathrm{gcd}(a, b)$, wh...
{"inputs": ["2\n3\n5\n", "2\n6\n5\n", "2\n9\n5\n", "2\n3\n9\n", "2\n6\n7\n", "2\n9\n7\n", "2\n3\n5\n", "2\n10\n7\n"], "outputs": ["1\n2\n", "3\n2\n", "4\n2\n", "1\n4\n", "3\n3\n", "4\n3\n", "1\n2\n", "5\n3\n"]}
coding
335
Solve the programming task below in a Python markdown code block. Given is an integer N. Find the minimum possible positive integer k such that (1+2+\cdots+k) is a multiple of N. It can be proved that such a positive integer k always exists. Constraints * 1 \leq N \leq 10^{15} * All values in input are integers. Inp...
{"inputs": ["5", "2", "9", "1", "85", "19", "91", "11"], "outputs": ["4\n", "3\n", "8\n", "1\n", "34\n", "18\n", "13\n", "10"]}
coding
139
Solve the programming task below in a Python markdown code block. Peter can see a clock in the mirror from the place he sits in the office. When he saw the clock shows 12:22 1 2 3 4 5 6 7 8 9 10 11 12 He knows that the time is 11:38 1 2 3 4 5 6 7 8 9 10 11 12 in the same manner: 05:25 --> 06:35 01:50 --...
{"functional": "_inputs = [['06:35'], ['11:59'], ['12:02'], ['04:00'], ['06:00'], ['12:00']]\n_outputs = [['05:25'], ['12:01'], ['11:58'], ['08:00'], ['06:00'], ['12:00']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, ab...
coding
289
Solve the programming task below in a Python markdown code block. In the pet store on sale there are: $a$ packs of dog food; $b$ packs of cat food; $c$ packs of universal food (such food is suitable for both dogs and cats). Polycarp has $x$ dogs and $y$ cats. Is it possible that he will be able to buy food for all ...
{"inputs": ["1\n0 0 0 0 1\n", "1\n114514 1 1 1 1\n", "1\n114515 1 1 114515 2\n", "1\n114515 0 0 114514 0\n", "2\n2 3 5 4 4\n2 3 5 4 4\n", "2\n2 3 4 4 4\n2 3 4 4 4\n", "1\n55555 55555 55555 55555 55555\n", "1\n114514 114514 114514 114514 114514\n"], "outputs": ["NO\n", "YES\n", "YES\n", "YES\n", "YES\nYES\n", "YES\nYES\...
coding
419
Solve the programming task below in a Python markdown code block. A study has shown that playing a musical instrument helps in increasing one's IQ by 7 points. Chef knows he can't beat Einstein in physics, but he wants to try to beat him in an IQ competition. You know that Einstein had an IQ of 170, and Chef currently...
{"inputs": ["165", "120"], "outputs": ["Yes", "No"]}
coding
407
Solve the programming task below in a Python markdown code block. You are given a square map as a matrix of integer strings. Each cell of the map has a value denoting its depth. We will call a cell of the map a cavity if and only if this cell is not on the border of the map and each cell adjacent to it has strictly sma...
{"inputs": ["4\n1112\n1912\n1892\n1234\n"], "outputs": ["1112\n1X12\n18X2\n1234\n"]}
coding
451
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Sheokand loves strings. Chef has $N$ strings $S_{1}, S_{2}, \dots, S_{N}$ which he wants to give to Sheokand; however, he doesn't want to give them away for free, so Sheokand...
{"inputs": ["4\nabcd\nabce\nabcdex\nabcde\n3\n3 abcy\n3 abcde\n4 abcde"], "outputs": ["abcd\nabcdex\nabcde"]}
coding
630
Solve the programming task below in a Python markdown code block. You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q. For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo". Note it i...
{"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 1 2\n1\n", "3 3 2\nzyx\n", "3 2 3\nejt\n", "3 2 2\nzyx\n", "3 2 3\nzyx\n", "3 2 2\naaa\n"], "outputs": ["1\n1\n", "1\n1\n", "1\n1\n", "1\nzyx\n", "1\nejt\n", "-1\n", "1\nzyx\n", "-1\n"]}
coding
352
Solve the programming task below in a Python markdown code block. Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings ...
{"inputs": ["c\n", "a\n", "b\n", "z\n", "d\n", "`\n", "e\n", "{\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
coding
182
Solve the programming task below in a Python markdown code block. When provided with a number between 0-9, return it in words. Input :: 1 Output :: "One". If your language supports it, try using a switch statement. Also feel free to reuse/extend the following starter code: ```python def switch_it_up(number): ```
{"functional": "_inputs = [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9]]\n_outputs = [['Zero'], ['One'], ['Two'], ['Three'], ['Four'], ['Five'], ['Six'], ['Seven'], ['Eight'], ['Nine']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, ...
coding
73
Solve the programming task below in a Python markdown code block. ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word...
{"inputs": ["2 1\n1 2\n", "2 1\n1 2\n", "2 0\n1 2\n", "2 0\n1 3\n", "2 1\n1 100\n", "2 1\n1 100\n", "2 1\n2 100\n", "2 0\n1 100\n"], "outputs": ["2", "2\n", "1\n", "1\n", "1", "1\n", "1\n", "1\n"]}
coding
566
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be pseudo-palindromic if at least one permutation of the node values in the path is a palindrome. Return the number of...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([2,3,1,3,1,None,1])) == 2 \n assert candidate(root = tree_node([2,1,1,1,3,None,None,None,None,None,1])) == 1 \n assert candidate(root = tree_node([9])) == 1\n\n\ncheck(Solution().pseudoPalindromicPaths)"}
coding
173
Solve the programming task below in a Python markdown code block. You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely l...
{"inputs": ["3\n", "1422\n", "1000000000000000000\n"], "outputs": ["5\n", "52277\n", "787014179\n"]}
coding
332
Solve the programming task below in a Python markdown code block. You are given three numbers $a$, $b$, $c$ . Write a program to determine the largest number that is less than or equal to $c$ and leaves a remainder $b$ when divided by $a$. -----Input:----- - First line will contain $T$, number of testcases. Then the t...
{"inputs": ["1\n7 2 10"], "outputs": ["9"]}
coding
198
Solve the programming task below in a Python markdown code block. You are given an array of integers [A1,A2,…,AN]$[A_1, A_2, \ldots, A_N]$. Let's call adding an element to this array at any position (including the beginning and the end) or removing an arbitrary element from it a modification. It is not allowed to remov...
{"inputs": ["2\n5\n1 4 1 2 2\n4\n2 3 2 3"], "outputs": ["1\n2"]}
coding
520
Solve the programming task below in a Python markdown code block. Every day, N passengers arrive at Takahashi Airport. The i-th passenger arrives at time T_i. Every passenger arrived at Takahashi airport travels to the city by bus. Each bus can accommodate up to C passengers. Naturally, a passenger cannot take a bus t...
{"inputs": ["5 5 5\n1\n1\n4\n6\n4", "5 5 5\n1\n1\n0\n6\n3", "5 3 5\n1\n7\n3\n6\n1", "5 3 5\n1\n4\n3\n6\n12", "5 5 5\n1\n4\n3\n6\n12", "5 5 5\n1\n1\n3\n6\n12", "5 5 5\n1\n1\n3\n6\n18", "5 5 5\n1\n1\n0\n6\n18"], "outputs": ["1\n", "2\n", "2\n", "3\n", "2\n", "2\n", "2\n", "3\n"]}
coding
357
Solve the programming task below in a Python markdown code block. Min Element Given the sequence a_1, a_2, .., a_N. Find the minimum number in this sequence. If the minimum value is in more than one place, answer the one with the lowest number. input N a_1 a_2 ... a_N output Output the smallest i such that a_i...
{"inputs": ["6\n8 6 9 0 2 1", "6\n8 6 9 1 2 0", "6\n6 0 9 1 2 1", "6\n1 6 9 1 2 0", "6\n1 6 9 0 2 0", "6\n8 3 9 1 2 1", "6\n6 6 9 0 2 1", "6\n8 6 9 2 2 0"], "outputs": ["4\n", "6\n", "2\n", "6\n", "4\n", "4\n", "4\n", "6\n"]}
coding
171
Solve the programming task below in a Python markdown code block. MoEngage has given you an array A consisting of N positive integers. You should perform Q queries of the following two types: 1 i X : Set A_{i} to X. 2 L R : Find the minimum non-negative integer K such that the sequence [|A_{L} - K|, |A_{L+1} - K|, \l...
{"inputs": ["5 7\n5 3 2 6 0\n2 1 5\n1 2 7\n2 1 5\n1 4 2\n2 1 5\n1 2 5\n2 1 2"], "outputs": ["4\n-1\n5\n0\n"]}
coding
561
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a non-negative integer num, return true if num can be expressed as the sum of any non-negative integer and its reverse, or false otherwise.   Please complete the following python code precisely: ```python class ...
{"functional": "def check(candidate):\n assert candidate(num = 443) == True\n assert candidate(num = 63) == False\n assert candidate(num = 181) == True\n\n\ncheck(Solution().sumOfNumberAndReverse)"}
coding
80
Solve the programming task below in a Python markdown code block. Let's consider a random permutation p_{1}, p_{2}, ..., p_{N} of numbers 1, 2, ..., N and calculate the value F=(X_{2}+...+X_{N-1})^{K}, where X_{i} equals 1 if one of the following two conditions holds: p_{i-1} < p_{i} > p_{i+1} or p_{i-1} > p_{i} < p_{i...
{"inputs": ["1 1000\n"], "outputs": ["1996 / 3\n"]}
coding
220
Solve the programming task below in a Python markdown code block. The number "zero" is called "love" (or "l'oeuf" to be precise, literally means "egg" in French), for example when denoting the zero score in a game of tennis. Aki is fond of numbers, especially those with trailing zeros. For example, the number $9200$ ...
{"inputs": ["6 9\n", "5 2\n", "1 2\n", "2 2\n", "2 2\n", "1 2\n", "9 9\n", "9 2\n"], "outputs": ["1\n", "3\n", "0\n", "1\n", "1\n", "0\n", "2\n", "7\n"]}
coding
593
Solve the programming task below in a Python markdown code block. Chef has a binary string S of length N. Chef can perform the following operation on the string: Choose any substring of S; Remove the chosen substring from S; Concatenate the remaining parts of the string S, obtained after removing the substring. Find ...
{"inputs": ["3\n4\n1010\n6\n011011\n11\n01011011101\n"], "outputs": ["2\n2\n3\n"]}
coding
645
Solve the programming task below in a Python markdown code block. ## Task: You have to write a function `pattern` which returns the following Pattern (See Pattern & Examples) upto `n` number of rows. * Note: `Returning` the pattern is not the same as `Printing` the pattern. ### Rules/Note: * If `n < 1` then it shoul...
{"functional": "_inputs = [[1], [2], [5], [0], [-25]]\n_outputs = [['1'], ['21\\n2'], ['54321\\n5432\\n543\\n54\\n5'], [''], ['']]\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, t...
coding
448
Solve the programming task below in a Python markdown code block. You are given a string S of length N consisting of A, C, G and T. Answer the following Q queries: - Query i (1 \leq i \leq Q): You will be given integers l_i and r_i (1 \leq l_i < r_i \leq N). Consider the substring of S starting at index l_i and ending...
{"inputs": ["2 1\nAA\n1 2\n", "8 3\nACACTACG\n3 7\n2 3\n1 6", "8 3\nGCATCACA\n3 7\n2 3\n1 8", "8 3\nACBCTADG\n3 7\n2 3\n1 6", "8 3\nACACTACG\n3 7\n2 3\n1 2", "8 3\nACACTACG\n3 7\n4 3\n1 2", "8 3\nGAATCCCA\n3 7\n3 3\n2 8", "8 3\nACACTADG\n3 7\n2 4\n1 6"], "outputs": ["0\n", "2\n0\n2\n", "1\n0\n1\n", "0\n0\n1\n", "2\n0\n...
coding
442
Solve the programming task below in a Python markdown code block. There is a very long bench. The bench is divided into M sections, where M is a very large integer. Initially, the bench is vacant. Then, M people come to the bench one by one, and perform the following action: * We call a section comfortable if the sec...
{"inputs": ["1\nX", "3\n---", "5\n-X--X", "5\n-X-X-", "5\nX-X--", "5\n-XX--", "5\n---XX", "5\n--XX-"], "outputs": ["500000004 0 500000003", "0 0 0", "0 0 1\n", "500000004 0 500000002\n", "0 0 666666672\n", "0 0 0\n", "0 0 0\n", "0 0 0\n"]}
coding
632
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 2D integer array items where items[i] = [pricei, beautyi] denotes the price and beauty of an item respectively. You are also given a 0-indexed integer array queries. For each queries[j], you want to de...
{"functional": "def check(candidate):\n assert candidate(items = [[1,2],[3,2],[2,4],[5,6],[3,5]], queries = [1,2,3,4,5,6]) == [2,4,5,5,6,6]\n assert candidate(items = [[1,2],[1,2],[1,3],[1,4]], queries = [1]) == [4]\n assert candidate(items = [[10,1000]], queries = [5]) == [0]\n\n\ncheck(Solution().maximumBeau...
coding
165
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Yesterday Chef had a great party and doesn't remember the way he celebreated it. But he found a strange paper in his kitchen containing n digits (lets give them indices from 1 to n and name the...
{"inputs": ["10 3\n0324152397\n1\n4\n7", "10 3\n0324152397\n1\n6\n7", "10 1\n0324152397\n1\n6\n7", "10 2\n0324152397\n1\n6\n7", "10 3\n0324152397\n2\n4\n7", "10 2\n0324152397\n1\n7\n7", "10 3\n0324152397\n1\n3\n7", "10 3\n0324152397\n3\n1\n7"], "outputs": ["0\n7\n9", "0\n15\n9\n", "0\n", "0\n15\n", "3\n7\n9\n", "0\n9\n...
coding
572
Solve the programming task below in a Python markdown code block. Problem Here is a list of strings. Let's take a break and play with shiritori. Shiritori is performed according to the following rules. 1. First of all, select one of your favorite strings from the list and exclude that string from the list. 2. Next, s...
{"inputs": ["5\nuoy\nate\nmy\nhum\ntoast", "5\nuoy\nate\nmy\nhum\ntoasu", "5\nuoy\natf\nmy\nhum\ntoasu", "5\nuyp\natf\nmy\nhum\ntoasu", "5\npyu\nauf\nmy\nhum\ntoasu", "5\npyu\nauf\nmy\nmuh\ntoasu", "5\npyu\nfua\nmy\nmuh\ntoasu", "5\npyu\nfua\nmy\nmui\ntoasu"], "outputs": ["e\nt\ny\n", "e\ny\n", "f\ny\n", "f\np\ny\n", "...
coding
377
Please solve the programming task below using a self-contained code snippet in a markdown code block. Reversing an integer means to reverse all its digits. For example, reversing 2021 gives 1202. Reversing 12300 gives 321 as the leading zeros are not retained. Given an integer num, reverse num to get reversed1, then...
{"functional": "def check(candidate):\n assert candidate(num = 526) == True\n assert candidate(num = 1800) == False\n assert candidate(num = 0) == True\n\n\ncheck(Solution().isSameAfterReversals)"}
coding
134
Solve the programming task below in a Python markdown code block. Chef is hosting a party at his house and N people are invited to it. Everyone has arrived and they are eager to make a group and chit-chat. The i^{th} person prefers to be in a group of exactly P_{i} people (including himself). A person who is not in a ...
{"inputs": ["4\n5\n2 3 2 3 3\n5\n5 5 5 5 5\n5\n3 2 2 3 2\n4\n4 4 4 3\n"], "outputs": ["YES\nYES\nNO\nNO\n"]}
coding
563
Solve the programming task below in a Python markdown code block. A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt. Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught....
{"inputs": ["6\n2 3\n2 6\n2 1\n4 3\n5 31\n6 89", "6\n2 0\n2 6\n3 1\n2 3\n5 61\n6 57", "6\n2 1\n2 8\n3 1\n2 3\n4 61\n1 57", "6\n2 1\n2 8\n3 1\n2 3\n4 61\n1 69", "6\n3 2\n6 8\n4 1\n2 3\n3 29\n1 54", "6\n1 14\n2 6\n3 3\n4 3\n5 40\n6 37", "6\n2 14\n2 6\n3 1\n4 3\n5 31\n6 37", "6\n2 14\n2 6\n3 0\n4 3\n5 31\n6 57"], "outputs...
coding
226
Solve the programming task below in a Python markdown code block. We have two indistinguishable pieces placed on a number line. Both pieces are initially at coordinate 0. (They can occupy the same position.) We can do the following two kinds of operations: * Choose a piece and move it to the right (the positive direc...
{"inputs": ["5 1 1", "4 4 6", "5 2 2", "5 2 3", "7 1 2", "6 2 3", "3 1 2", "4 1 1"], "outputs": ["4\n", "0\n", "8\n", "7\n", "6\n", "12\n", "2\n", "3\n"]}
coding
396
Solve the programming task below in a Python markdown code block. # The museum of incredible dull things The museum of incredible dull things wants to get rid of some exhibitions. Miriam, the interior architect, comes up with a plan to remove the most boring exhibitions. She gives them a rating, and then removes the o...
{"functional": "_inputs = [[[1, 2, 3, 4, 5]], [[1, 2, 3, 4]], [[5, 3, 2, 1, 4]], [[1, 2, 3, 1, 1]], [[]]]\n_outputs = [[[2, 3, 4, 5]], [[2, 3, 4]], [[5, 3, 2, 4]], [[2, 3, 1, 1]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, r...
coding
284
Solve the programming task below in a Python markdown code block. Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days. In Boboniu's chat group, there's a person called Du Yi who likes to make fun of Boboniu every day. Du will chat in the group for $n$ day...
{"inputs": ["1 1 0\n0\n", "1 1 1\n2\n", "1 1 0\n0\n", "1 1 1\n2\n", "1 0 0\n0\n", "1 1 0\n2\n", "1 1 -1\n1\n", "1 1 -1\n2\n"], "outputs": ["0\n", "2\n", "0\n", "2\n", "0\n", "2\n", "1\n", "2\n"]}
coding
576
Solve the programming task below in a Python markdown code block. You are playing a game on a $n \times m$ grid, in which the computer has selected some cell $(x, y)$ of the grid, and you have to determine which one. To do so, you will choose some $k$ and some $k$ cells $(x_1, y_1),\, (x_2, y_2), \ldots, (x_k, y_k)$, ...
{"inputs": ["2\n2 3\n3 1\n", "2\n999 21\n21 999\n"], "outputs": ["2\n1\n", "2\n2\n"]}
coding
578
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer n. Let even denote the number of even indices in the binary representation of n with value 1. Let odd denote the number of odd indices in the binary representation of n with value 1. N...
{"functional": "def check(candidate):\n assert candidate(n = 17) == [2,0]\n assert candidate(n = 2) == [0,1]\n\n\ncheck(Solution().evenOddBit)"}
coding
120
Solve the programming task below in a Python markdown code block. Where do odds begin, and where do they end? Where does hope emerge, and will they ever break? Given an integer sequence a_1, a_2, ..., a_{n} of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of...
{"inputs": ["1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "1\n-2\n", "2\n1 1\n", "2\n1 1\n", "2\n0 1\n"], "outputs": ["Yes\n", "No\n", "No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n"]}
coding
466
Solve the programming task below in a Python markdown code block. Similar to the [previous kata](https://www.codewars.com/kata/string-subpattern-recognition-ii/), but this time you need to operate with shuffled strings to identify if they are composed repeating a subpattern Since there is no deterministic way to tell ...
{"functional": "_inputs = [['a'], ['aaaa'], ['abcd'], ['babababababababa'], ['bbabbaaabbaaaabb'], ['123a123a123a'], ['123A123a123a'], ['12aa13a21233'], ['12aa13a21233A'], ['abcdabcaccd']]\n_outputs = [['a'], ['a'], ['abcd'], ['ab'], ['ab'], ['123a'], ['111222333Aaa'], ['123a'], ['111222333Aaaa'], ['aaabbccccdd']]\nimpo...
coding
321
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed binary matrix grid. In one operation, you can flip any 1 in grid to be 0. A binary matrix is well-isolated if there is no 1 in the matrix that is 4-directionally connected (i.e., horizontal a...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,1,0],[0,1,1],[1,1,1]]) == 3\n assert candidate(grid = [[0,0,0],[0,0,0],[0,0,0]]) == 0\n assert candidate(grid = [[0,1],[1,0]]) == 0\n\n\ncheck(Solution().minimumOperations)"}
coding
127
Solve the programming task below in a Python markdown code block. Tired of boring office work, Denis decided to open a fast food restaurant. On the first day he made $a$ portions of dumplings, $b$ portions of cranberry juice and $c$ pancakes with condensed milk. The peculiarity of Denis's restaurant is the procedure ...
{"inputs": ["2\n2 2 8\n3 2 2\n", "2\n2 2 8\n3 2 2\n", "2\n2 2 8\n3 3 2\n", "2\n2 2 7\n3 3 0\n", "2\n1 2 7\n3 3 0\n", "2\n1 3 7\n5 0 0\n", "2\n1 3 7\n5 0 1\n", "2\n2 2 8\n2 2 2\n"], "outputs": ["5\n5\n", "5\n5\n", "5\n5\n", "5\n3\n", "4\n3\n", "4\n1\n", "4\n2\n", "5\n4\n"]}
coding
550
Solve the programming task below in a Python markdown code block. Toad Rash has a binary string $s$. A binary string consists only of zeros and ones. Let $n$ be the length of $s$. Rash needs to find the number of such pairs of integers $l$, $r$ that $1 \leq l \leq r \leq n$ and there is at least one pair of integers ...
{"inputs": ["0\n", "0\n", "1\n", "00\n", "01\n", "00\n", "01\n", "000\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n"]}
coding
398
Solve the programming task below in a Python markdown code block. n! = n × (n − 1) × (n − 2) × ... × 3 × 2 × 1 Is called the factorial of n. For example, the factorial of 12 12! = 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = 479001600 And there are two consecutive 0s at the end. Write a program that inputs th...
{"inputs": ["2\n6\n11000\n0", "2\n6\n11100\n0", "2\n6\n10000\n0", "2\n3\n11100\n0", "2\n6\n10101\n0", "2\n1\n11110\n0", "2\n3\n10100\n0", "2\n0\n11110\n0"], "outputs": ["0\n1\n2748\n", "0\n1\n2772\n", "0\n1\n2499\n", "0\n0\n2772\n", "0\n1\n2523\n", "0\n0\n2774\n", "0\n0\n2523\n", "0\n"]}
coding
276
Solve the programming task below in a Python markdown code block. Chef gives you a sequence A of length N. Let X denote the MEX of the sequence A. Chef is interested in the count of positive values k, such that, if every element A_{i} of A is replaced by \texttt{max}(A_{i}-k,0), the MEX of the sequence still remains ...
{"inputs": ["3\n4\n1 2 3 5\n1\n0\n7\n5 10 2 4 0 6 1"], "outputs": ["0\n-1\n1"]}
coding
578
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed m x n binary matrix grid. A 0-indexed m x n difference matrix diff is created with the following procedure: Let the number of ones in the ith row be onesRowi. Let the number of ones in the j...
{"functional": "def check(candidate):\n assert candidate(grid = [[0,1,1],[1,0,1],[0,0,1]]) == [[0,0,4],[0,0,4],[-2,-2,2]]\n assert candidate(grid = [[1,1,1],[1,1,1]]) == [[5,5,5],[5,5,5]]\n\n\ncheck(Solution().onesMinusZeros)"}
coding
172
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array arr, return the mean of the remaining integers after removing the smallest 5% and the largest 5% of the elements. Answers within 10-5 of the actual answer will be considered accepted.   Please c...
{"functional": "def check(candidate):\n assert candidate(arr = [1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3]) == 2.00000\n assert candidate(arr = [6,2,7,5,1,2,0,3,10,2,5,0,5,5,0,8,7,6,8,0]) == 4.00000\n assert candidate(arr = [6,0,7,0,7,5,7,8,3,4,0,7,8,1,6,8,1,1,2,4,8,1,9,5,4,3,8,5,10,8,6,6,1,0,6,10,8,2,3,4]) == 4...
coding
94
Solve the programming task below in a Python markdown code block. We define the score of permutations of combinations, of an integer number (the function to obtain this value:```sc_perm_comb```) as the total sum of all the numbers obtained from the permutations of all the possible combinations of its digits. For exampl...
{"functional": "_inputs = [[348], [340], [333], [6], [0]]\n_outputs = [[3675], [1631], [369], [6], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) ...
coding
359
Please solve the programming task below using a self-contained code snippet in a markdown code block. We build a table of n rows (1-indexed). We start by writing 0 in the 1st row. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10. For e...
{"functional": "def check(candidate):\n assert candidate(n = 1, k = 1) == 0\n assert candidate(n = 2, k = 1) == 0\n assert candidate(n = 2, k = 2) == 1\n\n\ncheck(Solution().kthGrammar)"}
coding
181
Solve the programming task below in a Python markdown code block. N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N. The i-th tile from the left is painted black if the i-th character of S is 0, and painted white if that character is 1. You want to...
{"inputs": ["1", "0", "0\n", "1\n", "010", "100", "101", "011"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "1\n", "0\n", "1\n"]}
coding
203
Solve the programming task below in a Python markdown code block. During her tantrums the princess usually smashes some collectable porcelain. Every furious shriek is accompanied with one item smashed. The collection of porcelain is arranged neatly on n shelves. Within each shelf the items are placed in one row, so th...
{"inputs": ["1 1\n1 100\n", "1 3\n4 4 5 1 2\n", "1 3\n4 4 5 0 2\n", "1 3\n4 4 3 1 2\n", "3 2\n1 10\n1 2\n1 5\n", "3 2\n1 13\n1 2\n1 5\n", "3 2\n1 14\n1 2\n1 5\n", "3 2\n1 13\n1 2\n1 10\n"], "outputs": ["100\n", "11\n", "11\n", "9\n", "15\n", "18\n", "19\n", "23\n"]}
coding
448
Solve the programming task below in a Python markdown code block. In Aizu prefecture, we decided to create a new town to increase the population. To that end, we decided to cultivate a new rectangular land and divide this land into squares of the same size. The cost of developing this land is proportional to the number...
{"inputs": ["9 6 1", "3 3 1", "3 3 2", "2 1 8", "3 5 1", "3 6 2", "1 3 4", "5 1 1"], "outputs": ["6\n", "1\n", "2\n", "16\n", "15\n", "4\n", "12\n", "5\n"]}
coding
254
Solve the programming task below in a Python markdown code block. The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called x. Also, there are two operations: Operation ++ increases the value of variable x...
{"inputs": ["1\n++X\n", "1\nX--\n", "1\nX--\n", "1\n--X\n", "1\nX++\n", "1\n++X\n", "2\nX++\n--X\n", "2\n--X\n--X\n"], "outputs": ["1\n", "-1\n", "-1\n", "-1\n", "1\n", "1\n", "0\n", "-2\n"]}
coding
323
Solve the programming task below in a Python markdown code block. Chef Shifu wanted to celebrate the success of his new restaurant with all his employees. He was willing to host a party and he had decided the location of the party as well. However, Chef Shifu was a shy person and wanted to communicate with the least po...
{"inputs": ["2\n3 3\n1 2\n2 3\n1 3\n4 3\n1 2\n2 3\n3 4"], "outputs": ["1\n2"]}
coding
510
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Tuzik is a little dog. But despite the fact he is still a puppy he already knows about the pretty things that coins are. He knows that for every coin he can get very tasty bone from his master....
{"inputs": ["2\n5 4\n8 6", "2\n5 2\n5 3", "2\n9 6\n5 7", "2\n9 7\n8 3", "2\n9 7\n1 9", "2\n6 7\n8 7", "2\n6 7\n5 9", "2\n3 7\n4 6"], "outputs": ["2\n3\n", "1\n2\n", "4\n5\n", "4\n2\n", "4\n1\n", "6\n3\n", "6\n5\n", "3\n4\n"]}
coding
471
Solve the programming task below in a Python markdown code block. Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations. Fangy takes some positive integer x and wants to get a number one from it. While x is not equal to 1, Fangy repeats the following ac...
{"inputs": ["1\n", "11\n", "101010\n", "111010\n", "111110\n", "110010\n", "110011\n", "111011\n"], "outputs": ["0\n", "3\n", "9\n", "8\n", "7\n", "9\n", "9\n", "8\n"]}
coding
334
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s that contains digits 0-9, addition symbols '+', and multiplication symbols '*' only, representing a valid math expression of single digit numbers (e.g., 3+5*2). This expression was given to n ...
{"functional": "def check(candidate):\n assert candidate(s = \"7+3*1*2\", answers = [20,13,42]) == 7\n assert candidate(s = \"3+5*2\", answers = [13,0,10,13,13,16,16]) == 19\n assert candidate(s = \"6+0*1\", answers = [12,9,6,4,8,6]) == 10\n\n\ncheck(Solution().scoreOfStudents)"}
coding
256
Solve the programming task below in a Python markdown code block. Laura really hates people using acronyms in her office and wants to force her colleagues to remove all acronyms before emailing her. She wants you to build a system that will edit out all known acronyms or else will notify the sender if unknown acronyms ...
{"functional": "_inputs = [['BRB I need to go into a KPI meeting before EOD'], ['I am IAM so will be OOO until EOD'], ['Going to WAH today. NRN. OOO'], [\"We're looking at SMB on SM DMs today\"], ['OOO'], ['KPI'], ['EOD'], ['TBD'], ['TBD by EOD'], ['BRB I am OOO'], ['WAH'], ['IAM'], ['NRN'], ['CTA'], ['Hi PAB'], ['HATD...
coding
434
Solve the programming task below in a Python markdown code block. Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with s...
{"inputs": ["1\n4 2\n1 2 3 4"], "outputs": ["1"]}
coding
409
Solve the programming task below in a Python markdown code block. Oh no! Ghosts have reportedly swarmed the city. It's your job to get rid of them and save the day! In this kata, strings represent buildings while whitespaces within those strings represent ghosts. So what are you waiting for? Return the building(strin...
{"functional": "_inputs = [['Factor y'], ['O f fi ce'], ['BusStation'], ['Suite '], ['YourHouse'], ['H o t e l ']]\n_outputs = [['Factory'], ['Office'], [\"You just wanted my autograph didn't you?\"], ['Suite'], [\"You just wanted my autograph didn't you?\"], ['Hotel']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n ...
coding
114
Solve the programming task below in a Python markdown code block. Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ......
{"inputs": ["5\n2 0 1 8 7", "5\n2 2 3 5 5", "5\n2 2 3 5 10", "5\n2 0 1 8 10", "5\n2 2 2 5 10", "5\n2 2 2 8 10", "5\n2 0 2 8 10", "6\n6 0 4 3 2 1"], "outputs": ["10\n", "2", "6\n", "13\n", "7\n", "10\n", "12\n", "15\n"]}
coding
297
Solve the programming task below in a Python markdown code block. We have N ID cards, and there are M gates. We can pass the i-th gate if we have one of the following ID cards: the L_i-th, (L_i+1)-th, ..., and R_i-th ID cards. How many of the ID cards allow us to pass all the gates alone? -----Constraints----- - All ...
{"inputs": ["1 1\n1 1\n", "4 2\n1 6\n2 4", "4 1\n1 4\n2 4", "4 2\n1 4\n2 4", "4 2\n1 0\n2 4", "4 2\n1 3\n2 0", "4 2\n0 6\n2 4", "4 2\n1 0\n2 6"], "outputs": ["1\n", "3\n", "4\n", "3\n", "0\n", "0\n", "3\n", "0\n"]}
coding
291
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef’s girlfriend's birthday is near, so he wants to surprise her by making a special cake for her. Chef knows that his girlfriend likes cherries on the cake, so he puts cher...
{"inputs": ["2\n4 5\nRGRGR\nGRGRG\nRGRGR\nGRGRG\n2 3\nRRG\nGGR"], "outputs": ["0\n8"]}
coding
444
Solve the programming task below in a Python markdown code block. Takahashi and Aoki are going to together construct a sequence of integers. First, Takahashi will provide a sequence of integers a, satisfying all of the following conditions: - The length of a is N. - Each element in a is an integer between 1 and K, in...
{"inputs": ["1 5", "2 2", "2 4", "2 0", "4 4", "6 4", "2 3", "2 6"], "outputs": ["5\n", "2\n", "4\n", "0\n", "28\n", "184\n", "3\n", "6\n"]}
coding
317
Solve the programming task below in a Python markdown code block. In number world, two different numbers are friends if they have a lot in common, but also each one has unique perks. More precisely, two different numbers $a$ and $b$ are friends if $gcd(a,b)$, $\frac{a}{gcd(a,b)}$, $\frac{b}{gcd(a,b)}$ can form sides o...
{"inputs": ["3\n1 5 7\n", "3\n1 5 5\n", "3\n1 5 10\n", "3\n1 5 10\n", "6\n30 432 8 193 7 1\n", "6\n30 432 8 243 7 1\n", "6\n30 216 8 243 7 1\n", "6\n41 216 8 243 8 1\n"], "outputs": ["1\n3\n4\n", "1\n3\n3\n", "1\n3\n3\n", "1\n3\n3\n", "8\n76\n4\n39\n4\n1\n", "8\n76\n4\n48\n4\n1\n", "8\n42\n4\n48\n4\n1\n", "11\n42\n4\n4...
coding
396
Solve the programming task below in a Python markdown code block. Read problems statements in mandarin chinese, russian and vietnamese as well. Mike is a network administrator in a university. One of his primary responsibilities in the job is to create an effective firewall so that the students are not able to visit ...
{"inputs": ["4\n- codeforces\n+ codechef\n- youtube\n+ google"], "outputs": ["2\ncodef\ny"]}
coding
561
Solve the programming task below in a Python markdown code block. When naming identifiers (variables and functions) in programming, compound words that concatenate words are used. However, if you concatenate them as they are, you will not be able to understand the word breaks, so in general, select and apply the one th...
{"inputs": ["get_user_name L\ngetUserOame U\nGetUserName D\nEndOfInput X", "get_user_name L\ngetUserName U\nGrtUseeName D\nEndOfInput X", "get_user_nbme L\ngetUserOame U\nGetUserName D\nEndOfInput X", "embn_resu_teg L\ngetUserOame U\nGetUserName D\nEndOfInput X", "get_user_name L\ngetUserNamd U\nGetUserName D\nEndOfInp...
coding
372
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integer arrays arr1 and arr2, return the minimum number of operations (possibly zero) needed to make arr1 strictly increasing. In one operation, you can choose two indices 0 <= i < arr1.length and 0 <= j < a...
{"functional": "def check(candidate):\n assert candidate(arr1 = [1,5,3,6,7], arr2 = [1,3,2,4]) == 1\n assert candidate(arr1 = [1,5,3,6,7], arr2 = [4,3,1]) == 2\n assert candidate(arr1 = [1,5,3,6,7], arr2 = [1,6,3,3]) == -1\n\n\ncheck(Solution().makeArrayIncreasing)"}
coding
150
Solve the programming task below in a Python markdown code block. YouKn0wWho has two even integers x and y. Help him to find an integer n such that 1 ≤ n ≤ 2 ⋅ 10^{18} and n mod x = y mod n. Here, a mod b denotes the remainder of a after division by b. If there are multiple such integers, output any. It can be shown th...
{"inputs": ["1\n1000000000 1000000000\n", "1\n1000010000 1000000000\n", "1\n1001010000 1000000000\n", "1\n1001010010 1000000000\n", "1\n1001010010 1000100000\n", "1\n1000010010 1000000000\n", "1\n1000010011 1000000000\n", "1\n1001000000 1000000000\n"], "outputs": ["1000000000 \n", "2000010000\n", "2001010000\n", "20010...
coding
352
Solve the programming task below in a Python markdown code block. It’s the company's 3^rd anniversary, and everyone is super-excited about it. There is a tradition in the company, that the interns decide the seating arrangement of all the members. The requirements of this order are: The CEO of the company must sit in t...
{"inputs": ["80 82 81\n3\n50 90 65"], "outputs": ["79"]}
coding
304
Solve the programming task below in a Python markdown code block. An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of ...
{"inputs": ["3\n1\n1\n1", "3\n1\n5\n0", "3\n1\n0\n1", "3\n2\n0\n1", "3\n42\n5\n0", "3\n42\n5\n1", "3\n18\n5\n1", "3\n33\n5\n1"], "outputs": ["1\n", "3\n", "2\n", "3\n", "3\n", "3\n", "3\n", "3\n"]}
coding
341
Solve the programming task below in a Python markdown code block. Caracal is fighting with a monster. The health of the monster is H. Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens: - If the monster's health is 1, it drops to 0. - If t...
{"inputs": ["8", "3", "7", "1", "5", "6", "9", "4"], "outputs": ["15\n", "3\n", "7\n", "1\n", "7\n", "7\n", "15\n", "7"]}
coding
283
Please solve the programming task below using a self-contained code snippet in a markdown code block. The XOR total of an array is defined as the bitwise XOR of all its elements, or 0 if the array is empty. For example, the XOR total of the array [2,5,6] is 2 XOR 5 XOR 6 = 1. Given an array nums, return the sum of a...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3]) == 6\n assert candidate(nums = [5,1,6]) == 28\n assert candidate(nums = [3,4,5,6,7,8]) == 480\n\n\ncheck(Solution().subsetXORSum)"}
coding
166
Solve the programming task below in a Python markdown code block. In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that th...
{"inputs": ["1 1\n0\n", "2 4\n0 3\n", "2 4\n0 5\n", "9 10\n0 3 5 7 100 110 200 300 311\n", "4 1000000000\n0 1000 1000000 1000000000\n"], "outputs": ["1\n", "7\n", "8\n", "67\n", "2000000000\n"]}
coding
287
Please solve the programming task below using a self-contained code snippet in a markdown code block. Alice has some number of cards and she wants to rearrange the cards into groups so that each group is of size groupSize, and consists of groupSize consecutive cards. Given an integer array hand where hand[i] is the va...
{"functional": "def check(candidate):\n assert candidate(hand = [1,2,3,6,2,3,4,7,8], groupSize = 3) == True\n assert candidate(hand = [1,2,3,4,5], groupSize = 4) == False\n\n\ncheck(Solution().isNStraightHand)"}
coding
127
Solve the programming task below in a Python markdown code block. There are N cards. The i-th card has an integer A_i written on it. For any two cards, the integers on those cards are different. Using these cards, Takahashi and Aoki will play the following game: * Aoki chooses an integer x. * Starting from Takahashi,...
{"inputs": ["2 2\n4 25 18 55\n4\n2\n8", "1 2\n4 25 18 55\n4\n4\n6", "2 1\n0 3 59 55\n4\n1\n13", "2 1\n0 1 59 55\n4\n1\n13", "2 1\n0 43 68 85\n4\n0\n3", "4 3\n0 16 30 40\n2\n33\n8", "4 3\n1 20 30 46\n2\n33\n8", "4 3\n1 20 37 40\n2\n34\n8"], "outputs": ["25\n25\n", "4\n4\n", "3\n", "1\n", "43\n", "70\n56\n70\n", "76\n66\...
coding
478
Solve the programming task below in a Python markdown code block. Tom gives a number N to Roy and ask him to tell the total number of even divisors of the number N. Help Roy to answer the question of Tom. INPUT: First line contains the number of testcases T, followed by T lines each containing an integer N. OUTPUT:...
{"inputs": ["2\n9\n8", "100\n2\n4\n8\n16\n32\n64\n128\n256\n512\n1024\n2048\n4096\n8192\n16384\n32768\n65536\n131072\n262144\n524288\n1048576\n2097152\n4194304\n8388608\n16777216\n33554432\n67108864\n134217728\n268435456\n536870912\n397453457\n442566979\n265107982\n780169103\n183899109\n444753183\n990164631\n199710138\...
coding
127
Solve the programming task below in a Python markdown code block. For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order. Constraints * $1 \leq n \leq 9$ * $a_i$ consist of $1, 2, ..., n$ Input A sequence is given in the following form...
{"inputs": ["3\n3 3 1", "3\n3 1 3", "3\n3 3 2", "3\n6 1 3", "3\n3 5 2", "3\n0 5 2", "3\n6 1 4", "3\n6 1 6"], "outputs": ["3 1 3\n3 3 1\n", "1 3 3\n3 1 3\n3 3 1\n", "3 2 3\n3 3 2\n", "3 6 1\n6 1 3\n6 3 1\n", "3 2 5\n3 5 2\n5 2 3\n", "0 2 5\n0 5 2\n2 0 5\n", "4 6 1\n6 1 4\n6 4 1\n", "1 6 6\n6 1 6\n6 6 1\n"]}
coding
225
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef is a network engineer at CodeChef. Currently, he has to design a network that connects $N$ computers (numbered $1$ through $N$). The network sh...
{"inputs": ["3\n2 3\n5 6\n3 3"], "outputs": ["2\n2\n2"]}
coding
727
Solve the programming task below in a Python markdown code block. A city has been infected by a contagious virus. In a survey, it was found that A out of the N people living in the city are currently infected. It has been observed that the only way for a person to get infected is if he comes in contact with an already...
{"inputs": ["3\n2 1\n3 2\n3 1"], "outputs": ["1\n1\n1"]}
coding
456
Solve the programming task below in a Python markdown code block. Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is...
{"inputs": ["CODEFESTIVAM", "CPDEFESTIVAM", "BPDEFDSTIVBM", "MBVITSDFEDPB", "MBWITSDFEDPB", "BPCEFDSTIWBM", "CPCEFDSTJWBM", "WPCEFDSTJCAM"], "outputs": ["CODE\n", "CPDE\n", "BPDE\n", "MBVI\n", "MBWI\n", "BPCE\n", "CPCE\n", "WPCE\n"]}
coding
228
Solve the programming task below in a Python markdown code block. D: Is greed the best? story In Japan, where there are 1, 5, 10, 50, 100, 500 yen coins, it is known that the number of coins can be minimized by using as many coins as possible when paying a certain amount. .. If the amount of coins is different from ...
{"inputs": ["2 6", "6 7", "5 7", "4 5", "7 9", "3 4", "2 7", "2 3"], "outputs": ["-1\n", "12\n", "10\n", "8\n", "14\n", "6\n", "-1\n", "-1\n"]}
coding
350