Dataset Viewer
Auto-converted to Parquet Duplicate
task_type
stringclasses
4 values
problem
stringlengths
14
5.23k
solution
stringlengths
1
8.29k
problem_tokens
int64
9
1.02k
solution_tokens
int64
1
1.98k
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Gritukan likes to take cyclic trips around the world. There are $N$ countries numbered $1$ through $N$ in the world. Before starting his travels, Gritukan chooses a permutation $P$ of all $N$ countries. Then, he visits all countries (some countries may be visited multiple times) using the following algorithm: for each $v$ from $1$ to $N$ inclusive: - travel to country $v$ - travel from country $v$ to country $P_{v}$, then from country $P_{v}$ to country $P_{P_{v}}$, and so on until he reaches country $v$ again; let's call this sequence of visited countries a *cyclic route* (Each country appears at most once in a cyclic route. It is also possible for a route to contain only one country if $v=P_{v}$, in which case Gritukan's travel along this route consists of staying in country $v$.) Unfortunately, Gritukan does not remember the routes he took. He only remembers a sequence $A_{1..N}$ with the following meaning: for each country $v$, the number of cyclic routes which contained this country is $A_{v}$. Given the sequence $A$, Gritukan asks you to calculate the number of permutations $P$ consistent with this sequence, modulo $998244353$ (it's prime). ------ 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}, \dots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer — the number of possible permutations modulo $998244353$ (it's prime). ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ N ≤ 10^{6}$ $1 ≤ A_{i} ≤ N$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (40 points): $1 ≤ N ≤ 5000$ Subtask #2 (60 points): original constraints ----- Sample Input 1 ------ 2 6 1 1 1 1 1 1 6 6 6 6 6 6 6 ----- Sample Output 1 ------ 1 120
{"inputs": ["2\n6\n1 1 1 1 1 1\n6\n6 6 6 6 6 6"], "outputs": ["1\n120"]}
595
44
coding
Solve the programming task below in a Python markdown code block. Passer ratings are the generally accepted standard for evaluating NFL quarterbacks. I knew a rating of 100 is pretty good, but never knew what makes up the rating. So out of curiosity I took a look at the wikipedia page and had an idea or my first kata: https://en.wikipedia.org/wiki/Passer_rating ## Formula There are four parts to the NFL formula: ```python A = ((Completions / Attempts) - .3) * 5 B = ((Yards / Attempts) - 3) * .25 C = (Touchdowns / Attempt) * 20 D = 2.375 - ((Interceptions / Attempts) * 25) ``` However, if the result of any calculation is greater than `2.375`, it is set to `2.375`. If the result is a negative number, it is set to zero. Finally the passer rating is: `((A + B + C + D) / 6) * 100` Return the rating rounded to the nearest tenth. ## Example Last year Tom Brady had 432 attempts, 3554 yards, 291 completions, 28 touchdowns, and 2 interceptions. His passer rating was 112.2 Happy coding! Also feel free to reuse/extend the following starter code: ```python def passer_rating(att, yds, comp, td, ints): ```
{"functional": "_inputs = [[432, 3554, 291, 28, 2], [5, 76, 4, 1, 0], [48, 192, 19, 2, 3], [1, 2, 1, 1, 0], [34, 172, 20, 1, 1], [10, 17, 2, 0, 1]]\n_outputs = [[112.2], [158.3], [39.6], [118.8], [69.7], [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(passer_rating(*i), o[0])"}
325
296
coding
Solve the programming task below in a Python markdown code block. ~~~if:csharp,javascript,cfml,php Given a 2D array of size `m * n`. Your task is to find the sum of minimum value in each row. ~~~ ~~~if:cpp Given a 2D vector of size `m * n`. Your task is to find the sum of minimum value in each row. ~~~ ~~~if:python,ruby Given a 2D list of size `m * n`. Your task is to find the sum of minimum value in each row. ~~~ For Example: ```python [ [1, 2, 3, 4, 5], # minimum value of row is 1 [5, 6, 7, 8, 9], # minimum value of row is 5 [20, 21, 34, 56, 100] # minimum value of row is 20 ] ``` So, the function should return `26` because sum of minimums is as `1 + 5 + 20 = 26` ~~~if:javascript,php Note: You will be always given non-empty array containing Positive values. ~~~ ~~~if:python Note: You will be always given non-empty list containing Positive values. ~~~ ~~~if:cpp Note: You will be always given non-empty vector containing Positive values. ~~~ ~~~if:c# Note: You will be always given non-empty vector containing Positive values. ~~~ ~~~if:cfml Note: You will be always given non-empty array containing Positive values. ~~~ ENJOY CODING :) Also feel free to reuse/extend the following starter code: ```python def sum_of_minimums(numbers): ```
{"functional": "_inputs = [[[[7, 9, 8, 6, 2], [6, 3, 5, 4, 3], [5, 8, 7, 4, 5]]], [[[11, 12, 14, 54], [67, 89, 90, 56], [7, 9, 4, 3], [9, 8, 6, 7]]]]\n_outputs = [[9], [76]]\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(sum_of_minimums(*i), o[0])"}
394
261
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n integer matrix matrix with the following two properties: Each row is sorted in non-decreasing order. The first integer of each row is greater than the last integer of the previous row. Given an integer target, return true if target is in matrix or false otherwise. You must write a solution in O(log(m * n)) time complexity.   Please complete the following python code precisely: ```python class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: ```
{"functional": "def check(candidate):\n assert candidate(matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3) == True\n assert candidate(matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13) == False\n\n\ncheck(Solution().searchMatrix)"}
127
112
coding
Solve the programming task below in a Python markdown code block. You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters. Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation: * Operation: Choose one of the strings A, B and C, and specify an integer i between 1 and N (inclusive). Change the i-th character from the beginning of the chosen string to some other lowercase English letter. What is the minimum number of operations required to achieve the objective? Constraints * 1 \leq N \leq 100 * Each of the strings A, B and C is a string of length N. * Each character in each of the strings A, B and C is a lowercase English letter. Input Input is given from Standard Input in the following format: N A B C Output Print the minimum number of operations required. Examples Input 4 west east wait Output 3 Input 9 different different different Output 0 Input 7 zenkoku touitsu program Output 13
{"inputs": ["4\nwest\neast\nw`it", "4\nwesu\neast\nw`it", "4\nwetu\neast\nw`it", "4\nwetv\n`est\ntiaw", "4\ntewv\n`ftt\nsaiw", "4\nwetu\ne`st\nw`it", "4\nwetu\n`est\nw`it", "4\nwetu\n`est\nwait"], "outputs": ["4\n", "5\n", "6\n", "7\n", "8\n", "5\n", "5\n", "5\n"]}
252
144
coding
Solve the programming task below in a Python markdown code block. Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not carry in his hands objects of two different types. In other words, Polycarpus can't carry both postcards and photos simultaneously. Sometimes he goes to the closet and puts the objects there, thus leaving his hands free. Polycarpus must put all the postcards and photos to the closet. He cannot skip objects. What minimum number of times he should visit the closet if he cannot carry more than 5 items? Input The only line of the input data contains a non-empty string consisting of letters "С" and "P" whose length does not exceed 100 characters. If the i-th character in the string is the letter "С", that means that the i-th object (the numbering goes from the left to the right) on Polycarpus' wall is a postcard. And if the i-th character is the letter "P", than the i-th object on the wall is a photo. Output Print the only number — the minimum number of times Polycarpus has to visit the closet. Examples Input CPCPCPC Output 7 Input CCCCCCPPPPPP Output 4 Input CCCCCCPPCPPPPPPPPPP Output 6 Input CCCCCCCCCC Output 2 Note In the first sample Polycarpus needs to take one item to the closet 7 times. In the second sample Polycarpus can first take 3 postcards to the closet; then 3 more. He can take the 6 photos that are left in the similar way, going to the closet twice. In the third sample Polycarpus can visit the closet twice, both times carrying 3 postcards. Then he can take there 2 photos at once, then one postcard and finally, he can carry the last 10 photos if he visits the closet twice. In the fourth sample Polycarpus can visit the closet twice and take there all 10 postcards (5 items during each go).
{"inputs": ["P\n", "C\n", "CP\n", "PC\n", "PPPP\n", "PPPPP\n", "CPCCPPC\n", "CPPCCPC\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "1\n", "1\n", "5\n", "5\n"]}
503
77
coding
Solve the programming task below in a Python markdown code block. Lenny is playing a game on a 3 × 3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on. Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light. -----Input----- The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The j-th number in the i-th row is the number of times the j-th light of the i-th row of the grid is pressed. -----Output----- Print three lines, each containing three characters. The j-th character of the i-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". -----Examples----- Input 1 0 0 0 0 0 0 0 1 Output 001 010 100 Input 1 0 1 8 8 8 2 0 3 Output 010 011 100
{"inputs": ["1 0 0\n0 0 0\n0 0 1\n", "1 0 1\n8 8 8\n2 0 3\n", "0 0 0\n0 0 0\n0 0 0\n", "0 0 0\n0 1 0\n0 0 0\n", "0 0 0\n0 0 0\n0 0 1\n", "0 0 0\n0 0 0\n0 0 1\n", "0 0 0\n0 1 0\n0 0 0\n", "0 0 0\n0 0 0\n0 0 0\n"], "outputs": ["001\n010\n100\n", "010\n011\n100\n", "111\n111\n111\n", "101\n000\n101\n", "111\n110\n100\n", "111\n110\n100\n", "101\n000\n101\n", "111\n111\n111\n"]}
318
278
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n integer matrix grid. We define an hourglass as a part of the matrix with the following form: Return the maximum sum of the elements of an hourglass. Note that an hourglass cannot be rotated and must be entirely contained within the matrix.   Please complete the following python code precisely: ```python class Solution: def maxSum(self, grid: List[List[int]]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(grid = [[6,2,1,3],[4,2,1,5],[9,2,8,7],[4,1,2,9]]) == 30\n assert candidate(grid = [[1,2,3],[4,5,6],[7,8,9]]) == 35\n\n\ncheck(Solution().maxSum)"}
105
91
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic. Given an integer n, return true if n is strictly palindromic and false otherwise. A string is palindromic if it reads the same forward and backward.   Please complete the following python code precisely: ```python class Solution: def isStrictlyPalindromic(self, n: int) -> bool: ```
{"functional": "def check(candidate):\n assert candidate(n = 9) == False\n assert candidate(n = 4) == False\n\n\ncheck(Solution().isStrictlyPalindromic)"}
129
46
coding
Solve the programming task below in a Python markdown code block. You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}] of length N. You can right rotate it any number of times (possibly, zero). What is the maximum value of A_{1} + A_{N} you can get? Note: Right rotating the array [A_{1}, A_{2}, \ldots, A_{N}] once gives the array [A_{N}, A_{1}, A_{2}, \ldots, A_{N-1}]. For example, right rotating [1, 2, 3] once gives [3, 1, 2], and right rotating it again gives [2, 3, 1]. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. The description of the test cases follows. - The first line of each test case contains a single integer N, denoting the length of array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} — denoting the array A. ------ Output Format ------ For each test case, output on a new line the maximum value of A_{1}+A_{N} you can get after several right rotations. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ across all test cases does not exceed $10^{5}$ ----- Sample Input 1 ------ 3 2 5 8 3 5 10 15 4 4 4 4 4 ----- Sample Output 1 ------ 13 25 8 ----- explanation 1 ------ Test case $1$: Whether you right rotate the array or not, you will always end up with $A_{1}+A_{N} = 13$. Test case $2$: It is optimal to right rotate the array once after which the array becomes $[15,5,10]$ with $A_{1} + A_{N} = 25$. Test case $3$: No matter how much you right rotate the array, you will always obtain $A_{1} + A_{N} = 8$.
{"inputs": ["3\n2\n5 8\n3\n5 10 15\n4\n4 4 4 4\n"], "outputs": ["13\n25\n8\n"]}
527
46
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A bit flip of a number x is choosing a bit in the binary representation of x and flipping it from either 0 to 1 or 1 to 0. For example, for x = 7, the binary representation is 111 and we may choose any bit (including any leading zeros not shown) and flip it. We can flip the first bit from the right to get 110, flip the second bit from the right to get 101, flip the fifth bit from the right (a leading zero) to get 10111, etc. Given two integers start and goal, return the minimum number of bit flips to convert start to goal.   Please complete the following python code precisely: ```python class Solution: def minBitFlips(self, start: int, goal: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(start = 10, goal = 7) == 3\n assert candidate(start = 3, goal = 4) == 3\n\n\ncheck(Solution().minBitFlips)"}
195
56
coding
Solve the programming task below in a Python markdown code block. ----- Statement ----- You need to find a string which has exactly K positions in it such that the character at that position comes alphabetically later than the character immediately after it. If there are many such strings, print the one which has the shortest length. If there is still a tie, print the string which comes the lexicographically earliest (would occur earlier in a dictionary). -----Input----- The first line contains the number of test cases T. Each test case contains an integer K (≤ 100). -----Output----- Output T lines, one for each test case, containing the required string. Use only lower-case letters a-z. -----Sample Input ----- 2 1 2 -----Sample Output----- ba cba
{"inputs": ["2\n1\n2", "2\n2\n2", "2\n2\n3", "2\n3\n2", "2\n2\n5", "2\n4\n5", "2\n3\n5", "2\n5\n5"], "outputs": ["ba\ncba", "cba\ncba\n", "cba\ndcba\n", "dcba\ncba\n", "cba\nfedcba\n", "edcba\nfedcba\n", "dcba\nfedcba\n", "fedcba\nfedcba\n"]}
161
121
coding
Solve the programming task below in a Python markdown code block. Watson gives four 3-dimensional points to Sherlock and asks him if they all lie in the same plane. Your task here is to help Sherlock. Input Format First line contains T, the number of testcases. Each test case consists of four lines. Each line contains three integers, denoting x_{i} y_{i} z_{i}. Output Format For each test case, print YES or NO whether all four points lie in same plane or not, respectively. Constraints 1 ≤ T ≤ 10^{4} -10^{3} ≤ x_{i},y_{i},z_{i} ≤ 10^{3} Sample Input 1 1 2 0 2 3 0 4 0 0 0 0 0 Sample Output YES Explanation All points have z_{i} = 0, hence they lie in the same plane, and output is YES
{"inputs": ["1\n1 2 0\n2 3 0\n4 0 0\n0 0 0\n"], "outputs": ["YES\n"]}
213
38
coding
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is constraints. You are given a sequence $a$ consisting of $n$ positive integers. Let's define a three blocks palindrome as the sequence, consisting of at most two distinct elements (let these elements are $a$ and $b$, $a$ can be equal $b$) and is as follows: $[\underbrace{a, a, \dots, a}_{x}, \underbrace{b, b, \dots, b}_{y}, \underbrace{a, a, \dots, a}_{x}]$. There $x, y$ are integers greater than or equal to $0$. For example, sequences $[]$, $[2]$, $[1, 1]$, $[1, 2, 1]$, $[1, 2, 2, 1]$ and $[1, 1, 2, 1, 1]$ are three block palindromes but $[1, 2, 3, 2, 1]$, $[1, 2, 1, 2, 1]$ and $[1, 2]$ are not. Your task is to choose the maximum by length subsequence of $a$ that is a three blocks palindrome. You have to answer $t$ independent test cases. Recall that the sequence $t$ is a a subsequence of the sequence $s$ if $t$ can be derived from $s$ by removing zero or more elements without changing the order of the remaining elements. For example, if $s=[1, 2, 1, 3, 1, 2, 1]$, then possible subsequences are: $[1, 1, 1, 1]$, $[3]$ and $[1, 2, 1, 3, 1, 2, 1]$, but not $[3, 2, 3]$ and $[1, 1, 1, 1, 2]$. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2000$) — 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 2000$) — the length of $a$. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 26$), where $a_i$ is the $i$-th element of $a$. Note that the maximum value of $a_i$ can be up to $26$. It is guaranteed that the sum of $n$ over all test cases does not exceed $2000$ ($\sum n \le 2000$). -----Output----- For each test case, print the answer — the maximum possible length of some subsequence of $a$ that is a three blocks palindrome. -----Example----- Input 6 8 1 1 2 2 3 2 1 1 3 1 3 3 4 1 10 10 1 1 26 2 2 1 3 1 1 1 Output 7 2 4 1 1 3
{"inputs": ["6\n8\n1 1 2 6 3 2 1 1\n3\n2 1 3\n4\n2 10 9 1\n1\n26\n2\n1 1\n3\n1 1 1\n", "6\n8\n1 1 2 6 3 2 1 1\n3\n2 3 3\n4\n2 10 9 1\n1\n26\n2\n1 1\n3\n2 1 1\n", "6\n8\n1 1 2 6 3 2 1 1\n3\n2 1 3\n4\n2 10 9 1\n1\n26\n2\n1 1\n3\n2 1 1\n", "6\n8\n1 1 2 6 3 2 1 2\n3\n2 1 3\n4\n2 10 9 1\n1\n26\n2\n1 1\n3\n2 1 1\n", "6\n8\n1 1 2 6 3 2 1 2\n3\n2 1 3\n4\n2 10 9 2\n1\n26\n2\n1 1\n3\n2 1 1\n", "6\n8\n1 1 2 6 3 2 1 2\n3\n2 3 3\n4\n2 10 9 1\n1\n26\n2\n1 1\n3\n2 1 1\n", "6\n8\n1 1 2 6 2 2 1 2\n3\n2 3 3\n4\n2 10 9 1\n1\n26\n2\n1 1\n3\n2 1 1\n", "6\n8\n2 1 2 6 1 2 1 1\n3\n2 1 3\n4\n2 10 9 1\n1\n26\n2\n1 1\n3\n2 1 1\n"], "outputs": ["6\n1\n1\n1\n2\n3\n", "6\n2\n1\n1\n2\n2\n", "6\n1\n1\n1\n2\n2\n", "4\n1\n1\n1\n2\n2\n", "4\n1\n3\n1\n2\n2\n", "4\n2\n1\n1\n2\n2\n", "5\n2\n1\n1\n2\n2\n", "5\n1\n1\n1\n2\n2\n"]}
743
598
coding
Solve the programming task below in a Python markdown code block. If you have not ever heard the term **Arithmetic Progrossion**, refer to: http://www.codewars.com/kata/find-the-missing-term-in-an-arithmetic-progression/python And here is an unordered version. Try if you can survive lists of **MASSIVE** numbers (which means time limit should be considered). :D Note: Don't be afraid that the minimum or the maximum element in the list is missing, e.g. [4, 6, 3, 5, 2] is missing 1 or 7, but this case is excluded from the kata. Example: ```python find([3, 9, 1, 11, 13, 5]) # => 7 ``` Also feel free to reuse/extend the following starter code: ```python def find(seq): ```
{"functional": "_inputs = [[[3, 9, 1, 11, 13, 5]], [[5, -1, 0, 3, 4, -3, 2, -2]], [[2, -2, 8, -8, 4, -4, 6, -6]]]\n_outputs = [[7], [1], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(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(*i), o[0])"}
193
224
coding
Solve the programming task below in a Python markdown code block. Two moving objects A and B are moving accross the same orbit (those can be anything: two planets, two satellites, two spaceships,two flying saucers, or spiderman with batman if you prefer). If the two objects start to move from the same point and the orbit is circular, write a function that gives the time the two objects will meet again, given the time the objects A and B need to go through a full orbit, Ta and Tb respectively, and the radius of the orbit r. As there can't be negative time, the sign of Ta and Tb, is an indication of the direction in which the object moving: positive for clockwise and negative for anti-clockwise. The function will return a string that gives the time, in two decimal points. Ta and Tb will have the same unit of measurement so you should not expect it in the solution. Hint: Use angular velocity "w" rather than the classical "u". Also feel free to reuse/extend the following starter code: ```python def meeting_time(Ta, Tb, r): ```
{"functional": "_inputs = [[12, 15, 5], [12, -15, 6], [-14, -5, 5], [23, 16, 5], [0, 0, 7], [12, 0, 10], [0, 15, 17], [-24, 0, 10], [0, -18, 14], [32, -14, 14]]\n_outputs = [['60.00'], ['6.67'], ['7.78'], ['52.57'], ['0.00'], ['12.00'], ['15.00'], ['24.00'], ['18.00'], ['9.74']]\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(meeting_time(*i), o[0])"}
234
323
coding
Solve the programming task below in a Python markdown code block. You are at your grandparents' house and you are playing an old video game on a strange console. Your controller has only two buttons and each button has a number written on it. Initially, your score is $0$. The game is composed of $n$ rounds. For each $1\le i\le n$, the $i$-th round works as follows. On the screen, a symbol $s_i$ appears, which is either ${+}$ (plus) or ${-}$ (minus). Then you must press one of the two buttons on the controller once. Suppose you press a button with the number $x$ written on it: your score will increase by $x$ if the symbol was ${+}$ and will decrease by $x$ if the symbol was ${-}$. After you press the button, the round ends. After you have played all $n$ rounds, you win if your score is $0$. Over the years, your grandparents bought many different controllers, so you have $q$ of them. The two buttons on the $j$-th controller have the numbers $a_j$ and $b_j$ written on them. For each controller, you must compute whether you can win the game playing with that controller. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2\cdot 10^5$) — the number of rounds. The second line contains a string $s$ of length $n$ — where $s_i$ is the symbol that will appear on the screen in the $i$-th round. It is guaranteed that $s$ contains only the characters ${+}$ and ${-}$. The third line contains an integer $q$ ($1 \le q \le 10^5$) — the number of controllers. The following $q$ lines contain two integers $a_j$ and $b_j$ each ($1 \le a_j, b_j \le 10^9$) — the numbers on the buttons of controller $j$. -----Output----- Output $q$ lines. On line $j$ print ${YES}$ if the game is winnable using controller $j$, otherwise print ${NO}$. -----Examples----- Input 8 +-+---+- 5 2 1 10 3 7 9 10 10 5 3 Output YES NO NO NO YES Input 6 +-++-- 2 9 7 1 1 Output YES YES Input 20 +-----+--+--------+- 2 1000000000 99999997 250000000 1000000000 Output NO YES -----Note----- In the first sample, one possible way to get score $0$ using the first controller is by pressing the button with numnber $1$ in rounds $1$, $2$, $4$, $5$, $6$ and $8$, and pressing the button with number $2$ in rounds $3$ and $7$. It is possible to show that there is no way to get a score of $0$ using the second controller.
{"inputs": ["6\n+-++--\n2\n9 7\n1 1\n", "1\n-\n1\n427470105 744658699\n", "8\n+-+---+-\n5\n2 1\n10 3\n7 9\n10 10\n5 3\n", "20\n+-----+--+--------+-\n2\n1000000000 99999997\n250000000 1000000000\n"], "outputs": ["YES\nYES\n", "NO\n", "YES\nNO\nNO\nNO\nYES\n", "NO\nYES\n"]}
706
172
coding
Solve the programming task below in a Python markdown code block. Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. -----Input----- The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). -----Output----- Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. -----Examples----- Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 -----Note----- In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1 2 2 1 3 3 1 3 2 3 2 1 4
{"inputs": ["1\n", "2\n", "3\n", "8\n", "4\n", "5\n", "6\n", "8\n"], "outputs": ["1\n", "2\n", "2 1\n", "4\n", "3\n", "3 1\n", "3 2\n", "4 \n"]}
485
77
coding
Solve the programming task below in a Python markdown code block. You probably know that the "mode" of a set of data is the data point that appears most frequently. Looking at the characters that make up the string `"sarsaparilla"` we can see that the letter `"a"` appears four times, more than any other letter, so the mode of `"sarsaparilla"` is `"a"`. But do you know what happens when two or more data points occur the most? For example, what is the mode of the letters in `"tomato"`? Both `"t"` and `"o"` seem to be tied for appearing most frequently. Turns out that a set of data can, in fact, have multiple modes, so `"tomato"` has two modes: `"t"` and `"o"`. It's important to note, though, that if *all* data appears the same number of times there is no mode. So `"cat"`, `"redder"`, and `[1, 2, 3, 4, 5]` do not have a mode. Your job is to write a function `modes()` that will accept one argument `data` that is a sequence like a string or a list of numbers and return a sorted list containing the mode(s) of the input sequence. If data does not contain a mode you should return an empty list. For example: ```python >>> modes("tomato") ["o", "t"] >>> modes([1, 3, 3, 7]) [3] >>> modes(["redder"]) [] ``` You can trust that your input data will always be a sequence and will always contain orderable types (no inputs like `[1, 2, 2, "a", "b", "b"]`). Also feel free to reuse/extend the following starter code: ```python def modes(data): ```
{"functional": "_inputs = [['tomato'], [[1, 3, 3, 7]], [['redder']]]\n_outputs = [[['o', 't']], [[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(modes(*i), o[0])"}
393
181
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef has taken his first dose of vaccine D days ago. He may take the second dose no less than L days and no more than R days since his first dose. Determine if Chef is too early, too late, or in the correct range for taking his second dose. ------ Input Format ------ - First line will contain T, number of testcases. Then the testcases follow. - Each testcase contains of a single line of input, three integers D, L, R. ------ Output Format ------ For each test case, print a single line containing one string - "Too Early" (without quotes) if it's too early to take the vaccine, "Too Late" (without quotes) if it's too late to take the vaccine, "Take second dose now" (without quotes) if it's the correct time to take the vaccine. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ D ≤ 10^{9}$ $1 ≤ L ≤ R ≤ 10^{9}$ ------ subtasks ------ Subtask 1 (100 points): Original constraints ----- Sample Input 1 ------ 4 10 8 12 14 2 10 4444 5555 6666 8 8 12 ----- Sample Output 1 ------ Take second dose now Too Late Too Early Take second dose now ----- explanation 1 ------ Test case $1$: The second dose needs to be taken within $8$ to $12$ days and since the Day $10$ lies in this range, we can take the second dose now. Test case $2$: The second dose needs to be taken within $2$ to $10$ days since Day $14$ lies after this range, it is too late now. Test case $3$: The second dose needs to be taken within $5555$ to $6666$ days and since the Day $4444$ lies prior to this range, it is too early now.
{"inputs": ["4\n10 8 12 \n14 2 10\n4444 5555 6666 \n8 8 12\n"], "outputs": ["Take second dose now\nToo Late\nToo Early\nTake second dose now"]}
479
67
coding
Solve the programming task below in a Python markdown code block. Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known. It's known that if at least one participant's rating has changed, then the round was rated for sure. It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed. In this problem, you should not make any other assumptions about the rating system. Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not. -----Input----- The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of round participants. Each of the next n lines contains two integers a_{i} and b_{i} (1 ≤ a_{i}, b_{i} ≤ 4126) — the rating of the i-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings. -----Output----- If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". -----Examples----- Input 6 3060 3060 2194 2194 2876 2903 2624 2624 3007 2991 2884 2884 Output rated Input 4 1500 1500 1300 1300 1200 1200 1400 1400 Output unrated Input 5 3123 3123 2777 2777 2246 2246 2246 2246 1699 1699 Output maybe -----Note----- In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated. In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure. In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.
{"inputs": ["2\n1 1\n1 1\n", "2\n1 1\n2 2\n", "2\n2 2\n1 1\n", "2\n2 1\n1 2\n", "2\n3 2\n3 2\n", "2\n1 2\n2 1\n", "2\n3 1\n9 8\n", "2\n2 1\n1 1\n"], "outputs": ["maybe\n", "unrated\n", "maybe\n", "rated\n", "rated\n", "rated\n", "rated\n", "rated\n"]}
630
135
coding
Solve the programming task below in a Python markdown code block. 3R2 as DJ Mashiro - Happiness Breeze Ice - DJ Mashiro is dead or alive NEKO#ΦωΦ has just got a new maze game on her PC! The game's main puzzle is a maze, in the forms of a $2 \times n$ rectangle grid. NEKO's task is to lead a Nekomimi girl from cell $(1, 1)$ to the gate at $(2, n)$ and escape the maze. The girl can only move between cells sharing a common side. However, at some moments during the game, some cells may change their state: either from normal ground to lava (which forbids movement into that cell), or vice versa (which makes that cell passable again). Initially all cells are of the ground type. After hours of streaming, NEKO finally figured out there are only $q$ such moments: the $i$-th moment toggles the state of cell $(r_i, c_i)$ (either from ground to lava or vice versa). Knowing this, NEKO wonders, after each of the $q$ moments, whether it is still possible to move from cell $(1, 1)$ to cell $(2, n)$ without going through any lava cells. Although NEKO is a great streamer and gamer, she still can't get through quizzes and problems requiring large amount of Brain Power. Can you help her? -----Input----- The first line contains integers $n$, $q$ ($2 \le n \le 10^5$, $1 \le q \le 10^5$). The $i$-th of $q$ following lines contains two integers $r_i$, $c_i$ ($1 \le r_i \le 2$, $1 \le c_i \le n$), denoting the coordinates of the cell to be flipped at the $i$-th moment. It is guaranteed that cells $(1, 1)$ and $(2, n)$ never appear in the query list. -----Output----- For each moment, if it is possible to travel from cell $(1, 1)$ to cell $(2, n)$, print "Yes", otherwise print "No". There should be exactly $q$ answers, one after every update. You can print the words in any case (either lowercase, uppercase or mixed). -----Example----- Input 5 5 2 3 1 4 2 4 2 3 1 4 Output Yes No No No Yes -----Note----- We'll crack down the example test here: After the first query, the girl still able to reach the goal. One of the shortest path ways should be: $(1,1) \to (1,2) \to (1,3) \to (1,4) \to (1,5) \to (2,5)$. After the second query, it's impossible to move to the goal, since the farthest cell she could reach is $(1, 3)$. After the fourth query, the $(2, 3)$ is not blocked, but now all the $4$-th column is blocked, so she still can't reach the goal. After the fifth query, the column barrier has been lifted, thus she can go to the final goal again.
{"inputs": ["4 1\n1 4\n", "4 1\n1 4\n", "2 2\n2 1\n1 2\n", "2 2\n2 1\n1 2\n", "2 4\n2 1\n1 2\n1 2\n1 2\n", "2 4\n2 1\n1 2\n1 2\n1 2\n", "5 5\n2 3\n1 4\n2 4\n2 3\n1 4\n", "6 5\n2 3\n1 4\n2 4\n2 3\n1 4\n"], "outputs": ["Yes\n", "Yes\n", "Yes\nNo\n", "Yes\nNo\n", "Yes\nNo\nYes\nNo\n", "Yes\nNo\nYes\nNo\n", "Yes\nNo\nNo\nNo\nYes\n", "Yes\nNo\nNo\nNo\nYes\n"]}
707
214
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. There are N students living in the dormitory of Berland State University. Each of them sometimes wants to use the kitchen, so the head of the dormitory came up with a timetable for kitchen's usage in order to avoid the conflicts: The first student starts to use the kitchen at the time 0 and should finish the cooking not later than at the time A_{1}. The second student starts to use the kitchen at the time A_{1} and should finish the cooking not later than at the time A_{2}. And so on. The N-th student starts to use the kitchen at the time A_{N-1} and should finish the cooking not later than at the time A_{N} The holidays in Berland are approaching, so today each of these N students wants to cook some pancakes. The i-th student needs B_{i} units of time to cook. The students have understood that probably not all of them will be able to cook everything they want. How many students will be able to cook without violating the schedule? ------ Input Format ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. \ Each test case contains 3 lines of input - The first line of each test case contains a single integer N denoting the number of students. - The second line contains N space-separated integers A1, A2, ..., AN denoting the moments of time by when the corresponding student should finish cooking. - The third line contains N space-separated integers B1, B2, ..., BN denoting the time required for each of the students to cook. ------ Output Format ------ For each test case, output a single line containing the number of students that will be able to finish the cooking. ------ Constraints ------ 1 ≤ T ≤ 10 \ 1 ≤ N ≤ 104 \ 0 A1 A2 AN 109 \ 1 ≤ Bi ≤ 109 ----- Sample Input 1 ------ 2 3 1 10 15 1 10 3 3 10 20 30 15 5 20 ----- Sample Output 1 ------ 2 1 ----- explanation 1 ------ Example case 1. The first student has 1 unit of time - the moment 0. It will be enough for her to cook. The second student has 9 units of time, but wants to cook for 10 units of time, and won't fit in time. The third student has 5 units of time and will fit in time, because needs to cook only for 3 units of time. Example case 2. Each of students has 10 units of time, but only the second one will be able to fit in time.
{"inputs": ["2\n3\n1 4 15\n1 2 1\n3\n18 40 30\n6 2 22", "2\n3\n1 4 15\n2 2 1\n3\n18 40 30\n6 2 22", "2\n3\n1 4 15\n1 2 1\n3\n26 40 30\n6 2 22", "2\n3\n2 4 15\n2 2 1\n3\n18 40 30\n6 2 22", "2\n3\n2 4 15\n2 0 1\n3\n18 40 30\n6 2 22", "2\n3\n1 4 5\n0 2 1\n3\n18 40 30\n13 0 35", "2\n3\n2 4 15\n2 0 1\n3\n18 40 30\n6 2 41", "2\n3\n1 4 5\n0 2 1\n3\n18 40 30\n11 0 35"], "outputs": ["3\n2\n", "2\n2\n", "3\n2\n", "3\n2\n", "3\n2\n", "3\n2\n", "3\n2\n", "3\n2\n"]}
608
342
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n. We say that two integers x and y form a prime number pair if: 1 <= x <= y <= n x + y == n x and y are prime numbers Return the 2D sorted list of prime number pairs [xi, yi]. The list should be sorted in increasing order of xi. If there are no prime number pairs at all, return an empty array. Note: A prime number is a natural number greater than 1 with only two factors, itself and 1.   Please complete the following python code precisely: ```python class Solution: def findPrimePairs(self, n: int) -> List[List[int]]: ```
{"functional": "def check(candidate):\n assert candidate(n = 10) == [[3,7],[5,5]]\n assert candidate(n = 2) == []\n\n\ncheck(Solution().findPrimePairs)"}
158
53
coding
Solve the programming task below in a Python markdown code block. #Unflatten a list (Easy) There are several katas like "Flatten a list". These katas are done by so many warriors, that the count of available list to flattin goes down! So you have to build a method, that creates new arrays, that can be flattened! #Shorter: You have to unflatten a list/an array. You get an array of integers and have to unflatten it by these rules: ``` - You start at the first number. - If this number x is smaller than 3, take this number x direct for the new array and continue with the next number. - If this number x is greater than 2, take the next x numbers (inclusive this number) as a sub-array in the new array. Continue with the next number AFTER this taken numbers. - If there are too few numbers to take by number, take the last available numbers. ``` The given array will always contain numbers. There will only be numbers > 0. Example: ``` [1,4,5,2,1,2,4,5,2,6,2,3,3] -> [1,[4,5,2,1],2,[4,5,2,6],2,[3,3]] Steps: 1. The 1 is added directly to the new array. 2. The next number is 4. So the next 4 numbers (4,5,2,1) are added as sub-array in the new array. 3. The 2 is added directly to the new array. 4. The next number is 4. So the next 4 numbers (4,5,2,6) are added as sub-array in the new array. 5. The 2 is added directly to the new array. 6. The next number is 3. So the next 3 numbers would be taken. There are only 2, so take these (3,3) as sub-array in the new array. ``` There is a harder version of this kata! Unflatten a list (Harder than easy) Have fun coding it and please don't forget to vote and rank this kata! :-) I have created other katas. Have a look if you like coding and challenges. Also feel free to reuse/extend the following starter code: ```python def unflatten(flat_array): ```
{"functional": "_inputs = [[[3, 5, 2, 1]], [[1, 4, 5, 2, 1, 2, 4, 5, 2, 6, 2, 3, 3]], [[1, 1, 1, 1]], [[1]], [[99, 1, 1, 1]], [[3, 1, 1, 3, 1, 1]]]\n_outputs = [[[[3, 5, 2], 1]], [[1, [4, 5, 2, 1], 2, [4, 5, 2, 6], 2, [3, 3]]], [[1, 1, 1, 1]], [[1]], [[[99, 1, 1, 1]]], [[[3, 1, 1], [3, 1, 1]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, 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(unflatten(*i), o[0])"}
512
346
coding
Solve the programming task below in a Python markdown code block. Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds a_{i} candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later. Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n). Print -1 if she can't give him k candies during n given days. -----Input----- The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000). The second line contains n integers a_1, a_2, a_3, ..., a_{n} (1 ≤ a_{i} ≤ 100). -----Output----- If it is impossible for Arya to give Bran k candies within n days, print -1. Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. -----Examples----- Input 2 3 1 2 Output 2 Input 3 17 10 10 10 Output 3 Input 1 9 10 Output -1 -----Note----- In the first sample, Arya can give Bran 3 candies in 2 days. In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day. In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
{"inputs": ["1 9\n10\n", "1 7\n10\n", "1 9\n10\n", "2 3\n1 2\n", "2 8\n7 8\n", "2 9\n4 8\n", "2 3\n3 3\n", "2 2\n1 2\n"], "outputs": ["-1", "1\n", "-1\n", "2", "2", "2", "1", "2"]}
473
110
coding
Solve the programming task below in a Python markdown code block. There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples. Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows: - Move: When at town i (i < N), move to town i + 1. - Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money. For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.) During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel. Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i. Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen. -----Constraints----- - 1 ≦ N ≦ 10^5 - 1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N) - A_i are distinct. - 2 ≦ T ≦ 10^9 - In the initial state, Takahashi's expected profit is at least 1 yen. -----Input----- The input is given from Standard Input in the following format: N T A_1 A_2 ... A_N -----Output----- Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen. -----Sample Input----- 3 2 100 50 200 -----Sample Output----- 1 In the initial state, Takahashi can achieve the maximum profit of 150 yen as follows: - Move from town 1 to town 2. - Buy one apple for 50 yen at town 2. - Move from town 2 to town 3. - Sell one apple for 200 yen at town 3. If, for example, Aoki changes the price of an apple at town 2 from 50 yen to 51 yen, Takahashi will not be able to achieve the profit of 150 yen. The cost of performing this operation is 1, thus the answer is 1. There are other ways to decrease Takahashi's expected profit, such as changing the price of an apple at town 3 from 200 yen to 199 yen.
{"inputs": ["3 8\n100 7 21", "3 8\n100 8 21", "3 2\n100 8 21", "3 8\n100 4 21", "3 2\n100 2 21", "3 8\n100 7 200", "3 0\n100 0 200", "3 2\n100 12 21"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
769
153
coding
Solve the programming task below in a Python markdown code block. Check Tutorial tab to know how to to solve. You are given a string $N$. Your task is to verify that $N$ is a floating point number. In this task, a valid float number must satisfy all of the following requirements: $>$ Number can start with +, - or . symbol. For example: +4.50 -1.0 .5 -.7 +.4 -+4.5 $>$ Number must contain at least $\mbox{I}$ decimal value. For example: 12. 12.0   $>$ Number must have exactly one . symbol. $>$ Number must not give any exceptions when converted using $\mbox{float}(N)$. Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. The next $\mathbf{T}$ line(s) contains a string $N$. Constraints $0<T<10$ Output Format Output True or False for each test case. Sample Input 0 4 4.0O0 -1.00 +4.54 SomeRandomStuff Sample Output 0 False True True False Explanation 0 $4.000$: O is not a digit. $-1.00$: is valid. $+4.54$: is valid. SomeRandomStuff: is not a number.
{"inputs": ["4\n4.0O0\n-1.00\n+4.54\nSomeRandomStuff\n"], "outputs": ["False\nTrue\nTrue\nFalse\n"]}
324
42
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a time represented in the format "HH:MM", form the next closest time by reusing the current digits. There is no limit on how many times a digit can be reused. You may assume the given input string is always valid. For example, "01:34", "12:09" are all valid. "1:34", "12:9" are all invalid.   Please complete the following python code precisely: ```python class Solution: def nextClosestTime(self, time: str) -> str: ```
{"functional": "def check(candidate):\n assert candidate(\"19:34\") == \"19:39\"\n assert candidate(\"23:59\") == \"22:22\"\n\n\ncheck(Solution().nextClosestTime)"}
135
59
coding
Solve the programming task below in a Python markdown code block. IT City company developing computer games decided to upgrade its way to reward its employees. Now it looks the following way. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is not divisible by any number from 2 to 10 every developer of this game gets a small bonus. A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it. -----Input----- The only line of the input contains one integer n (1 ≤ n ≤ 10^18) — the prediction on the number of people who will buy the game. -----Output----- Output one integer showing how many numbers from 1 to n are not divisible by any number from 2 to 10. -----Examples----- Input 12 Output 2
{"inputs": ["1\n", "1\n", "0\n", "9\n", "12\n", "18\n", "15\n", "27\n"], "outputs": ["1", "1\n", "0\n", "1\n", "2", "4\n", "3\n", "6\n"]}
238
72
coding
Solve the programming task below in a Python markdown code block. Lavrenty, a baker, is going to make several buns with stuffings and sell them. Lavrenty has n grams of dough as well as m different stuffing types. The stuffing types are numerated from 1 to m. Lavrenty knows that he has ai grams left of the i-th stuffing. It takes exactly bi grams of stuffing i and ci grams of dough to cook a bun with the i-th stuffing. Such bun can be sold for di tugriks. Also he can make buns without stuffings. Each of such buns requires c0 grams of dough and it can be sold for d0 tugriks. So Lavrenty can cook any number of buns with different stuffings or without it unless he runs out of dough and the stuffings. Lavrenty throws away all excess material left after baking. Find the maximum number of tugriks Lavrenty can earn. Input The first line contains 4 integers n, m, c0 and d0 (1 ≤ n ≤ 1000, 1 ≤ m ≤ 10, 1 ≤ c0, d0 ≤ 100). Each of the following m lines contains 4 integers. The i-th line contains numbers ai, bi, ci and di (1 ≤ ai, bi, ci, di ≤ 100). Output Print the only number — the maximum number of tugriks Lavrenty can earn. Examples Input 10 2 2 1 7 3 2 100 12 3 1 10 Output 241 Input 100 1 25 50 15 5 20 10 Output 200 Note To get the maximum number of tugriks in the first sample, you need to cook 2 buns with stuffing 1, 4 buns with stuffing 2 and a bun without any stuffing. In the second sample Lavrenty should cook 4 buns without stuffings.
{"inputs": ["2 1 2 1\n1 2 1 1\n", "1 1 1 1\n1 1 1 1\n", "2 1 2 1\n0 2 1 1\n", "2 1 1 1\n1 1 1 1\n", "2 1 2 1\n1 3 1 1\n", "2 1 1 1\n1 1 2 1\n", "4 1 2 4\n10 1 3 7\n", "4 1 2 4\n10 1 3 8\n"], "outputs": ["1", "1", "1\n", "2\n", "1\n", "2\n", "8", "8\n"]}
445
181
coding
Solve the programming task below in a Python markdown code block. During a break in the buffet of the scientific lyceum of the Kingdom of Kremland, there was formed a queue of $n$ high school students numbered from $1$ to $n$. Initially, each student $i$ is on position $i$. Each student $i$ is characterized by two numbers — $a_i$ and $b_i$. Dissatisfaction of the person $i$ equals the product of $a_i$ by the number of people standing to the left of his position, add the product $b_i$ by the number of people standing to the right of his position. Formally, the dissatisfaction of the student $i$, which is on the position $j$, equals $a_i \cdot (j-1) + b_i \cdot (n-j)$. The director entrusted Stas with the task: rearrange the people in the queue so that minimize the total dissatisfaction. Although Stas is able to solve such problems, this was not given to him. He turned for help to you. -----Input----- The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of people in the queue. Each of the following $n$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq 10^8$) — the characteristic of the student $i$, initially on the position $i$. -----Output----- Output one integer — minimum total dissatisfaction which can be achieved by rearranging people in the queue. -----Examples----- Input 3 4 2 2 3 6 1 Output 12 Input 4 2 4 3 3 7 1 2 3 Output 25 Input 10 5 10 12 4 31 45 20 55 30 17 29 30 41 32 7 1 5 5 3 15 Output 1423 -----Note----- In the first example it is optimal to put people in this order: ($3, 1, 2$). The first person is in the position of $2$, then his dissatisfaction will be equal to $4 \cdot 1+2 \cdot 1=6$. The second person is in the position of $3$, his dissatisfaction will be equal to $2 \cdot 2+3 \cdot 0=4$. The third person is in the position of $1$, his dissatisfaction will be equal to $6 \cdot 0+1 \cdot 2=2$. The total dissatisfaction will be $12$. In the second example, you need to put people in this order: ($3, 2, 4, 1$). The total dissatisfaction will be $25$.
{"inputs": ["1\n55 7\n", "1\n86 7\n", "1\n86 9\n", "1\n86 4\n", "1\n86 3\n", "1\n86 0\n", "1\n49 0\n", "1\n55 60\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0"]}
627
110
coding
Solve the programming task below in a Python markdown code block. Polycarp plays "Game 23". Initially he has a number $n$ and his goal is to transform it to $m$. In one move, he can multiply $n$ by $2$ or multiply $n$ by $3$. He can perform any number of moves. Print the number of moves needed to transform $n$ to $m$. Print -1 if it is impossible to do so. It is easy to prove that any way to transform $n$ to $m$ contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation). -----Input----- The only line of the input contains two integers $n$ and $m$ ($1 \le n \le m \le 5\cdot10^8$). -----Output----- Print the number of moves to transform $n$ to $m$, or -1 if there is no solution. -----Examples----- Input 120 51840 Output 7 Input 42 42 Output 0 Input 48 72 Output -1 -----Note----- In the first example, the possible sequence of moves is: $120 \rightarrow 240 \rightarrow 720 \rightarrow 1440 \rightarrow 4320 \rightarrow 12960 \rightarrow 25920 \rightarrow 51840.$ The are $7$ steps in total. In the second example, no moves are needed. Thus, the answer is $0$. In the third example, it is impossible to transform $48$ to $72$.
{"inputs": ["1 1\n", "1 2\n", "1 4\n", "1 5\n", "1 6\n", "2 5\n", "4 9\n", "2 7\n"], "outputs": ["0\n", "1\n", "2\n", "-1\n", "2\n", "-1\n", "-1\n", "-1\n"]}
364
86
coding
Solve the programming task below in a Python markdown code block. Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length. A block with side a has volume a^3. A tower consisting of blocks with sides a_1, a_2, ..., a_{k} has the total volume a_1^3 + a_2^3 + ... + a_{k}^3. Limak is going to build a tower. First, he asks you to tell him a positive integer X — the required total volume of the tower. Then, Limak adds new blocks greedily, one by one. Each time he adds the biggest block such that the total volume doesn't exceed X. Limak asks you to choose X not greater than m. Also, he wants to maximize the number of blocks in the tower at the end (however, he still behaves greedily). Secondarily, he wants to maximize X. Can you help Limak? Find the maximum number of blocks his tower can have and the maximum X ≤ m that results this number of blocks. -----Input----- The only line of the input contains one integer m (1 ≤ m ≤ 10^15), meaning that Limak wants you to choose X between 1 and m, inclusive. -----Output----- Print two integers — the maximum number of blocks in the tower and the maximum required total volume X, resulting in the maximum number of blocks. -----Examples----- Input 48 Output 9 42 Input 6 Output 6 6 -----Note----- In the first sample test, there will be 9 blocks if you choose X = 23 or X = 42. Limak wants to maximize X secondarily so you should choose 42. In more detail, after choosing X = 42 the process of building a tower is: Limak takes a block with side 3 because it's the biggest block with volume not greater than 42. The remaining volume is 42 - 27 = 15. The second added block has side 2, so the remaining volume is 15 - 8 = 7. Finally, Limak adds 7 blocks with side 1, one by one. So, there are 9 blocks in the tower. The total volume is is 3^3 + 2^3 + 7·1^3 = 27 + 8 + 7 = 42.
{"inputs": ["6\n", "1\n", "2\n", "7\n", "8\n", "9\n", "2\n", "9\n"], "outputs": ["6 6\n", "1 1\n", "2 2\n", "7 7\n", "7 7\n", "7 7\n", "2 2\n", "7 7\n"]}
541
86
coding
Solve the programming task below in a Python markdown code block. Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer. Help Pasha count the maximum number he can get if he has the time to make at most k swaps. -----Input----- The single line contains two integers a and k (1 ≤ a ≤ 10^18; 0 ≤ k ≤ 100). -----Output----- Print the maximum number that Pasha can get if he makes at most k swaps. -----Examples----- Input 1990 1 Output 9190 Input 300 0 Output 300 Input 1034 2 Output 3104 Input 9090000078001234 6 Output 9907000008001234
{"inputs": ["300 0\n", "5 100\n", "5 100\n", "4 100\n", "360 0\n", "7 100\n", "700 0\n", "6 100\n"], "outputs": ["300\n", "5\n", "5\n", "4\n", "360\n", "7\n", "700\n", "6\n"]}
224
108
coding
Solve the programming task below in a Python markdown code block. The objective is to disambiguate two given names: the original with another Let's start simple, and just work with plain ascii strings. The function ```could_be``` is given the original name and another one to test against. ```python # should return True if the other name could be the same person > could_be("Chuck Norris", "Chuck") True # should False otherwise (whatever you may personnaly think) > could_be("Chuck Norris", "superman") False ``` Let's say your name is *Carlos Ray Norris*, your objective is to return True if the other given name matches any combinaison of the original fullname: ```python could_be("Carlos Ray Norris", "Carlos Ray Norris") : True could_be("Carlos Ray Norris", "Carlos Ray") : True could_be("Carlos Ray Norris", "Norris") : True could_be("Carlos Ray Norris", "Norris Carlos") : True ``` For the sake of simplicity: * the function is case sensitive and accent sensitive for now * it is also punctuation sensitive * an empty other name should not match any original * an empty orginal name should not be matchable * the function is not symmetrical The following matches should therefore fail: ```python could_be("Carlos Ray Norris", " ") : False could_be("Carlos Ray Norris", "carlos") : False could_be("Carlos Ray Norris", "Norris!") : False could_be("Carlos Ray Norris", "Carlos-Ray Norris") : False could_be("Ray Norris", "Carlos Ray Norris") : False could_be("Carlos", "Carlos Ray Norris") : False ``` Too easy ? Try the next steps: * [Author Disambiguation: a name is a Name!](https://www.codewars.com/kata/author-disambiguation-a-name-is-a-name) * or even harder: [Author Disambiguation: Signatures worth it](https://www.codewars.com/kata/author-disambiguation-signatures-worth-it) Also feel free to reuse/extend the following starter code: ```python def could_be(original, another): ```
{"functional": "_inputs = [['Carlos Ray Norris', 'Carlos Ray Norris'], ['Carlos Ray Norris', 'Carlos Ray'], ['Carlos Ray Norris', 'Ray Norris'], ['Carlos Ray Norris', 'Carlos Norris'], ['Carlos Ray Norris', 'Norris'], ['Carlos Ray Norris', 'Carlos'], ['Carlos Ray Norris', 'Norris Carlos'], ['Carlos Ray Norris', 'Carlos Ray Norr'], ['Carlos Ray Norris', 'Ra Norris'], ['', 'C'], ['', ''], ['Carlos Ray Norris', ' '], ['Carlos Ray Norris', 'carlos Ray Norris'], ['Carlos', 'carlos'], ['Carlos Ray Norris', 'Norris!'], ['Carlos Ray Norris', 'Carlos-Ray Norris'], ['Carlos Ray', 'Carlos Ray Norris'], ['Carlos', 'Carlos Ray Norris']]\n_outputs = [[True], [True], [True], [True], [True], [True], [True], [False], [False], [False], [False], [False], [False], [False], [False], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if 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(could_be(*i), o[0])"}
472
357
coding
Solve the programming task below in a Python markdown code block. Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≤ s ≤ 2N$) a *summary integer* if there is a contiguous subsequence of $A$ such that the sum of its elements is equal to $s$. Rima wants to count all the summary integers. Can you help her? ------ 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}, \dots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer — the number of summary integers. ------ Constraints ------ $1 ≤ T ≤ 5$ $1 ≤ N ≤ 2 \cdot 10^{6}$ $1 ≤ A_{i} ≤ 2$ for each valid $i$ ----- Sample Input 1 ------ 1 3 2 1 2 ----- Sample Output 1 ------ 4
{"inputs": ["1\n3\n2 1 2"], "outputs": ["4"]}
317
20
coding
Solve the programming task below in a Python markdown code block. At the annual meeting of Board of Directors of Acme Inc. If everyone attending shakes hands exactly one time with every other attendee, how many handshakes are there? Example $n=3$ There are $3$ attendees, ${p1}$, $p2$ and $p3$. ${p1}$ shakes hands with $p2$ and $p3$, and $p2$ shakes hands with $p3$. Now they have all shaken hands after $3$ handshakes. Function Description Complete the handshakes function in the editor below. handshakes has the following parameter: int n: the number of attendees Returns int: the number of handshakes Input Format The first line contains the number of test cases ${t}}$. Each of the following ${t}}$ lines contains an integer, $n$. Constraints $1\leq t\leq1000$ $0<n<10^6$ Sample Input 2 1 2 Sample Output 0 1 Explanation Case 1 : The lonely board member shakes no hands, hence 0. Case 2 : There are 2 board members, so 1 handshake takes place.
{"inputs": ["2\n1\n2\n"], "outputs": ["0\n1\n"]}
280
20
coding
Solve the programming task below in a Python markdown code block. You get a "text" and have to shift the vowels by "n" positions to the right. (Negative value for n should shift to the left.) "Position" means the vowel's position if taken as one item in a list of all vowels within the string. A shift by 1 would mean, that every vowel shifts to the place of the next vowel. Shifting over the edges of the text should continue at the other edge. Example: text = "This is a test!" n = 1 output = "Thes is i tast!" text = "This is a test!" n = 3 output = "This as e tist!" If text is null or empty return exactly this value. Vowels are "a,e,i,o,u". Have fun coding it and please don't forget to vote and rank this kata! :-) I have created other katas. Have a look if you like coding and challenges. Also feel free to reuse/extend the following starter code: ```python def vowel_shift(text, n): ```
{"functional": "_inputs = [[None, 0], ['', 0], ['This is a test!', 0], ['This is a test!', 1], ['This is a test!', 3], ['This is a test!', 4], ['This is a test!', -1], ['This is a test!', -5], ['Brrrr', 99], ['AEIOUaeiou', 1]]\n_outputs = [[None], [''], ['This is a test!'], ['Thes is i tast!'], ['This as e tist!'], ['This is a test!'], ['This as e tist!'], ['This as e tist!'], ['Brrrr'], ['uAEIOUaeio']]\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_shift(*i), o[0])"}
229
296
coding
Solve the programming task below in a Python markdown code block. The [half-life](https://en.wikipedia.org/wiki/Half-life) of a radioactive substance is the time it takes (on average) for one-half of its atoms to undergo radioactive decay. # Task Overview Given the initial quantity of a radioactive substance, the quantity remaining after a given period of time, and the period of time, return the half life of that substance. # Usage Examples ```if:csharp Documentation: Kata.HalfLife Method (Double, Double, Int32) Returns the half-life for a substance given the initial quantity, the remaining quantity, and the elasped time. Syntax public static double HalfLife( double quantityInitial,   double quantityRemaining, int time   ) Parameters quantityInitial Type: System.Double The initial amount of the substance. quantityRemaining Type: System.Double The current amount of the substance. time Type: System.Int32 The amount of time elapsed. Return Value Type: System.Double A floating-point number representing the half-life of the substance. ``` Also feel free to reuse/extend the following starter code: ```python def half_life(initial, remaining, time): ```
{"functional": "_inputs = [[10, 5, 1], [8, 4, 2], [12, 3, 2]]\n_outputs = [[1], [2], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, 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(half_life(*i), o[0])"}
264
187
coding
Solve the programming task below in a Python markdown code block. Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are n piles of cows, with the i-th pile containing a_{i} cows. During each player's turn, that player calls upon the power of Sunlight, and uses it to either: Remove a single cow from a chosen non-empty pile. Choose a pile of cows with even size 2·x (x > 0), and replace it with k piles of x cows each. The player who removes the last cow wins. Given n, k, and a sequence a_1, a_2, ..., a_{n}, help Kevin and Nicky find the winner, given that both sides play in optimal way. -----Input----- The first line of the input contains two space-separated integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 10^9). The second line contains n integers, a_1, a_2, ... a_{n} (1 ≤ a_{i} ≤ 10^9) describing the initial state of the game. -----Output----- Output the name of the winning player, either "Kevin" or "Nicky" (without quotes). -----Examples----- Input 2 1 3 4 Output Kevin Input 1 2 3 Output Nicky -----Note----- In the second sample, Nicky can win in the following way: Kevin moves first and is forced to remove a cow, so the pile contains two cows after his move. Next, Nicky replaces this pile of size 2 with two piles of size 1. So the game state is now two piles of size 1. Kevin then removes one of the remaining cows and Nicky wins by removing the other.
{"inputs": ["1 2\n3\n", "1 1\n1\n", "1 2\n1\n", "1 2\n1\n", "1 1\n1\n", "1 0\n1\n", "1 2\n2\n", "1 0\n2\n"], "outputs": ["Nicky\n", "Kevin\n", "Kevin\n", "Kevin\n", "Kevin\n", "Kevin\n", "Kevin\n", "Kevin\n"]}
414
103
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 <= i <= j < n.   Please complete the following python code precisely: ```python class Solution: def findMaximumXOR(self, nums: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(nums = [3,10,5,25,2,8]) == 28\n assert candidate(nums = [14,70,53,83,49,91,36,80,92,51,66,70]) == 127\n\n\ncheck(Solution().findMaximumXOR)"}
78
94
coding
Solve the programming task below in a Python markdown code block. There is a non-negative integer array A of length N. Chef and Cook will play a game on the array with Chef starting first. In one turn the player will perform the following operation: Choose two indices i,j such that 1 ≤ i < j ≤ N and A_{i} > 0. Set A_{i} ⬅ A_{i} - 1 and A_{j} ⬅ A_{j} + 1, i.e, subtract 1 from A_{i} and add 1 to A_{j}. The player who is unable to perform the operation loses. If both Chef and Cook play optimally, who will win? ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - The first line of each test case contains a single integer N denoting the length of the array. - The second line of teach test case contains N integers A_{1},A_{2},\ldots,A_{N} denoting the initial values of the array. ------ Output Format ------ For each test case, output "Chef" if Chef wins, otherwise output "Cook" (without quotes). Each letter of the output may be printed in either uppercase or lowercase. For example, Chef, chEf, CHEF, and cHEf will all be treated as equivalent. ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤ N ≤ 100$ $0 ≤ A_{i} ≤ 10^{9}$ - There are no limits on the sum of $N$ over all test cases. ----- Sample Input 1 ------ 3 4 1 0 1 0 4 1 2 3 4 1 420 ----- Sample Output 1 ------ Chef Chef Cook ----- explanation 1 ------ For the first test case, Chef wins. Here is the strategy for Chef. - Initially, $A = [1, 0, 1, 0]$. - In the first turn, Chef will pick $i=1$ and $j=3$. Then, $A = [0,0,2,0]$. - In the second turn, Cook is can only pick $i=3$ and $j=4$. Then $A=[0,0,1,1]$. - In the third turn, Chef will pick $i=3$ and $j=4$. Then $A=[0,0,0,2]$. - In the fourth turn, Cook cannot perform any operation and loses. Therefore, Chef has won.
{"inputs": ["3\n4\n1 0 1 0\n4\n1 2 3 4\n1\n420\n"], "outputs": ["Chef\nChef\nCook\n"]}
565
44
coding
Solve the programming task below in a Python markdown code block. Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %. Find the expected number of games that will be played, and print it as follows. We can represent the expected value as P/Q with coprime integers P and Q. Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q \equiv P\pmod {10^9+7}. (Such an integer R always uniquely exists under the constraints of this problem.) Constraints * 1 \leq N \leq 100000 * 0 \leq A,B,C \leq 100 * 1 \leq A+B * A+B+C=100 * All values in input are integers. Input Input is given from Standard Input in the following format: N A B C Output Print the expected number of games that will be played, in the manner specified in the statement. Examples Input 1 25 25 50 Output 2 Input 4 50 50 0 Output 312500008 Input 1 100 0 0 Output 1 Input 100000 31 41 28 Output 104136146
{"inputs": ["8 50 50 0", "1 000 0 0", "2 100 0 0", "6 50 50 0", "5 50 50 0", "3 50 50 0", "4 100 0 0", "2 50 50 0"], "outputs": ["127441420\n", "0\n", "2\n", "386718762\n", "351562510\n", "125000005\n", "4\n", "500000006\n"]}
359
166
coding
Solve the programming task below in a Python markdown code block. Nezzar's favorite digit among $1,\ldots,9$ is $d$. He calls a positive integer lucky if $d$ occurs at least once in its decimal representation. Given $q$ integers $a_1,a_2,\ldots,a_q$, for each $1 \le i \le q$ Nezzar would like to know if $a_i$ can be equal to a sum of several (one or more) lucky numbers. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 9$) — the number of test cases. The first line of each test case contains two integers $q$ and $d$ ($1 \le q \le 10^4$, $1 \le d \le 9$). The second line of each test case contains $q$ integers $a_1,a_2,\ldots,a_q$ ($1 \le a_i \le 10^9$). -----Output----- For each integer in each test case, print "YES" in a single line if $a_i$ can be equal to a sum of lucky numbers. Otherwise, print "NO". You can print letters in any case (upper or lower). -----Examples----- Input 2 3 7 24 25 27 10 7 51 52 53 54 55 56 57 58 59 60 Output YES NO YES YES YES NO YES YES YES YES YES YES NO -----Note----- In the first test case, $24 = 17 + 7$, $27$ itself is a lucky number, $25$ cannot be equal to a sum of lucky numbers.
{"inputs": ["2\n3 2\n6 47 1\n10 3\n50 52 2 43 113 92 9 73 42 60\n", "2\n3 7\n24 44 40\n10 7\n4 52 4 54 64 54 66 2 25 60\n", "2\n3 2\n5 47 1\n10 3\n50 52 2 43 113 92 9 73 42 60\n", "2\n3 7\n10 25 27\n10 5\n13 52 53 2 55 56 57 58 9 8\n", "2\n3 2\n5 47 1\n10 3\n50 52 1 43 113 92 8 73 42 60\n", "2\n3 2\n24 44 10\n10 7\n4 52 4 54 64 54 66 1 25 60\n", "2\n3 2\n24 44 10\n10 7\n4 52 4 54 64 54 66 1 25 49\n", "2\n3 2\n24 44 10\n10 7\n4 52 4 54 64 54 66 1 47 49\n"], "outputs": ["YES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n", "YES\nYES\nNO\nNO\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nNO\n", "NO\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n", "NO\nNO\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\n", "NO\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nNO\nYES\nYES\nYES\n", "YES\nYES\nYES\nNO\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nNO\n", "YES\nYES\nYES\nNO\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n", "YES\nYES\nYES\nNO\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\n"]}
399
622
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters. For example, "ace" is a subsequence of "abcde". A common subsequence of two strings is a subsequence that is common to both strings.   Please complete the following python code precisely: ```python class Solution: def longestCommonSubsequence(self, text1: str, text2: str) -> int: ```
{"functional": "def check(candidate):\n assert candidate(text1 = \"abcde\", text2 = \"ace\" ) == 3 \n assert candidate(text1 = \"abc\", text2 = \"abc\") == 3\n assert candidate(text1 = \"abc\", text2 = \"def\") == 0\n\n\ncheck(Solution().longestCommonSubsequence)"}
153
83
coding
Solve the programming task below in a Python markdown code block. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? -----Input----- The first line contains a single integer n (1 ≤ n ≤ 3·10^5). The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^6) — the initial group that is given to Toastman. -----Output----- Print a single integer — the largest possible score. -----Examples----- Input 3 3 1 5 Output 26 Input 1 10 Output 10 -----Note----- Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
{"inputs": ["1\n3\n", "1\n5\n", "1\n2\n", "1\n1\n", "1\n10\n", "1\n10\n", "2\n1 2\n", "2\n2 3\n"], "outputs": ["3\n", "5\n", "2\n", "1\n", "10\n", "10\n", "6\n", "10\n"]}
534
95
coding
Solve the programming task below in a Python markdown code block. Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies. -----Constraints----- - 1 \leq A,B \leq 100 - Both A and B are integers. -----Input----- Input is given from Standard Input in the following format: A B -----Output----- If it is possible to give cookies so that each of the three goats can have the same number of cookies, print Possible; otherwise, print Impossible. -----Sample Input----- 4 5 -----Sample Output----- Possible If Snuke gives nine cookies, each of the three goats can have three cookies.
{"inputs": ["4 0", "1 2", "7 0", "0 2", "5 0", "0 8", "0 6", "0 0"], "outputs": ["Possible\n", "Possible\n", "Possible\n", "Possible\n", "Possible\n", "Possible\n", "Possible\n", "Possible\n"]}
205
78
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 26$ - $1 \leq K \leq 26$ -----Sample Input:----- 2 2 4 -----Sample Output:----- A 12 A 12 ABC 1234 -----EXPLANATION:----- No need, else pattern can be decode easily.
{"inputs": ["2\n2\n4"], "outputs": ["A\n12\nA\n12\nABC\n1234"]}
186
31
coding
Solve the programming task below in a Python markdown code block. For given a circle $c$ and a line $l$, print the coordinates of the cross points of them. Constraints * $p1$ and $p2$ are different * The circle and line have at least one cross point * $1 \leq q \leq 1,000$ * $-10,000 \leq cx, cy, x1, y1, x2, y2 \leq 10,000$ * $1 \leq r \leq 10,000$ Input The input is given in the following format. $cx\; cy\; r$ $q$ $Line_1$ $Line_2$ : $Line_q$ In the first line, the center coordinate of the circle and its radius are given by $cx$, $cy$ and $r$. In the second line, the number of queries $q$ is given. In the following $q$ lines, as queries, $Line_i$ are given ($1 \leq i \leq q$) in the following format. $x_1\; y_1\; x_2\; y_2$ Each line is represented by two points $p1$ and $p2$ which the line crosses. The coordinate of $p1$ and $p2$ are given by ($x1$, $y1$) and ($x2$, $y2$) respectively. All input values are given in integers. Output For each query, print the coordinates of the cross points in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001. Example Input 2 1 1 2 0 1 4 1 3 0 3 3 Output 1.00000000 1.00000000 3.00000000 1.00000000 3.00000000 1.00000000 3.00000000 1.00000000
{"inputs": ["2 0 1\n2\n0 1 4 1\n3 0 3 3", "2 0 2\n2\n0 1 4 1\n3 0 3 3", "2 0 2\n2\n0 1 4 2\n3 0 3 3", "2 0 2\n2\n0 1 4 2\n3 0 5 3", "2 0 2\n1\n0 1 4 2\n3 0 5 3", "2 0 2\n1\n0 1 4 0\n3 0 5 3", "2 0 2\n1\n0 1 8 0\n1 0 5 3", "2 0 2\n1\n0 2 8 0\n1 0 5 3"], "outputs": ["2.00000000 1.00000000 2.00000000 1.00000000\n3.00000000 0.00000000 3.00000000 0.00000000\n", "0.26794919 1.00000000 3.73205081 1.00000000\n3.00000000 -1.73205081 3.00000000 1.73205081\n", "0.31603429 1.07900857 2.97808335 1.74452084\n3.00000000 -1.73205081 3.00000000 1.73205081\n", "0.31603429 1.07900857 2.97808335 1.74452084\n1.68347100 -1.97479351 3.70114439 1.05171658\n", "0.31603429 1.07900857 2.97808335 1.74452084\n", "0.23529412 0.94117647 4.00000000 0.00000000\n", "0.25026098 0.96871738 3.93435441 0.50820570\n", "1.02191665 1.74452084 3.68396571 1.07900857\n"]}
536
750
coding
Solve the programming task below in a Python markdown code block. Problem GPA is an abbreviation for "Galaxy Point of Aizu" and takes real numbers from 0 to 4. GPA rock-paper-scissors is a game played by two people. After each player gives a signal of "rock-paper-scissors, pon (hoi)" to each other's favorite move, goo, choki, or par, the person with the higher GPA becomes the winner, and the person with the lower GPA becomes the loser. If they are the same, it will be a draw. Since the GPA data of N people is given, output the points won in each round-robin battle. However, the points won will be 3 when winning, 1 when drawing, and 0 when losing. Round-robin is a system in which all participants play against participants other than themselves exactly once. Constraints The input satisfies the following conditions. * 2 ≤ N ≤ 105 * N is an integer * 0.000 ≤ ai ≤ 4.000 (1 ≤ i ≤ N) * ai is a real number (1 ≤ i ≤ N) * Each GPA is given up to 3 decimal places Input The input is given in the following format. N a1 a2 ... aN The first line is given the number of people N to play GPA rock-paper-scissors. The following N lines are given the data ai of the i-th person's GPA in one line. Output Output the points of the i-th person on the i-line on one line. (1 ≤ i ≤ N) Examples Input 3 1.000 3.000 3.000 Output 0 4 4 Input 3 1.000 2.000 3.000 Output 0 3 6
{"inputs": ["3\n1.000\n2.000\n3.000", "3\n1.000\n3.000\n3.000", "3\n1.000\n2.000\n3.4274102096399073", "3\n1.3153899733914476\n3.000\n3.000", "3\n1.000\n3.000\n3.1230319554116766", "3\n1.000\n2.000\n3.9759367558439593", "3\n1.000\n2.5451927881659007\n3.000", "3\n1.6470390157297516\n3.000\n3.000"], "outputs": ["0\n3\n6", "0\n4\n4", "0\n3\n6\n", "0\n4\n4\n", "0\n3\n6\n", "0\n3\n6\n", "0\n3\n6\n", "0\n4\n4\n"]}
403
314
coding
Solve the programming task below in a Python markdown code block. Problem Statement: Nash, a high school student studies the concepts of Functions(Mathematics), for the first time.After learning the definitions of Domain and Range, he tries to find the number of functions possible,given the number of elements in domain and range.He comes to you for help.Can you help him with this? Input Format: The first line of Input contains t,the number of testcases. Then t lines follow, each line consist of two integers X and Y, indicating the size of domain and range. Output Format: For each testcase, output a single number which is the number of functions that can be created for given size of Domain and Range.Since the answer can be large, output the value of ans%1000000007(ie the reminder when the ans is divided by 10e9+7). Input Constraints: 1 ≤ t ≤ 100 1 ≤ X ≤ 1000 1 ≤ Y ≤ 1000 SAMPLE INPUT 2 2 4 1 1 SAMPLE OUTPUT 16 1 Explanation For the first input, the number of functions possible is 16.The reminder when 16 is divided by 10e9 + 7 is 16.(Quotient is 0). Similarly, the output value for second testcase is 1.
{"inputs": ["5\n6 4\n4 6\n15 2\n2 85\n4 7", "47\n428 580\n692 254\n221 613\n14 794\n116 115\n926 200\n325 265\n517 290\n219 90\n947 543\n218 544\n149 976\n28 233\n879 494\n530 715\n853 618\n5 378\n369 781\n813 967\n880 841\n610 707\n205 655\n73 468\n187 715\n442 535\n413 765\n152 199\n72 58\n24 116\n900 962\n982 272\n694 763\n372 478\n210 830\n628 348\n895 136\n663 187\n595 76\n271 220\n449 414\n611 749\n959 627\n441 188\n309 528\n713 196\n891 144\n886 998"], "outputs": ["4096\n1296\n32768\n7225\n2401", "33172914\n969001528\n763558838\n264421526\n408857237\n138817814\n945568635\n679200755\n136796419\n431775807\n403600246\n592139643\n998347316\n775182218\n806076022\n275325338\n186504349\n459109290\n586196054\n465998479\n743346655\n956463920\n966983531\n863722125\n55560866\n375873458\n439742780\n315389316\n117263467\n440998506\n531892981\n911973175\n368768052\n808296506\n182228648\n359621874\n233396409\n249709483\n628904483\n739769030\n558447399\n150083872\n539262880\n576043888\n404562125\n723117300\n294016284"]}
294
897
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s consisting of lowercase English letters, return the first letter to appear twice. Note: A letter a appears twice before another letter b if the second occurrence of a is before the second occurrence of b. s will contain at least one letter that appears twice.   Please complete the following python code precisely: ```python class Solution: def repeatedCharacter(self, s: str) -> str: ```
{"functional": "def check(candidate):\n assert candidate(s = \"abccbaacz\") == \"c\"\n assert candidate(s = \"abcdd\") == \"d\"\n\n\ncheck(Solution().repeatedCharacter)"}
101
50
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most one element. We define an array is non-decreasing if nums[i] <= nums[i + 1] holds for every i (0-based) such that (0 <= i <= n - 2).   Please complete the following python code precisely: ```python class Solution: def checkPossibility(self, nums: List[int]) -> bool: ```
{"functional": "def check(candidate):\n assert candidate(nums = [4,2,3]) == True\n assert candidate(nums = [4,2,1]) == False\n\n\ncheck(Solution().checkPossibility)"}
115
50
coding
Solve the programming task below in a Python markdown code block. # MOD 256 without the MOD operator The MOD-operator % (aka mod/modulus/remainder): ``` Returns the remainder of a division operation. The sign of the result is the same as the sign of the first operand. (Different behavior in Python!) ``` The short unbelievable mad story for this kata: I wrote a program and needed the remainder of the division by 256. And then it happened: The "5"/"%"-Key did not react. It must be broken! So I needed a way to: ``` Calculate the remainder of the division by 256 without the %-operator. ``` Also here some examples: ``` Input 254 -> Result 254 Input 256 -> Result 0 Input 258 -> Result 2 Input -258 -> Result -2 (in Python: Result: 254!) ``` It is always expected the behavior of the MOD-Operator of the language! The input number will always between -10000 and 10000. For some languages the %-operator will be blocked. If it is not blocked and you know how to block it, tell me and I will include it. For all, who say, this would be a duplicate: No, this is no duplicate! There are two katas, in that you have to write a general method for MOD without %. But this kata is only for MOD 256. And so you can create also other specialized solutions. ;-) Of course you can use the digit "5" in your solution. :-) I'm very curious for your solutions and the way you solve it. I found several interesting "funny" ways. Have fun coding it and please don't forget to vote and rank this kata! :-) I have also created other katas. Take a look if you enjoyed this kata! Also feel free to reuse/extend the following starter code: ```python def mod256_without_mod(number): ```
{"functional": "_inputs = [[254], [256], [258], [-254], [-256], [-258]]\n_outputs = [[254], [0], [2], [2], [0], [254]]\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(mod256_without_mod(*i), o[0])"}
437
204
coding
Solve the programming task below in a Python markdown code block. We consider permutations of the numbers $1,..., N$ for some $N$. By permutation we mean a rearrangment of the number $1,...,N$. For example 24517638245176382 \quad 4 \quad 5 \quad 1 \quad 7 \quad 6 \quad 3 \quad 8 is a permutation of $1,2,...,8$. Of course, 12345678123456781 \quad 2 \quad 3 \quad 4 \quad 5 \quad 6 \quad 7 \quad 8 is also a permutation of $1,2,...,8$. We can "walk around" a permutation in a interesting way and here is how it is done for the permutation above: Start at position $1$. At position $1$ we have $2$ and so we go to position $2$. Here we find $4$ and so we go to position $4$. Here we find $1$, which is a position that we have already visited. This completes the first part of our walk and we denote this walk by ($1$ $2$ $4$ $1$). Such a walk is called a cycle. An interesting property of such walks, that you may take for granted, is that the position we revisit will always be the one we started from! We continue our walk by jumping to first unvisited position, in this case position $3$ and continue in the same manner. This time we find $5$ at position $3$ and so we go to position $5$ and find $7$ and we go to position $7$ and find $3$ and thus we get the cycle ($3$ $5$ $7$ $3$). Next we start at position $6$ and get ($6$ $6$), and finally we start at position $8$ and get the cycle ($8$ $8$). We have exhausted all the positions. Our walk through this permutation consists of $4$ cycles. One can carry out this walk through any permutation and obtain a set of cycles as the result. Your task is to print out the cycles that result from walking through a given permutation. -----Input:----- The first line of the input is a positive integer $N$ indicating the length of the permutation. The next line contains $N$ integers and is a permutation of $1,2,...,N$. -----Output:----- The first line of the output must contain a single integer $k$ denoting the number of cycles in the permutation. Line $2$ should describe the first cycle, line $3$ the second cycle and so on and line $k+1$ should describe the $k^{th}$ cycle. -----Constraints:----- - $1 \leq N \leq 1000$. -----Sample input 1:----- 8 2 4 5 1 7 6 3 8 -----Sample output 1:----- 4 1 2 4 1 3 5 7 3 6 6 8 8 -----Sample input 2:----- 8 1 2 3 4 5 6 7 8 -----Sample output 2:----- 8 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8
{"inputs": ["8\n2 4 5 1 7 6 3 8", "8\n1 2 3 4 5 6 7 8"], "outputs": ["4\n1 2 4 1\n3 5 7 3\n6 6\n8 8", "8\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8"]}
747
106
coding
Solve the programming task below in a Python markdown code block. In Math, an improper fraction is a fraction where the numerator (the top number) is greater than or equal to the denominator (the bottom number) For example: ```5/3``` (five third). A mixed numeral is a whole number and a fraction combined into one "mixed" number. For example: ```1 1/2``` (one and a half) is a mixed numeral. ## Task Write a function `convertToMixedNumeral` to convert the improper fraction into a mixed numeral. The input will be given as a ```string``` (e.g. ```'4/3'```). The output should be a ```string```, with a space in between the whole number and the fraction (e.g. ```'1 1/3'```). You do not need to reduce the result to its simplest form. For the purpose of this exercise, there will be no ```0```, ```empty string``` or ```null``` input value. However, the input can be: - a negative fraction - a fraction that does not require conversion - a fraction that can be converted into a whole number ## Example Also feel free to reuse/extend the following starter code: ```python def convert_to_mixed_numeral(parm): ```
{"functional": "_inputs = [['74/3'], ['9999/24'], ['74/30'], ['13/5'], ['5/3'], ['1/1'], ['10/10'], ['900/10'], ['9920/124'], ['6/2'], ['9/77'], ['96/100'], ['12/18'], ['6/36'], ['1/18'], ['-64/8'], ['-6/8'], ['-9/78'], ['-504/26'], ['-47/2'], ['-21511/21']]\n_outputs = [['24 2/3'], ['416 15/24'], ['2 14/30'], ['2 3/5'], ['1 2/3'], ['1'], ['1'], ['90'], ['80'], ['3'], ['9/77'], ['96/100'], ['12/18'], ['6/36'], ['1/18'], ['-8'], ['-6/8'], ['-9/78'], ['-19 10/26'], ['-23 1/2'], ['-1024 7/21']]\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(convert_to_mixed_numeral(*i), o[0])"}
275
429
coding
Solve the programming task below in a Python markdown code block. You had $n$ positive integers $a_1, a_2, \dots, a_n$ arranged in a circle. For each pair of neighboring numbers ($a_1$ and $a_2$, $a_2$ and $a_3$, ..., $a_{n - 1}$ and $a_n$, and $a_n$ and $a_1$), you wrote down: are the numbers in the pair equal or not. Unfortunately, you've lost a piece of paper with the array $a$. Moreover, you are afraid that even information about equality of neighboring elements may be inconsistent. So, you are wondering: is there any array $a$ which is consistent with information you have about equality or non-equality of corresponding pairs? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases. Next $t$ cases follow. The first and only line of each test case contains a non-empty string $s$ consisting of characters E and/or N. The length of $s$ is equal to the size of array $n$ and $2 \le n \le 50$. For each $i$ from $1$ to $n$: if $s_i =$ E then $a_i$ is equal to $a_{i + 1}$ ($a_n = a_1$ for $i = n$); if $s_i =$ N then $a_i$ is not equal to $a_{i + 1}$ ($a_n \neq a_1$ for $i = n$). -----Output----- For each test case, print YES if it's possible to choose array $a$ that are consistent with information from $s$ you know. Otherwise, print NO. It can be proved, that if there exists some array $a$, then there exists an array $a$ of positive integers with values less or equal to $10^9$. -----Examples----- Input 4 EEE EN ENNEENE NENN Output YES NO YES YES -----Note----- In the first test case, you can choose, for example, $a_1 = a_2 = a_3 = 5$. In the second test case, there is no array $a$, since, according to $s_1$, $a_1$ is equal to $a_2$, but, according to $s_2$, $a_2$ is not equal to $a_1$. In the third test case, you can, for example, choose array $a = [20, 20, 4, 50, 50, 50, 20]$. In the fourth test case, you can, for example, choose $a = [1, 3, 3, 7]$.
{"inputs": ["2\nEEEEEN\nEE\n", "2\nEEEEEN\nEE\n", "2\nEENEEE\nEE\n", "2\nEEEEEN\nEEEEEN\n", "2\nEEEEEN\nEEEEEN\n", "2\nNEEEEE\nEEEEEN\n", "2\nEEEEEEN\nEEEEEEEN\n", "2\nEEEEEEN\nEEEEEEEN\n"], "outputs": ["NO\nYES\n", "NO\nYES\n", "NO\nYES\n", "NO\nNO\n", "NO\nNO\n", "NO\nNO\n", "NO\nNO\n", "NO\nNO\n"]}
624
136
coding
Solve the programming task below in a Python markdown code block. In this kata, you've to count lowercase letters in a given string and return the letter count in a hash with 'letter' as key and count as 'value'. The key must be 'symbol' instead of string in Ruby and 'char' instead of string in Crystal. Example: ```python letter_count('arithmetics') #=> {"a": 1, "c": 1, "e": 1, "h": 1, "i": 2, "m": 1, "r": 1, "s": 1, "t": 2} ``` Also feel free to reuse/extend the following starter code: ```python def letter_count(s): ```
{"functional": "_inputs = [['codewars'], ['activity'], ['arithmetics'], ['traveller'], ['daydreamer']]\n_outputs = [[{'a': 1, 'c': 1, 'd': 1, 'e': 1, 'o': 1, 'r': 1, 's': 1, 'w': 1}], [{'a': 1, 'c': 1, 'i': 2, 't': 2, 'v': 1, 'y': 1}], [{'a': 1, 'c': 1, 'e': 1, 'h': 1, 'i': 2, 'm': 1, 'r': 1, 's': 1, 't': 2}], [{'a': 1, 'e': 2, 'l': 2, 'r': 2, 't': 1, 'v': 1}], [{'a': 2, 'd': 2, 'e': 2, 'm': 1, 'r': 2, 'y': 1}]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, 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(letter_count(*i), o[0])"}
159
382
coding
Solve the programming task below in a Python markdown code block. In this problem MEX of a certain array is the smallest positive integer not contained in this array. Everyone knows this definition, including Lesha. But Lesha loves MEX, so he comes up with a new problem involving MEX every day, including today. You are given an array $a$ of length $n$. Lesha considers all the non-empty subarrays of the initial array and computes MEX for each of them. Then Lesha computes MEX of the obtained numbers. An array $b$ is a subarray of an array $a$, if $b$ can be obtained from $a$ by deletion of several (possible none or all) elements from the beginning and several (possibly none or all) elements from the end. In particular, an array is a subarray of itself. Lesha understands that the problem is very interesting this time, but he doesn't know how to solve it. Help him and find the MEX of MEXes of all the subarrays! -----Input----- The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the length of the array. The next line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) — the elements of the array. -----Output----- Print a single integer — the MEX of MEXes of all subarrays. -----Examples----- Input 3 1 3 2 Output 3 Input 5 1 4 3 1 2 Output 6
{"inputs": ["1\n1\n", "1\n1\n", "3\n1 3 2\n", "3\n1 3 2\n", "4\n4 1 3 2\n", "5\n1 4 3 1 2\n", "5\n1 4 3 1 2\n", "9\n5 4 3 2 1 2 3 4 5\n"], "outputs": ["1\n", "1\n", "3\n", "3\n", "3\n", "6\n", "6\n", "7\n"]}
350
132
coding
Solve the programming task below in a Python markdown code block. Complete the function which returns the weekday according to the input number: * `1` returns `"Sunday"` * `2` returns `"Monday"` * `3` returns `"Tuesday"` * `4` returns `"Wednesday"` * `5` returns `"Thursday"` * `6` returns `"Friday"` * `7` returns `"Saturday"` * Otherwise returns `"Wrong, please enter a number between 1 and 7"` Also feel free to reuse/extend the following starter code: ```python def whatday(num): ```
{"functional": "_inputs = [[1], [2], [3], [4], [5], [6], [7], [0], [8], [20]]\n_outputs = [['Sunday'], ['Monday'], ['Tuesday'], ['Wednesday'], ['Thursday'], ['Friday'], ['Saturday'], ['Wrong, please enter a number between 1 and 7'], ['Wrong, please enter a number between 1 and 7'], ['Wrong, please enter a number between 1 and 7']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_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(whatday(*i), o[0])"}
120
243
coding
Solve the programming task below in a Python markdown code block. Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card. Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. -----Input----- The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. -----Output----- For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). -----Examples----- Input MC CSKA 9 28 a 3 y 62 h 25 y 66 h 42 y 70 h 25 y 77 a 4 y 79 a 25 y 82 h 42 r 89 h 16 y 90 a 13 r Output MC 25 70 MC 42 82 CSKA 13 90
{"inputs": ["A\nAA\n2\n1 a 1 y\n2 h 1 y\n", "A\nAA\n2\n1 a 1 y\n2 h 1 y\n", "TANB\nXNCPR\n1\n15 h 6 r\n9 h 27 r\n", "AB\nBC\n3\n1 h 1 y\n2 h 1 y\n3 h 1 r\n", "AB\nBC\n3\n1 h 1 y\n2 h 1 y\n3 h 1 r\n", "TANC\nXNCOR\n2\n15 h 27 r\n6 h 27 r\n", "AB\nBC\n3\n1 h 1 y\n2 h 2 y\n3 h 1 r\n", "TANC\nXNCOR\n2\n15 h 54 r\n6 h 27 r\n"], "outputs": ["", "\n", "TANB 6 15\n", "AB 1 2\n", "AB 1 2\n", "TANC 27 15\n", "AB 1 3\n", "TANC 54 15\nTANC 27 6\n"]}
597
272
coding
Solve the programming task below in a Python markdown code block. Stephanie just learned about a game called Nim in which there are two players and $n$ piles of stones. During each turn, a player must choose any non-empty pile and take as many stones as they want. The first player who cannot complete their turn (i.e., because all piles are empty) loses. Stephanie knows that, for each start position in this game, it's possible to know which player will win (i.e., the first or second player) if both players play optimally. Now she wants to know the number of different games that exist that satisfy all of the following conditions: The game starts with $n$ non-empty piles and each pile contains less than $2^{m}$ stones. All the piles contain pairwise different numbers of stones. The first player wins if that player moves optimally. Help Stephanie by finding and printing the number of such games satisfying all the above criteria, modulo $10^9+7$. Input Format The first line contains two space-separated integers describing the respective values of $n$ and $m$. Constraints $1\leq n,m\leq10^7$ Output Format Print the number of such games, modulo $10^9+7$. Sample Input 0 2 2 Sample Output 0 6 Explanation 0 We want to know the number of games with $n=2$ piles where each pile contains $<2^m=2^2=4$ stones. There are six such possible games with the following distributions of stones: $(1,2),(1,3),(2,1),(2,3),(3,1),(3,2)$. Thus, we print the result of $6\ \text{mod}\ (10^9+7)=6$ as our answer.
{"inputs": ["2 2\n"], "outputs": ["6\n"]}
393
16
coding
Solve the programming task below in a Python markdown code block. Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes. Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels. Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), and if k = 2, they do not rhyme (ommit ≠ ermit). Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines): * Clerihew (aabb); * Alternating (abab); * Enclosed (abba). If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented by aaaa). If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem is aaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme. Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task. Input The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104. If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1, 2, 3, 4; the second one contains lines number 5, 6, 7, 8; and so on. Output Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes. Examples Input 1 1 day may sun fun Output aabb Input 1 1 day may gray way Output aaaa Input 2 1 a a a a a a e e Output aabb Input 2 1 day may sun fun test hill fest thrill Output NO Note In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".
{"inputs": ["1 1\na\ne\ne\na\n", "1 1\ne\na\ne\na\n", "1 1\na\ne\ne\ne\n", "1 1\ne\ne\ne\ne\n", "1 1\na\na\na\na\n", "1 1\na\ne\na\ne\n", "1 1\na\na\na\ne\n", "1 1\ne\na\ne\ne\n"], "outputs": ["abba\n", "abab\n", "NO\n", "aaaa\n", "aaaa\n", "abab\n", "NO\n", "NO\n"]}
688
153
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Reversing an integer means to reverse all its digits. For example, reversing 2021 gives 1202. Reversing 12300 gives 321 as the leading zeros are not retained. Given an integer num, reverse num to get reversed1, then reverse reversed1 to get reversed2. Return true if reversed2 equals num. Otherwise return false.   Please complete the following python code precisely: ```python class Solution: def isSameAfterReversals(self, num: int) -> bool: ```
{"functional": "def check(candidate):\n assert candidate(num = 526) == True\n assert candidate(num = 1800) == False\n assert candidate(num = 0) == True\n\n\ncheck(Solution().isSameAfterReversals)"}
134
61
coding
Solve the programming task below in a Python markdown code block. There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$. Pak Chanek has $3$ bags numbered from $1$ to $3$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick. After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $w_j$ be the weight of the brick Bu Dengklek takes from bag $j$. The score is calculated as $|w_1 - w_2| + |w_2 - w_3|$, where $|x|$ denotes the absolute value of $x$. It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally? -----Input----- Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. The following lines contain the description of each test case. The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) — the number of bricks. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the weights of the bricks. It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally. -----Examples----- Input 3 5 3 1 5 2 3 4 17 8 19 45 8 265 265 265 265 265 265 265 265 Output 6 63 0 -----Note----- In the first test case, one way of achieving a final score of $6$ is to do the following: Put bricks $1$, $4$, and $5$ into bag $1$. Put brick $3$ into bag $2$. Put brick $2$ into bag $3$. If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is: Take brick $5$ from bag $1$. Take brick $3$ from bag $2$. Take brick $2$ from bag $3$. The score is $|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution. It can be shown that there is no other distribution that results in a final score bigger than $6$.
{"inputs": ["3\n5\n3 1 5 2 3\n4\n17 8 19 45\n8\n265 265 265 265 265 265 265 265\n"], "outputs": ["6\n63\n0\n"]}
695
78
coding
Solve the programming task below in a Python markdown code block. You are making your very own boardgame. The game is played by two opposing players, featuring a 6 x 6 tile system, with the players taking turns to move their pieces (similar to chess). The design is finished, now it's time to actually write and implement the features. Being the good programmer you are, you carefully plan the procedure and break the program down into smaller managable sections. You decide to start coding the logic for resolving "fights" when two pieces engage in combat on a tile. Your boardgame features four unique pieces: Swordsman, Cavalry, Archer and Pikeman Each piece has unique movement and has advantages and weaknesses in combat against one of the other pieces. Task You must write a function ```fightResolve``` that takes the attacking and defending piece as input parameters, and returns the winning piece. It may be the case that both the attacking and defending piece belong to the same player, after which you must return an error value to indicate an illegal move. In C++ and C, the pieces will be represented as ```chars```. Values will be case-sensitive to display ownership. Let the following char values represent each piece from their respective player. Player 1: ```p```= Pikeman, ```k```= Cavalry, ```a```= Archer, ```s```= Swordsman Player 2: ```P```= Pikeman, ```K```= Cavalry, ```A```= Archer, ```S```= Swordsman The outcome of the fight between two pieces depends on which piece attacks, the type of the attacking piece and the type of the defending piece. Archers always win against swordsmens, swordsmen always win against pikemen, pikemen always win against cavalry and cavalry always win against archers. If a matchup occurs that was not previously mentioned (for example Archers vs Pikemen) the attacker will always win. This table represents the winner of each possible engagement between an attacker and a defender. (Attacker→) (Defender↓) Archer Pikeman Swordsman Knight Knight Defender Attacker Attacker Attacker Swordsman Attacker Defender Attacker Attacker Archer Attacker Attacker Defender Attacker Pikeman Attacker Attacker Attacker Defender If two pieces from the same player engage in combat, i.e P vs S or k vs a, the function must return -1 to signify and illegal move. Otherwise assume that no other illegal values will be passed. Examples Function prototype: fightResolve(defender, attacker) 1. fightResolve('a', 'P') outputs 'P'. No interaction defined between Pikemen and Archer. Pikemen is the winner here because it is the attacking piece. 2. fightResolve('k', 'A') outputs 'k'. Knights always defeat archers, even if Archer is the attacking piece here. 3. fightResolve('S', 'A') outputs -1. Friendly units don't fight. Return -1 to indicate error. Also feel free to reuse/extend the following starter code: ```python def fight_resolve(defender, attacker): ```
{"functional": "_inputs = [['K', 'A'], ['S', 'A'], ['k', 's'], ['a', 'a'], ['k', 'A'], ['K', 'a']]\n_outputs = [[-1], [-1], [-1], [-1], ['k'], ['K']]\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(fight_resolve(*i), o[0])"}
681
204
coding
Solve the programming task below in a Python markdown code block. Initially, Chef had an array A of length N. Chef performs the following operation on A at most once: Select L and R such that 1 ≤ L ≤ R ≤ N and set A_{i} := A_{i} + 1 for all L ≤ i ≤ R. Determine the maximum number of *inversions* Chef can decrease from the array A by applying the operation at most once. More formally, let the final array obtained after applying the operation at most once be B. You need to determine the maximum value of inv(A) - inv(B) (where inv(X) denotes the number of *inversions* in array X). Note: The number of *inversions* in an array X is the number of pairs (i, j) such that 1 ≤ i < j ≤ N and X_{i} > X_{j}. ------ 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 maximum value of inv(A) - inv(B) which can be obtained after applying at most one operation. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤N ≤10^{5}$ $1 ≤A_{i} ≤N$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 4 2 3 1 5 6 1 2 3 4 5 6 4 2 1 1 1 ----- Sample Output 1 ------ 2 0 3 ----- explanation 1 ------ Test case $1$: The initial array $A$ is $[4, 2, 3, 1, 5]$ which has $5$ inversions. We can perform operation on $L = 3, R = 4$. The resultant array will be $[4, 2, 4, 2, 5]$ which has $3$ inversions. Therefore we reduce the number of inversion by $2$ which is the maximum decrement possible. Test case $2$: The initial array $A$ is $[1, 2, 3, 4, 5, 6]$ which has $0$ inversions. In this case, we do not need to apply any operation and the final array $B$ will be same as the initial array $A$. Therefore the maximum possible decrement in inversions is $0$. Test case $3$: The initial array $A$ is $[2, 1, 1, 1]$ which has $3$ inversions. We can perform operation on $L = 2, R = 4$. The resultant array will be $[2, 2, 2, 2]$ which has $0$ inversions. Therefore we reduce the number of inversion by $3$ which is the maximum decrement possible.
{"inputs": ["3\n5\n4 2 3 1 5\n6\n1 2 3 4 5 6\n4\n2 1 1 1\n"], "outputs": ["2\n0\n3\n"]}
704
54
coding
Solve the programming task below in a Python markdown code block. "Everything in the universe is balanced. Every disappointment you face in life will be balanced by something good for you! Keep going, never give up." Let's call a string balanced if all characters that occur in this string occur in it the same number of times. You are given a string $S$; this string may only contain uppercase English letters. You may perform the following operation any number of times (including zero): choose one letter in $S$ and replace it by another uppercase English letter. Note that even if the replaced letter occurs in $S$ multiple times, only the chosen occurrence of this letter is replaced. Find the minimum number of operations required to convert the given string to a balanced string. -----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 and only line of each test case contains a single string $S$. -----Output----- For each test case, print a single line containing one integer ― the minimum number of operations. -----Constraints----- - $1 \le T \le 10,000$ - $1 \le |S| \le 1,000,000$ - the sum of $|S|$ over all test cases does not exceed $5,000,000$ - $S$ contains only uppercase English letters -----Subtasks----- Subtask #1 (20 points): - $T \le 10$ - $|S| \le 18$ Subtask #2 (80 points): original constraints -----Example Input----- 2 ABCB BBC -----Example Output----- 1 1 -----Explanation----- Example case 1: We can change 'C' to 'A'. The resulting string is "ABAB", which is a balanced string, since the number of occurrences of 'A' is equal to the number of occurrences of 'B'. Example case 2: We can change 'C' to 'B' to make the string "BBB", which is a balanced string.
{"inputs": ["2\nABCB\nBBC"], "outputs": ["1\n1"]}
452
19
coding
Solve the programming task below in a Python markdown code block. When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read the i-th book. Valera decided to choose an arbitrary book with number i and read the books one by one, starting from this book. In other words, he will first read book number i, then book number i + 1, then book number i + 2 and so on. He continues the process until he either runs out of the free time or finishes reading the n-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it. Print the maximum number of books Valera can read. -----Input----- The first line contains two integers n and t (1 ≤ n ≤ 10^5; 1 ≤ t ≤ 10^9) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^4), where number a_{i} shows the number of minutes that the boy needs to read the i-th book. -----Output----- Print a single integer — the maximum number of books Valera can read. -----Examples----- Input 4 5 3 1 2 1 Output 3 Input 3 3 2 2 3 Output 1
{"inputs": ["1 3\n5\n", "1 3\n5\n", "1 10\n4\n", "1 10\n4\n", "2 10\n6 4\n", "2 10\n6 4\n", "2 10\n6 6\n", "2 11\n6 6\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "2\n", "2\n", "1\n", "1\n"]}
381
116
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array heights representing the heights of buildings, some bricks, and some ladders. You start your journey from building 0 and move to the next building by possibly using bricks or ladders. While moving from building i to building i+1 (0-indexed), If the current building's height is greater than or equal to the next building's height, you do not need a ladder or bricks. If the current building's height is less than the next building's height, you can either use one ladder or (h[i+1] - h[i]) bricks. Return the furthest building index (0-indexed) you can reach if you use the given ladders and bricks optimally.   Please complete the following python code precisely: ```python class Solution: def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(heights = [4,2,7,6,9,14,12], bricks = 5, ladders = 1) == 4\n assert candidate(heights = [4,12,2,7,3,18,20,3,19], bricks = 10, ladders = 2) == 7\n assert candidate(heights = [14,3,19,3], bricks = 17, ladders = 0) == 3\n\n\ncheck(Solution().furthestBuilding)"}
203
136
coding
Solve the programming task below in a Python markdown code block. ## Task Your challenge is to write a function named `getSlope`/`get_slope`/`GetSlope` that calculates the slope of the line through two points. ## Input ```if:javascript,python Each point that the function takes in is an array 2 elements long. The first number is the x coordinate and the second number is the y coordinate. If the line through the two points is vertical or if the same point is given twice, the function should return `null`/`None`. ``` ```if:csharp `GetSlope` will take in two Point objects. If the line through the two points is vertical, or the two points are the same, return `null`. The Point object: ~~~ public class Point : System.Object { public double X; public double Y; public Point(double x, double y) { this.X = x; this.Y = y; } public override string ToString() { return $"({this.X}, {this.Y})"; } public override bool Equals(object point) { // Typechecking if (point == null || point.GetType() != this.GetType()) { return false; } return this.ToString() == point.ToString(); } } ~~~ ``` Also feel free to reuse/extend the following starter code: ```python def getSlope(p1, p2): ```
{"functional": "_inputs = [[[1, 1], [2, 2]], [[-5, -5], [9, 9]], [[1, 8], [2, 9]], [[8, 3], [-4, 5]], [[5, 3], [8, 9]], [[1, 3], [0, 3]], [[11, 1], [1, 11]], [[1, 1], [1, 2]], [[-5, 9], [-5, 12]], [[1, 1], [1, 1]], [[-5, 9], [-5, 9]]]\n_outputs = [[1], [1], [1], [-0.16666666666666666], [2], [0], [-1], [None], [None], [None], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_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(getSlope(*i), o[0])"}
315
338
coding
Solve the programming task below in a Python markdown code block. Chef is in need of money, so he decided to play a game with Ramsay. In this game, there are $N$ rows of coins (numbered $1$ through $N$). For each valid $i$, the $i$-th row contains $C_i$ coins with values $A_{i, 1}, A_{i, 2}, \ldots, A_{i, C_i}$. Chef and Ramsay alternate turns; Chef plays first. In each turns, the current player can choose one row that still contains coins and take one of the coins remaining in this row. Chef may only take the the first (leftmost) remaining coin in the chosen row, while Ramsay may only take the last (rightmost) remaining coin in the chosen row. The game ends when there are no coins left. Each player wants to maximise the sum of values of the coins he took. Assuming that both Chef and Ramsay play optimally, what is the maximum amount of money (sum of values of coins) Chef can earn through this game? -----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$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains an integer $C_i$, followed by a space and $C_i$ space-separated integers $A_{i, 1}, A_{i, 2}, \ldots, A_{i, C_i}$. -----Output----- For each test case, print a single line containing one integer ― the maximum amount of money Chef can earn. -----Constraints----- - $1 \le T \le 10$ - $1 \le N \le 10^4$ - $1 \le C_i \le 10$ for each valid $i$ - $1 \le A_{i, j} \le 10^5$ for each valid $i$ and $j$ -----Subtasks----- Subtask #1 (20 points): $N = 1$ Subtask #2 (80 points): original constraints -----Example Input----- 1 2 4 5 2 3 4 2 1 6 -----Example Output----- 8 -----Explanation----- Example case 1: One optimal sequence of moves is: Chef takes the coin with value $5$, Ramsay takes $4$, Chef takes $2$, Ramsay takes $3$, Chef takes $1$ and Ramsay takes $6$. At the end, Chef has $5+2+1 = 8$ units of money.
{"inputs": ["1\n2\n4 5 2 3 4\n2 1 6"], "outputs": ["8"]}
589
30
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef has recently got a broadband internet connection. His history of internet data usage is provided as below. During the first T_{1} minutes, the internet data used was D_{1} MBs per minute, and during the next T_{2} minutes, it was D_{2} MBs per minute, and so on till during last T_{N} minutes it was D_{N} MBs per minute. The internet provider charges the Chef 1 dollar for every 1 MB data used, except for the first K minutes, when the internet data is free as part of the plan provided to Chef. Please find out the total amount that Chef has to pay the internet provider (in dollars). ------ Input ------ First line of the input contains a single integer TC the number of test cases. Description of TC test cases follow. First line of each test case contains two space separated integers N and K. Next N lines of each test case contains information about the internet data usage. Specifically, in the i-th line, there will be two space separated integers: T_{i} and D_{i}. ------ Output ------ For each test case output a single integer in separate line, the amount that Chef has to pay in dollars. ------ Constraints ------ $1 ≤ TC ≤ 1,000$ $1 ≤ N ≤ 10$ $0 ≤ K ≤ T_{1} + T_{2} + ... + T_{N} $ $1 ≤ T_{i}, D_{i} ≤ 10$ ----- Sample Input 1 ------ 3 2 2 2 1 2 3 2 2 1 2 2 3 3 0 1 2 2 4 10 10 ----- Sample Output 1 ------ 6 3 110 ----- explanation 1 ------ Example case 1. For the first two minutes, internet data of usage of Chef is free. He has to pay for last 2 minutes only, for which he will be charged at 3 dollars per minute, i.e. total 6 dollars. Example case 2. For the first two minutes, internet data of usage of Chef is free. He has to pay for last 1 minute only, for which he is being charged at 3 dollars per minute. So, in total he has to pay 3 dollars. Example case 3. This time, Chef is not provided any free data usage. He has to pay for entire data usage, which comes out to be 1 * 2 + 2 * 4 + 10 * 10 = 110 dollars.
{"inputs": ["3\n2 2\n2 1\n2 3\n2 2\n1 2\n2 3\n3 0\n1 2\n2 4\n10 10"], "outputs": ["6\n3\n110"]}
580
60
coding
Solve the programming task below in a Python markdown code block. A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway. A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well. The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top. All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like, The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top. Input The first line contains three integers r, g and b (0 ≤ r, g, b ≤ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student. Output Print a single number — the minimal time the students need for the whole group to ascend to the top of the mountain. Examples Input 1 3 2 Output 34 Input 3 2 1 Output 33 Note Let's analyze the first sample. At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30. At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31. At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32. At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty. At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34. Thus, all the students are on the top, overall the ascension took exactly 34 minutes.
{"inputs": ["1 2 2\n", "1 2 1\n", "2 0 0\n", "2 1 1\n", "0 2 1\n", "5 4 5\n", "2 0 2\n", "2 1 2\n"], "outputs": ["32", "32", "30", "32", "32", "38", "32", "32"]}
625
102
coding
Solve the programming task below in a Python markdown code block. You are given a string S of length N, containing lowercase Latin letters. You are also given an integer K. You would like to create a new string S' by following the following process: First, partition S into exactly K non-empty [subsequences] S_{1}, S_{2}, \ldots, S_{K}. Note that every character of S must be present in exactly one of the S_{i}. Then, create S' as the concatenation of these subsequences, i.e, S' = S_{1} + S_{2} + \ldots + S_{K}, where + denotes string concatenation. Determine the lexicographically smallest S' that can be created. ------ Input Format ------ - The first line of 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 two space-separated integers, N and K. - The second line of each test case contains the string S. ------ Output Format ------ For each test case, output on a new line the lexicographically smallest string S' that can be created. ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ N$ $S$ contains only lowercase Latin letters. - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 6 1 whizzy 14 2 aaacdecdebacde 4 3 dbca ----- Sample Output 1 ------ whizzy aaaaccdecdebde abcd ----- explanation 1 ------ Test Case $1$: $K = 1$, so our only option is to set $S' = S_{1} = whizzy$. Test Case $2$: Partition $S = \textcolor{red}{aaa}\textcolor{blue}{cdecdeb}\textcolor{red}{ac}\textcolor{blue}{de}$ into $S_{1} = \textcolor{red}{aaaac}$ and $S_{2} = \textcolor{blue}{cdecdebde}$, to form $S' = aaaaccdecdebde$. Test Case $3$: Partition $S = d\textcolor{blue}{bc}\textcolor{red}{a}$ into $S_{1} = \textcolor{red}{a}$, $S_{2} = \textcolor{blue}{bc}$, and $S_{3} = d$ to form $S' = abcd$. In both test cases $2$ and $3$, it can be shown that no other partition gives a lexicographically smaller $S'$.
{"inputs": ["3\n6 1\nwhizzy\n14 2\naaacdecdebacde\n4 3\ndbca\n"], "outputs": ["whizzy\naaaaccdecdebde\nabcd"]}
598
49
coding
Solve the programming task below in a Python markdown code block. The summer is at its peak in Chefland. Chef is planning to purchase a water cooler to keep his room cool. He has two options available: Rent a cooler at the cost of X coins per month. Purchase a cooler for Y coins. Chef wonders what is the maximum number of months for which he can rent the cooler such that the cost of renting is strictly less than the cost of purchasing it. ------ Input Format ------ - The first line of input will contain an integer T — the number of test cases. The description of T test cases follows. - The first and only line of each test case contains two integers X and Y, as described in the problem statement. ------ Output Format ------ For each test case, output the maximum number of months for which he can rent the cooler such that the cost of renting is strictly less than the cost of purchasing it. If Chef should not rent a cooler at all, output 0. ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤ X, Y ≤ 10^{9}$ ----- Sample Input 1 ------ 2 5 12 5 5 ----- Sample Output 1 ------ 2 0 ----- explanation 1 ------ Test case $1$: Cost of renting the cooler $= 5$ coins per month. Cost of purchasing the cooler $= 12$ coins. So, Chef can rent the cooler for $2$ months at the cost of $10$ coins, which is strictly less than $12$ coins. Test case $2$: Cost of renting the cooler $= 5$ coins per month. Cost of purchasing the cooler $= 5$ coins. If Chef rents the cooler for $1$ month, it will cost $5$ coins, which is not strictly less than the cost of purchasing it. So, Chef should not rent the cooler.
{"inputs": ["2\n5 12\n5 5"], "outputs": ["2\n0"]}
406
23
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have some apples and a basket that can carry up to 5000 units of weight. Given an integer array weight where weight[i] is the weight of the ith apple, return the maximum number of apples you can put in the basket.   Please complete the following python code precisely: ```python class Solution: def maxNumberOfApples(self, weight: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(weight = [100,200,150,1000]) == 4\n assert candidate(weight = [900,950,800,1000,700,800]) == 5\n\n\ncheck(Solution().maxNumberOfApples)"}
101
83
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin Chinese] and [Bengali]. Given n (n is even), determine the number of black cells in an n \times n chessboard. ------ Input Format ------ The only line of the input contains a single integer n. ------ Output Format ------ Output the number of black cells in an n \times n chessboard. ------ Constraints ------ $2 ≤ n ≤ 100$ $n$ is even ----- Sample Input 1 ------ 8 ----- Sample Output 1 ------ 32 ----- explanation 1 ------ There are $32$ black cells and $32$ white cells in an $8 \times 8$ chessboard. So the answer is $32$.
{"inputs": ["8"], "outputs": ["32"]}
168
13
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n binary matrix grid. A move consists of choosing any row or column and toggling each value in that row or column (i.e., changing all 0's to 1's, and all 1's to 0's). Every row of the matrix is interpreted as a binary number, and the score of the matrix is the sum of these numbers. Return the highest possible score after making any number of moves (including zero moves).   Please complete the following python code precisely: ```python class Solution: def matrixScore(self, grid: List[List[int]]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(grid = [[0,0,1,1],[1,0,1,0],[1,1,0,0]]) == 39\n assert candidate(grid = [[0]]) == 1\n\n\ncheck(Solution().matrixScore)"}
144
66
coding
Solve the programming task below in a Python markdown code block. Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to $120^{\circ}$. Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it. He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles. -----Input----- The first and the single line of the input contains 6 space-separated integers a_1, a_2, a_3, a_4, a_5 and a_6 (1 ≤ a_{i} ≤ 1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists. -----Output----- Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split. -----Examples----- Input 1 1 1 1 1 1 Output 6 Input 1 2 1 2 1 2 Output 13 -----Note----- This is what Gerald's hexagon looks like in the first sample: $\theta$ And that's what it looks like in the second sample: $A$
{"inputs": ["1 1 1 1 1 1\n", "1 2 1 2 1 2\n", "2 4 5 3 3 6\n", "7 5 4 8 4 5\n", "3 2 1 4 1 2\n", "7 1 7 3 5 3\n", "9 2 9 3 8 3\n", "1 6 1 5 2 5\n"], "outputs": ["6\n", "13\n", "83\n", "175\n", "25\n", "102\n", "174\n", "58\n"]}
352
160
coding
Solve the programming task below in a Python markdown code block. A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≤ b, he or she likes it if and only if he can climb into this car and 2a ≥ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. -----Input----- You are given four integers V_1, V_2, V_3, V_{m}(1 ≤ V_{i} ≤ 100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V_1 > V_2 > V_3. -----Output----- Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). -----Examples----- Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 -----Note----- In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
{"inputs": ["3 2 1 1\n", "5 4 3 1\n", "4 3 2 1\n", "98 2 1 1\n", "27 3 2 3\n", "13 7 6 2\n", "15 6 4 5\n", "21 3 1 3\n"], "outputs": ["4\n3\n1\n", "-1\n", "4\n3\n2\n", "98\n3\n1\n", "-1\n", "-1\n", "15\n11\n5\n", "-1\n"]}
429
142
coding
Solve the programming task below in a Python markdown code block. You will be given a fruit which a farmer has harvested, your job is to see if you should buy or sell. You will be given 3 pairs of fruit. Your task is to trade your harvested fruit back into your harvested fruit via the intermediate pair, you should return a string of 3 actions. if you have harvested apples, you would buy this fruit pair: apple_orange, if you have harvested oranges, you would sell that fruit pair. (In other words, to go from left to right (apples to oranges) you buy, and to go from right to left you sell (oranges to apple)) e.g. apple_orange, orange_pear, apple_pear 1. if you have harvested apples, you would buy this fruit pair: apple_orange 2. Then you have oranges, so again you would buy this fruit pair: orange_pear 3. After you have pear, but now this time you would sell this fruit pair: apple_pear 4. Finally you are back with the apples So your function would return a list: [“buy”,”buy”,”sell”] If any invalid input is given, "ERROR" should be returned Also feel free to reuse/extend the following starter code: ```python def buy_or_sell(pairs, harvested_fruit): ```
{"functional": "_inputs = [[[['apple', 'orange'], ['orange', 'pear'], ['apple', 'pear']], 'apple'], [[['orange', 'apple'], ['orange', 'pear'], ['pear', 'apple']], 'apple'], [[['apple', 'orange'], ['pear', 'orange'], ['apple', 'pear']], 'apple'], [[['orange', 'apple'], ['pear', 'orange'], ['pear', 'apple']], 'apple'], [[['orange', 'apple'], ['orange', 'pear'], ['apple', 'pear']], 'apple'], [[['apple', 'orange'], ['pear', 'orange'], ['pear', 'apple']], 'apple'], [[['apple', 'orange'], ['orange', 'pear'], ['pear', 'apple']], 'apple'], [[['orange', 'apple'], ['pear', 'orange'], ['apple', 'pear']], 'apple'], [[['orange', 'apple'], ['pear', 'orange'], ['apple', 'paer']], 'apple']]\n_outputs = [[['buy', 'buy', 'sell']], [['sell', 'buy', 'buy']], [['buy', 'sell', 'sell']], [['sell', 'sell', 'buy']], [['sell', 'buy', 'sell']], [['buy', 'sell', 'buy']], [['buy', 'buy', 'buy']], [['sell', 'sell', 'sell']], ['ERROR']]\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(buy_or_sell(*i), o[0])"}
286
425
coding
Solve the programming task below in a Python markdown code block. Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems. The boy has found an online judge with tasks divided by topics they cover. He has picked $p^{k_i}$ problems from $i$-th category ($p$ is his favorite number). He wants to solve them in two weeks (the patience condition is too hard for Johnny, so for simplicity, he looks only at easy tasks, which can be solved in such a period). Now our future grandmaster has to decide which topics to cover first and which the second week. Help him assign topics in such a way, that workload is balanced. Formally, given $n$ numbers $p^{k_i}$, the boy wants to divide them into two disjoint sets, minimizing the absolute difference between sums of numbers in each set. Find the minimal absolute difference. Output the result modulo $10^{9}+7$. -----Input----- Input consists of multiple test cases. The first line contains one integer $t$ $(1 \leq t \leq 10^5)$ — the number of test cases. Each test case is described as follows: The first line contains two integers $n$ and $p$ $(1 \leq n, p \leq 10^6)$. The second line contains $n$ integers $k_i$ $(0 \leq k_i \leq 10^6)$. The sum of $n$ over all test cases doesn't exceed $10^6$. -----Output----- Output one integer — the reminder of division the answer by $1\,000\,000\,007$. -----Example----- Input 4 5 2 2 3 4 4 3 3 1 2 10 1000 4 5 0 1 1 100 1 8 89 Output 4 1 146981438 747093407 -----Note----- You have to minimize the difference, not it's remainder. For example, if the minimum difference is equal to $2$, but there is also a distribution where the difference is $10^9 + 8$, then the answer is $2$, not $1$. In the first test case of the example, there're the following numbers: $4$, $8$, $16$, $16$, and $8$. We can divide them into such two sets: ${4, 8, 16}$ and ${8, 16}$. Then the difference between the sums of numbers in sets would be $4$.
{"inputs": ["1\n1 2\n88\n", "1\n1 2\n88\n", "1\n1 3\n88\n", "1\n1 2\n70\n", "1\n1 5\n88\n", "1\n1 3\n103\n", "1\n1 3\n198\n", "1\n1 1\n103\n"], "outputs": ["140130951\n", "140130951\n", "772681989\n", "270016253\n", "467137716\n", "923126036\n", "792924246\n", "1\n"]}
613
185
coding
Solve the programming task below in a Python markdown code block. Ma5termind is going through the Euler's book of knowledge when he finds the following function: def function(L,R): sum=0 for i in range(L,R+1): #[L,R] for j in range(1,i+1): #[1,i] cnt=0 if (j)*(j+1) == 2*i : for k in range(1,i+1): #[1,i] if __gcd(k,i)==1: #__gcd Greatest Common Divisor cnt+=1 sum=sum+cnt return sum The function seems weird as well as interesting. Don't you think ?? Fascinated by the function, Ma5termind codes it and successfully compiles it in the first go itself. After all, he is a good coder. Ma5termind checks the output computed by the function for all the values of $\mathbf{L}$ and $\mathbf{R}$ in the range $\mathbf{[1,100]}$ and finds that the results are correct. But as we all know, Ma5termind loves large numbers - very large numbers. When he inputs $\mathbf{L=1}$ & $\mathbf{R=10^{12}}$, the code does not produce any output #TimeLimitExceeded. He still wants to know the answer for such large ranges. Can you help him by writing a code that can also produce an answer for such large ranges? Input Format First line of input contains a single integer $\mathbf{T}$ denoting the number of test cases. First and the only line of each test case contains two space separated integers $\mathbf{L}$ and $\mathbf{R}$ denoting inputs to the above function. Output Format Output consists of $\mathbf{T}$ lines each containing result computed by the function when corresponding range is inputted to the function. Constraints $\mathbf{1\leq T\leq10^5}$ $\mathbf{1\leq L\leq R\leq10^{12}}$ Sample Input 2 1 10 2 5 Sample Output 9 2 Explanation Pass Parameters to the function and check the result.
{"inputs": ["2\n1 10\n2 5\n"], "outputs": ["9\n2\n"]}
495
25
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef lives in Chefcity. Chefcity can be represented as a straight line with Chef's house at point 0 on this line. There is an infinite number of subway stations in Chefcity, numbered by positive integers. The first station is located at point 1 and for each i ≥ 1, the distance between stations i and i+1 is equal to i+1. (Station i+1 is always located at a higher coordinate than station i, i.e., the subway stations are located at points 1, 3, 6, 10, 15 etc.) Subway trains in Chefcity allow Chef to move between any pair of adjacent stations in one minute, regardless of the distance between them. Chef can also move by walking; his walking speed is one unit of distance in one minute. Chef can enter or exit the subway at any station. Chef has decided to go to the cinema. The only cinema in Chefcity is located at point X. (Note that the cinema can be placed at the same point as a subway station.) Help Chef determine the minimum possible time required to get to the cinema from his house. ------ 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 and only line of each test case contains a single integer X. ------ Output ------ For each test case, print a single line containing one integer - the minimum possible travel time. ------ Constraints ------ $1 ≤ T ≤ 200$ $1 ≤ X ≤ 10^{9}$ ----- Sample Input 1 ------ 4 1 2 3 9 ----- Sample Output 1 ------ 1 2 2 5 ----- explanation 1 ------ Example case 4: Chef will walk from x = 0 to x = 1 in one minute, then he will enter the subway and move from station 1 (at x = 1) to station 2 (at x = 3) in one minute, then from station 2 to station 3 (at x = 6) in one minute, from station 3 to station 4 (at x = 10) in one minute, and finally, he will walk from x = 10 to x = 9 in one minute, which makes the total travel time 5 minutes.
{"inputs": ["4\n1\n2\n3\n9"], "outputs": ["1\n2\n2\n5"]}
525
26
coding
Solve the programming task below in a Python markdown code block. There are N different types of colours numbered from 1 to N. Chef has A_{i} balls having colour i, (1≤ i ≤ N). Chef will arrange some boxes and put each ball in exactly one of those boxes. Find the minimum number of boxes Chef needs so that no box contains two balls of same colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. The description of the test cases follows. - The first line of each test case contains a single integer N, denoting the number of colors. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} — denoting the number of balls having colour i. ------ Output Format ------ For each test case, output the minimum number of boxes required so that no box contains two balls of same colour. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 100$ $1 ≤ A_{i} ≤ 10^{5}$ ----- Sample Input 1 ------ 3 2 8 5 3 5 10 15 4 4 4 4 4 ----- Sample Output 1 ------ 8 15 4 ----- explanation 1 ------ Test case $1$: Chef needs at least $8$ boxes such that no box has two balls of same colour. A possible configuration of the $8$ boxes would be $\{[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1], [1], [1]\}$ where the $i^{th}$ element of this set denotes the colour of balls in the $i^{th}$ box. Test case $2$: Chef needs at least $15$ boxes such that no box has two balls of same colour. Test case $3$: Chef needs at least $4$ boxes such that no box has two balls of same colour. A possible configuration of the $4$ boxes would be $\{[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]\}$ where the $i^{th}$ element of this set denotes the colour of balls in the $i^{th}$ box.
{"inputs": ["3\n2\n8 5\n3\n5 10 15\n4\n4 4 4 4\n"], "outputs": ["8\n15\n4\n"]}
537
45
coding
Solve the programming task below in a Python markdown code block. Taro's summer vacation starts tomorrow, and he has decided to make plans for it now. The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day: * A: Swim in the sea. Gain a_i points of happiness. * B: Catch bugs in the mountains. Gain b_i points of happiness. * C: Do homework at home. Gain c_i points of happiness. As Taro gets bored easily, he cannot do the same activities for two or more consecutive days. Find the maximum possible total points of happiness that Taro gains. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq a_i, b_i, c_i \leq 10^4 Input Input is given from Standard Input in the following format: N a_1 b_1 c_1 a_2 b_2 c_2 : a_N b_N c_N Output Print the maximum possible total points of happiness that Taro gains. Examples Input 3 10 40 70 20 50 80 30 60 90 Output 210 Input 1 100 10 1 Output 100 Input 7 6 7 8 8 8 3 2 5 2 7 8 6 4 6 8 2 3 4 7 5 1 Output 46
{"inputs": ["1\n110 1 0", "1\n010 3 0", "1\n011 3 1", "1\n001 3 0", "1\n001 4 0", "1\n001 6 0", "1\n000 2 0", "1\n100 16 1"], "outputs": ["110\n", "10\n", "11\n", "3\n", "4\n", "6\n", "2\n", "100\n"]}
365
133
coding
Solve the programming task below in a Python markdown code block. Consider an array containing cats and dogs. Each dog can catch only one cat, but cannot catch a cat that is more than `n` elements away. Your task will be to return the maximum number of cats that can be caught. For example: ```Haskell solve(['D','C','C','D','C'], 2) = 2, because the dog at index 0 (D0) catches C1 and D3 catches C4. solve(['C','C','D','D','C','D'], 2) = 3, because D2 catches C0, D3 catches C1 and D5 catches C4. solve(['C','C','D','D','C','D'], 1) = 2, because D2 catches C1, D3 catches C4. C0 cannot be caught because n == 1. solve(['D','C','D','D','C'], 1) = 2, too many dogs, so all cats get caught! ``` Do not modify the input array. More examples in the test cases. Good luck! Also feel free to reuse/extend the following starter code: ```python def solve(arr,n): ```
{"functional": "_inputs = [[['D', 'C', 'C', 'D', 'C'], 1], [['C', 'C', 'D', 'D', 'C', 'D'], 2], [['C', 'C', 'D', 'D', 'C', 'D'], 1], [['D', 'C', 'D', 'C', 'C', 'D'], 3], [['C', 'C', 'C', 'D', 'D'], 3], [['C', 'C', 'C', 'D', 'D'], 2], [['C', 'C', 'C', 'D', 'D'], 1], [['C', 'C', 'C', 'D', 'D', 'D', 'C', 'D', 'D', 'D', 'C', 'D', 'C', 'C'], 2]]\n_outputs = [[2], [3], [2], [3], [2], [2], [1], [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(solve(*i), o[0])"}
263
353
coding
Solve the programming task below in a Python markdown code block. Take an integer `n (n >= 0)` and a digit `d (0 <= d <= 9)` as an integer. Square all numbers `k (0 <= k <= n)` between 0 and n. Count the numbers of digits `d` used in the writing of all the `k**2`. Call `nb_dig` (or nbDig or ...) the function taking `n` and `d` as parameters and returning this count. #Examples: ``` n = 10, d = 1, the k*k are 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 We are using the digit 1 in 1, 16, 81, 100. The total count is then 4. nb_dig(25, 1): the numbers of interest are 1, 4, 9, 10, 11, 12, 13, 14, 19, 21 which squared are 1, 16, 81, 100, 121, 144, 169, 196, 361, 441 so there are 11 digits `1` for the squares of numbers between 0 and 25. ``` Note that `121` has twice the digit `1`. Also feel free to reuse/extend the following starter code: ```python def nb_dig(n, d): ```
{"functional": "_inputs = [[5750, 0], [11011, 2], [12224, 8], [11549, 1], [14550, 7], [8304, 7], [10576, 9], [12526, 1], [7856, 4], [14956, 1]]\n_outputs = [[4700], [9481], [7733], [11905], [8014], [3927], [7860], [13558], [7132], [17267]]\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(nb_dig(*i), o[0])"}
365
309
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef likes to write poetry. Today, he has decided to write a X pages long poetry, but unfortunately his notebook has only Y pages left in it. Thus he decided to buy a new CHEFMATE notebook and went to the stationary shop. Shopkeeper showed him some N notebooks, where the number of pages and price of the i^{th} one are P_{i} pages and C_{i} rubles respectively. Chef has spent some money preparing for Ksen's birthday, and then he has only K rubles left for now. Chef wants to buy a single notebook such that the price of the notebook should not exceed his budget and he is able to complete his poetry. Help Chef accomplishing this task. You just need to tell him whether he can buy such a notebook or not. Note that Chef can use all of the Y pages in the current notebook, and Chef can buy only one notebook because Chef doesn't want to use many notebooks. ------ Input ------ The first line of input contains an integer T, denoting the number of test cases. Then T test cases are follow. The first line of each test case contains four space-separated integers X, Y, K and N, described in the statement. The i^{th} line of the next N lines contains two space-separated integers P_{i} and C_{i}, denoting the number of pages and price of the i^{th} notebook respectively. ------ Output ------ For each test case, Print "LuckyChef" if Chef can select such a notebook, otherwise print "UnluckyChef" (quotes for clarity). ------ ------ Constraints ----- $1 ≤ T ≤ 10^{5}$ $1 ≤ Y < X ≤ 10^{3}$ $1 ≤ K ≤ 10^{3}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ P_{i}, C_{i} ≤ 10^{3}$ Subtask 1: 40 points $Sum of N over all test cases in one test file does not exceed 10^{4}.$ Subtask 2: 60 points $Sum of N over all test cases in one test file does not exceed 10^{6}.$ ----- Sample Input 1 ------ 3 3 1 2 2 3 4 2 2 3 1 2 2 2 3 2 3 3 1 2 2 1 1 1 2 ----- Sample Output 1 ------ LuckyChef UnluckyChef UnluckyChef ----- explanation 1 ------ Example case 1. In this case, Chef wants to write X = 3 pages long poetry, but his notebook has only Y = 1 page. And his budget is K = 2 rubles, and there are N = 2 notebooks in the shop. The first notebook has P1 = 3 pages, but Chef cannot buy it, because its price is C1 = 4 rubles. The second notebook has P2 = 2 pages, and its price is C2 = 2 rubles. Thus Chef can select the second notebook to accomplish the task. He will write 1 page of poetry in the old notebook, and 2 page of poetry in the new notebook. Example case 2. Chef cannot buy any notebook, because the prices exceed the Chef's budget. Example case 3. No notebook contains sufficient number of pages required to write poetry.
{"inputs": ["3\n3 1 2 2\n3 4\n2 2 \n3 1 2 2\n2 3\n2 3 \n3 1 2 2\n1 1\n1 2"], "outputs": ["LuckyChef\nUnluckyChef\nUnluckyChef"]}
753
76
coding
Solve the programming task below in a Python markdown code block. HackerRank-city is an acyclic connected graph (or tree). Its not an ordinary place, the construction of the whole tree takes place in $N$ steps. The process is described below: It initially has $\mbox{1}$ node. At each step, you must create $3$ duplicates of the current tree, and create $2$ new nodes to connect all $\begin{array}{c}4\end{array}$ copies in the following H shape: At each $i^{\mbox{th}}$ step, the tree becomes $\begin{array}{c}4\end{array}$ times bigger plus $2$ new nodes, as well as $5$ new edges connecting everything together. The length of the new edges being added at step $\boldsymbol{i}$ is denoted by input $A_i$. Calculate the sum of distances between each pair of nodes; as these answers may run large, print your answer modulo $\textbf{1000000007}$. Input Format The first line contains an integer, $N$ (the number of steps). The second line contains $N$ space-separated integers describing $\boldsymbol{A_0}$, $A_1,\ldots,A_{N-2},A_{N-1}$. Constraints $1\leq N\leq10^6$ $1\leq A_i\leq9$ Subtask For $50\%$ score $1\leq N\leq10$ Output Format Print the sum of distances between each pair of nodes modulo $\textbf{1000000007}$. Sample Input 0 1 1 Sample Output 0 29 Sample Input 1 2 2 1 Sample Output 1 2641 Explanation Sample 0 In this example, our tree looks like this: Let $d(u,v)$ denote the distance between nodes $\mbox{u}$ and $\boldsymbol{\nu}$. $d(1,2)+d(1,3)+d(1,4)+d(1,5)+d(1,6)$ $+d(2,3)+d(2,4)+d(2,5)+d(2,6)+d(3,4)$ $+d(3,5)+d(3,6)+d(4,5)+d(4,6)+d(5,6)=$ $3+1+2+2+3+2+1+3+2+1+1+2+2+1+3=29$. We print the result of $29\{%10000007$ as our answer. Sample 1 In this example, our tree looks like this: We calculate and sum the distances between nodes in the same manner as Sample 0 above, and print the result of our $answer\% 10000007}$, which is $2641$.
{"inputs": ["1\n1\n", "2\n2 1\n"], "outputs": ["29\n", "2641\n"]}
661
32
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of strings strs. You could concatenate these strings together into a loop, where for each string, you could choose to reverse it or not. Among all the possible loops Return the lexicographically largest string after cutting the loop, which will make the looped string into a regular one. Specifically, to find the lexicographically largest string, you need to experience two phases: Concatenate all the strings into a loop, where you can reverse some strings or not and connect them in the same order as given. Cut and make one breakpoint in any place of the loop, which will make the looped string into a regular one starting from the character at the cutpoint. And your job is to find the lexicographically largest one among all the possible regular strings.   Please complete the following python code precisely: ```python class Solution: def splitLoopedString(self, strs: List[str]) -> str: ```
{"functional": "def check(candidate):\n assert candidate(strs = [\"abc\",\"xyz\"]) == \"zyxcba\"\n assert candidate(strs = [\"abc\"]) == \"cba\"\n\n\ncheck(Solution().splitLoopedString)"}
210
57
coding
Solve the programming task below in a Python markdown code block. Your task is to calculate the distance between two $n$ dimensional vectors $x = \\{x_1, x_2, ..., x_n\\}$ and $y = \\{y_1, y_2, ..., y_n\\}$. The Minkowski's distance defined below is a metric which is a generalization of both the Manhattan distance and the Euclidean distance. \\[ D_{xy} = (\sum_{i=1}^n |x_i - y_i|^p)^{\frac{1}{p}} \\] It can be the Manhattan distance \\[ D_{xy} = |x_1 - y_1| + |x_2 - y_2| + ... + |x_n - y_n| \\] where $p = 1 $. It can be the Euclidean distance \\[ D_{xy} = \sqrt{(|x_1 - y_1|)^{2} + (|x_2 - y_2|)^{2} + ... + (|x_n - y_n|)^{2}} \\] where $p = 2 $. Also, it can be the Chebyshev distance \\[ D_{xy} = max_{i=1}^n (|x_i - y_i|) \\] where $p = \infty$ Write a program which reads two $n$ dimensional vectors $x$ and $y$, and calculates Minkowski's distance where $p = 1, 2, 3, \infty$ respectively. Constraints * $1 \leq n \leq 100$ * $0 \leq x_i, y_i \leq 1000$ Input In the first line, an integer $n$ is given. In the second and third line, $x = \\{x_1, x_2, ... x_n\\}$ and $y = \\{y_1, y_2, ... y_n\\}$ are given respectively. The elements in $x$ and $y$ are given in integers. Output Print the distance where $p = 1, 2, 3$ and $\infty$ in a line respectively. The output should not contain an absolute error greater than 10-5. Example Input 3 1 2 3 2 0 4 Output 4.000000 2.449490 2.154435 2.000000
{"inputs": ["3\n2 2 3\n2 0 4", "3\n1 2 3\n2 0 4", "3\n2 2 3\n2 -1 4", "3\n2 4 5\n2 -1 4", "3\n3 4 5\n2 -1 4", "3\n6 4 5\n2 -1 4", "3\n6 5 5\n2 -1 4", "3\n6 5 5\n2 -1 3"], "outputs": ["3.000000\n2.236068\n2.080084\n2.000000\n", "4.000000\n2.449490\n2.154435\n2.000000", "4.000000\n3.162278\n3.036589\n3.000000\n", "6.000000\n5.099020\n5.013298\n5.000000\n", "7.000000\n5.196152\n5.026526\n5.000000\n", "10.000000\n6.480741\n5.748897\n5.000000\n", "11.000000\n7.280110\n6.549912\n6.000000\n", "12.000000\n7.483315\n6.603854\n6.000000\n"]}
554
432
coding
Solve the programming task below in a Python markdown code block. Read problems statements [Hindi] , [Vietnamese] , [Mandarin Chinese] , [Russian] and [Bengali] as well. "Every beginning has an end... and an editorial." - taran_{1407} What the hell are all these interactive problems? What does flushing output mean? So many questions... Chef explains it in an easy way: you must communicate with a grader program, which accepts your input only if you flushed the output. There is a contest with interactive problems where $N$ people participate. Each contestant has a known rating. Chef wants to know which contestants will not forget to flush the output in interactive problems. Fortunately, he knows that contestants with rating at least $r$ never forget to flush their output and contestants with rating smaller than $r$ always forget to do it. Help Chef! ------ Input ------ The first line of the input contains two space-separated integers $N$ and $r$. Each of the following $N$ lines contains a single integer $R$ denoting the rating of one contestant. ------ Output ------ For each contestant, print a single line containing the string "Good boi" if this contestant does not forget to flush the output or "Bad boi" otherwise. ------ Constraints ------ $1 ≤ N ≤ 1,000$ $1,300 ≤ r, R ≤ 1,501$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 2 1500 1499 1501 ----- Sample Output 1 ------ Bad boi Good boi
{"inputs": ["2 1500\n1499\n1501"], "outputs": ["Bad boi\nGood boi"]}
366
33
coding
Solve the programming task below in a Python markdown code block. Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) and the system counts the score. The number of points you score equals to the length of the maximum sequence of cubes of the same color that follow consecutively. Write a program that determines the maximum possible number of points you can score. Remember, you may delete no more than k any cubes. It is allowed not to delete cubes at all. Input The first line contains three integers n, m and k (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 105, 0 ≤ k < n). The second line contains n integers from 1 to m — the numbers of cube colors. The numbers of colors are separated by single spaces. Output Print the maximum possible number of points you can score. Examples Input 10 3 2 1 2 1 1 3 2 1 1 2 2 Output 4 Input 10 2 2 1 2 1 2 1 1 2 1 1 2 Output 5 Input 3 1 2 1 1 1 Output 3 Note In the first sample you should delete the fifth and the sixth cubes. In the second sample you should delete the fourth and the seventh cubes. In the third sample you shouldn't delete any cubes.
{"inputs": ["1 1 0\n1\n", "3 1 2\n1 1 1\n", "10 2 2\n1 1 1 2 1 2 1 2 1 1\n", "10 2 2\n1 2 1 2 1 1 2 1 1 2\n", "10 3 2\n1 2 1 1 3 2 1 1 2 2\n", "20 6 3\n4 1 2 6 3 3 2 5 2 5 2 1 1 4 1 2 2 1 1 4\n", "20 2 5\n2 2 1 2 1 2 1 2 1 1 2 1 2 2 1 2 2 1 2 1\n", "20 3 5\n2 2 3 1 2 2 3 3 3 2 1 2 3 1 1 3 3 3 2 3\n"], "outputs": ["1", "3", "5", "5", "4", "5", "7", "7"]}
359
288
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Kerim is an environment-friendly guy. Today, he accepted Samir's challenge of planting 20 million trees by 2020. Currently, there are $N$ trees (numbered $1$ through $N$) planted at distinct positions on a line; for each valid $i$, the position of the $i$-th tree is $A_{i}$. A set of trees is *beautiful* if for each tree in this set (let's denote its position by $x$), there is a tree at the position $x-1$ and/or a tree at the position $x+1$. Kerim's task is to plant some (possibly zero) trees in such a way that the resulting set of all planted trees (the initial $N$ trees and those planted by Kerim) is beautiful. It is only allowed to plant trees at integer (possibly negative) positions. Find the minimum number of trees he needs to plant in order to achieve that. ------ 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 trees Kerim needs to plant. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ $A_{1}, A_{2}, \ldots, A_{N}$ are pairwise distinct the sum of $N$ over all test cases does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (50 points): $N ≤ 1,000$ $A_{i} ≤ 2,000$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{4}$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 3 2 7 4 ----- Sample Output 1 ------ 2 ----- explanation 1 ------ Example case 1: Kerim should plant trees at the positions $3$ and $6$ to make the grid beautiful, so the answer is $2$.
{"inputs": ["1\n3\n2 7 4"], "outputs": ["2"]}
585
20
coding
Solve the programming task below in a Python markdown code block. Create a function that transforms any positive number to a string representing the number in words. The function should work for all numbers between 0 and 999999. ### Examples ``` number2words(0) ==> "zero" number2words(1) ==> "one" number2words(9) ==> "nine" number2words(10) ==> "ten" number2words(17) ==> "seventeen" number2words(20) ==> "twenty" number2words(21) ==> "twenty-one" number2words(45) ==> "forty-five" number2words(80) ==> "eighty" number2words(99) ==> "ninety-nine" number2words(100) ==> "one hundred" number2words(301) ==> "three hundred one" number2words(799) ==> "seven hundred ninety-nine" number2words(800) ==> "eight hundred" number2words(950) ==> "nine hundred fifty" number2words(1000) ==> "one thousand" number2words(1002) ==> "one thousand two" number2words(3051) ==> "three thousand fifty-one" number2words(7200) ==> "seven thousand two hundred" number2words(7219) ==> "seven thousand two hundred nineteen" number2words(8330) ==> "eight thousand three hundred thirty" number2words(99999) ==> "ninety-nine thousand nine hundred ninety-nine" number2words(888888) ==> "eight hundred eighty-eight thousand eight hundred eighty-eight" ``` Also feel free to reuse/extend the following starter code: ```python def number2words(n): ```
{"functional": "_inputs = [[0], [1], [8], [5], [9], [10], [19], [20], [22], [54], [80], [98], [100], [301], [793], [800], [650], [1000], [1003], [3052], [7300], [7217], [8340], [99997], [888887]]\n_outputs = [['zero'], ['one'], ['eight'], ['five'], ['nine'], ['ten'], ['nineteen'], ['twenty'], ['twenty-two'], ['fifty-four'], ['eighty'], ['ninety-eight'], ['one hundred'], ['three hundred one'], ['seven hundred ninety-three'], ['eight hundred'], ['six hundred fifty'], ['one thousand'], ['one thousand three'], ['three thousand fifty-two'], ['seven thousand three hundred'], ['seven thousand two hundred seventeen'], ['eight thousand three hundred forty'], ['ninety-nine thousand nine hundred ninety-seven'], ['eight hundred eighty-eight thousand eight hundred eighty-seven']]\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(number2words(*i), o[0])"}
448
392
coding
Solve the programming task below in a Python markdown code block. Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs delicious if he found it delicious, safe if he did not found it delicious but did not get a stomachache either, and dangerous if he got a stomachache. -----Constraints----- - 1 ≤ X,A,B ≤ 10^9 -----Input----- Input is given from Standard Input in the following format: X A B -----Output----- Print delicious if Takahashi found the food delicious; print safe if he neither found it delicious nor got a stomachache; print dangerous if he got a stomachache. -----Sample Input----- 4 3 6 -----Sample Output----- safe He ate the food three days after the "best-by" date. It was not delicious or harmful for him.
{"inputs": ["0 3 6", "6 5 0", "4 2 6", "1 3 6", "1 0 6", "2 0 6", "4 0 6", "4 1 6"], "outputs": ["dangerous\n", "delicious\n", "safe\n", "dangerous\n", "dangerous\n", "dangerous\n", "dangerous\n", "dangerous\n"]}
276
101
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef is on a vacation these days, so his friend Chefza is trying to solve Chef's everyday tasks. Today's task is to make a sweet roll. Rolls are made by a newly invented cooking machine. The machine is pretty universal - it can make lots of dishes and Chefza is thrilled about this. To make a roll, Chefza has to set all the settings to specified integer values. There are lots of settings, each of them set to some initial value. The machine is pretty complex and there is a lot of cooking to be done today, so Chefza has decided to use only two quick ways to change the settings. In a unit of time, he can pick one setting (let's say its current value is v) and change it in one of the following ways. If v is even, change this setting to v/2. If v is odd, change it to (v − 1)/2. Change setting to 2 × v The receipt is given as a list of integer values the settings should be set to. It is guaranteed that each destination setting can be represented as an integer power of 2. Since Chefza has just changed his profession, he has a lot of other things to do. Please help him find the minimum number of operations needed to set up a particular setting of the machine. You can prove that it can be done in finite time. ------ 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 only line of each test case contains two integers A and B denoting the initial and desired values of the setting, respectively. ------ Output ------ For each test case, output a single line containing minimum number of operations Chefza has to perform in order to set up the machine. ------ Constraints ------ $1 ≤ T ≤ 200$ $1 ≤ A ≤ 10^{7}$ $1 ≤ B ≤ 10^{7}, and B is an integer power of 2$ ------ Subtasks ------ $Subtask #1 [40 points]: A ≤ 100 and B ≤ 100$ $Subtask #2 [60 points]: No additional constraints$ ----- Sample Input 1 ------ 6 1 1 2 4 3 8 4 16 4 1 1 4 ----- Sample Output 1 ------ 0 1 4 2 2 2 ----- explanation 1 ------ In the first test case, you don't need to do anything. In the second test case, you need to multiply 2 by 2 and get 4. This is done in 1 operation. In the third test case, you need to obtain 1 from 3 and then multiply it by 2 three times to obtain 8. A total of 4 operations. In the fourth test case, multiply 4 by 2 twice. In the fifth test case, divide 4 by 2 twice. In the sixth test case, multiply 1 by 2 twice.
{"inputs": ["6\n1 1\n2 1\n3 8\n4 1\n2 1\n2 4", "6\n1 2\n2 4\n6 8\n4 8\n1 1\n2 4", "6\n1 1\n2 4\n3 2\n4 4\n4 1\n1 4", "6\n2 2\n2 4\n6 8\n4 8\n1 1\n2 4", "6\n1 1\n2 1\n4 8\n5 1\n2 1\n2 4", "6\n1 1\n2 4\n3 8\n4 16\n4 1\n1 4", "6\n1 1\n2 4\n3 1\n4 16\n4 1\n1 4", "6\n1 1\n2 4\n3 8\n4 16\n1 1\n1 4"], "outputs": ["0\n1\n4\n2\n1\n1\n", "1\n1\n5\n1\n0\n1\n", "0\n1\n2\n0\n2\n2\n", "0\n1\n5\n1\n0\n1\n", "0\n1\n1\n2\n1\n1\n", "0\n1\n4\n2\n2\n2", "0\n1\n1\n2\n2\n2\n", "0\n1\n4\n2\n0\n2\n"]}
662
336
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
17