task_type
stringclasses
1 value
problem
stringlengths
209
3.39k
answer
stringlengths
35
6.15k
problem_tokens
int64
60
774
answer_tokens
int64
12
2.04k
coding
Solve the programming task below in a Python markdown code block. #It's show time! Archers have gathered from all around the world to participate in the Arrow Function Faire. But the faire will only start if there are archers signed and if they all have enough arrows in their quivers - at least 5 is the requirement! Are all the archers ready? #Reference https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions #Argument `archers` is an array of integers, in which each element corresponds to the number of arrows each archer has. #Return Your function must return `true` if the requirements are met or `false` otherwise. #Examples `archersReady([1, 2, 3, 4, 5, 6, 7, 8])` returns `false` because there are archers with not enough arrows. `archersReady([5, 6, 7, 8])` returns `true`. Also feel free to reuse/extend the following starter code: ```python def archers_ready(archers): ```
{"functional": "_inputs = [[[]], [[1, 2, 3, 4]], [[5, 6, 7, 8]], [[5, 6, 7, 4]], [[1, 2, 3, 4, 5, 6, 7, 8]]]\n_outputs = [[False], [False], [True], [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 isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(archers_ready(*i), o[0])"}
238
228
coding
Solve the programming task below in a Python markdown code block. You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D. -----Constraints----- - 1\leq A\leq B\leq 10^{18} - 1\leq C,D\leq 10^9 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: A B C D -----Output----- Print the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D. -----Sample Input----- 4 9 2 3 -----Sample Output----- 2 5 and 7 satisfy the condition.
{"inputs": ["4 5 2 3", "1 5 2 3", "1 5 2 6", "1 4 8 8", "4 9 2 3", "4 9 2 3\n", "1 1 1 1\n", "2 40 8 8"], "outputs": ["1\n", "2\n", "3\n", "4\n", "2", "2\n", "0\n", "34\n"]}
170
113
coding
Solve the programming task below in a Python markdown code block. "We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme." "Little Alena got an array as a birthday present..." The array b of length n is obtained from the array a of length n and two integers l and r (l ≤ r) using the following procedure: b_1 = b_2 = b_3 = b_4 = 0. For all 5 ≤ i ≤ n: b_{i} = 0 if a_{i}, a_{i} - 1, a_{i} - 2, a_{i} - 3, a_{i} - 4 > r and b_{i} - 1 = b_{i} - 2 = b_{i} - 3 = b_{i} - 4 = 1 b_{i} = 1 if a_{i}, a_{i} - 1, a_{i} - 2, a_{i} - 3, a_{i} - 4 < l and b_{i} - 1 = b_{i} - 2 = b_{i} - 3 = b_{i} - 4 = 0 b_{i} = b_{i} - 1 otherwise You are given arrays a and b' of the same length. Find two integers l and r (l ≤ r), such that applying the algorithm described above will yield an array b equal to b'. It's guaranteed that the answer exists. -----Input----- The first line of input contains a single integer n (5 ≤ n ≤ 10^5) — the length of a and b'. The second line of input contains n space separated integers a_1, ..., a_{n} ( - 10^9 ≤ a_{i} ≤ 10^9) — the elements of a. The third line of input contains a string of n characters, consisting of 0 and 1 — the elements of b'. Note that they are not separated by spaces. -----Output----- Output two integers l and r ( - 10^9 ≤ l ≤ r ≤ 10^9), conforming to the requirements described above. If there are multiple solutions, output any of them. It's guaranteed that the answer exists. -----Examples----- Input 5 1 2 3 4 5 00001 Output 6 15 Input 10 -10 -9 -8 -7 -6 6 7 8 9 10 0000111110 Output -5 5 -----Note----- In the first test case any pair of l and r pair is valid, if 6 ≤ l ≤ r ≤ 10^9, in that case b_5 = 1, because a_1, ..., a_5 < l.
{"inputs": ["5\n1 2 3 4 5\n00001\n", "5\n1 2 3 4 5\n00001\n", "5\n0 2 3 4 5\n00001\n", "5\n2 0 4 0 2\n00001\n", "5\n1 2 3 0 5\n00001\n", "5\n2 2 3 0 5\n00001\n", "5\n2 0 3 0 5\n00001\n", "5\n2 0 4 0 5\n00001\n"], "outputs": ["6 1000000000\n", "6 1000000000\n", "6 1000000000\n", "5 1000000000\n", "6 1000000000\n", "6 1000000000\n", "6 1000000000\n", "6 1000000000\n"]}
631
286
coding
Solve the programming task below in a Python markdown code block. You are in the future. It's the time of autonomous cars. Switching lanes is a pretty difficult task for autonomous cars, and you have the logs from an experiment you had run with two cars. You want to verify whether the logs are corrupted, or could be valid. In that experiment, you had a highway consisting of two lanes. These were represented by 2 rows of an infinite grid. The cell (1, 1) is the top left cell which is the starting point of the first lane. Cell (2, 1) is the bottom left cell of the grid which is the starting point of the second lane. There are two cars, 1 and 2 that start from the cell (1, 1) and (2, 1). At each instant, a car has the following choices. - Stay at the current position. - Move one cell to the right. - Switch Lanes. When a car switches its lane, it stays in the same column. That is, from (1, i) it could go to (2, i), or from (2, i) it could go to (1, i). But both both cars shouldn't end up at the same cell at any point. Note that there could have been a car which had moved at the very instant that you move into it. Consider one such scenario of driving cars. Time $t = 0$ 1..... 2..... Time $t = 1$. Car 2 advances one cell right. Car 1 stays at the same place. 1..... .2.... Time $t = 2$. Car 2 stays at its place. Car 1 switches the lane. ...... 12.... Time $t = 3$. Car 2 moves one cell to the right. Car 1 also moves one cell to the right. ...... .12... Time $t = 4$. Both the cars stay in the same place. ...... .12... You are given positions of the car at $n$ instants. Your task is to check whether this situation is feasible or not. -----Input----- - The first line of the input contains an integer $T$ denoting the number of test cases. The description of the test cases follows. - The first line of each test case contains an integer $n$ denoting the number of instants where the positions of the cars were recorded. - Each of next $n$ lines contains 5 space separated integers denoting $t_i, x_i, y_i, X_i, Y_i$ denoting time, $x$ and $y$ coordinate of the first car, and that of second car. -----Output----- For each test case, output either yes or no according to the answer to the problem. -----Constraints----- - $1 \le T \le 10^5$ - $1 \le n \leq 10^5$ - $1 \le t_i, y_i, X_i, Y_i \leq 10^9$ - $1 \leq x_i \leq 2$ - $t_i < t_{i+1}$ - Sum of $n$ over all the test cases doesn't exceed $10^6$ -----Example Input----- 2 3 1 1 1 2 2 2 2 1 2 2 4 2 2 2 3 1 1 1 3 2 2 -----Example Output----- yes no
{"inputs": ["2\n3\n1 1 1 2 2\n2 2 1 2 2\n4 2 2 2 3\n1\n1 1 3 2 2"], "outputs": ["yes\nno"]}
746
58
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a string that has lowercase letters and numbers. Your task is to compare the number groupings and return the largest number. Numbers will not have leading zeros. For example, `solve("gh12cdy695m1") = 695`, because this is the largest of all number groupings. Good luck! Please also try [Simple remove duplicates](https://www.codewars.com/kata/5ba38ba180824a86850000f7) Also feel free to reuse/extend the following starter code: ```python def solve(s): ```
{"functional": "_inputs = [['gh12cdy695m1'], ['2ti9iei7qhr5'], ['vih61w8oohj5'], ['f7g42g16hcu5'], ['lu1j8qbbb85']]\n_outputs = [[695], [9], [61], [42], [85]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(solve(*i), o[0])"}
152
225
coding
Solve the programming task below in a Python markdown code block. Count the number of distinct sequences a_1, a_2, ..., a_{n} (1 ≤ a_{i}) consisting of positive integers such that gcd(a_1, a_2, ..., a_{n}) = x and $\sum_{i = 1}^{n} a_{i} = y$. As this number could be large, print the answer modulo 10^9 + 7. gcd here means the greatest common divisor. -----Input----- The only line contains two positive integers x and y (1 ≤ x, y ≤ 10^9). -----Output----- Print the number of such sequences modulo 10^9 + 7. -----Examples----- Input 3 9 Output 3 Input 5 8 Output 0 -----Note----- There are three suitable sequences in the first test: (3, 3, 3), (3, 6), (6, 3). There are no suitable sequences in the second test.
{"inputs": ["3 9\n", "5 8\n", "1 8\n", "1 9\n", "1 1\n", "1 1\n", "1 9\n", "1 8\n"], "outputs": ["3\n", "0\n", "120\n", "252\n", "1\n", "1\n", "252\n", "120\n"]}
220
94
coding
Solve the programming task below in a Python markdown code block. Given a matrix (H × W) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s. Constraints * 1 ≤ H, W ≤ 1,400 Input H W c1,1 c1,2 ... c1,W c2,1 c2,2 ... c2,W : cH,1 cH,2 ... cH,W In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given. Output Print the area (the number of 0s) of the largest rectangle. Example Input 4 5 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 Output 6
{"inputs": ["4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 0 1\n0 0 0 1 0", "1 5\n0 0 1 0 0\n1 0 0 0 1\n0 0 0 1 0\n0 0 0 1 0", "4 5\n1 0 1 1 0\n1 0 0 0 0\n0 0 1 0 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "4 5\n0 0 0 0 0\n1 1 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 1\n0 0 0 1 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 1 0 0 0\n0 0 0 0 0\n0 0 0 1 0"], "outputs": ["8\n", "6\n", "2\n", "4\n", "10\n", "9\n", "6\n", "6\n"]}
213
399
coding
Solve the programming task below in a Python markdown code block. Binary trees are defined recursively. A binary tree T is a structure defined on a finite set of nodes that either * contains no nodes, or * is composed of three disjoint sets of nodes: - a root node. - a binary tree called its left subtree. - a binary tree called its right subtree. Your task is to write a program which perform tree walks (systematically traverse all nodes in a tree) based on the following algorithms: 1. Print the root, the left subtree and right subtree (preorder). 2. Print the left subtree, the root and right subtree (inorder). 3. Print the left subtree, right subtree and the root (postorder). Here, the given binary tree consists of n nodes and evey node has a unique ID from 0 to n-1. Constraints * 1 ≤ n ≤ 25 Input The first line of the input includes an integer n, the number of nodes of the tree. In the next n linen, the information of each node is given in the following format: id left right id is the node ID, left is ID of the left child and right is ID of the right child. If the node does not have the left (right) child, the left(right) is indicated by -1 Output In the 1st line, print "Preorder", and in the 2nd line print a list of node IDs obtained by the preorder tree walk. In the 3rd line, print "Inorder", and in the 4th line print a list of node IDs obtained by the inorder tree walk. In the 5th line, print "Postorder", and in the 6th line print a list of node IDs obtained by the postorder tree walk. Print a space character before each node ID. Example Input 9 0 1 4 1 2 3 2 -1 -1 3 -1 -1 4 5 8 5 6 7 6 -1 -1 7 -1 -1 8 -1 -1 Output Preorder 0 1 2 3 4 5 6 7 8 Inorder 2 1 3 0 6 5 7 4 8 Postorder 2 3 1 6 7 5 8 4 0
{"inputs": ["9\n0 2 4\n1 0 3\n2 -1 -1\n3 0 0\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1", "9\n0 2 4\n1 0 3\n2 -1 -1\n3 -1 0\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1", "9\n0 1 4\n1 2 5\n2 -1 -1\n3 -1 -1\n4 3 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1", "9\n0 2 4\n1 1 3\n2 -1 -1\n3 -1 -1\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1", "9\n0 2 4\n1 0 3\n2 -1 -1\n3 -1 -1\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1", "9\n0 1 4\n1 2 3\n2 -1 -1\n3 -1 -1\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1"], "outputs": ["Preorder\n 1 0 2 4 5 6 7 8 3 0 2 4 5 6 7 8 0 2 4 5 6 7 8\nInorder\n 2 0 6 5 7 4 8 1 2 0 6 5 7 4 8 3 2 0 6 5 7 4 8\nPostorder\n 2 6 7 5 8 4 0 2 6 7 5 8 4 0 2 6 7 5 8 4 0 3 1\n", "Preorder\n 1 0 2 4 5 6 7 8 3 0 2 4 5 6 7 8\nInorder\n 2 0 6 5 7 4 8 1 3 2 0 6 5 7 4 8\nPostorder\n 2 6 7 5 8 4 0 2 6 7 5 8 4 0 3 1\n", "Preorder\n 0 1 2 5 6 7 4 3 8\nInorder\n 2 1 6 5 7 0 3 4 8\nPostorder\n 2 6 7 5 1 3 8 4 0\n", "Preorder\n 0 2 4 5 6 7 8\nInorder\n 2 0 6 5 7 4 8\nPostorder\n 2 6 7 5 8 4 0\n", "Preorder\n 1 0 2 4 5 6 7 8 3\nInorder\n 2 0 6 5 7 4 8 1 3\nPostorder\n 2 6 7 5 8 4 0 3 1\n", "Preorder\n 0 1 2 3 4 5 6 7 8\nInorder\n 2 1 3 0 6 5 7 4 8\nPostorder\n 2 3 1 6 7 5 8 4 0"]}
512
869
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Alexandra has some distinct integer numbers a_{1},a_{2}...a_{n}. Count number of pairs (i,j) such that: 1≤ i ≤ n 1≤ j ≤ n a_{i} < a_{j}   ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.The first line of each test case contains a single integer n denoting the number of numbers Alexandra has. The second line contains n space-separated distinct integers a_{1}, a_{2}, ..., a_{n} denoting these numbers.   ------ Output ------ For each test case, output a single line containing number of pairs for corresponding test case.   ------ Constraints ------ $1 ≤ T ≤ 4$ $1 ≤ n ≤ 100000$ $0 ≤ a_{i} ≤ 10^{9}$ $All the a_{i} are distinct ----- Sample Input 1 ------ 2 2 12 11 3 13 11 12 ----- Sample Output 1 ------ 1 3 ----- explanation 1 ------ Case 1: Only one such pair of (i, j) indices exists: (2,1), since a2 1. Case 2: 3 possible pairs of indices: (2,1), (2,3), (3,1) .
{"inputs": ["2\n2\n12 11\n3\n13 11 12"], "outputs": ["1\n3"]}
329
33
coding
Solve the programming task below in a Python markdown code block. ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bills from it, and the bills may be of at most two distinct denominations. For example, if a country uses bills with denominations 10, 50, 100, 500, 1000 and 5000 burles, then at k = 20 such ATM can give sums 100 000 burles and 96 000 burles, but it cannot give sums 99 000 and 101 000 burles. Let's suppose that the country uses bills of n distinct denominations, and the ATM that you are using has an unlimited number of bills of each type. You know that during the day you will need to withdraw a certain amount of cash q times. You know that when the ATM has multiple ways to give money, it chooses the one which requires the minimum number of bills, or displays an error message if it cannot be done. Determine the result of each of the q of requests for cash withdrawal. Input The first line contains two integers n, k (1 ≤ n ≤ 5000, 1 ≤ k ≤ 20). The next line contains n space-separated integers ai (1 ≤ ai ≤ 107) — the denominations of the bills that are used in the country. Numbers ai follow in the strictly increasing order. The next line contains integer q (1 ≤ q ≤ 20) — the number of requests for cash withdrawal that you will make. The next q lines contain numbers xi (1 ≤ xi ≤ 2·108) — the sums of money in burles that you are going to withdraw from the ATM. Output For each request for cash withdrawal print on a single line the minimum number of bills it can be done, or print - 1, if it is impossible to get the corresponding sum. Examples Input 6 20 10 50 100 500 1000 5000 8 4200 100000 95000 96000 99000 10100 2015 9950 Output 6 20 19 20 -1 3 -1 -1 Input 5 2 1 2 3 5 8 8 1 3 5 7 9 11 13 15 Output 1 1 1 2 2 2 2 -1
{"inputs": ["1 1\n1\n1\n1\n", "1 20\n1\n1\n200000000\n", "2 2\n1 2\n1\n200000000\n", "2 5\n1 2\n1\n200000000\n", "1 1\n42\n5\n1\n41\n42\n43\n84\n", "1 1\n42\n5\n1\n39\n42\n43\n84\n", "1 1\n1000000\n1\n200000000\n", "1 1\n1000000\n1\n179035188\n"], "outputs": ["1\n", "-1\n", "-1\n", "-1\n", "-1\n-1\n1\n-1\n-1\n", "-1\n-1\n1\n-1\n-1\n", "-1\n", "-1\n"]}
632
239
coding
Solve the programming task below in a Python markdown code block. You will get an array of numbers. Every preceding number is smaller than the one following it. Some numbers will be missing, for instance: ``` [-3,-2,1,5] //missing numbers are: -1,0,2,3,4 ``` Your task is to return an array of those missing numbers: ``` [-1,0,2,3,4] ``` Also feel free to reuse/extend the following starter code: ```python def find_missing_numbers(arr): ```
{"functional": "_inputs = [[[-3, -2, 1, 4]], [[-1, 0, 1, 2, 3, 4]], [[]], [[0]], [[-4, 4]]]\n_outputs = [[[-1, 0, 2, 3]], [[]], [[]], [[]], [[-3, -2, -1, 0, 1, 2, 3]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(find_missing_numbers(*i), o[0])"}
120
234
coding
Solve the programming task below in a Python markdown code block. Monk was asked to answer some queries in an interview. He is given an empty array A. Queries are of 4 types:- 1. 1 X - Add number X to the array A. 2. 2 X - Remove a single instance of number X from the array A. If not possible, print "-1" without the quotes. 3. 3 - Find the maximum element in the array A. 4. 4 - Find the minimum element in the array A. Input: The first line contains the integer Q. The next Q lines will each contain a query like the ones mentioned above. Output: For queries 3 and 4, print the answer in a new line. If the array is empty for query 3 and 4, then print "-1" without the quotes. Constraints: 1 ≤ Q ≤ 100000 1 ≤ X ≤ 100000 SAMPLE INPUT 5 1 5 1 9 1 6 3 2 1 SAMPLE OUTPUT 9 -1 Explanation There are 5 queries. Query 1 - 5 is added to the array. Query 2 - 9 is added to the array. Query 3 - 6 is added to the array. Query 4 - The maximum element in the array is 9. Query 5 - Since there is no element in the array with value 1, so the output is -1.
{"inputs": ["10\n1 5\n3\n3\n3\n1 4\n1 1\n1 8\n3\n1 6\n4\n", "100\n1 5\n1 22393\n2 22393\n4\n1 28040\n1 9505\n1 22027\n3\n1 2173\n4\n1 16189\n1 15918\n1 2896\n4\n4\n3\n4\n1 6654\n1 8716\n3\n4\n2 1472\n3\n4\n4\n1 2463\n2 2463\n2 19805\n4\n4\n4\n1 30479\n1 12892\n3\n3\n2 1\n4\n1 17656\n2 26370\n3\n2 28040\n3\n4\n4\n2 6263\n2 22393\n1 13976\n4\n1 29799\n2 17056\n2 9505\n2 8637\n3\n2 9505\n4\n3\n2 11520\n4\n2 17656\n1 26087\n3\n1 27752\n3\n3\n1 23205\n1 9203\n3\n1 31976\n2 16240\n4\n1 24526\n4\n1 31583\n3\n1 2450\n1 24435\n1 13808\n3\n3\n2 6654\n1 29766\n3\n3\n1 6033\n2 10111\n3\n3\n4\n2 9505\n2 2333\n2 17656\n2 16433\n2 2896\n4\n2 5136\n3\n2 6033\n3\n4\n1 19872\n"], "outputs": ["5\n5\n5\n8\n1\n", "5\n28040\n5\n5\n5\n28040\n5\n28040\n5\n-1\n28040\n5\n5\n-1\n5\n5\n5\n30479\n30479\n-1\n5\n-1\n30479\n30479\n5\n5\n-1\n-1\n5\n-1\n-1\n30479\n-1\n5\n30479\n-1\n5\n30479\n30479\n30479\n30479\n-1\n5\n5\n31976\n31976\n31976\n31976\n31976\n-1\n31976\n31976\n5\n-1\n-1\n-1\n-1\n5\n-1\n31976\n31976\n5\n"]}
319
795
coding
Solve the programming task below in a Python markdown code block. Darshit is planning to celebrate the birthday of his friend, Diksha. There are two types of gifts that Diksha wants from Darshit: one is black and the other is white. To make her happy, Darshit has to buy B number of black gifts and W number of white gifts. The cost of each black gift is X units. The cost of every white gift is Y units. The cost of converting each black gift into white gift or vice versa is Z units. Help Darshit by deducing the minimum amount he needs to spend on Diksha's gifts. INPUT The first line will contain an integer T which will be the number of test cases. There will be T pairs of lines. The first line of each test case will contain the values of integers B and W. Another line of each test case will contain the values of integers X, Y, and Z. OUTPUT T lines, each containing an integer: the minimum amount of units Darshit needs to spend on gifts. Constraints 1≤T≤10 0≤X,Y,Z,B,W≤109 SAMPLE INPUT 5 10 10 1 1 1 5 9 2 3 4 3 6 9 1 1 7 7 4 2 1 3 3 1 9 2 SAMPLE OUTPUT 20 37 12 35 12 Explanation SAMPLE CASE 1: There is no benefit to converting the white gifts into black or the black gifts into white, so Darshit will have to buy each gift for 1 unit. So cost of buying all gifts will be: 10∗1+10∗1=20. SAMPLE CASE 2: Again, we can't decrease the cost of black or white gifts by converting colors. We will buy gifts at their original price. So cost of buying all gifts will be: 5∗2+9∗3=10+27=37. SAMPLE CASE 3: We will buy white gifts at their original price, 1. For black gifts, we will first buy white one and color them to black, so that their cost will be reduced to 1+1=2. So cost of buying all gifts will be: 3∗2+6∗1=12. SAMPLE CASE 4: Similarly, we will buy white gifts at their original price, 2. For black gifts, we will first buy white one and color them to black, so that their cost will be reduced to 2+1=3. So cost of buying all gifts will be: 7∗3+7∗2=35. SAMPLE CASE 5: We will buy black gifts at their original price, 1. For white gifts, we will first black gifts worth 1 unit and color them to white with another 2 units, so cost for white gifts is reduced to 3 units. So cost of buying all gifts will be: 3∗1+3∗3=3+9=12.
{"inputs": ["5\n10 10\n1 1 1\n5 9\n2 3 4\n3 6\n9 1 1\n7 7\n4 2 1\n3 3\n1 9 2", "10\n330 557\n867513 531885 919789\n911 967\n707275 206718 144846\n897 543\n515113 825642 564879\n485 557\n368448 250548 443004\n398 561\n222741 277616 976299\n263 914\n323768 832927 597107\n595 257\n104664 621107 969493\n804 369\n386811 764431 717087\n657 327\n861981 46769 513320\n860 605\n274229 795307 2153", "10\n71805 9169\n905480 255669 334440\n56399 55940\n594189 471473 231368\n15994 44048\n874583 375348 332432\n10269 66173\n512771 387924 613661\n31470 73137\n999563 625186 287011\n33416 87228\n357232 567986 517178\n34394 39790\n142699 939873 995458\n77138 96271\n851397 71326 484096\n99116 87319\n228143 473698 879018\n76926 319\n945190 589696 288242", "10\n443463982 833847400\n429734889 628664883 610875522\n623669229 435417504\n266946955 600641444 515391879\n763364819 37220400\n711640763 34378393 655626808\n177742229 51792729\n358392247 642296973 158448705\n402332409 253667421\n384186676 728988281 883897044\n962555475 753433321\n20275090 23915540 815412555\n853918694 319895873\n649259954 136169934 948560755\n112651828 759839162\n236494610 379598782 212996957\n751886489 142963601\n250217357 463527251 29858345\n905844164 493785831\n81651073 116752762 136082804"], "outputs": ["20\n37\n12\n35\n12", "582539235\n520171110\n910379967\n318252516\n244393494\n846446262\n221899579\n593071083\n383271936\n403048050", "44717005806\n59885865031\n27853562024\n30935740251\n74431068072\n61481547320\n42305536076\n49710767582\n63975457250\n67724371612", "714782523241122198\n428016399954183471\n528005272909240819\n90470040201136571\n339491328041275785\n37534663611326090\n597975411899462458\n315075570539747764\n228175680952112475\n131614007567103194"]}
657
1,606
coding
Solve the programming task below in a Python markdown code block. Today is Chocolate day and Kabir and Tara are visiting a Valentine fair. Upon arriving, they find a stall with an interesting game. There are N$N$ jars having some chocolates in them. To win the game, one has to select the maximum number of consecutive jars such that the sum of count of chocolates in maximum and second maximum jar is less than or equal to k$k$ in that range. Kabir wants to win the game so that he can gift the chocolates to Tara. You are a friend of Kabiir, help him win the game. There will be at least one possible answer. Note$Note$ : - You have to select at least two jars. - Count of chocolates in maximum and second maximum jar among selected consecutive jars may be equal. -----Input:----- - First line will contain T$T$, number of test cases. - First line of each test case contains two space separated integers N,k$N, k$. - Second line of each test case contains N$N$ space separated integer ai$a_i$ denotes number of chocolates in the jar. -----Output:----- For each test case print maximum number of jars. -----Constraints:----- - 1≤T≤10$1 \leq T \leq 10$ - 2≤N≤105$2 \leq N \leq 10^5$ - 1≤ai≤105$1 \leq a_i \leq 10^5$ -----Sample Input:----- 1 6 5 1 3 3 1 1 5 -----Sample Output:----- 3 -----EXPLANATION:----- You can select 3rd$3^{rd}$, 4th$4^{th}$, and 5th$5^{th}$ jar as the sum of max and second max is equal to 4 which is less then 5.
{"inputs": ["1\n6 5\n1 3 3 1 1 5"], "outputs": ["3"]}
412
28
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. You are given a sequence A_{1}, A_{2}, \ldots, A_{N} which contains pairwise distinct elements and a sequence B_{1}, B_{2}, \ldots, B_{N}, which also contains pairwise distinct elements (but not necessarily distinct from elements of A). For each valid i, 1 ≤ A_{i}, B_{i} ≤ 2 \cdot N. You may rotate B as many times as you want. A rotation consists of moving the first element of the sequence to the end. Afterwards, let's define a sequence C_{1}, C_{2}, \ldots, C_{N} as C_{i} = (A_{i} + B_{i}) \% N for each valid i. There are N possible sequences C. Find the lexicographically smallest of these sequences. Note: A sequence x is lexicographically smaller than a different sequence y if x_{i} < y_{i}, where i is the smallest valid index where the sequences x and y differ. ------ Input Format ------ - The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N. - The second line contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}. - The third line contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}. ------ Output Format ------ For each test case, print a single line containing N space-separated integers C_{1}, C_{2}, \ldots, C_{N} denoting the lexicographically smallest sequence. ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 2 \cdot N$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$ ------ subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 1 3 1 4 5 1 3 4 ----- Sample Output 1 ------ 1 2 0 ----- explanation 1 ------ Example case 1: After rotating $B$ once, it becomes $(3,4,1)$. Now $C = (1,2,0)$. This is the lexicographically smallest of all possible sequences $C$.
{"inputs": ["1\n3\n1 4 5\n1 3 4"], "outputs": ["1 2 0"]}
581
30
coding
Solve the programming task below in a Python markdown code block. Monocarp is the coach of the Berland State University programming teams. He decided to compose a problemset for a training session for his teams. Monocarp has $n$ problems that none of his students have seen yet. The $i$-th problem has a topic $a_i$ (an integer from $1$ to $n$) and a difficulty $b_i$ (an integer from $1$ to $n$). All problems are different, that is, there are no two tasks that have the same topic and difficulty at the same time. Monocarp decided to select exactly $3$ problems from $n$ problems for the problemset. The problems should satisfy at least one of two conditions (possibly, both): the topics of all three selected problems are different; the difficulties of all three selected problems are different. Your task is to determine the number of ways to select three problems for the problemset. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 50000$) — the number of testcases. The first line of each testcase contains an integer $n$ ($3 \le n \le 2 \cdot 10^5$) — the number of problems that Monocarp have. In the $i$-th of the following $n$ lines, there are two integers $a_i$ and $b_i$ ($1 \le a_i, b_i \le n$) — the topic and the difficulty of the $i$-th problem. It is guaranteed that there are no two problems that have the same topic and difficulty at the same time. The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$. -----Output----- Print the number of ways to select three training problems that meet either of the requirements described in the statement. -----Examples----- Input 2 4 2 4 3 4 2 1 1 3 5 1 5 2 4 3 3 4 2 5 1 Output 3 10 -----Note----- In the first example, you can take the following sets of three problems: problems $1$, $2$, $4$; problems $1$, $3$, $4$; problems $2$, $3$, $4$. Thus, the number of ways is equal to three.
{"inputs": ["2\n4\n2 4\n3 4\n2 1\n1 3\n5\n1 5\n2 4\n3 3\n4 2\n5 1\n", "2\n4\n2 4\n3 4\n2 1\n2 3\n5\n1 5\n2 4\n3 3\n4 2\n5 1\n", "2\n4\n2 4\n3 3\n2 2\n1 3\n5\n1 5\n2 4\n3 3\n4 2\n5 1\n", "2\n4\n4 4\n3 3\n2 2\n2 3\n5\n1 5\n2 4\n3 3\n4 2\n5 1\n", "2\n4\n2 4\n3 4\n2 2\n2 3\n5\n1 5\n2 3\n3 3\n4 2\n2 1\n", "2\n4\n4 4\n3 4\n2 2\n2 3\n5\n2 5\n2 4\n3 5\n4 2\n4 1\n", "2\n4\n2 4\n3 4\n2 2\n2 3\n5\n2 5\n2 3\n3 3\n4 2\n2 1\n", "2\n4\n4 4\n3 3\n2 2\n2 3\n5\n1 5\n3 4\n3 3\n4 4\n5 1\n"], "outputs": ["3\n10\n", "2\n10\n", "4\n10\n", "3\n10\n", "2\n9\n", "4\n9\n", "2\n8\n", "3\n9\n"]}
522
410
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s consisting only of lowercase English letters. In one move, you can select any two adjacent characters of s and swap them. Return the minimum number of moves needed to make s a palindrome. Note that the input will be generated such that s can always be converted to a palindrome.   Please complete the following python code precisely: ```python class Solution: def minMovesToMakePalindrome(self, s: str) -> int: ```
{"functional": "def check(candidate):\n assert candidate(s = \"aabb\") == 2\n assert candidate(s = \"letelt\") == 2\n\n\ncheck(Solution().minMovesToMakePalindrome)"}
111
48
coding
Solve the programming task below in a Python markdown code block. A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object. There are $n$ students in the class, and you are given an array $s$ in non-decreasing order, where $s_i$ is the shoe size of the $i$-th student. A shuffling of shoes is valid only if no student gets their own shoes and if every student gets shoes of size greater than or equal to their size. You have to output a permutation $p$ of $\{1,2,\ldots,n\}$ denoting a valid shuffling of shoes, where the $i$-th student gets the shoes of the $p_i$-th student ($p_i \ne i$). And output $-1$ if a valid shuffling does not exist. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array) and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array). -----Input----- Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1\leq n\leq10^5$) — the number of students. The second line of each test case contains $n$ integers $s_1, s_2,\ldots,s_n$ ($1\leq s_i\leq10^9$, and for all $1\le i<n$, $s_i\le s_{i+1}$) — the shoe sizes of the students. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, print the answer in a single line using the following format. If a valid shuffling does not exist, print the number $-1$ as the answer. If a valid shuffling exists, print $n$ space-separated integers — a permutation $p$ of $1,2,\ldots,n$ denoting a valid shuffling of shoes where the $i$-th student gets the shoes of the $p_i$-th student. If there are multiple answers, then print any of them. -----Examples----- Input 2 5 1 1 1 1 1 6 3 6 8 13 15 21 Output 5 1 2 3 4 -1 -----Note----- In the first test case, any permutation $p$ of $1,\ldots,n$ where $p_i\ne i$ would represent a valid shuffling since all students have equal shoe sizes, and thus anyone can wear anyone's shoes. In the second test case, it can be shown that no valid shuffling is possible.
{"inputs": ["2\n5\n1 1 1 1 1\n6\n3 6 8 13 15 21\n", "2\n7\n2 2 3 3 3 4 4\n6\n1 2 2 2 3 3\n", "6\n1\n95\n12\n1 1 1 1 1 1 1 39 39 39 39 39\n3\n5 5 5\n9\n46 46 46 46 46 46 46 46 46\n8\n18 18 18 18 35 35 35 35\n17\n23 23 25 25 25 25 25 25 25 36 36 66 66 95 95 96 96\n", "3\n11\n195927690 195927690 195927690 195927690 648407515 648407515 648407515 648407515 723866428 723866428 723866428\n33\n40510088 40510088 40510088 40510088 40510088 40510088 235029827 235029827 281017349 281017349 281017349 479119612 479119612 479119612 725087676 725087676 725087676 725087676 725087676 725087676 767831567 767831567 767831567 850812995 850812995 850812995 893044761 893044761 893044761 893044761 919517599 919517599 919517599\n6\n120432071 120432071 235546117 235546117 240892467 240892467\n"], "outputs": ["5 1 2 3 4 \n-1\n", "2 1 5 3 4 7 6 \n-1\n", "-1\n7 1 2 3 4 5 6 12 8 9 10 11 \n3 1 2 \n9 1 2 3 4 5 6 7 8 \n4 1 2 3 8 5 6 7 \n2 1 9 3 4 5 6 7 8 11 10 13 12 15 14 17 16 \n", "4 1 2 3 8 5 6 7 11 9 10 \n6 1 2 3 4 5 8 7 11 9 10 14 12 13 20 15 16 17 18 19 23 21 22 26 24 25 30 27 28 29 33 31 32 \n2 1 4 3 6 5 \n"]}
709
1,022
coding
Solve the programming task below in a Python markdown code block. On some square in the lowest row of a chessboard a stands a pawn. It has only two variants of moving: upwards and leftwards or upwards and rightwards. The pawn can choose from which square of the lowest row it can start its journey. On each square lay from 0 to 9 peas. The pawn wants to reach the uppermost row having collected as many peas as possible. As there it will have to divide the peas between itself and its k brothers, the number of peas must be divisible by k + 1. Find the maximal number of peas it will be able to collect and which moves it should make to do it. The pawn cannot throw peas away or leave the board. When a pawn appears in some square of the board (including the first and last square of the way), it necessarily takes all the peas. Input The first line contains three integers n, m, k (2 ≤ n, m ≤ 100, 0 ≤ k ≤ 10) — the number of rows and columns on the chessboard, the number of the pawn's brothers. Then follow n lines containing each m numbers from 0 to 9 without spaces — the chessboard's description. Each square is described by one number — the number of peas in it. The first line corresponds to the uppermost row and the last line — to the lowest row. Output If it is impossible to reach the highest row having collected the number of peas divisible by k + 1, print -1. Otherwise, the first line must contain a single number — the maximal number of peas the pawn can collect given that the number must be divisible by k + 1. The second line must contain a single number — the number of the square's column in the lowest row, from which the pawn must start its journey. The columns are numbered from the left to the right with integral numbers starting from 1. The third line must contain a line consisting of n - 1 symbols — the description of the pawn's moves. If the pawn must move upwards and leftwards, print L, if it must move upwards and rightwards, print R. If there are several solutions to that problem, print any of them. Examples Input 3 3 1 123 456 789 Output 16 2 RL Input 3 3 0 123 456 789 Output 17 3 LR Input 2 2 10 98 75 Output -1
{"inputs": ["2 2 0\n02\n64\n", "2 2 3\n15\n52\n", "2 2 9\n82\n68\n", "2 2 2\n82\n68\n", "2 2 2\n44\n68\n", "2 2 3\n15\n67\n", "2 2 10\n98\n12\n", "2 2 10\n98\n75\n"], "outputs": ["8\n1\nR\n", "-1\n", "-1\n", "-1", "12\n2\nL\n", "8\n2\nL\n", "11\n2\nL\n", "-1\n"]}
545
169
coding
Solve the programming task below in a Python markdown code block. It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups. The bus stop queue has n groups of people. The i-th group from the beginning has a_{i} people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most m people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue. Your task is to determine how many buses is needed to transport all n groups to the dacha countryside. -----Input----- The first line contains two integers n and m (1 ≤ n, m ≤ 100). The next line contains n integers: a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ m). -----Output----- Print a single integer — the number of buses that is needed to transport all n groups to the dacha countryside. -----Examples----- Input 4 3 2 3 2 1 Output 3 Input 3 4 1 2 1 Output 1
{"inputs": ["1 5\n4\n", "1 5\n4\n", "1 73\n24\n", "2 6\n1 4\n", "2 5\n5 5\n", "2 6\n1 4\n", "2 5\n5 5\n", "1 73\n24\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "1\n", "2\n", "1\n"]}
323
114
coding
Solve the programming task below in a Python markdown code block. Tom has finally taken over the business empire and now looking for a new Name of the business to make a new start. Joe (Tom's dear friend) suggested a string $S$ consisting of Uppercase and lowercase letters Tom wants to make some changes as per the following criteria: 1) String should $not$ have any vowels . 2) Every other uppercase consonant(other characters except vowels) should be in lowercase For ex: If the consonant character is Z then it should be z 3) There should be a character "." before each consonant. Help Tom to make the required Changes. -----Input:----- - First line will contain string $S$,This string only consists of uppercase and lowercase letters. -----Output:----- Print the resulting string. It is guaranteed that this string is not empty. -----Constraints----- - Length of string is in [1 .. 100] -----Sample Input:----- $CodeSprInT$ -----Sample Output:----- .c.d.s.p.r.n.t -----EXPLANATION:----- C is a consonant and it is in uppercase so turn it in lower case and add a “.” before it o is a vowel so it is deleted d is a consonant and in lowercase so just add a “.” before it e is a vowel so it is deleted S is a consonant and it is in uppercase so turn it in lower case and add a “.” before it p is a consonant and in lowercase so just add a “.” before it r is a consonant and in lowercase so just add a “.” before it I is a vowel so it is deleted n is a consonant and in lowercase so just add a “.” before it T is a consonant and it is in uppercase so turn it in lower case and add a “.” before it
{"inputs": ["CodeSprInT"], "outputs": [".c.d.s.p.r.n.t"]}
408
22
coding
Solve the programming task below in a Python markdown code block. You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: Swap two neighboring matrix rows, that is, rows with indexes i and i + 1 for some integer i (1 ≤ i < 5). Swap two neighboring matrix columns, that is, columns with indexes j and j + 1 for some integer j (1 ≤ j < 5). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful. -----Input----- The input consists of five lines, each line contains five integers: the j-th integer in the i-th line of the input represents the element of the matrix that is located on the intersection of the i-th row and the j-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. -----Output----- Print a single integer — the minimum number of moves needed to make the matrix beautiful. -----Examples----- Input 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 3 Input 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 1
{"inputs": ["0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n", "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"], "outputs": ["3\n", "1\n", "0\n", "4\n", "3\n", "4\n", "2\n", "3\n"]}
411
454
coding
Solve the programming task below in a Python markdown code block. Little chief has his own restaurant in the city. There are N workers there. Each worker has his own salary. The salary of the i-th worker equals to W_{i} (i = 1, 2, ..., N). Once, chief decided to equalize all workers, that is, he wants to make salaries of all workers to be equal. But for this goal he can use only one operation: choose some worker and increase by 1 salary of each worker, except the salary of the chosen worker. In other words, the chosen worker is the loser, who will be the only worker, whose salary will be not increased during this particular operation. But loser-worker can be different for different operations, of course. Chief can use this operation as many times as he wants. But he is a busy man. That's why he wants to minimize the total number of operations needed to equalize all workers. Your task is to find this number. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of workers. The second line contains N space-separated integers W_{1}, W_{2}, ..., W_{N} denoting the salaries of the workers. ------ Output ------ For each test case, output a single line containing the minimum number of operations needed to equalize all workers. ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ N_{} ≤ 100$ $0 ≤ W_{i} ≤ 10000 (10^{4})$ ----- Sample Input 1 ------ 2 3 1 2 3 2 42 42 ----- Sample Output 1 ------ 3 0 ----- explanation 1 ------ Example Case 1. Chief can equalize all salaries in 3 turns: Turn ID IDs of involved workers Salaries after the move1 1 2 2 3 32 1 2 3 4 33 1 3 4 4 4Example Case 2. All salaries are already equal. He doesn't need to do anything.
{"inputs": ["2\n3\n1 4 3\n2\n7 2", "2\n3\n1 0 3\n2\n8 2", "2\n3\n1 4 3\n2\n42 7", "2\n3\n1 4 3\n2\n47 7", "2\n3\n1 4 3\n2\n20 7", "2\n3\n1 4 3\n2\n20 8", "2\n3\n1 0 2\n2\n1 17", "2\n3\n1 4 3\n2\n20 2"], "outputs": ["5\n5\n", "4\n6\n", "5\n35\n", "5\n40\n", "5\n13\n", "5\n12\n", "3\n16\n", "5\n18\n"]}
485
202
coding
Solve the programming task below in a Python markdown code block. There is a 120 minute videotape with standard recording. When I set the VCR counter to 00:00:00 with the tape completely rewound and recorded in standard recording mode, I got a certain counter value. Enter this counter value (hours, minutes, seconds), find the length of the remaining tape (recordable time), and create a program that outputs in the format of hours: minutes: seconds. However, the input must be within 2 hours (120 minutes). The remaining amount of tape is calculated in two ways, standard recording mode and triple recording mode, and outputs two digits each for hours, minutes, and seconds as shown in the output example. If the tens digit is 0, such as "05", add "0". input Given multiple datasets. Each dataset is as follows. T H S T, H, and S are integers that represent hours, minutes, and seconds, respectively. Input ends when T, H, and S are all -1. The number of datasets does not exceed 50. output For each dataset On the first line, the hours, minutes, and seconds of the recordable time when the rest of the tape is recorded as standard, separated by half-width colons. On the second line, the hours, minutes, and seconds of the recordable time when the rest of the tape is recorded three times are separated by half-width colons. Please output. Example Input 1 30 0 -1 -1 -1 Output 00:30:00 01:30:00
{"inputs": ["0 9 1\n-1 -1 -1", "1 8 0\n-1 -1 -1", "0 8 1\n-1 -1 -1", "1 9 0\n-1 -1 -1", "1 5 0\n-1 -1 -1", "0 9 0\n-1 -1 -1", "0 8 2\n-1 -1 -1", "1 7 0\n-1 -1 -1"], "outputs": ["01:50:59\n05:32:57\n", "00:52:00\n02:36:00\n", "01:51:59\n05:35:57\n", "00:51:00\n02:33:00\n", "00:55:00\n02:45:00\n", "01:51:00\n05:33:00\n", "01:51:58\n05:35:54\n", "00:53:00\n02:39:00\n"]}
351
278
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n.   Please complete the following python code precisely: ```python class Solution: def smallestEvenMultiple(self, n: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(n = 5) == 10\n assert candidate(n = 6) == 6\n\n\ncheck(Solution().smallestEvenMultiple)"}
70
46
coding
Solve the programming task below in a Python markdown code block. # Number encrypting: cypher ## Part I of Number encrypting Katas *** ## Introduction Back then when the internet was coming up, most search functionalities simply looked for keywords in text to show relevant documents. Hackers weren't very keen on having their information displayed on websites, bulletin boards, newsgroups or any other place, so they started to replace certain letters in words. It started out with simple vowel substitutions like a 4 instead of an A, or a 3 instead of an E. This meant that topics like cracking or hacking remained undetected. Here we will use a reduced version of the *Leet Speak alphabet*, but you can find more information [here](http://www.gamehouse.com/blog/leet-speak-cheat-sheet/) or at [Wikipedia](https://en.wikipedia.org/wiki/Leet). ## Task You will receive a string composed by English words, `string`. You will have to return a cyphered version of that string. The numbers corresponding to each letter are represented at the table below. Notice that different letters can share the same number. In those cases, one letter will be upper case and the other one lower case. .cell { border: 1px solid white; text-align: center; width: 7%; } .title { border: 1px solid white; border-bottom: 1px solid white; text-align: center; min-width: 11em; } .no-border {border: none} table { margin-bottom: 10px } 1 2 3 4 5 6 7 8 9 0 Upper case I R E A S G T B O Lower case l z e a s b t g o Any character that is not at the table, does not change when cyphered. ## Examples * **Input:** "Hello World". **Output**: "H3110 W0r1d" * **Input:** "I am your father". **Output**: "1 4m y0ur f47h3r" * **Input:** "I do not know what else I can test. Be cool. Good luck". **Output**: "1 d0 n07 kn0w wh47 3153 1 c4n 7357. 83 c001. 600d 1uck" ## Part II If you liked this Kata, you can find the [part II: *Number encrypting: decypher*](https://www.codewars.com/kata/number-encrypting-decypher), where your goal is to decypher the strings. Also feel free to reuse/extend the following starter code: ```python def cypher(string): ```
{"functional": "_inputs = [['Hello World'], ['I am your father'], ['I do not know what else I can test. Be cool. Good luck'], ['IlRzEeAaSsGbTtBgOo'], ['']]\n_outputs = [['H3110 W0r1d'], ['1 4m y0ur f47h3r'], ['1 d0 n07 kn0w wh47 3153 1 c4n 7357. 83 c001. 600d 1uck'], ['112233445566778900'], ['']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(cypher(*i), o[0])"}
678
290
coding
Solve the programming task below in a Python markdown code block. Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars. There are $n$ banknote denominations on Mars: the value of $i$-th banknote is $a_i$. Natasha has an infinite number of banknotes of each denomination. Martians have $k$ fingers on their hands, so they use a number system with base $k$. In addition, the Martians consider the digit $d$ (in the number system with base $k$) divine. Thus, if the last digit in Natasha's tax amount written in the number system with the base $k$ is $d$, the Martians will be happy. Unfortunately, Natasha does not know the Martians' divine digit yet. Determine for which values $d$ Natasha can make the Martians happy. Natasha can use only her banknotes. Martians don't give her change. -----Input----- The first line contains two integers $n$ and $k$ ($1 \le n \le 100\,000$, $2 \le k \le 100\,000$) — the number of denominations of banknotes and the base of the number system on Mars. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — denominations of banknotes on Mars. All numbers are given in decimal notation. -----Output----- On the first line output the number of values $d$ for which Natasha can make the Martians happy. In the second line, output all these values in increasing order. Print all numbers in decimal notation. -----Examples----- Input 2 8 12 20 Output 2 0 4 Input 3 10 10 20 30 Output 1 0 -----Note----- Consider the first test case. It uses the octal number system. If you take one banknote with the value of $12$, you will get $14_8$ in octal system. The last digit is $4_8$. If you take one banknote with the value of $12$ and one banknote with the value of $20$, the total value will be $32$. In the octal system, it is $40_8$. The last digit is $0_8$. If you take two banknotes with the value of $20$, the total value will be $40$, this is $50_8$ in the octal system. The last digit is $0_8$. No other digits other than $0_8$ and $4_8$ can be obtained. Digits $0_8$ and $4_8$ could also be obtained in other ways. The second test case uses the decimal number system. The nominals of all banknotes end with zero, so Natasha can give the Martians only the amount whose decimal notation also ends with zero.
{"inputs": ["1 2\n1\n", "1 5\n4\n", "1 5\n3\n", "1 8\n6\n", "1 7\n6\n", "1 9\n6\n", "1 8\n5\n", "1 6\n4\n"], "outputs": ["2\n0 1 ", "5\n0 1 2 3 4 ", "5\n0 1 2 3 4 ", "4\n0 2 4 6 ", "7\n0 1 2 3 4 5 6 ", "3\n0 3 6 ", "8\n0 1 2 3 4 5 6 7 ", "3\n0 2 4 "]}
703
169
coding
Solve the programming task below in a Python markdown code block. Bob needs a fast way to calculate the volume of a cuboid with three values: `length`, `width` and the `height` of the cuboid. Write a function to help Bob with this calculation. ```if:shell In bash the script is ran with the following 3 arguments: `length` `width` `height` ``` Also feel free to reuse/extend the following starter code: ```python def getVolumeOfCubiod(length, width, height): ```
{"functional": "_inputs = [[2, 5, 6], [6.3, 3, 5]]\n_outputs = [[60], [94.5]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(getVolumeOfCubiod(*i), o[0])"}
114
182
coding
Solve the programming task below in a Python markdown code block. Once Vasya played bricks. All the bricks in the set had regular cubical shape. Vasya vas a talented architect, however the tower he built kept falling apart. Let us consider the building process. Vasya takes a brick and puts it on top of the already built tower so that the sides of the brick are parallel to the sides of the bricks he has already used. Let's introduce a Cartesian coordinate system on the horizontal plane, where Vasya puts the first brick. Then the projection of brick number i on the plane is a square with sides parallel to the axes of coordinates with opposite corners in points (xi, 1, yi, 1) and (xi, 2, yi, 2). The bricks are cast from homogeneous plastic and the weight of a brick a × a × a is a3 grams. It is guaranteed that Vasya puts any brick except the first one on the previous one, that is the area of intersection of the upper side of the previous brick and the lower side of the next brick is always positive. We (Vasya included) live in a normal world where the laws of physical statics work. And that is why, perhaps, if we put yet another brick, the tower will collapse under its own weight. Vasya puts the cubes consecutively one on top of the other until at least one cube loses the balance and falls down. If it happens, Vasya gets upset and stops the construction. Print the number of bricks in the maximal stable tower, that is the maximal number m satisfying the condition that all the towers consisting of bricks 1, 2, ..., k for every integer k from 1 to m remain stable. Input The first input file contains an integer n (1 ≤ n ≤ 100) which is the number of bricks. Each of the next n lines contains four numbers xi, 1, yi, 1, xi, 2, yi, 2 (xi, 1 ≠ xi, 2, |xi, 1 - xi, 2| = |yi, 1 - yi, 2|) which are the coordinates of the opposite angles of the base of the brick number i. The coordinates are integers and their absolute value does not exceed 50. The cubes are given in the order Vasya puts them. It is guaranteed that the area of intersection of the upper side of the brick number i - 1 and the lower side of the brick number i is strictly strictly greater than zero for all i ≥ 2. Output Print the number of bricks in the maximal stable tower. Examples Input 2 0 0 3 3 1 0 4 3 Output 2 Input 2 0 0 3 3 2 0 5 3 Output 1 Input 3 0 0 3 3 1 0 4 3 2 0 5 3 Output 3
{"inputs": ["1\n0 0 1 1\n", "1\n0 0 2 1\n", "1\n0 0 4 1\n", "1\n-50 -50 50 50\n", "1\n-50 -93 50 50\n", "2\n0 0 4 3\n1 0 4 3\n", "2\n0 0 3 3\n1 0 4 3\n", "2\n0 0 3 3\n2 0 5 3\n"], "outputs": ["1", "1", "1", "1", "1", "2", "2", "1"]}
634
160
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, reverse only all the vowels in the string and return it. The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more than once.   Please complete the following python code precisely: ```python class Solution: def reverseVowels(self, s: str) -> str: ```
{"functional": "def check(candidate):\n assert candidate(s = \"hello\") == \"holle\"\n assert candidate(s = \"leetcode\") == \"leotcede\"\n\n\ncheck(Solution().reverseVowels)"}
100
50
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 candies, where candies[i] represents the flavor of the ith candy. Your mom wants you to share these candies with your little sister by giving her k consecutive candies, but you want to keep as many flavors of candies as possible. Return the maximum number of unique flavors of candy you can keep after sharing with your sister.   Please complete the following python code precisely: ```python class Solution: def shareCandies(self, candies: List[int], k: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(candies = [1,2,2,3,4,3], k = 3) == 3\n assert candidate(candies = [2,2,2,2,3,3], k = 2) == 2\n assert candidate(candies = [2,4,5], k = 0) == 3\n\n\ncheck(Solution().shareCandies)"}
129
102
coding
Solve the programming task below in a Python markdown code block. The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single line of input, one integer $K$. -----Output:----- For each test case, output as the pattern. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq K \leq 100$ -----Sample Input:----- 5 1 2 3 4 5 -----Sample Output:----- 1 1 32 1 32 654 1 32 654 10987 1 32 654 10987 1514131211 -----EXPLANATION:----- No need, else pattern can be decode easily.
{"inputs": ["5\n1\n2\n3\n4\n5"], "outputs": ["1\n1\n32\n1\n32\n654\n1\n32\n654\n10987\n1\n32\n654\n10987\n1514131211"]}
235
77
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums of even length n and an integer limit. In one move, you can replace any integer from nums with another integer between 1 and limit, inclusive. The array nums is complementary if for all indices i (0-indexed), nums[i] + nums[n - 1 - i] equals the same number. For example, the array [1,2,3,4] is complementary because for all indices i, nums[i] + nums[n - 1 - i] = 5. Return the minimum number of moves required to make nums complementary.   Please complete the following python code precisely: ```python class Solution: def minMoves(self, nums: List[int], limit: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,4,3], limit = 4) == 1\n assert candidate(nums = [1,2,2,1], limit = 2) == 2\n assert candidate(nums = [1,2,1,2], limit = 2) == 0\n\n\ncheck(Solution().minMoves)"}
172
88
coding
Solve the programming task below in a Python markdown code block. A subsequence of length |x| of string s = s1s2... s|s| (where |s| is the length of string s) is a string x = sk1sk2... sk|x| (1 ≤ k1 < k2 < ... < k|x| ≤ |s|). You've got two strings — s and t. Let's consider all subsequences of string s, coinciding with string t. Is it true that each character of string s occurs in at least one of these subsequences? In other words, is it true that for all i (1 ≤ i ≤ |s|), there is such subsequence x = sk1sk2... sk|x| of string s, that x = t and for some j (1 ≤ j ≤ |x|) kj = i. Input The first line contains string s, the second line contains string t. Each line consists only of lowercase English letters. The given strings are non-empty, the length of each string does not exceed 2·105. Output Print "Yes" (without the quotes), if each character of the string s occurs in at least one of the described subsequences, or "No" (without the quotes) otherwise. Examples Input abab ab Output Yes Input abacaba aba Output No Input abc ba Output No Note In the first sample string t can occur in the string s as a subsequence in three ways: abab, abab and abab. In these occurrences each character of string s occurs at least once. In the second sample the 4-th character of the string s doesn't occur in any occurrence of string t. In the third sample there is no occurrence of string t in string s.
{"inputs": ["aa\naaa\n", "cba\nba\n", "cca\nba\n", "abc\nba\n", "abc\nbac\n", "ab\nabcd\n", "abc\nbab\n", "ab\ndbca\n"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
387
88
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 nums and cost consisting each of n positive integers. You can do the following operation any number of times: Increase or decrease any element of the array nums by 1. The cost of doing one operation on the ith element is cost[i]. Return the minimum total cost such that all the elements of the array nums become equal.   Please complete the following python code precisely: ```python class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,5,2], cost = [2,3,1,14]) == 8\n assert candidate(nums = [2,2,2,2,2], cost = [4,2,8,1,3]) == 0\n\n\ncheck(Solution().minCost)"}
127
82
coding
Solve the programming task below in a Python markdown code block. Write a program which converts uppercase/lowercase letters to lowercase/uppercase for a given string. Constraints * The length of the input string < 1200 Input A string is given in a line. Output Print the converted string in a line. Note that you do not need to convert any characters other than alphabetical letters. Example Input fAIR, LATER, OCCASIONALLY CLOUDY. Output Fair, later, occasionally cloudy.
{"inputs": ["f@IR, LATER, OCCASIONALLY CLOUDY.", "f@IR, LATER, YLLANOISACCO CLOUDY.", "f@IR, LATER, OLLANOISACCY CLOUDY.", "f@IR, LATER, OLKANOISACCY CLOUDY.", ",RI@f LATER, OLKANOISACCY CLOUDY.", ",RI@f KATER, OLKANOISACCY CLOUDY.", ",RI@g KATER, OLKANOISACCY CLOUDY.", ",RI@g KATER, OLKANOISACCY CLOUDX."], "outputs": ["F@ir, later, occasionally cloudy.\n", "F@ir, later, yllanoisacco cloudy.\n", "F@ir, later, ollanoisaccy cloudy.\n", "F@ir, later, olkanoisaccy cloudy.\n", ",ri@F later, olkanoisaccy cloudy.\n", ",ri@F kater, olkanoisaccy cloudy.\n", ",ri@G kater, olkanoisaccy cloudy.\n", ",ri@G kater, olkanoisaccy cloudx.\n"]}
110
273
coding
Solve the programming task below in a Python markdown code block. You are given an integer $x$ of $n$ digits $a_1, a_2, \ldots, a_n$, which make up its decimal notation in order from left to right. Also, you are given a positive integer $k < n$. Let's call integer $b_1, b_2, \ldots, b_m$ beautiful if $b_i = b_{i+k}$ for each $i$, such that $1 \leq i \leq m - k$. You need to find the smallest beautiful integer $y$, such that $y \geq x$. -----Input----- The first line of input contains two integers $n, k$ ($2 \leq n \leq 200\,000, 1 \leq k < n$): the number of digits in $x$ and $k$. The next line of input contains $n$ digits $a_1, a_2, \ldots, a_n$ ($a_1 \neq 0$, $0 \leq a_i \leq 9$): digits of $x$. -----Output----- In the first line print one integer $m$: the number of digits in $y$. In the next line print $m$ digits $b_1, b_2, \ldots, b_m$ ($b_1 \neq 0$, $0 \leq b_i \leq 9$): digits of $y$. -----Examples----- Input 3 2 353 Output 3 353 Input 4 2 1234 Output 4 1313
{"inputs": ["2 1\n33\n", "2 1\n99\n", "2 1\n31\n", "2 1\n33\n", "2 1\n12\n", "2 1\n31\n", "2 1\n12\n", "2 1\n33\n"], "outputs": ["2\n33\n", "2\n99\n", "2\n33\n", "2\n33\n", "2\n22\n", "2\n33\n", "2\n22\n", "2\n33\n"]}
373
134
coding
Solve the programming task below in a Python markdown code block. Master Oogway has forseen that a panda named Po will be the dragon warrior, and the master of Chi. But he did not tell anyone about the spell that would make him the master of Chi, and has left Po confused. Now Po has to defeat Kai, who is the super villian, the strongest of them all. Po needs to master Chi, and he finds a spell which unlocks his powerful Chi. But the spell is rather strange. It asks Po to calculate the factorial of a number! Po is very good at mathematics, and thinks that this is very easy. So he leaves the spell, thinking it's a hoax. But little does he know that this can give him the ultimate power of Chi. Help Po by solving the spell and proving that it's not a hoax. -----Input----- First line of input contains an integer T denoting the number of test cases. The next T lines contain an integer N. -----Output----- For each test case, print a single line containing the solution to the spell which is equal to factorial of N, i.e. N!. Since the output could be large, output it modulo 1589540031(Grand Master Oogway's current age). -----Constraints----- - 1 ≤ T ≤ 100000 - 1 ≤ N ≤ 100000 -----Example----- Input: 4 1 2 3 4 Output: 1 2 6 24
{"inputs": ["4\n1\n2\n3\n4"], "outputs": ["1\n2\n6\n24"]}
320
27
coding
Solve the programming task below in a Python markdown code block. Ayu loves distinct letter sequences ,a distinct letter sequence is defined by a sequence of small case english alphabets such that no character appears more then once. But however there are two phrases that she doesn't like these phrases are "kar" and "shi" and she is given a sequence of distinct characters and she wonders how many such sequences she can form using all the characters such that these phrases don't occur. Help her finding the number of such sequences. New Year Gift - It is guaranteed that for sequences of length greater then 6 letters k,a,r,s,h,i will be present(we thought of being generous, thank us later :)). -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each line consists of a string $S$ (3<=s.length<=18) of distinct characters. -----Output:----- Print the number of sequences that can be formed by permuting all the characters such that phrases "kar" and "shi" don't occur. -----Constraints----- - $1 \leq T \leq 10$ - $3 \leq S.length \leq 18$ -----Sample Input:----- 2 karp abcd -----Sample Output:----- 22 24
{"inputs": ["2\nkarp\nabcd"], "outputs": ["22\n24"]}
280
21
coding
Solve the programming task below in a Python markdown code block. A reversed arabic no is one whose digits have been written in the reversed order. However in this any trailing zeroes are omitted. The task at hand here is a simple one. You need to add two numbers which have been written in reversed arabic and return the output back in reversed arabic form, assuming no zeroes were lost while reversing. -----Input----- The input consists of N cases. The first line of the input contains only a positive integer N. Then follow the cases. Each case consists of exactly one line with two positive integers seperated by space. These are the reversednumbers you are to add. -----Output----- For each case, print exactly one line containing only one integer- the reversed sum of two reversed numbers. Omit any leading zeroes in the output. -----Example----- Input: 1 24 1 Output: 34
{"inputs": ["1\n24 1"], "outputs": ["34"]}
185
18
coding
Solve the programming task below in a Python markdown code block. Chloe is fascinated by prime numbers. She came across the number $283002$ on a sign and, though the number is not prime, found some primes hiding in it by using the following rules: Every three consecutive digits sum to a prime: $\underbrace{283}002\quad\underbrace{2830}02\quad28\underbrace{300}2\quad283\underbrace{002}$ Every four consecutive digits sum to a prime: $\underbrace{28300}2\quad\underbrace{28300}2\quad28\underbrace{3002}$ Every five consecutive digits sum to a prime: $\underbrace{283002}\quad2\underbrace{83002}$ You must answer $\textit{q}$ queries, where each query consists of an integer, $n$. For each $n$, find and print the number of positive $n$-digit numbers, modulo $10^9+7$, that satisfy all three of Chloe's rules (i.e., every three, four, and five consecutive digits sum to a prime). Input Format The first line contains an integer, $\textit{q}$, denoting the number of queries. Each of the $\textit{q}$ subsequent lines contains an integer denoting the value of $n$ for a query. Constraints $1\leq q\leq2\times10^4$ $1\leq n\leq4\times10^5$ Output Format For each query, print the number of $n$-digit numbers satisfying Chloe's rules, modulo $10^9+7$, on a new line. Sample Input 0 1 6 Sample Output 0 95 Explanation 0 There are $95$ six-digit numbers satisfying the property above, where the respective first and last ones are $\textbf{101101}$ and $\boldsymbol{902005}$.
{"inputs": ["1\n6\n"], "outputs": ["95\n"]}
469
17
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n different online courses numbered from 1 to n. You are given an array courses where courses[i] = [durationi, lastDayi] indicate that the ith course should be taken continuously for durationi days and must be finished before or on lastDayi. You will start on the 1st day and you cannot take two or more courses simultaneously. Return the maximum number of courses that you can take.   Please complete the following python code precisely: ```python class Solution: def scheduleCourse(self, courses: List[List[int]]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(courses = [[100, 200], [200, 1300], [1000, 1250], [2000, 3200]]) == 3\n assert candidate(courses = [[1,2]]) == 1\n assert candidate(courses = [[3,2],[4,3]]) == 0\n\n\ncheck(Solution().scheduleCourse)"}
135
108
coding
Solve the programming task below in a Python markdown code block. # Background My pet bridge-maker ants are marching across a terrain from left to right. If they encounter a gap, the first one stops and then next one climbs over him, then the next, and the next, until a bridge is formed across the gap. What clever little things they are! Now all the other ants can walk over the ant-bridge. When the last ant is across, the ant-bridge dismantles itself similar to how it was constructed. This process repeats as many times as necessary (there may be more than one gap to cross) until all the ants reach the right hand side. # Kata Task My little ants are marching across the terrain from left-to-right in the order ```A``` then ```B``` then ```C```... What order do they exit on the right hand side? # Notes * ```-``` = solid ground * ```.``` = a gap * The number of ants may differ but there are always enough ants to bridge the gaps * The terrain never starts or ends with a gap * Ants cannot pass other ants except by going over ant-bridges * If there is ever ambiguity which ant should move, then the ant at the **back** moves first # Example ## Input * ants = ````GFEDCBA```` * terrain = ```------------...-----------``` ## Output * result = ```EDCBAGF``` ## Details Ants moving left to right. GFEDCBA ------------...----------- The first one arrives at a gap. GFEDCB A ------------...----------- They start to bridge over the gap... GFED ABC ------------...----------- ...until the ant-bridge is completed! GF ABCDE ------------...----------- And then the remaining ants can walk across the bridge. F G ABCDE ------------...----------- And when no more ants need to cross... ABCDE GF ------------...----------- ... the bridge dismantles itself one ant at a time.... CDE BAGF ------------...----------- ...until all ants get to the other side EDCBAGF ------------...----------- Also feel free to reuse/extend the following starter code: ```python def ant_bridge(ants, terrain): ```
{"functional": "_inputs = [['GFEDCBA', '-----------------------'], ['GFEDCBA', '------------...-----------'], ['GFEDCBA', '------------.....---------'], ['GFEDCBA', '------.....------.....---------'], ['GFEDCBA', '------------...-----..----'], ['CBA', '--.--.---'], ['GFEDCBA', '------....-.---'], ['EDCBA', '--..---...-..-...----..-----'], ['JIHGFEDCBA', '--........------.-........-........---....-----'], ['JIHGFEDCBA', '-.....------........-.......-.......----'], ['JIHGFEDCBA', '-------.......-.......-'], ['JIHGFEDCBA', '-------.......-.......-.......-'], ['GFEDCBA', '-.-.-.-']]\n_outputs = [['GFEDCBA'], ['EDCBAGF'], ['GFEDCBA'], ['GFEDCBA'], ['BAGFEDC'], ['CBA'], ['AGFEDCB'], ['EDCBA'], ['GFEDCBAJIH'], ['CBAJIHGFED'], ['GFEDCBAJIH'], ['EDCBAJIHGF'], ['GFEDCBA']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(ant_bridge(*i), o[0])"}
480
409
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and an integer k. You may partition nums into one or more subsequences such that each element in nums appears in exactly one of the subsequences. Return the minimum number of subsequences needed such that the difference between the maximum and minimum values in each subsequence is at most k. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.   Please complete the following python code precisely: ```python class Solution: def partitionArray(self, nums: List[int], k: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(nums = [3,6,1,2,5], k = 2) == 2\n assert candidate(nums = [1,2,3], k = 1) == 2\n assert candidate(nums = [2,2,4,5], k = 0) == 3\n\n\ncheck(Solution().partitionArray)"}
144
88
coding
Solve the programming task below in a Python markdown code block. ![](http://www.grindtv.com/wp-content/uploads/2015/08/drone.jpg) The other day I saw an amazing video where a guy hacked some wifi controlled lightbulbs by flying a drone past them. Brilliant. In this kata we will recreate that stunt... sort of. You will be given two strings: `lamps` and `drone`. `lamps` represents a row of lamps, currently off, each represented by `x`. When these lamps are on, they should be represented by `o`. The `drone` string represents the position of the drone `T` (any better suggestion for character??) and its flight path up until this point `=`. The drone always flies left to right, and always begins at the start of the row of lamps. Anywhere the drone has flown, including its current position, will result in the lamp at that position switching on. Return the resulting `lamps` string. See example tests for more clarity. Also feel free to reuse/extend the following starter code: ```python def fly_by(lamps, drone): ```
{"functional": "_inputs = [['xxxxxx', '====T'], ['xxxxxxxxx', '==T'], ['xxxxxxxxxxxxxxx', '=========T']]\n_outputs = [['ooooox'], ['oooxxxxxx'], ['ooooooooooxxxxx']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(fly_by(*i), o[0])"}
242
189
coding
Solve the programming task below in a Python markdown code block. Alice and Bob are playing a game of table tennis where irrespective of the point scored, every player makes 2 consecutive serves before the service changes. Alice makes the first serve of the match. Therefore the first 2 serves will be made by Alice, then the next 2 serves will be made by Bob and so on. Let's consider the following example match for more clarity: Alice makes the 1^{st} serve. Let us assume, Bob wins this point. (Score is 0 for Alice and 1 for Bob) Alice makes the 2^{nd} serve. Let us assume, Alice wins this point. (Score is 1 for Alice and 1 for Bob) Bob makes the 3^{rd} serve. Let us assume, Alice wins this point. (Score is 2 for Alice and 1 for Bob) Bob makes the 4^{th} serve. Let us assume, Alice wins this point. (Score is 3 for Alice and 1 for Bob) Alice makes the 5^{th} serve. And the game continues \ldots After the score reaches P and Q for Alice and Bob respectively, both the players forgot whose serve it is. Help them determine whose service it is. ------ Input Format ------ - The first line contains a single integer T — the number of test cases. Then the test cases follow. - The first line of each test case contains two integers P and Q — the score of Alice and Bob respectively. ------ Output Format ------ For each test case, determine which player's (Alice or Bob) serve it is. You may print each character of Alice and Bob in uppercase or lowercase (for example, Bob, BOB, boB will be considered identical). ------ Constraints ------ $1 ≤ T ≤ 200$ $0 ≤P, Q ≤10$ ----- Sample Input 1 ------ 4 0 0 0 2 2 2 4 7 ----- Sample Output 1 ------ Alice Bob Alice Bob ----- explanation 1 ------ - Test Case 1: Since no points have been scored yet, this is the first serve of the match. Alice makes the $1^{st}$ serve of the match. - Test Case 2: Two points have been scored yet. Thus, it is the third serve of the match. Bob makes the $3^{rd}$ serve of the match. - Test Case 3: Four points have been scored yet. Thus, it is the fifth serve of the match. Alice makes the $5^{th}$ serve of the match. - Test Case 4: Eleven points have been scored yet. Thus, it is the twelfth serve of the match. Bob makes the $12^{th}$ serve of the match.
{"inputs": ["4\n0 0\n0 2\n2 2\n4 7\n"], "outputs": ["Alice\nBob\nAlice\nBob\n"]}
589
36
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s and an array of strings words. All the strings of words are of the same length. A concatenated string is a string that exactly contains all the strings of any permutation of words concatenated. For example, if words = ["ab","cd","ef"], then "abcdef", "abefcd", "cdabef", "cdefab", "efabcd", and "efcdab" are all concatenated strings. "acdbef" is not a concatenated string because it is not the concatenation of any permutation of words. Return an array of the starting indices of all the concatenated substrings in s. You can return the answer in any order.   Please complete the following python code precisely: ```python class Solution: def findSubstring(self, s: str, words: List[str]) -> List[int]: ```
{"functional": "def check(candidate):\n assert candidate(s = \"barfoothefoobarman\", words = [\"foo\",\"bar\"]) == [0,9]\n assert candidate(s = \"wordgoodgoodgoodbestword\", words = [\"word\",\"good\",\"best\",\"word\"]) == []\n assert candidate(s = \"barfoofoobarthefoobarman\", words = [\"bar\",\"foo\",\"the\"]) == [6,9,12]\n\n\ncheck(Solution().findSubstring)"}
191
115
coding
Solve the programming task below in a Python markdown code block. There is an array $a$ of length $n$. You may perform the following operation any number of times: Choose two indices $l$ and $r$ where $1 \le l < r \le n$ and $a_l = a_r$. Then, set $a[l \ldots r] = [a_{l+1}, a_{l+2}, \ldots, a_r, a_l]$. You are also given another array $b$ of length $n$ which is a permutation of $a$. Determine whether it is possible to transform array $a$ into an array $b$ using the above operation some number of times. -----Input----- Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $n$ ($1 \le n \le 2 \cdot 10 ^ 5$) — the length of array $a$ and $b$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) — elements of the array $a$. The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($1 \le b_i \le n$) — elements of the array $b$. It is guaranteed that $b$ is a permutation of $a$. It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10 ^ 5$ -----Output----- For each test case, print "YES" (without quotes) if it is possible to transform array $a$ to $b$, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response). -----Examples----- Input 5 5 1 2 3 3 2 1 3 3 2 2 5 1 2 4 2 1 4 2 2 1 1 5 2 4 5 5 2 2 2 4 5 5 3 1 2 3 1 2 3 3 1 1 2 2 1 1 Output YES YES NO YES NO -----Note----- In the first test case, we can choose $l=2$ and $r=5$ to form $[1, 3, 3, 2, 2]$. In the second test case, we can choose $l=2$ and $r=4$ to form $[1, 4, 2, 2, 1]$. Then, we can choose $l=1$ and $r=5$ to form $[4, 2, 2, 1, 1]$. In the third test case, it can be proven that it is not possible to transform array $a$ to $b$ using the operation.
{"inputs": ["5\n5\n1 2 3 3 2\n1 3 3 2 2\n5\n1 2 4 2 1\n4 2 2 1 1\n5\n2 4 5 5 2\n2 2 4 5 5\n3\n1 2 3\n1 2 3\n3\n1 1 2\n2 1 1\n"], "outputs": ["YES\nYES\nNO\nYES\nNO\n"]}
725
116
coding
Solve the programming task below in a Python markdown code block. **Background** You most probably know, that the *kilo* used by IT-People differs from the *kilo* used by the rest of the world. Whereas *kilo* in kB is (mostly) intrepreted as 1024 Bytes (especially by operating systems) the non-IT *kilo* denotes the factor 1000 (as in "1 kg is 1000g"). The same goes for the prefixes mega, giga, tera, peta and so on. To avoid misunderstandings (like your hardware shop selling you a 1E+12 Byte harddisk as 1 TB, whereas your Windows states that it has only 932 GB, because the shop uses factor 1000 whereas operating systems use factor 1024 by default) the International Electrotechnical Commission has proposed to use **kibibyte** for 1024 Byte.The according unit symbol would be **KiB**. Other Prefixes would be respectivly: ``` 1 MiB = 1024 KiB 1 GiB = 1024 MiB 1 TiB = 1024 GiB ``` **Task** Your task is to write a conversion function between the kB and the KiB-Units. The function receives as parameter a memory size including a unit and converts into the corresponding unit of the other system: ``` memorysizeConversion ( "10 KiB") -> "10.24 kB" memorysizeConversion ( "1 kB") -> "0.977 KiB" memorysizeConversion ( "10 TB") -> "9.095 TiB" memorysizeConversion ( "4.1 GiB") -> "4.402 GB" ``` **Hints** - the parameter always contains a (fractioned) number, a whitespace and a valid unit - units are case sensitive, valid units are **kB MB GB TB KiB MiB GiB TiB** - result must be rounded to 3 decimals (round half up,no trailing zeros) see examples above **Resources** If you want to read more on ...ibi-Units: https://en.wikipedia.org/wiki/Kibibyte Also feel free to reuse/extend the following starter code: ```python def memorysize_conversion(memorysize): ```
{"functional": "_inputs = [['1 KiB']]\n_outputs = [['1.024 kB']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(memorysize_conversion(*i), o[0])"}
521
162
coding
Solve the programming task below in a Python markdown code block. Chef has an 8 \times 8 chessboard. He placed a knight on the square (X_{1}, Y_{1}). Note that, the square at the intersection of the i^{th} row and j^{th} column is denoted by (i, j). Chef wants to determine whether the knight can end up at the square (X_{2}, Y_{2}) in exactly 100 moves or not. For reference, a knight can move to a square which is: One square horizontally and two squares vertically away from the current square, or One square vertically and two squares horizontally away from the current square A visual description of this may be found [here]#Movement). ------ Input Format ------ - The first line contains a single integer T — the number of test cases. Then the test cases follow. - The first and only line of each test case contains 4 integers X_{1}, Y_{1}, X_{2}, Y_{2} — where (X_{1}, Y_{1}) denotes the starting square of the knight and (X_{2}, Y_{2}) denotes the ending square of the knight. ------ Output Format ------ For each test case, output YES if knight can move from (X_{1}, Y_{1}) to (X_{2}, Y_{2}) in exactly 100 moves. Otherwise, output NO. You may print each character of YES and NO in uppercase or lowercase (for example, yes, yEs, Yes will be considered identical). ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤X_{1}, Y_{1}, X_{2}, Y_{2} ≤8$ ----- Sample Input 1 ------ 3 1 1 1 1 8 8 7 6 8 8 8 6 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test Case 1: Knight can first move to $(2, 3)$ and then back to $(1, 1)$. He can repeat this $50$ times and he will end up at $(1, 1)$ after $100$ moves. Test Case 2: It can be proven that it is not possible for the knight to end at $(7, 6)$ after $100$ moves. Test Case 3: Knight can first move to $(6, 7)$ and then to $(8, 6)$. After that, he can alternate between $(6, 7)$ and $(8, 6)$ for $49$ times and he will end up at $(8, 6)$ after $100$ moves.
{"inputs": ["3\n1 1 1 1\n8 8 7 6\n8 8 8 6\n"], "outputs": ["YES\nNO\nYES"]}
580
41
coding
Solve the programming task below in a Python markdown code block. Alice has a string $s$. She really likes the letter "a". She calls a string good if strictly more than half of the characters in that string are "a"s. For example "aaabb", "axaa" are good strings, and "baca", "awwwa", "" (empty string) are not. Alice can erase some characters from her string $s$. She would like to know what is the longest string remaining after erasing some characters (possibly zero) to get a good string. It is guaranteed that the string has at least one "a" in it, so the answer always exists. -----Input----- The first line contains a string $s$ ($1 \leq |s| \leq 50$) consisting of lowercase English letters. It is guaranteed that there is at least one "a" in $s$. -----Output----- Print a single integer, the length of the longest good string that Alice can get after erasing some characters from $s$. -----Examples----- Input xaxxxxa Output 3 Input aaabaa Output 6 -----Note----- In the first example, it's enough to erase any four of the "x"s. The answer is $3$ since that is the maximum number of characters that can remain. In the second example, we don't need to erase any characters.
{"inputs": ["a\n", "a\n", "ap\n", "ap\n", "pa\n", "aq\n", "dya\n", "ass\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
297
71
coding
Solve the programming task below in a Python markdown code block. There was a test in your class and you passed it. Congratulations! But you're an ambitious person. You want to know if you're better than the average student in your class. You receive an array with your peers' test scores. Now calculate the average and compare your score! ~~~if-not:nasm,racket Return `True` if you're better, else `False`! ~~~ ~~~if:racket Return #t if you're better, else #f. ~~~ ~~~if:nasm Return `1` if you're better, else `0`! ~~~ ### Note: Your points are not included in the array of your class's points. For calculating the average point you may add your point to the given array! Also feel free to reuse/extend the following starter code: ```python def better_than_average(class_points, your_points): ```
{"functional": "_inputs = [[[2, 3], 5], [[100, 40, 34, 57, 29, 72, 57, 88], 75], [[12, 23, 34, 45, 56, 67, 78, 89, 90], 69]]\n_outputs = [[True], [True], [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_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(better_than_average(*i), o[0])"}
195
245
coding
Solve the programming task below in a Python markdown code block. Mr. Retardo has lost his marbles. He's a professor, and absolutely loathes his students. And since going full retard, he asks them all sorts of useless questions. His latest obsession is prime numbers, and he gives all his a students random number n and asks them to check if it is prime. Check if it is!! Note that the permitted language list for this problem has been altered. Please check before solving. EDIT Maximum number of test cases - 500, 0 ≤ n ≤ 5*10^9 SAMPLE INPUT 5 2 3 4 5 6 SAMPLE OUTPUT YES YES NO YES NO
{"inputs": ["10\n\n9223372036854775807\n104729\n103141\n99999989\n9563494117\n8670344929\n11812315811854\n828456218949862\n0\n12198789456"], "outputs": ["NO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO"]}
154
142
coding
Solve the programming task below in a Python markdown code block. The most dangerous cyborg Jenish is finally entrapped on a narrow bridge over a valley. The bridge is $N$ meters long. For convenience, position $i$ represents a portion of bridge between whose left border is at distance $i-1$ meters from left end and right border is at distance $i$ meters from left end. There are $N$ batteries placed at positions $1,2...N$. The $i^{th}$ one has energy $a[i]$. There are two tanks of strength $X$ at positions $0$ and $N+1$. Initially Jenish has $0$ energy. From now at any second $t$ starting from $1$, first, Jenish can select any battery placed at position $i$ such that $(t \leq i \leq N-t+1)$ and add $a[i]$ to his energy (every battery can be used atmost once). Then both the tanks move one meter towards each other. If there are still any batteries present at positions where the tanks are heading, the battery gets destroyed. At any moment if Jenish's total energy is greater than or equal to $X$, he destroys both the tanks and he escapes the cops. If by the end of $\lfloor \frac {(n+1)}{2}\rfloor^{th}$ second, he can't destroy the tanks, he himself gets destroyed. Find out if he can escape. -----Input:----- - The first line consists of a single integer $T$, the number of test cases. - The first line of each test case contains two space separated integers which represents $N$ and $X$ for that test case respectively. - The second line of each test case contains $N$ space separated integers, $i^{th}$ of which represents $a[i]$. -----Output:----- For each test case, print in a single line, $YES$ if Jenish can escape or $NO$ if he gets destroyed. -----Constraints:----- - $1 \leq X \leq 10^9$ - $0 \leq a[i] \leq 10^6$ - $ 1 \leq N \leq 10^5$ - $\Sigma$ $N$ over all the test cases does not exceed $10^5$ -----Sample Input:----- 3 4 8 5 1 4 2 3 4 3 1 2 2 7 5 5 -----Sample Output:----- YES YES NO -----Explanation----- For test $1$, in the 1st second, first Jenish will select battery at index $1$ and then the tanks from either side will move one meter closer, thus destroying the battery at index $4$.Then, in the next second, Jenish will select battery at index $3$.Then,tanks will move one meter closer again to destroy the remaining battery at index $2$.But now, Jenish has a total energy of $9$ units which is more than enough to destroy the tanks. For test $2$, Jenish can use batteries at index $1$ and $2$ to get a total energy of $4$ units. For test $3$, Jenish can use batteries at index $1$ or $2$ and get a maximum of $5$ units of energy which is less than required.
{"inputs": ["3\n4 8\n5 1 4 2\n3 4\n3 1 2\n2 7\n5 5"], "outputs": ["YES\nYES\nNO"]}
721
46
coding
Solve the programming task below in a Python markdown code block. Ashu and Arvind participated in a coding contest, as a result of which they received N chocolates. Now they want to divide the chocolates between them equally. Can you help them by deciding if it is possible for them to divide all the N chocolates in such a way that they each get an equal number of chocolates? You cannot break a chocolate in two or more pieces. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - The first and only line of each test case contains a single integer N — the number of chocolates they received. ------ Output Format ------ For each test case output the answer on a new line — "Yes" (without quotes) if they can divide chocolates between them equally, and "No" (without quotes) otherwise. Each letter of the output may be printed in either uppercase or lowercase, i.e, "Yes", "YES", and "yEs" will all be treated as equivalent. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10$ ----- Sample Input 1 ------ 4 10 4 3 2 ----- Sample Output 1 ------ Yes Yes No Yes ----- explanation 1 ------ Test case $1$: They can divide $10$ chocolates such that both of them get $5$ chocolates each. Test case $2$: They can divide $4$ chocolates such that both of them get $2$ chocolates each. Test case $3$: There is no way to divide $3$ chocolates so that they get equal number of chocolates. Test case $4$: They can divide $2$ chocolates such that both of them get $1$ chocolate each.
{"inputs": ["4\n10\n4\n3\n2\n"], "outputs": ["Yes\nYes\nNo\nYes"]}
375
28
coding
Solve the programming task below in a Python markdown code block. Shil likes Round numbers very much . A number is called Round number if its non-negative and its first and last digits are same. For example 0 , 3 , 343 and 50005 are round numbers whereas 1000 is not a round number. Shil has an array A1 , A2 .. AN . He wants to answer Q queries of following two type : 1 l r : Find total number of round numbers in range [l, r] 2 i K : Update i^th element of array A to K i.e perform the operation Ai = K. Since you are the friend of Shil , he asks for your help . INPUT: First line consists of two integers N and Q. Next line consists of N integers A1 , A2 .. AN. Next line consists of Q queries. Each query consists of three integers as mentioned in the problem. OUTPUT: For each query of type 2 , output total number of round numbers in range [l,r]. CONSTRAINTS: 1 ≤ N , Q ≤ 2*10^5 -10^18 ≤ Ai ≤ 10^18 1 ≤ l,r ≤ N -10^18 ≤ K ≤ 10^18 SAMPLE INPUT 5 5 1 2 33 456 111 1 1 2 1 1 5 2 1 6 2 2 1000 1 1 5 SAMPLE OUTPUT 2 4 3 Explanation Out of all the initial numbers given in array A :- 1,2,33,111 are round numbers . For 1^st query , there are two round numbers - A[1] and A[2]. For 2^st query , there are 4 round numbers - A[1] , A[2] , A[3] , A[5]. In 3^rd query , we are updating 1st position with 6 , which is a round number. In 4^th query , we are updating 2nd position with 1000 , which isn't a round number. For 5^th query , there are 3 round numbers - A[1] , A[3] and A[5].
{"inputs": ["10 10\n999999999999980689 -999999999999985424 999999999999997259 -999999999999980547 999999999999980429 999999999999985309 999999999999988309 -999999999999978240 999999999999973229 -999999999999986703 \n2 9 999999999999974279\n2 3 999999999999975369\n2 3 999999999999991679\n2 5 999999999999968959\n1 1 7\n1 5 9\n2 10 999999999999972219\n1 1 5\n2 4 999999999999993719\n2 5 999999999999995119\n"], "outputs": ["5\n4\n3\n"]}
521
393
coding
Solve the programming task below in a Python markdown code block. Manasa was sulking her way through a boring class when suddenly her teacher singled her out and asked her a question. He gave her a number n and Manasa has to come up with the smallest number m which contains atleast n number of zeros at the end of m!. Help Manasa come out of the sticky situation. Input Format The first line contains an integer T i.e. the number of Test cases. Next T lines will contain an integer n. Output Format Print smallest such number m. Constraints 1 ≤ T ≤ 100 1 ≤ n ≤ 10^{16} Sample Input 3 1 2 3 Sample Output 5 10 15 Explanation As 4! = 24 and 5! = 120, so minimum value of m will be 5. As 9! = 362880 and 10! = 3628800, so minimum value of m will be 10. As 14! = 87178291200 and 15! = 1307674368000, so minimum value of m will be 15.
{"inputs": ["3\n1\n2\n3\n"], "outputs": ["5\n10\n15\n"]}
282
26
coding
Solve the programming task below in a Python markdown code block. `{a, e, i, o, u, A, E, I, O, U}` Natural Language Understanding is the subdomain of Natural Language Processing where people used to design AI based applications have ability to understand the human languages. HashInclude Speech Processing team has a project named Virtual Assistant. For this project they appointed you as a data engineer (who has good knowledge of creating clean datasets by writing efficient code). As a data engineer your first task is to make vowel recognition dataset. In this task you have to find the presence of vowels in all possible substrings of the given string. For each given string you have to return the total number of vowels. ## Example Given a string `"baceb"` you can split it into substrings: `b, ba, bac, bace, baceb, a, ac, ace, aceb, c, ce, ceb, e, eb, b`. The number of vowels in each of these substrings is `0, 1, 1, 2, 2, 1, 1, 2, 2, 0, 1, 1, 1, 1, 0`; if you sum up these number, you get `16` - the expected output. **Note**: your solution should have linear time complexity. Also feel free to reuse/extend the following starter code: ```python def vowel_recognition(s): ```
{"functional": "_inputs = [['bbbb'], ['baceb'], ['aeiou'], ['aeiouAEIOU']]\n_outputs = [[0], [16], [35], [220]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(vowel_recognition(*i), o[0])"}
310
185
coding
Solve the programming task below in a Python markdown code block. The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between them. For example, for the string "abaca" the following strings are subsequences: "abaca", "aba", "aaa", "a" and "" (empty string). But the following strings are not subsequences: "aabaca", "cb" and "bcaa". You are given a string $s$ consisting of $n$ lowercase Latin letters. In one move you can take any subsequence $t$ of the given string and add it to the set $S$. The set $S$ can't contain duplicates. This move costs $n - |t|$, where $|t|$ is the length of the added subsequence (i.e. the price equals to the number of the deleted characters). Your task is to find out the minimum possible total cost to obtain a set $S$ of size $k$ or report that it is impossible to do so. -----Input----- The first line of the input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the length of the string and the size of the set, correspondingly. The second line of the input contains a string $s$ consisting of $n$ lowercase Latin letters. -----Output----- Print one integer — if it is impossible to obtain the set $S$ of size $k$, print -1. Otherwise, print the minimum possible total cost to do it. -----Examples----- Input 4 5 asdf Output 4 Input 5 6 aaaaa Output 15 Input 5 7 aaaaa Output -1 Input 10 100 ajihiushda Output 233 -----Note----- In the first example we can generate $S$ = { "asdf", "asd", "adf", "asf", "sdf" }. The cost of the first element in $S$ is $0$ and the cost of the others is $1$. So the total cost of $S$ is $4$.
{"inputs": ["1 2\nu\n", "1 5\nw\n", "1 5\nw\n", "1 2\nu\n", "1 0\ns\n", "1 10\ns\n", "1 25\no\n", "1 50\ns\n"], "outputs": ["1\n", "-1\n", "-1\n", "1\n", "0\n", "-1\n", "-1\n", "-1\n"]}
496
105
coding
Solve the programming task below in a Python markdown code block. Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are n cashiers at the exit from the supermarket. At the moment the queue for the i-th cashier already has k_{i} people. The j-th person standing in the queue to the i-th cashier has m_{i}, j items in the basket. Vasya knows that: the cashier needs 5 seconds to scan one item; after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change. Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers. -----Input----- The first line contains integer n (1 ≤ n ≤ 100) — the number of cashes in the shop. The second line contains n space-separated integers: k_1, k_2, ..., k_{n} (1 ≤ k_{i} ≤ 100), where k_{i} is the number of people in the queue to the i-th cashier. The i-th of the next n lines contains k_{i} space-separated integers: m_{i}, 1, m_{i}, 2, ..., m_{i}, k_{i} (1 ≤ m_{i}, j ≤ 100) — the number of products the j-th person in the queue for the i-th cash has. -----Output----- Print a single integer — the minimum number of seconds Vasya needs to get to the cashier. -----Examples----- Input 1 1 1 Output 20 Input 4 1 4 3 2 100 1 2 2 3 1 9 1 7 8 Output 100 -----Note----- In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue.
{"inputs": ["1\n1\n1\n", "1\n1\n1\n", "1\n1\n100\n", "1\n1\n100\n", "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n", "4\n1 4 3 2\n100\n1 4 2 3\n1 0 1\n7 8\n", "4\n1 4 3 2\n100\n1 4 2 3\n2 0 1\n7 8\n", "4\n1 4 3 2\n100\n1 4 2 3\n1 9 1\n7 8\n"], "outputs": ["20\n", "20\n", "515\n", "515\n", "100\n", "55\n", "60\n", "100\n"]}
609
222
coding
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, the two players alternately take a card. The card should be chosen in the following manner: * Takahashi should take the card with the largest integer among the remaining card. * Aoki should take the card with the integer closest to x among the remaining card. If there are multiple such cards, he should take the card with the smallest integer among those cards. * The game ends when there is no card remaining. You are given Q candidates for the value of x: X_1, X_2, ..., X_Q. For each i (1 \leq i \leq Q), find the sum of the integers written on the cards that Takahashi will take if Aoki chooses x = X_i. Constraints * 2 \leq N \leq 100 000 * 1 \leq Q \leq 100 000 * 1 \leq A_1 < A_2 < ... < A_N \leq 10^9 * 1 \leq X_i \leq 10^9 (1 \leq i \leq Q) * All values in input are integers. Input Input is given from Standard Input in the following format: N Q A_1 A_2 ... A_N X_1 X_2 : X_Q Output Print Q lines. The i-th line (1 \leq i \leq Q) should contain the answer for x = X_i. Examples Input 5 5 3 5 7 11 13 1 4 9 10 13 Output 31 31 27 23 23 Input 4 3 10 20 30 40 2 34 34 Output 70 60 60
{"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\n76\n", "77\n60\n77\n"]}
478
245
coding
Solve the programming task below in a Python markdown code block. To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes. The parking lot before the office consists of one line of (2n - 2) parking spaces. Unfortunately the total number of cars is greater than the parking lot capacity. Furthermore even amount of cars of each make is greater than the amount of parking spaces! That's why there are no free spaces on the parking lot ever. Looking on the straight line of cars the company CEO thought that parking lot would be more beautiful if it contained exactly n successive cars of the same make. Help the CEO determine the number of ways to fill the parking lot this way. -----Input----- The only line of the input contains one integer n (3 ≤ n ≤ 30) — the amount of successive cars of the same make. -----Output----- Output one integer — the number of ways to fill the parking lot by cars of four makes using the described way. -----Examples----- Input 3 Output 24 -----Note----- Let's denote car makes in the following way: A — Aston Martin, B — Bentley, M — Mercedes-Maybach, Z — Zaporozhets. For n = 3 there are the following appropriate ways to fill the parking lot: AAAB AAAM AAAZ ABBB AMMM AZZZ BBBA BBBM BBBZ BAAA BMMM BZZZ MMMA MMMB MMMZ MAAA MBBB MZZZ ZZZA ZZZB ZZZM ZAAA ZBBB ZMMM Originally it was planned to grant sport cars of Ferrari, Lamborghini, Maserati and Bugatti makes but this idea was renounced because it is impossible to drive these cars having small road clearance on the worn-down roads of IT City.
{"inputs": ["3\n", "4\n", "5\n", "6\n", "7\n", "6\n", "5\n", "7\n"], "outputs": ["24", "132", "672", "3264", "15360", "3264\n", "672\n", "15360\n"]}
392
86
coding
Solve the programming task below in a Python markdown code block. Shivam is the youngest programmer in the world, he is just 12 years old. Shivam is learning programming and today he is writing his first program. Program is very simple, Given two integers A and B, write a program to add these two numbers. -----Input----- The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains two Integers A and B. -----Output----- For each test case, add A and B and display it in a new line. -----Constraints----- - 1 ≤ T ≤ 1000 - 0 ≤ A,B ≤ 10000 -----Example----- Input 3 1 2 100 200 10 40 Output 3 300 50
{"inputs": ["3\n1 2\n100 200\n10 40"], "outputs": ["3\n300\n50"]}
187
37
coding
Solve the programming task below in a Python markdown code block. Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least a_{i} any pieces of information from the other computers. Doc can hack the computer only if he is right next to it. The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1. It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information. -----Input----- The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information. -----Output----- Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information. -----Examples----- Input 3 0 2 0 Output 1 Input 5 4 2 3 0 1 Output 3 Input 7 0 3 1 0 5 2 6 Output 2 -----Note----- In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece. In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer. In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7.
{"inputs": ["1\n0\n", "1\n0\n", "2\n0 1\n", "2\n0 1\n", "3\n0 2 0\n", "3\n0 2 1\n", "3\n0 2 1\n", "3\n0 2 0\n"], "outputs": ["0\n", "0", "0\n", "0", "1\n", "1\n", "1", "1"]}
576
102
coding
Solve the programming task below in a Python markdown code block. Write a function that receives two strings and returns n, where n is equal to the number of characters we should shift the first string forward to match the second. For instance, take the strings "fatigue" and "tiguefa". In this case, the first string has been rotated 5 characters forward to produce the second string, so 5 would be returned. If the second string isn't a valid rotation of the first string, the method returns -1. Examples: ``` "coffee", "eecoff" => 2 "eecoff", "coffee" => 4 "moose", "Moose" => -1 "isn't", "'tisn" => 2 "Esham", "Esham" => 0 "dog", "god" => -1 ``` For Swift, your function should return an Int?. So rather than returning -1 when the second string isn't a valid rotation of the first, return nil. Also feel free to reuse/extend the following starter code: ```python def shifted_diff(first, second): ```
{"functional": "_inputs = [['fatigue', 'tiguefa'], ['hoop', 'pooh'], ['eecoff', 'coffee'], ['Moose', 'moose'], [\"isn't\", \"'tisn\"], ['Esham', 'Esham'], [' ', ' '], ['dog', 'god'], [' ', ' '], ['doomhouse', 'hoodmouse'], ['123456789!@#$%^&*( )qwerty', '9!@#$%^&*( )qwerty12345678']]\n_outputs = [[5], [-1], [4], [-1], [2], [0], [0], [-1], [-1], [-1], [18]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(shifted_diff(*i), o[0])"}
240
304
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a list of strings dict where all the strings are of the same length. Return true if there are 2 strings that only differ by 1 character in the same index, otherwise return false.   Please complete the following python code precisely: ```python class Solution: def differByOne(self, dict: List[str]) -> bool: ```
{"functional": "def check(candidate):\n assert candidate(dict = [\"abcd\",\"acbd\", \"aacd\"]) == True\n assert candidate(dict = [\"ab\",\"cd\",\"yz\"]) == False\n assert candidate(dict = [\"abcd\",\"cccc\",\"abyd\",\"abab\"]) == True\n\n\ncheck(Solution().differByOne)"}
89
79
coding
Solve the programming task below in a Python markdown code block. KISS stands for Keep It Simple Stupid. It is a design principle for keeping things simple rather than complex. You are the boss of Joe. Joe is submitting words to you to publish to a blog. He likes to complicate things. Define a function that determines if Joe's work is simple or complex. Input will be non emtpy strings with no punctuation. It is simple if: ``` the length of each word does not exceed the amount of words in the string ``` (See example test cases) Otherwise it is complex. If complex: ```python return "Keep It Simple Stupid" ``` or if it was kept simple: ```python return "Good work Joe!" ``` Note: Random test are random and nonsensical. Here is a silly example of a random test: ```python "jump always mostly is touchy dancing choice is pineapples mostly" ``` Also feel free to reuse/extend the following starter code: ```python def is_kiss(words): ```
{"functional": "_inputs = [['Joe had a bad day'], ['Joe had some bad days'], ['Joe is having no fun'], ['Sometimes joe cries for hours'], ['Joe is having lots of fun'], ['Joe is working hard a lot'], ['Joe listened to the noise and it was an onamonapia'], ['Joe listened to the noises and there were some onamonapias']]\n_outputs = [['Good work Joe!'], ['Good work Joe!'], ['Keep It Simple Stupid'], ['Keep It Simple Stupid'], ['Good work Joe!'], ['Keep It Simple Stupid'], ['Good work Joe!'], ['Keep It Simple Stupid']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(is_kiss(*i), o[0])"}
218
274
coding
Solve the programming task below in a Python markdown code block. Eugeny loves listening to music. He has n songs in his play list. We know that song number i has the duration of t_{i} minutes. Eugeny listens to each song, perhaps more than once. He listens to song number i c_{i} times. Eugeny's play list is organized as follows: first song number 1 plays c_1 times, then song number 2 plays c_2 times, ..., in the end the song number n plays c_{n} times. Eugeny took a piece of paper and wrote out m moments of time when he liked a song. Now for each such moment he wants to know the number of the song that played at that moment. The moment x means that Eugeny wants to know which song was playing during the x-th minute of his listening to the play list. Help Eugeny and calculate the required numbers of songs. -----Input----- The first line contains two integers n, m (1 ≤ n, m ≤ 10^5). The next n lines contain pairs of integers. The i-th line contains integers c_{i}, t_{i} (1 ≤ c_{i}, t_{i} ≤ 10^9) — the description of the play list. It is guaranteed that the play list's total duration doesn't exceed 10^9 $(\sum_{i = 1}^{n} c_{i} \cdot t_{i} \leq 10^{9})$. The next line contains m positive integers v_1, v_2, ..., v_{m}, that describe the moments Eugeny has written out. It is guaranteed that there isn't such moment of time v_{i}, when the music doesn't play any longer. It is guaranteed that v_{i} < v_{i} + 1 (i < m). The moment of time v_{i} means that Eugeny wants to know which song was playing during the v_{i}-th munite from the start of listening to the playlist. -----Output----- Print m integers — the i-th number must equal the number of the song that was playing during the v_{i}-th minute after Eugeny started listening to the play list. -----Examples----- Input 1 2 2 8 1 16 Output 1 1 Input 4 9 1 2 2 1 1 1 2 2 1 2 3 4 5 6 7 8 9 Output 1 1 2 2 3 4 4 4 4
{"inputs": ["1 2\n2 8\n1 16\n", "1 2\n2 8\n1 16\n", "3 1\n2 50\n1 50\n1 50\n160\n", "3 1\n2 50\n1 50\n1 50\n160\n", "3 1\n2 50\n1 50\n1 82\n160\n", "3 1\n2 74\n1 50\n1 82\n160\n", "3 1\n2 74\n1 32\n1 82\n160\n", "3 1\n2 50\n1 53\n1 82\n160\n"], "outputs": ["1\n1\n", "1\n1\n", "3\n", "3\n", "3\n", "2\n", "2\n", "3\n"]}
555
222
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string array words, return an array of all characters that show up in all strings within the words (including duplicates). You may return the answer in any order.   Please complete the following python code precisely: ```python class Solution: def commonChars(self, words: List[str]) -> List[str]: ```
{"functional": "def check(candidate):\n assert candidate(words = [\"bella\",\"label\",\"roller\"]) == [\"e\",\"l\",\"l\"]\n assert candidate(words = [\"cool\",\"lock\",\"cook\"]) == [\"c\",\"o\"]\n\n\ncheck(Solution().commonChars)"}
83
68
coding
Solve the programming task below in a Python markdown code block. Chef has an array A of size N. He can perform the following operation on A: Select an i (1 ≤ i ≤ N) and for all 1 ≤ j ≤ i, set A_{j} := A_{j} + 1 (i.e. add 1 to every element in the prefix of length i). Chef wants to convert A to a *palindrome* by using the above operation minimum number of times. Can you help Chef? If it is not possible to convert A to a *palindrome*, output -1. Note: An array is called *palindrome* if it reads the same backwards and forwards, for e.g. [1, 4, 1] and [7, 3, 3, 7] are palindromic arrays. ------ Input Format ------ - The first line contains a single integer T — the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N — the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert A to a palindromic array. If it is not possible to do so, output -1. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 3 \cdot 10^{5}$ $1 ≤A_{i} ≤10^{9}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 4 4 2 2 4 5 5 4 3 2 1 4 1 2 3 4 ----- Sample Output 1 ------ 0 -1 3 ----- explanation 1 ------ Test case $1$: The given array is already a palindrome. Test case $2$: It can be proven that it is not possible to convert $A$ to a palindromic array using the given operation. Test case $3$: We can perform the following operations: - Select $i = 1$, $[1, 2, 3, 4] \rightarrow [2, 2, 3, 4]$ - Select $i = 2$, $[2, 2, 3, 4] \rightarrow [3, 3, 3, 4]$ - Select $i = 1$, $[3, 3, 3, 4] \rightarrow [4, 3, 3, 4]$
{"inputs": ["3\n4\n4 2 2 4\n5\n5 4 3 2 1\n4\n1 2 3 4\n"], "outputs": ["0\n-1\n3\n"]}
595
51
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. $N$ integers $A_{1}, A_{2}, \ldots, A_{N}$ are placed in a circle in such a way that for each valid $i$, $A_{i}$ and $A_{i+1}$ are adjacent, and $A_{1}$ and $A_{N}$ are also adjacent. We want to repeat the following operation exactly $N-1$ times (until only one number remains): Select two adjacent numbers. Let's denote them by $a$ and $b$. Score $a+b$ penalty points. Erase both $a$ and $b$ from the circle and insert $a+b$ in the space between them. What is the minimum number of penalty points we can score? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first line of each test case contains a single integer $N$. The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$. ------ Output ------ For each test case, print a single line containing one integer — the minimum number of penalty points. ------ Constraints ------ $1 ≤ T ≤ 10$ $2 ≤ N ≤ 400$ $1 ≤ a_{i} ≤ 10^{9}$ for each valid $i$ ------ Subtasks ------ Subtask #1 (10 points): $2 ≤ N ≤ 10$ $a_{i} ≤ 10$ for each valid $i$ Subtask #2 (10 points): $2 ≤ N ≤ 25$ $a_{1}, a_{2}, \ldots, a_{N}$ are distinct powers of $2$ (including $1$) Subtask #3 (10 points): $2 ≤ N ≤ 100$ Subtask #4 (70 points): original constraints ----- Sample Input 1 ------ 1 3 10 10 1 ----- Sample Output 1 ------ 32 ----- explanation 1 ------ - $[10,10,1] \rightarrow [10, 11]$, penalty: $11$ - $[10,11] \rightarrow [21]$, penalty: $21$ - Total penalty: $11+21=32$
{"inputs": ["1\n3\n10 10 1"], "outputs": ["32"]}
563
23
coding
Solve the programming task below in a Python markdown code block. For a given sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ which is sorted by ascending order, find a specific value $k$ given as a query. Constraints * $1 \leq n \leq 100,000$ * $1 \leq q \leq 200,000$ * $0 \leq a_0 \leq a_1 \leq ... \leq a_{n-1} \leq 1,000,000,000$ * $0 \leq k_i \leq 1,000,000,000$ Input The input is given in the following format. $n$ $a_0 \; a_1 \; ,..., \; a_{n-1}$ $q$ $k_1$ $k_2$ : $k_q$ The number of elements $n$ and each element $a_i$ are given in the first line and the second line respectively. In the third line, the number of queries $q$ is given and the following $q$ lines, $q$ integers $k_i$ are given as queries. Output For each query, print 1 if any element in $A$ is equivalent to $k$, and 0 otherwise. Example Input 4 1 2 2 4 3 2 3 5 Output 1 0 0
{"inputs": ["4\n1 2 2 4\n3\n2\n3\n6", "4\n1 1 2 4\n3\n0\n3\n8", "4\n0 1 2 6\n3\n0\n3\n6", "4\n1 2 1 4\n2\n0\n3\n8", "4\n0 1 2 7\n1\n0\n5\n3", "4\n0 2 3 4\n3\n2\n3\n4", "4\n0 2 2 1\n3\n4\n3\n0", "4\n1 1 1 4\n2\n0\n1\n8"], "outputs": ["1\n0\n0\n", "0\n0\n0\n", "1\n0\n1\n", "0\n0\n", "1\n", "1\n1\n1\n", "0\n0\n1\n", "0\n1\n"]}
335
214
coding
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$ days. On the $i$-th day: If Du can speak, he'll make fun of Boboniu with fun factor $a_i$. But after that, he may be muzzled depending on Boboniu's mood. Otherwise, Du won't do anything. Boboniu's mood is a constant $m$. On the $i$-th day: If Du can speak and $a_i>m$, then Boboniu will be angry and muzzle him for $d$ days, which means that Du won't be able to speak on the $i+1, i+2, \cdots, \min(i+d,n)$-th days. Otherwise, Boboniu won't do anything. The total fun factor is the sum of the fun factors on the days when Du can speak. Du asked you to find the maximum total fun factor among all possible permutations of $a$. -----Input----- The first line contains three integers $n$, $d$ and $m$ ($1\le d\le n\le 10^5,0\le m\le 10^9$). The next line contains $n$ integers $a_1, a_2, \ldots,a_n$ ($0\le a_i\le 10^9$). -----Output----- Print one integer: the maximum total fun factor among all permutations of $a$. -----Examples----- Input 5 2 11 8 10 15 23 5 Output 48 Input 20 2 16 20 5 8 2 18 16 2 16 16 1 5 16 2 13 6 16 4 17 21 7 Output 195 -----Note----- In the first example, you can set $a'=[15, 5, 8, 10, 23]$. Then Du's chatting record will be: Make fun of Boboniu with fun factor $15$. Be muzzled. Be muzzled. Make fun of Boboniu with fun factor $10$. Make fun of Boboniu with fun factor $23$. Thus the total fun factor is $48$.
{"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"]}
576
118
coding
Solve the programming task below in a Python markdown code block. Given a string `S` and a character `C`, return an array of integers representing the shortest distance from the current character in `S` to `C`. ### Notes * All letters will be lowercase. * If the string is empty, return an empty array. * If the character is not present, return an empty array. ## Examples ```python shortest_to_char("lovecodewars", "e") == [3, 2, 1, 0, 1, 2, 1, 0, 1, 2, 3, 4] shortest_to_char("aaaabbbb", "b") == [4, 3, 2, 1, 0, 0, 0, 0] shortest_to_char("", "b") == [] shortest_to_char("abcde", "") == [] ``` ___ If you liked it, please rate :D Also feel free to reuse/extend the following starter code: ```python def shortest_to_char(s, c): ```
{"functional": "_inputs = [['lovecodewars', 'e'], ['aaaaa', 'a'], ['aabbaabb', 'a'], ['aaaabbbb', 'b'], ['aaaaa', 'b'], ['lovecoding', ''], ['', '']]\n_outputs = [[[3, 2, 1, 0, 1, 2, 1, 0, 1, 2, 3, 4]], [[0, 0, 0, 0, 0]], [[0, 0, 1, 1, 0, 0, 1, 2]], [[4, 3, 2, 1, 0, 0, 0, 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) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(shortest_to_char(*i), o[0])"}
234
305
coding
Solve the programming task below in a Python markdown code block. Let $s$ be a string of lowercase Latin letters. Its price is the sum of the indices of letters (an integer between 1 and 26) that are included in it. For example, the price of the string abca is $1+2+3+1=7$. The string $w$ and the integer $p$ are given. Remove the minimal number of letters from $w$ so that its price becomes less than or equal to $p$ and print the resulting string. Note that the resulting string may be empty. You can delete arbitrary letters, they do not have to go in a row. If the price of a given string $w$ is less than or equal to $p$, then nothing needs to be deleted and $w$ must be output. Note that when you delete a letter from $w$, the order of the remaining letters is preserved. For example, if you delete the letter e from the string test, you get tst. -----Input----- The first line of input contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. The following are descriptions of $t$ test cases. Each case consists of two lines. The first of them is the string $w$, it is non-empty and consists of lowercase Latin letters. Its length does not exceed $2\cdot10^5$. The second line contains an integer $p$ ($1 \le p \le 5\,200000$). It is guaranteed that the sum of string lengths $w$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- Output exactly $t$ rows, the $i$-th of them should contain the answer to the $i$-th set of input data. Print the longest string that is obtained from $w$ by deleting letters such that its price is less or equal to $p$. If there are several answers, then output any of them. Note that the empty string — is one of the possible answers. In this case, just output an empty string. -----Examples----- Input 5 abca 2 abca 6 codeforces 1 codeforces 10 codeforces 100 Output aa abc cdc codeforces -----Note----- None
{"inputs": ["1\nvdjisjifreo\n39\n", "5\nabca\n2\nabca\n6\ncodeforces\n1\ncodeforces\n10\ncodeforces\n100\n"], "outputs": ["diife\n", "aa\naba\n\ncdc\ncodeforces\n"]}
510
73
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string text and another 0-indexed string pattern of length 2, both of which consist of only lowercase English letters. You can add either pattern[0] or pattern[1] anywhere in text exactly once. Note that the character can be added even at the beginning or at the end of text. Return the maximum number of times pattern can occur as a subsequence of the modified text. A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.   Please complete the following python code precisely: ```python class Solution: def maximumSubsequenceCount(self, text: str, pattern: str) -> int: ```
{"functional": "def check(candidate):\n assert candidate(text = \"abdcdbc\", pattern = \"ac\") == 4\n assert candidate(text = \"aabb\", pattern = \"ab\") == 6\n\n\ncheck(Solution().maximumSubsequenceCount)"}
169
58
coding
Solve the programming task below in a Python markdown code block. In this problem the input will consist of a number of lines of English text consisting of the letters of the English alphabet, the punctuation marks ' (apostrophe), . (full stop), , (comma), ; (semicolon), :(colon) and white space characters (blank, newline). Your task is print the words in the text in reverse order without any punctuation marks. For example consider the following candidate for the input text: $ $ This is a sample piece of text to illustrate this problem. If you are smart you will solve this right. $ $ The corresponding output would read as: $ $ right this solve will you smart are you If problem this illustrate to text of piece sample a is This $ $ That is, the lines are printed in reverse order and in each line the words are printed in reverse order. -----Input:----- The first line of input contains a single integer $N$, indicating the number of lines in the input. This is followed by $N$ lines of input text. -----Output:----- $N$ lines of output text containing the input lines in reverse order and where each line contains the words in reverse order as illustrated above. -----Constraints:----- - $1 \leq N \leq 10000$. - There are at most $80$ characters in each line -----Sample input----- 2 This is a sample piece of text to illustrate this problem. If you are smart you will solve this right. -----Sample output----- right this solve will you smart are you If problem this illustrate to text of piece sample a is This
{"inputs": ["2\nThis is a sample piece of text to illustrate this \nproblem. If you are smart you will solve this right.\n"], "outputs": ["right this solve will you smart are you If problem\nthis illustrate to text of piece sample a is This"]}
342
59
coding
Solve the programming task below in a Python markdown code block. An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train? -----Input----- The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cars in the train. The second line contains n integers p_{i} (1 ≤ p_{i} ≤ n, p_{i} ≠ p_{j} if i ≠ j) — the sequence of the numbers of the cars in the train. -----Output----- Print a single integer — the minimum number of actions needed to sort the railway cars. -----Examples----- Input 5 4 1 2 5 3 Output 2 Input 4 4 1 3 2 Output 2 -----Note----- In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
{"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "3\n1 2 3\n", "3\n1 3 2\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n"]}
295
102
coding
Solve the programming task below in a Python markdown code block. Vasya likes to solve equations. Today he wants to solve $(x~\mathrm{div}~k) \cdot (x \bmod k) = n$, where $\mathrm{div}$ and $\mathrm{mod}$ stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, $k$ and $n$ are positive integer parameters, and $x$ is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible $x$. Can you help him? -----Input----- The first line contains two integers $n$ and $k$ ($1 \leq n \leq 10^6$, $2 \leq k \leq 1000$). -----Output----- Print a single integer $x$ — the smallest positive integer solution to $(x~\mathrm{div}~k) \cdot (x \bmod k) = n$. It is guaranteed that this equation has at least one positive integer solution. -----Examples----- Input 6 3 Output 11 Input 1 2 Output 3 Input 4 6 Output 10 -----Note----- The result of integer division $a~\mathrm{div}~b$ is equal to the largest integer $c$ such that $b \cdot c \leq a$. $a$ modulo $b$ (shortened $a \bmod b$) is the only integer $c$ such that $0 \leq c < b$, and $a - c$ is divisible by $b$. In the first sample, $11~\mathrm{div}~3 = 3$ and $11 \bmod 3 = 2$. Since $3 \cdot 2 = 6$, then $x = 11$ is a solution to $(x~\mathrm{div}~3) \cdot (x \bmod 3) = 6$. One can see that $19$ is the only other positive integer solution, hence $11$ is the smallest one.
{"inputs": ["6 3\n", "1 2\n", "4 6\n", "2 2\n", "5 5\n", "9 8\n", "2 2\n", "5 5\n"], "outputs": ["11\n", "3\n", "10\n", "5\n", "26\n", "27\n", "5", "26"]}
460
89
coding
Solve the programming task below in a Python markdown code block. Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won. -----Input----- The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·10^5). The following n lines contain integer numbers a_{i} (|a_{i}| ≤ 10^9, a_{i} ≠ 0). If a_{i} is positive, that means that the first wrestler performed the technique that was awarded with a_{i} points. And if a_{i} is negative, that means that the second wrestler performed the technique that was awarded with ( - a_{i}) points. The techniques are given in chronological order. -----Output----- If the first wrestler wins, print string "first", otherwise print "second" -----Examples----- Input 5 1 2 -3 -4 3 Output second Input 3 -1 -2 3 Output first Input 2 4 -4 Output second -----Note----- Sequence x = x_1x_2... x_{|}x| is lexicographically larger than sequence y = y_1y_2... y_{|}y|, if either |x| > |y| and x_1 = y_1, x_2 = y_2, ... , x_{|}y| = y_{|}y|, or there is such number r (r < |x|, r < |y|), that x_1 = y_1, x_2 = y_2, ... , x_{r} = y_{r} and x_{r} + 1 > y_{r} + 1. We use notation |a| to denote length of sequence a.
{"inputs": ["2\n4\n-4\n", "2\n1\n-1\n", "2\n-4\n4\n", "2\n-5\n6\n", "2\n-5\n6\n", "2\n-4\n4\n", "2\n1\n-1\n", "2\n-5\n9\n"], "outputs": ["second\n", "second\n", "first\n", "first\n", "first\n", "first\n", "second\n", "first\n"]}
492
110
coding
Solve the programming task below in a Python markdown code block. Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime if it has exactly $K$ distinct prime factors. The game is quite simple. Alice will give three numbers $A$, $B$ & $K$ to Bob. Bob needs to tell Alice the number of $K$-prime numbers between $A$ & $B$ (both inclusive). If Bob gives the correct answer, he gets a point. If not, Alice gets a point. They play this game $T$ times. Bob hasn't prepared so well. But he really wants to win the game. He wants you to tell him the correct answer. ------ Input ------ First line of input contains a single integer $T$, the number of times they play. Each game is described in a single line containing the three numbers $A$,$B$ & $K$. ------ Output ------ For each game, output on a separate line the number of $K$-primes between $A$ & $B$. ------ Constraints: ------ $1 ≤ T ≤ 10000$ $2 ≤ A ≤ B ≤ 100000$ $1 ≤ K ≤ 5$ ----- Sample Input 1 ------ 4 2 5 1 4 10 2 14 15 2 2 20 3 ----- Sample Output 1 ------ 4 2 2 0 ----- explanation 1 ------ Test case $1$: The range includes $4$ integers $\{2, 3, 4,5 \}$. We need to find the number of integers in this range having only $1$ distinct prime factor. - For $2$, since it is prime, it has $1$ distinct prime factor. - For $3$, since it is prime, it has $1$ distinct prime factor. - For $4$, we can write it as $2\times 2$. Thus, it has $1$ distinct prime factor which is $2$. - For $5$, since it is prime, it has $1$ distinct prime factor. Thus, all $4$ integers in the given range are $1$-primes. Test case $2$: The only *K-primes* in the given range are $6$ and $10$. This is because $6 = 2\times 3$ and $10 = 2\times 5$. Thus both these integers have $2$ distinct prime factors. Test case $3$: The only *K-primes* in the given range are $14$ and $15$. This is because $14 = 2\times 7$ and $15 = 3\times 5$. Thus both these integers have $2$ distinct prime factors. Test case $4$: There are no *K-primes* in the given range.
{"inputs": ["4\n2 2 2\n3 8 2\n1 6 2\n4 16 5", "4\n2 2 2\n2 8 2\n2 15 4\n4 6 4", "4\n2 2 2\n3 6 2\n1 6 2\n4 16 1", "4\n5 0 1\n4 7 1\n1 15 0\n3 3 3", "4\n5 0 1\n7 7 1\n1 15 0\n3 3 3", "4\n2 0 1\n3 0 2\n1 15 2\n2 20 5", "4\n2 0 1\n2 12 1\n1 22 2\n2 0 1", "4\n2 2 2\n3 8 2\n1 15 2\n4 16 5"], "outputs": ["0\n1\n1\n0\n", "0\n1\n0\n0\n", "0\n1\n1\n8\n", "-3\n3\n0\n0\n", "-3\n1\n0\n0\n", "0\n0\n5\n0\n", "0\n8\n9\n0\n", "0\n1\n5\n0\n"]}
682
313
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array nums of size n consisting of non-negative integers. You need to apply n - 1 operations to this array where, in the ith operation (0-indexed), you will apply the following on the ith element of nums: If nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[i + 1] to 0. Otherwise, you skip this operation. After performing all the operations, shift all the 0's to the end of the array. For example, the array [1,0,2,0,0,1] after shifting all its 0's to the end, is [1,2,1,0,0,0]. Return the resulting array. Note that the operations are applied sequentially, not all at once.   Please complete the following python code precisely: ```python class Solution: def applyOperations(self, nums: List[int]) -> List[int]: ```
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,2,1,1,0]) == [1,4,2,0,0,0]\n assert candidate(nums = [0,1]) == [1,0]\n\n\ncheck(Solution().applyOperations)"}
221
69
coding
Solve the programming task below in a Python markdown code block. You are given <var>Q</var> tuples of integers <var>(L_i, A_i, B_i, M_i)</var>. For each tuple, answer the following question. There is an arithmetic progression with L terms: s_0, s_1, s_2, ... , s_{L-1}. The initial term is A, and the common difference is B. That is, s_i = A + B \times i holds. Consider the integer obtained by concatenating the terms written in base ten without leading zeros. For example, the sequence 3, 7, 11, 15, 19 would be concatenated into 37111519. What is the remainder when that integer is divided by M? -----Constraints----- - All values in input are integers. - 1 \leq L, A, B < 10^{18} - 2 \leq M \leq 10^9 - All terms in the arithmetic progression are less than 10^{18}. -----Input----- Input is given from Standard Input in the following format: L A B M -----Output----- Print the remainder when the integer obtained by concatenating the terms is divided by M. -----Sample Input----- 5 3 4 10007 -----Sample Output----- 5563 Our arithmetic progression is 3, 7, 11, 15, 19, so the answer is 37111519 mod 10007, that is, 5563.
{"inputs": ["5 5 4 10007", "2 5 4 10007", "2 1 4 10007", "5 3 4 10007", "5 3 4 10007\n", "6 8 1 1000000", "4 8 1 1001000", "3 8 1 1001000"], "outputs": ["358\n", "59\n", "15\n", "5563", "5563\n", "111213\n", "891011\n", "8910\n"]}
354
171
coding
Solve the programming task below in a Python markdown code block. We have a directed weighted graph with N vertices. Each vertex has two integers written on it, and the integers written on Vertex i are A_i and B_i. In this graph, there is an edge from Vertex x to Vertex y for all pairs 1 \leq x,y \leq N, and its weight is {\rm min}(A_x,B_y). We will consider a directed cycle in this graph that visits every vertex exactly once. Find the minimum total weight of the edges in such a cycle. Constraints * 2 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * 1 \leq B_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 B_1 A_2 B_2 : A_N B_N Output Print the minimum total weight of the edges in such a cycle. Examples Input 3 1 5 4 2 6 3 Output 7 Input 4 1 5 2 6 3 7 4 8 Output 10 Input 6 19 92 64 64 78 48 57 33 73 6 95 73 Output 227
{"inputs": ["3\n2 5\n4 2\n6 3", "3\n1 5\n4 4\n6 3", "3\n1 5\n4 2\n6 3", "4\n1 5\n2 6\n0 7\n4 8", "4\n1 5\n0 6\n0 7\n4 8", "4\n1 3\n0 6\n0 7\n4 8", "4\n1 5\n2 6\n3 7\n4 8", "4\n1 3\n0 6\n-1 7\n4 8"], "outputs": ["8\n", "9\n", "7", "7\n", "5\n", "4\n", "10", "3\n"]}
318
178
coding
Solve the programming task below in a Python markdown code block. Everybody is worried about Rakesh as the boy does not have much knowledge about the real world. He can not go from one place to another on his own. It's high time he learned to explore the city. He is going to a relative's house situated on the other side of the city on his own. As this is his first time, he is carrying a GPS tracker of a special kind. The tracker continuously sends information to the family of Rakesh about his movement. The information is sent using the following four letters: U, D, R, and L. Those letters indicate the moves taken by Rakesh. The city can be considered as a grid. Rakesh starts his journey from (0, 0) position of the grid. His relative's house is situated at (Rx, Ry). Rakesh can move in four directions: up, down, right, or left indicated by U, D, R, and L respectively. Any position of the city with x ordinate negative or greater than M is considered as dangerous. Also, any position of the city with y ordinate negative or greater than N is considered as dangerous. You will be given the total sequence of Rakesh's movement. You need to determine if Rakesh ended up being at his relative's house, at a dangerous place, or at a random place in the city. To make things clear, - U indicates a move that increases position along y-axis by 1 - D indicates a move that decreases position along y-axis by 1 - R indicates a move that increases position along x-axis by 1 - L indicates a move that decreases position along x-axis by 1 Note that we are interested in the position of Rakesh at the end of his journey only. He may visit some dangerous place or his relative's house at some intermediate point but that won't affect the answer. -----Input----- - The first line of the input contains an integer T denoting the number of test cases. The description of each test case follows. - The first line of each test case contains two integers M and N. - The second line contains two integers Rx and Ry. - The third line contains the length of Rakesh's move sequence. - The next line contains the move sequence containing letters U, D, R, and L only with no space. -----Output----- For each test case, print "Case i: ", and then the answer, where i is the testcase number, 1-indexed. The answer should be any of the following three strings: - "REACHED" if Rakesh could reach his relative's house - "DANGER" if Rakesh ended up being in a dangerous place - "SOMEWHERE" if Rakesh ended up being in somewhere safe place in the city other than his relative's place Don't print any quotation mark. Check the sample output. -----Constraints----- - 1 ≤ T ≤ 10 - 0 ≤ M, N ≤ 10000 - 0 ≤ Rx ≤ M - 0 ≤ Ry ≤ N - 0 ≤ Sum of the lengths of all sequences ≤ 10000 -----Example----- Input: 2 20 20 4 5 13 LLUUUUURRRRRR 10 10 3 4 7 UDUDDRR Output: Case 1: REACHED Case 2: DANGER
{"inputs": ["2\n20 20\n4 5\n13\nLLUUUUURRRRRR\n10 10\n3 4\n7\nUDUDDRR"], "outputs": ["Case 1: REACHED\nCase 2: DANGER"]}
744
62
coding
Solve the programming task below in a Python markdown code block. Given a word consisting of lowercase English letters, write a program to remove duplicates from the word. The characters in the output must preserve the same order, as their first appearance in the original word. Input Format The input consists of several test cases. The first line of the input file contains a positive integer T, the number of test cases. Then, T lines follow, each containing a single word W (no spaces, only lowercase English letters). Output Format The output must contain exactly T lines, each line containing a single word, the required answer. Constraints 1 ≤ T ≤ 100 1 ≤ |W| ≤ 31 SAMPLE INPUT 2 hello world mississippi SAMPLE OUTPUT helo world misp
{"inputs": ["5\nbananasqr\naaaaa\nabcde\nayacazkeafagahbcbdbebfbg\nqweer\n"], "outputs": ["bansqr\na\nabcde\nayczkefghbd\nqwer\n"]}
168
59
coding
Solve the programming task below in a Python markdown code block. Imagine you start on the 5th floor of a building, then travel down to the 2nd floor, then back up to the 8th floor. You have travelled a total of 3 + 6 = 9 floors of distance. Given an array representing a series of floors you must reach by elevator, return an integer representing the total distance travelled for visiting each floor in the array in order. ``` // simple examples elevatorDistance([5,2,8]) = 9 elevatorDistance([1,2,3]) = 2 elevatorDistance([7,1,7,1]) = 18 // if two consecutive floors are the same, //distance travelled between them is 0 elevatorDistance([3,3]) = 0 ``` Array will always contain at least 2 floors. Random tests will contain 2-20 elements in array, and floor values between 0 and 30. Also feel free to reuse/extend the following starter code: ```python def elevator_distance(array): ```
{"functional": "_inputs = [[[5, 2, 8]], [[1, 2, 3]], [[7, 1, 7, 1]]]\n_outputs = [[9], [2], [18]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(elevator_distance(*i), o[0])"}
235
189
coding
Solve the programming task below in a Python markdown code block. Of the real numbers, those with a circular decimal part and those with a finite number of digits can be expressed as fractions. Given a real number that can be represented by a fraction, write a program that outputs an irreducible fraction equal to that real number (a fraction that cannot be reduced any further). Input The input is given in the following format. str One line is given the string str that represents the real number you want to convert. The real value is greater than 0. The character string is a number or a character string having a length of 3 or more and 8 or less, including ".", "(", ")". "." Indicates the decimal point, "(" indicates the beginning of the number cycle, and ")" indicates the end of the number cycle. It is assumed that one or more digits are always given to both the integer part and the decimal part. However, given a recurring decimal, the string satisfies the following conditions: * The beginning and end pairs of the cycle appear only once to the right of the decimal point. * The ")" that indicates the end of the cycle appears at the end of the string. * A single or more digit is always given between the beginning and end of the cycle. Output Outputs a real number in irreducible fraction format (integer of numerator followed by integers of denominator separated by "/"). Examples Input 0.(3) Output 1/3 Input 1.0 Output 1/1 Input 5.2(143) Output 52091/9990 Input 0.0739 Output 739/10000
{"inputs": ["1.0", "0.(2)", "1.(3)", "1.(2)", "0.(3)", "0.0739", "3.2(145)", "3.3(145)"], "outputs": ["1/1", "2/9\n", "4/3\n", "11/9\n", "1/3", "739/10000", "32113/9990\n", "16556/4995\n"]}
352
124
coding
Solve the programming task below in a Python markdown code block. Your favorite shop sells n Kinder Surprise chocolate eggs. You know that exactly s stickers and exactly t toys are placed in n eggs in total. Each Kinder Surprise can be one of three types: * it can contain a single sticker and no toy; * it can contain a single toy and no sticker; * it can contain both a single sticker and a single toy. But you don't know which type a particular Kinder Surprise has. All eggs look identical and indistinguishable from each other. What is the minimum number of Kinder Surprise Eggs you have to buy to be sure that, whichever types they are, you'll obtain at least one sticker and at least one toy? Note that you do not open the eggs in the purchasing process, that is, you just buy some number of eggs. It's guaranteed that the answer always exists. Input The first line contains the single integer T (1 ≤ T ≤ 100) — the number of queries. Next T lines contain three integers n, s and t each (1 ≤ n ≤ 10^9, 1 ≤ s, t ≤ n, s + t ≥ n) — the number of eggs, stickers and toys. All queries are independent. Output Print T integers (one number per query) — the minimum number of Kinder Surprise Eggs you have to buy to be sure that, whichever types they are, you'll obtain at least one sticker and one toy Example Input 3 10 5 7 10 10 10 2 1 1 Output 6 1 2 Note In the first query, we have to take at least 6 eggs because there are 5 eggs with only toy inside and, in the worst case, we'll buy all of them. In the second query, all eggs have both a sticker and a toy inside, that's why it's enough to buy only one egg. In the third query, we have to buy both eggs: one with a sticker and one with a toy.
{"inputs": ["1\n5 3 2\n", "1\n5 4 2\n", "1\n5 4 4\n", "1\n5 1 4\n", "1\n3 1 4\n", "1\n7 4 4\n", "1\n6 5 2\n", "1\n1926 54 3018\n"], "outputs": ["4\n", "4\n", "2\n", "5\n", "3\n", "4\n", "5\n", "1873\n"]}
435
128
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 zero) as long as the following conditions are satisfied: - Chef can only jump from each hill to the next hill, i.e. from the i-th hill, he can jump to the i+1-th hill (if it exists). - It's always possible to jump to a hill with the same height as the current hill. - It's possible to jump to a taller hill if it's higher than the current hill by no more than U. - It's possible to jump to a lower hill if it's lower than the current hill by no more than D. - Chef can use a parachute and jump to a lower hill regardless of its height (as long as it's lower than the current hill). This jump can only be performed at most once. Chef would like to move as far right as possible. Determine the index of the rightmost hill Chef can reach. -----Input----- - The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains three space-separated integers N, U and D. - The second line contains N space-separated integers H1, H2, ..., HN. -----Output----- For each test case, print a single line containing one integer — the index of the rightmost reachable hill. -----Constraints----- - 1 ≤ T ≤ 100 - 1 ≤ N ≤ 100 - 1 ≤ U, D ≤ 1,000,000 - 1 ≤ Hi ≤ 1,000,000 for each valid i -----Subtasks----- Subtask #1 (100 points): original constraints -----Example----- Input: 3 5 3 2 2 5 2 6 3 5 2 3 4 4 4 4 4 5 2 7 1 4 3 2 1 Output: 3 5 1 -----Explanation----- Example case 1: Chef can jump to second hill because it's higher by no more than U=3 than first hill, to jump to third hill Chef has to use parachute because it's lower than second hill by 3 which is more than D=2, Chef can't jump to fourth hill because it's higher than third hill by 4 which is more than U=3 Example case 2: All hills are of the same height, so chef can reach the last hill with no problems. Example case 3: Chef can't jump to second hill because it's too high for him
{"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. You have found $M$ different types of jewels in a mine and each type of jewel is present in an infinite number. There are $N$ different boxes located at position $(1 ,2 ,3 ,...N)$. Each box can collect jewels up to a certain number ( box at position $i$ have $i$ different partitions and each partition can collect at most one jewel of any type). Boxes at odd positions are already fully filled with jewels while boxes at even positions are completely empty. Print the total number of different arrangements possible so that all boxes can be fully filled. As the answer can be very large you can print it by doing modulo with 1000000007(10^9+7). -----Input:----- - First line will contain $T$, number of testcases. - Each testcase contains of a single line of input, two integers $N , M$. -----Output:----- For each testcase, Print the total number of different arrangement. -----Constraints----- - $1 \leq T \leq 20000$ - $1 \leq N \leq 1e9$ - $1 \leq M \leq 1e14$ -----Sample Input:----- 2 1 10 5 2 -----Sample Output:----- 1 64
{"inputs": ["2\n1 10\n5 2"], "outputs": ["1\n64"]}
295
24
coding
Solve the programming task below in a Python markdown code block. Reading books is one of Sasha's passions. Once while he was reading one book, he became acquainted with an unusual character. The character told about himself like that: "Many are my names in many countries. Mithrandir among the Elves, Tharkûn to the Dwarves, Olórin I was in my youth in the West that is forgotten, in the South Incánus, in the North Gandalf; to the East I go not." And at that moment Sasha thought, how would that character be called in the East? In the East all names are palindromes. A string is a palindrome if it reads the same backward as forward. For example, such strings as "kazak", "oo" and "r" are palindromes, but strings "abb" and "ij" are not. Sasha believed that the hero would be named after one of the gods of the East. As long as there couldn't be two equal names, so in the East people did the following: they wrote the original name as a string on a piece of paper, then cut the paper minimum number of times $k$, so they got $k+1$ pieces of paper with substrings of the initial string, and then unite those pieces together to get a new string. Pieces couldn't be turned over, they could be shuffled. In this way, it's possible to achive a string abcdefg from the string f|de|abc|g using $3$ cuts (by swapping papers with substrings f and abc). The string cbadefg can't be received using the same cuts. More formally, Sasha wants for the given palindrome $s$ find such minimum $k$, that you can cut this string into $k + 1$ parts, and then unite them in such a way that the final string will be a palindrome and it won't be equal to the initial string $s$. It there is no answer, then print "Impossible" (without quotes). -----Input----- The first line contains one string $s$ ($1 \le |s| \le 5\,000$) — the initial name, which consists only of lowercase Latin letters. It is guaranteed that $s$ is a palindrome. -----Output----- Print one integer $k$ — the minimum number of cuts needed to get a new name, or "Impossible" (without quotes). -----Examples----- Input nolon Output 2 Input otto Output 1 Input qqqq Output Impossible Input kinnikkinnik Output 1 -----Note----- In the first example, you can cut the string in those positions: no|l|on, and then unite them as follows on|l|no. It can be shown that there is no solution with one cut. In the second example, you can cut the string right in the middle, and swap peaces, so you get toot. In the third example, you can't make a string, that won't be equal to the initial one. In the fourth example, you can cut the suffix nik and add it to the beginning, so you get nikkinnikkin.
{"inputs": ["a\n", "f\n", "a\n", "f\n", "`\n", "e\n", "b\n", "d\n"], "outputs": ["Impossible\n", "Impossible\n", "Impossible", "Impossible", "Impossible\n", "Impossible\n", "Impossible\n", "Impossible\n"]}
676
68
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n, the number of teams in a tournament that has strange rules: If the current number of teams is even, each team gets paired with another team. A total of n / 2 matches are played, and n / 2 teams advance to the next round. If the current number of teams is odd, one team randomly advances in the tournament, and the rest gets paired. A total of (n - 1) / 2 matches are played, and (n - 1) / 2 + 1 teams advance to the next round. Return the number of matches played in the tournament until a winner is decided.   Please complete the following python code precisely: ```python class Solution: def numberOfMatches(self, n: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(n = 7) == 6\n assert candidate(n = 14) == 13\n\n\ncheck(Solution().numberOfMatches)"}
180
45
coding
Solve the programming task below in a Python markdown code block. Roma is programmer and he likes memes about IT, Maxim is chemist and he likes memes about chemistry, Danik is designer and he likes memes about design, and Vlad likes all other memes. ___ You will be given a meme (string), and your task is to identify its category, and send it to the right receiver: `IT - 'Roma'`, `chemistry - 'Maxim'`, `design - 'Danik'`, or `other - 'Vlad'`. IT meme has letters `b, u, g`. Chemistry meme has letters `b, o, o, m`. Design meme has letters `e, d, i, t, s`. If there is more than 1 possible answer, the earliest match should be chosen. **Note:** letters are case-insensetive and should come in the order specified above. ___ ## Examples: (Matching letters are surrounded by curly braces for readability.) ``` this is programmer meme {b}ecause it has b{ug} this is also program{bu}r meme {g}ecause it has needed key word this is {ed}s{i}gner meme cause i{t} ha{s} key word this could {b}e chemistry meme b{u}t our{g}Gey word 'boom' is too late instead of this could {b}e chemistry meme but {o}ur gey w{o}rd 'boo{m}' is too late ``` Also feel free to reuse/extend the following starter code: ```python def memesorting(meme): ```
{"functional": "_inputs = [['This is programmer meme ecause it has bug'], ['This is also programbur meme gecause it has needed key word'], ['This is edsigner meme cause it has key word'], ['This could be chemistry meme but our gey word boom is too late'], ['This is meme']]\n_outputs = [['Roma'], ['Roma'], ['Danik'], ['Roma'], ['Vlad']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(memesorting(*i), o[0])"}
350
229
coding
Solve the programming task below in a Python markdown code block. A number is ternary if it contains only digits $0$, $1$ and $2$. For example, the following numbers are ternary: $1022$, $11$, $21$, $2002$. You are given a long ternary number $x$. The first (leftmost) digit of $x$ is guaranteed to be $2$, the other digits of $x$ can be $0$, $1$ or $2$. Let's define the ternary XOR operation $\odot$ of two ternary numbers $a$ and $b$ (both of length $n$) as a number $c = a \odot b$ of length $n$, where $c_i = (a_i + b_i) \% 3$ (where $\%$ is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by $3$. For example, $10222 \odot 11021 = 21210$. Your task is to find such ternary numbers $a$ and $b$ both of length $n$ and both without leading zeros that $a \odot b = x$ and $max(a, b)$ is the minimum possible. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow. The first line of the test case contains one integer $n$ ($1 \le n \le 5 \cdot 10^4$) — the length of $x$. The second line of the test case contains ternary number $x$ consisting of $n$ digits $0, 1$ or $2$. It is guaranteed that the first digit of $x$ is $2$. It is guaranteed that the sum of $n$ over all test cases does not exceed $5 \cdot 10^4$ ($\sum n \le 5 \cdot 10^4$). -----Output----- For each test case, print the answer — two ternary integers $a$ and $b$ both of length $n$ and both without leading zeros such that $a \odot b = x$ and $max(a, b)$ is the minimum possible. If there are several answers, you can print any. -----Example----- Input 4 5 22222 5 21211 1 2 9 220222021 Output 11111 11111 11000 10211 1 1 110111011 110111010
{"inputs": ["4\n5\n22222\n5\n21211\n1\n2\n9\n220222021\n", "4\n5\n22222\n5\n21211\n1\n2\n9\n220222021\n"], "outputs": ["11111\n11111\n11000\n10211\n1\n1\n110111011\n110111010\n", "11111\n11111\n11000\n10211\n1\n1\n110111011\n110111010\n"]}
623
178
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a wooden stick of length n units. The stick is labelled from 0 to n. For example, a stick of length 6 is labelled as follows: Given an integer array cuts where cuts[i] denotes a position you should perform a cut at. You should perform the cuts in order, you can change the order of the cuts as you wish. The cost of one cut is the length of the stick to be cut, the total cost is the sum of costs of all cuts. When you cut a stick, it will be split into two smaller sticks (i.e. the sum of their lengths is the length of the stick before the cut). Please refer to the first example for a better explanation. Return the minimum total cost of the cuts.   Please complete the following python code precisely: ```python class Solution: def minCost(self, n: int, cuts: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(n = 7, cuts = [1,3,4,5]) == 16\n assert candidate(n = 9, cuts = [5,6,1,4,2]) == 22\n\n\ncheck(Solution().minCost)"}
204
69
coding
Solve the programming task below in a Python markdown code block. Given an array of integers and a target sum, determine the sum nearest to but not exceeding the target that can be created. To create the sum, use any element of your array zero or more times. For example, if $arr=[2,3,4]$ and your target sum is $10$, you might select $[2,2,2,2,2],[2,2,3,3]$ or $[3,3,3,1]$. In this case, you can arrive at exactly the target. Function Description Complete the unboundedKnapsack function in the editor below. It must return an integer that represents the sum nearest to without exceeding the target value. unboundedKnapsack has the following parameter(s): k: an integer arr: an array of integers Input Format The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of test cases. Each of the next $\boldsymbol{\boldsymbol{t}}$ pairs of lines are as follows: - The first line contains two integers $n$ and $\boldsymbol{\mbox{k}}$, the length of $\textbf{arr}$ and the target sum. - The second line contains $n$ space separated integers $arr\left[i\right]$. Constraints $1\leq t\leq10$ $1\leq n,k,ar r[i]\leq2000$ Output Format Print the maximum sum for each test case which is as near as possible, but not exceeding, to the target sum on a separate line. Sample Input 2 3 12 1 6 9 5 9 3 4 4 4 8 Sample Output 12 9 Explanation In the first test case, one can pick {6, 6}. In the second, we can pick {3,3,3}.
{"inputs": ["2\n3 12\n1 6 9\n5 9\n3 4 4 4 8\n"], "outputs": ["12\n9\n"]}
425
42
coding
Solve the programming task below in a Python markdown code block. There is an infinitely large pond, which we consider as a number line. In this pond, there are N lotuses floating at coordinates 0, 1, 2, ..., N-2 and N-1. On the lotus at coordinate i, an integer s_i is written. You are standing on the lotus at coordinate 0. You will play a game that proceeds as follows: - 1. Choose positive integers A and B. Your score is initially 0. - 2. Let x be your current coordinate, and y = x+A. The lotus at coordinate x disappears, and you move to coordinate y. - If y = N-1, the game ends. - If y \neq N-1 and there is a lotus floating at coordinate y, your score increases by s_y. - If y \neq N-1 and there is no lotus floating at coordinate y, you drown. Your score decreases by 10^{100} points, and the game ends. - 3. Let x be your current coordinate, and y = x-B. The lotus at coordinate x disappears, and you move to coordinate y. - If y = N-1, the game ends. - If y \neq N-1 and there is a lotus floating at coordinate y, your score increases by s_y. - If y \neq N-1 and there is no lotus floating at coordinate y, you drown. Your score decreases by 10^{100} points, and the game ends. - 4. Go back to step 2. You want to end the game with as high a score as possible. What is the score obtained by the optimal choice of A and B? -----Constraints----- - 3 \leq N \leq 10^5 - -10^9 \leq s_i \leq 10^9 - s_0=s_{N-1}=0 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: N s_0 s_1 ...... s_{N-1} -----Output----- Print the score obtained by the optimal choice of A and B. -----Sample Input----- 5 0 2 5 1 0 -----Sample Output----- 3 If you choose A = 3 and B = 2, the game proceeds as follows: - Move to coordinate 0 + 3 = 3. Your score increases by s_3 = 1. - Move to coordinate 3 - 2 = 1. Your score increases by s_1 = 2. - Move to coordinate 1 + 3 = 4. The game ends with a score of 3. There is no way to end the game with a score of 4 or higher, so the answer is 3. Note that you cannot land the lotus at coordinate 2 without drowning later.
{"inputs": ["5\n0 2 5 0 0", "5\n0 2 5 1 0", "5\n0 2 5 1 0\n", "6\n0 7 -7 -4 0 0", "6\n0 2 -7 -1 -5 0", "6\n0 4 -7 -1 -3 0", "6\n0 4 -7 -1 -1 0", "6\n0 5 -7 -2 -1 0"], "outputs": ["2\n", "3", "3\n", "7\n", "0\n", "1\n", "3\n", "4\n"]}
634
152
coding
Solve the programming task below in a Python markdown code block. Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers A and B and then calculates the greatest common divisor of integers "A factorial" and "B factorial". Formally the hacker wants to find out GCD(A!, B!). It's well known that the factorial of an integer x is a product of all positive integers less than or equal to x. Thus x! = 1·2·3·...·(x - 1)·x. For example 4! = 1·2·3·4 = 24. Recall that GCD(x, y) is the largest positive integer q that divides (without a remainder) both x and y. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? -----Input----- The first and single line contains two integers A and B (1 ≤ A, B ≤ 10^9, min(A, B) ≤ 12). -----Output----- Print a single integer denoting the greatest common divisor of integers A! and B!. -----Example----- Input 4 3 Output 6 -----Note----- Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
{"inputs": ["4 3\n", "1 1\n", "5 3\n", "1 4\n", "5 4\n", "9 7\n", "2 3\n", "6 7\n"], "outputs": ["6\n", "1\n", "6\n", "1\n", "24\n", "5040\n", "2\n", "720\n"]}
409
92
coding
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 land where a 0 represents a hectare of forested land and a 1 represents a hectare of farmland. To keep the land organized, there are designated rectangular areas of hectares that consist entirely of farmland. These rectangular areas are called groups. No two groups are adjacent, meaning farmland in one group is not four-directionally adjacent to another farmland in a different group. land can be represented by a coordinate system where the top left corner of land is (0, 0) and the bottom right corner of land is (m-1, n-1). Find the coordinates of the top left and bottom right corner of each group of farmland. A group of farmland with a top left corner at (r1, c1) and a bottom right corner at (r2, c2) is represented by the 4-length array [r1, c1, r2, c2]. Return a 2D array containing the 4-length arrays described above for each group of farmland in land. If there are no groups of farmland, return an empty array. You may return the answer in any order.   Please complete the following python code precisely: ```python class Solution: def findFarmland(self, land: List[List[int]]) -> List[List[int]]: ```
{"functional": "def check(candidate):\n assert candidate(land = [[1,0,0],[0,1,1],[0,1,1]]) == [[0,0,0,0],[1,1,2,2]]\n assert candidate(land = [[1,1],[1,1]]) == [[0,0,1,1]]\n assert candidate(land = [[0]]) == []\n\n\ncheck(Solution().findFarmland)"}
299
105