task_type
stringclasses
1 value
problem
stringlengths
209
3.39k
answer
stringlengths
35
6.15k
problem_tokens
int64
60
774
answer_tokens
int64
12
2.04k
coding
Solve the programming task below in a Python markdown code block. Speedcubing is the hobby involving solving a variety of twisty puzzles, the most famous being the 3x3x3 puzzle or Rubik's Cube, as quickly as possible. In the majority of Speedcubing competitions, a Cuber solves a scrambled cube 5 times, and their result is found by taking the average of the middle 3 solves (ie. the slowest and fastest times are disregarded, and an average is taken of the remaining times). In some competitions, the unlikely event of a tie situation is resolved by comparing Cuber's fastest times. Write a function ```cube_times(times)``` that, given an array of floats ```times``` returns an array / tuple with the Cuber's result (to 2 decimal places) AND their fastest solve. For example: ```python cube_times([9.5, 7.6, 11.4, 10.5, 8.1]) = (9.37, 7.6) # Because (9.5 + 10.5 + 8.1) / 3 = 9.37 and 7.6 was the fastest solve. ``` Note: ```times``` will always be a valid array of 5 positive floats (representing seconds) Also feel free to reuse/extend the following starter code: ```python def cube_times(times): ```
{"functional": "_inputs = [[[9.5, 7.6, 11.4, 10.5, 8.1]], [[13.4, 12.3, 9.5, 11.9, 20.8]], [[28.3, 14.5, 17.3, 8.9, 10.1]]]\n_outputs = [[[9.37, 7.6]], [[12.53, 9.5]], [[13.97, 8.9]]]\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(cube_times(*i), o[0])"}
302
268
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. After a long time, Chef has finally decided to renovate his house. Chef's house has N rooms in it numbered from 1 to N. Each room is currently painted in one of the red, blue or green colors. Your are given configuration of colors of his house by a string S consisting of N characters. In this string, color red will be denoted by 'R', green by 'G' and blue by 'B'. Chef does not like current painting configuration that much and would like to repaint the house such that each room has same color. For painting, Chef has all the 3 color paints available and mixing any 2 color paints will result into 3rd color paint i.e R + B = G B + G = R G + R = B For example, painting a room having red color before with green color paint will make the color of room blue. Also, Chef has many buckets of paint of each color. Simply put, you can assume that he will not run out of paint. Being extraordinary lazy, our little chef does not want to work much and therefore, he has asked you to find the minimum number of rooms he has to repaint (possibly zero) in order to have all the rooms with same color. Can you please help him? ------ Input ------ First line of input contains a single integer T denoting the number of test cases. First line of each test case contains an integer N denoting the number of rooms in the chef's house. Next line of each test case contains a string S denoting the current color configuration of rooms. ------ Output ------ For each test case, Print the minimum number of rooms need to be painted in order to have all the rooms painted with same color i.e either red, blue or green. ------ Constraints ------ 1 ≤ T ≤ 10 1 ≤ N ≤ 10^{5} S_{i} = {'R','G','B'} ------ Scoring ------ $Subtask 1 (40 points) : 1 ≤ N ≤ 10 $ $Subtask 2 (60 points) : original constraints$ ----- Sample Input 1 ------ 3 3 RGR 3 RRR 3 RGB ----- Sample Output 1 ------ 1 0 2 ----- explanation 1 ------ Test 1: Chef prefers to paint room 2 with blue color such that the resulting color will be red and all the rooms have same color i.e red. Test 2: Given configuration has all the rooms painted with red color and therefore, chef does not need to do painting work at all. Test 3: One possible way of renovation is to paint room 1 with green color, room 2 with red color such that all rooms have same color i.e blue.
{"inputs": ["3\n3\nRGR\n3\nRRR\n3\nRGB", "3\n3\nRGR\n3\nRRR\n3\nGRB", "3\n3\nGRR\n3\nRRR\n3\nGRB", "3\n3\nRGR\n3\nRRR\n3\nRBG", "3\n3\nGRR\n3\nRRR\n3\nBRG", "3\n3\nRRG\n3\nRRR\n3\nRGB", "3\n3\nRGR\n3\nRRR\n3\nBRG", "3\n3\nRGR\n3\nRRR\n3\nBGR"], "outputs": ["1\n0\n2", "1\n0\n2\n", "1\n0\n2\n", "1\n0\n2\n", "1\n0\n2\n", "1\n0\n2\n", "1\n0\n2\n", "1\n0\n2\n"]}
603
211
coding
Solve the programming task below in a Python markdown code block. A space explorer's ship crashed on Mars! They send a series of SOS messages to Earth for help. Letters in some of the SOS messages are altered by cosmic radiation during transmission. Given the signal received by Earth as a string, $\boldsymbol{\mathrm{~S~}}$, determine how many letters of the SOS message have been changed by radiation. Example $s=\text{'SOSTOT'}$ The original message was SOSSOS. Two of the message's characters were changed in transit. Function Description Complete the marsExploration function in the editor below. marsExploration has the following parameter(s): string s: the string as received on Earth Returns int: the number of letters changed during transmission Input Format There is one line of input: a single string, $\boldsymbol{\mathrm{~S~}}$. Constraints $1\leq\ \text{length of}\ s\leq99$ $\textbf{length of}~s~\textbf{modulo}~~3=0$ $\boldsymbol{\mathrm{~S~}}$ will contain only uppercase English letters, ascii[A-Z]. Sample Input 0 SOSSPSSQSSOR Sample Output 0 3 Explanation 0 $\boldsymbol{\mathrm{~S~}}$ = SOSSPSSQSSOR, and signal length $\textbf{|s|}=\textbf{12}$. They sent $4$ SOS messages (i.e.: $12/3=4$). Expected signal: SOSSOSSOSSOS Recieved signal: SOSSPSSQSSOR Difference: X X X Sample Input 1 SOSSOT Sample Output 1 1 Explanation 1 $\boldsymbol{\mathrm{~S~}}$ = SOSSOT, and signal length $|s|=6$. They sent $2$ SOS messages (i.e.: $6/3=2$). Expected Signal: SOSSOS Received Signal: SOSSOT Difference: X Sample Input 2 SOSSOSSOS Sample Output 2 0 Explanation 2 Since no character is altered, return 0.
{"inputs": ["SOSSOT\n", "SOSSOSSOS\n", "SOSSPSSQSSOR\n"], "outputs": ["1\n", "0\n", "3\n"]}
483
42
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s consisting only of letters 'a' and 'b'. In a single step you can remove one palindromic subsequence from s. Return the minimum number of steps to make the given string empty. A string is a subsequence of a given string if it is generated by deleting some characters of a given string without changing its order. Note that a subsequence does not necessarily need to be contiguous. A string is called palindrome if is one that reads the same backward as well as forward.   Please complete the following python code precisely: ```python class Solution: def removePalindromeSub(self, s: str) -> int: ```
{"functional": "def check(candidate):\n assert candidate(s = \"ababa\") == 1\n assert candidate(s = \"abb\") == 2\n assert candidate(s = \"baabb\") == 2\n\n\ncheck(Solution().removePalindromeSub)"}
153
58
coding
Solve the programming task below in a Python markdown code block. Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction $\frac{a}{b}$ is called proper iff its numerator is smaller than its denominator (a < b) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1). During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button ( + ) instead of division button (÷) and got sum of numerator and denominator that was equal to n instead of the expected decimal notation. Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction $\frac{a}{b}$ such that sum of its numerator and denominator equals n. Help Petya deal with this problem. -----Input----- In the only line of input there is an integer n (3 ≤ n ≤ 1000), the sum of numerator and denominator of the fraction. -----Output----- Output two space-separated positive integers a and b, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. -----Examples----- Input 3 Output 1 2 Input 4 Output 1 3 Input 12 Output 5 7
{"inputs": ["3\n", "4\n", "5\n", "6\n", "8\n", "9\n", "9\n", "5\n"], "outputs": ["1 2\n", "1 3\n", "2 3\n", "1 5\n", "3 5\n", "4 5\n", "4 5\n", "2 3\n"]}
310
86
coding
Solve the programming task below in a Python markdown code block. Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey doesn't give up. Having obtained an empty certificate from a local hospital, he is going to use his knowledge of local doctor's handwriting to make a counterfeit certificate of illness. However, after writing most of the certificate, Andrey suddenly discovered that doctor's signature is impossible to forge. Or is it? For simplicity, the signature is represented as an $n\times m$ grid, where every cell is either filled with ink or empty. Andrey's pen can fill a $3\times3$ square without its central cell if it is completely contained inside the grid, as shown below. xxx x.x xxx Determine whether is it possible to forge the signature on an empty $n\times m$ grid. -----Input----- The first line of input contains two integers $n$ and $m$ ($3 \le n, m \le 1000$). Then $n$ lines follow, each contains $m$ characters. Each of the characters is either '.', representing an empty cell, or '#', representing an ink filled cell. -----Output----- If Andrey can forge the signature, output "YES". Otherwise output "NO". You can print each letter in any case (upper or lower). -----Examples----- Input 3 3 ### #.# ### Output YES Input 3 3 ### ### ### Output NO Input 4 3 ### ### ### ### Output YES Input 5 7 ....... .#####. .#.#.#. .#####. ....... Output YES -----Note----- In the first sample Andrey can paint the border of the square with the center in $(2, 2)$. In the second sample the signature is impossible to forge. In the third sample Andrey can paint the borders of the squares with the centers in $(2, 2)$ and $(3, 2)$: we have a clear paper: ... ... ... ... use the pen with center at $(2, 2)$. ### #.# ### ... use the pen with center at $(3, 2)$. ### ### ### ### In the fourth sample Andrey can paint the borders of the squares with the centers in $(3, 3)$ and $(3, 5)$.
{"inputs": ["3 3\n###\n#.#\n###\n", "3 3\n###\n###\n###\n", "3 3\n...\n...\n...\n", "3 3\n...\n...\n...\n", "3 3\n###\n.##\n###\n", "3 3\n###\n###\n###\n", "3 3\n###\n#.#\n###\n", "3 4\n####\n#.##\n####\n"], "outputs": ["YES", "NO", "YES", "YES\n", "NO\n", "NO\n", "YES\n", "NO"]}
527
152
coding
Solve the programming task below in a Python markdown code block. Rahul is a serial killer. Rahul has been betrayed by his lover in the past and now he want to eliminate entire Universe.He has already Eliminated majority of the population and now only a handful number of people are left. Like other Serial killers, he has an interesting pattern of killing people. He either kill one individual at a time or if he find two individuals of different heights,he eliminates both of them simultaneously. Now Rahul wants to eliminate them as quickly as he can. So given $N$ as the number of people left and an array containing height of those $N$ people,tell the minimum number of kills Rahul require to eliminate the entire universe. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each test case constitutes of Two lines. - First line contains $N$, representing the number of people left in the universe - The second line contains an array $a[i]$ of size $N$ containing heights of those $N$ people. -----Output:----- For each testcase, you have to output a Single line Containing the minimum number of kills required by Rahul to eliminate the Universe. -----Constraints----- - $1 \leq T \leq 50000$ - $1 \leq N \leq 50000$ - $100 \leq a[i] \leq 10^5$ -----Sample Input:----- 1 10 178 184 178 177 171 173 171 183 171 175 -----Sample Output:----- 5
{"inputs": ["1\n10\n178 184 178 177 171 173 171 183 171 175"], "outputs": ["5"]}
367
55
coding
Solve the programming task below in a Python markdown code block. Prof. Sergio Marquina is a mathematics teacher at the University of Spain. Whenever he comes across any good question(with complexity k), he gives that question to students within roll number range i and j. At the start of the semester he assigns a score of 10 to every student in his class if a student submits a question of complexity k, his score gets multiplied by k. This month he gave M questions and he is wondering what will be mean of maximum scores of all the students. He is busy planning a tour of the Bank of Spain for his students, can you help him? -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains the first line of input, two integers N, M i.e. Number of students in the class and number of questions given in this month. - Next M lines contain 3 integers -i,j,k i.e. starting roll number, end roll number, and complexity of the question -----Output:----- - For each test case, output in a single line answer - floor value of Mean of the maximum possible score for all students. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N, M \leq 105$ - $1 \leq i \leq j \leq N$ - $1 \leq k \leq 100$ -----Sample Input:----- 1 5 3 1 3 5 2 5 2 3 4 7 -----Sample Output:----- 202 -----EXPLANATION:----- Initial score of students will be : [10,10,10,10,10] after solving question 1 scores will be: [50,50,50,10,10] after solving question 2 scores will be: [50,100,100,20,20] after solving question 1 scores will be: [50,100,700,140,20] Hence after all questions mean of maximum scores will (50+100+700+140+20)/5=202
{"inputs": ["1\n5 3\n1 3 5\n2 5 2\n3 4 7"], "outputs": ["202"]}
497
36
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are playing a game with integers. You start with the integer 1 and you want to reach the integer target. In one move, you can either: Increment the current integer by one (i.e., x = x + 1). Double the current integer (i.e., x = 2 * x). You can use the increment operation any number of times, however, you can only use the double operation at most maxDoubles times. Given the two integers target and maxDoubles, return the minimum number of moves needed to reach target starting with 1.   Please complete the following python code precisely: ```python class Solution: def minMoves(self, target: int, maxDoubles: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(target = 5, maxDoubles = 0) == 4\n assert candidate(target = 19, maxDoubles = 2) == 7\n assert candidate(target = 10, maxDoubles = 4) == 4\n\n\ncheck(Solution().minMoves)"}
169
78
coding
Solve the programming task below in a Python markdown code block. It's tricky keeping track of who is owed what when spending money in a group. Write a function to balance the books. * The function should take one parameter: an object/dict with two or more name-value pairs which represent the members of the group and the amount spent by each. * The function should return an object/dict with the same names, showing how much money the members should pay or receive. **Further points:** * The values should be positive numbers if the person should receive money from the group, negative numbers if they owe money to the group. * If value is a decimal, round to two decimal places. Translations and comments (and upvotes!) welcome. ### Example 3 friends go out together: A spends £20, B spends £15, and C spends £10. The function should return an object/dict showing that A should receive £5, B should receive £0, and C should pay £5. Also feel free to reuse/extend the following starter code: ```python def split_the_bill(x): ```
{"functional": "_inputs = [[{'A': 20, 'B': 15, 'C': 10}], [{'A': 40, 'B': 25, 'X': 10}], [{'A': 40, 'B': 25, 'C': 10, 'D': 153, 'E': 58}], [{'A': 475, 'B': 384, 'C': 223, 'D': 111, 'E': 19}], [{'A': 20348, 'B': 493045, 'C': 2948, 'D': 139847, 'E': 48937534, 'F': 1938724, 'G': 4, 'H': 2084}]]\n_outputs = [[{'A': 5.0, 'B': 0.0, 'C': -5.0}], [{'A': 15.0, 'B': 0.0, 'X': -15.0}], [{'A': -17.2, 'B': -32.2, 'C': -47.2, 'D': 95.8, 'E': 0.8}], [{'A': 232.6, 'B': 141.6, 'C': -19.4, 'D': -131.4, 'E': -223.4}], [{'A': -6421468.75, 'B': -5948771.75, 'C': -6438868.75, 'D': -6301969.75, 'E': 42495717.25, 'F': -4503092.75, 'G': -6441812.75, 'H': -6439732.75}]]\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(split_the_bill(*i), o[0])"}
231
615
coding
Solve the programming task below in a Python markdown code block. Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function. Merge(A, left, mid, right) n1 = mid - left; n2 = right - mid; create array L[0...n1], R[0...n2] for i = 0 to n1-1 do L[i] = A[left + i] for i = 0 to n2-1 do R[i] = A[mid + i] L[n1] = SENTINEL R[n2] = SENTINEL i = 0; j = 0; for k = left to right-1 if L[i] <= R[j] then A[k] = L[i] i = i + 1 else A[k] = R[j] j = j + 1 Merge-Sort(A, left, right){ if left+1 < right then mid = (left + right)/2; call Merge-Sort(A, left, mid) call Merge-Sort(A, mid, right) call Merge(A, left, mid, right) Notes Constraints * n ≤ 500000 * 0 ≤ an element in S ≤ 109 Input In the first line n is given. In the second line, n integers are given. Output In the first line, print the sequence S. Two consequtive elements should be separated by a space character. In the second line, print the number of comparisons. Example Input 10 8 5 9 2 6 3 7 1 10 4 Output 1 2 3 4 5 6 7 8 9 10 34
{"inputs": ["10\n8 5 9 2 6 3 7 0 10 4", "10\n8 5 9 2 6 3 7 0 10 3", "10\n8 5 9 2 6 3 7 1 10 4", "10\n8 5 9 2 6 4 11 0 10 3", "10\n8 5 9 2 6 4 11 0 10 5", "10\n8 5 9 2 6 4 11 1 10 5", "10\n10 5 9 2 6 4 11 1 10 5", "10\n10 5 9 2 6 4 19 1 10 5"], "outputs": ["0 2 3 4 5 6 7 8 9 10\n34\n", "0 2 3 3 5 6 7 8 9 10\n34\n", "1 2 3 4 5 6 7 8 9 10\n34", "0 2 3 4 5 6 8 9 10 11\n34\n", "0 2 4 5 5 6 8 9 10 11\n34\n", "1 2 4 5 5 6 8 9 10 11\n34\n", "1 2 4 5 5 6 9 10 10 11\n34\n", "1 2 4 5 5 6 9 10 10 19\n34\n"]}
391
427
coding
Solve the programming task below in a Python markdown code block. N candidates (numbered from 1 to N) join Chef's firm. The first 5 candidates join on the first day, and then, on every subsequent day, the next 5 candidates join in. For example, if there are 12 candidates, candidates numbered 1 to 5 will join on day 1, candidates numbered 6 to 10 on day 2 and the remaining 2 candidates will join on day 3. Candidate numbered K decided to turn down his offer and thus, Chef adjusts the position by shifting up all the higher numbered candidates. This leads to a change in the joining day of some of the candidates. Help Chef determine the number of candidates who will join on a different day than expected. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, two space-separated integers N and K denoting the number of candidates and the candidate who turned down the offer. ------ Output Format ------ For each test case, output a single integer denoting the number of candidates whose joining day will be changed. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 1000$ $1 ≤ K ≤ N$ ----- Sample Input 1 ------ 4 7 3 6 6 2 1 14 2 ----- Sample Output 1 ------ 1 0 0 2 ----- explanation 1 ------ Test case $1$: The original joining day of each candidate is given as $[1, 1, 1, 1, 1, 2, 2]$ but as candidate $3$ turns down his offer, the new joining days are now $[1, 1, NA, 1, 1, 1, 2]$. Candidate numbered $6$ is the only one to have his joining day changed. Test case $2$: The original joining day of each candidate is given as $[1, 1, 1, 1, 1, 2]$ but as candidate $6$ turns down his offer, the new joining days are now $[1, 1, 1, 1, 1, NA]$. No candidate got his joining day changed. Test case $3$: The original joining day of each candidate is given as $[1, 1]$ but as candidate $1$ turns down his offer, the new joining days are now $[NA, 1]$. No candidate got his joining day changed. Test case $4$: The original joining day of each candidate is given as $[1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3]$ but as candidate $2$ turns down his offer, the new joining days are now $[1, NA, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3]$. Candidate numbered $6$ and $11$ are the only ones to have their joining days changed.
{"inputs": ["4\n7 3\n6 6\n2 1\n14 2"], "outputs": ["1\n0\n0\n2\n"]}
692
36
coding
Solve the programming task below in a Python markdown code block. Berland Football Cup starts really soon! Commentators from all over the world come to the event. Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation. If $n$ is not divisible by $m$, it is impossible to distribute the boxes to the delegations at the moment. Organizers can build a new commentary box paying $a$ burles and demolish a commentary box paying $b$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes. What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$)? -----Input----- The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box. -----Output----- Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$. -----Examples----- Input 9 7 3 8 Output 15 Input 2 7 3 7 Output 14 Input 30 6 17 19 Output 0 -----Note----- In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them. In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them. In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $5$ boxes.
{"inputs": ["9 7 3 8\n", "2 7 3 7\n", "7 2 3 7\n", "1 2 1 1\n", "9 2 1 1\n", "1 2 5 1\n", "7 2 1 2\n", "5 2 2 2\n"], "outputs": ["15\n", "14\n", "3\n", "1\n", "1\n", "1\n", "1\n", "2\n"]}
515
120
coding
Solve the programming task below in a Python markdown code block. It's bonus time in the big city! The fatcats are rubbing their paws in anticipation... but who is going to make the most money? Build a function that takes in two arguments (salary, bonus). Salary will be an integer, and bonus a boolean. If bonus is true, the salary should be multiplied by 10. If bonus is false, the fatcat did not make enough money and must receive only his stated salary. Return the total figure the individual will receive as a string prefixed with "£" (= `"\u00A3"`, JS, Go, and Java), "$" (C#, C++, Ruby, Clojure, Elixir, PHP and Python, Haskell, Lua) or "¥" (Rust). Also feel free to reuse/extend the following starter code: ```python def bonus_time(salary, bonus): ```
{"functional": "_inputs = [[10000, True], [25000, True], [10000, False], [60000, False], [2, True], [78, False], [67890, True]]\n_outputs = [['$100000'], ['$250000'], ['$10000'], ['$60000'], ['$20'], ['$78'], ['$678900']]\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(bonus_time(*i), o[0])"}
192
252
coding
Solve the programming task below in a Python markdown code block. Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on. Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted. -----Input----- The first line of input will be a single string s (1 ≤ |s| ≤ 50), the word Hongcow initially learns how to spell. The string s consists only of lowercase English letters ('a'–'z'). -----Output----- Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. -----Examples----- Input abcd Output 4 Input bbb Output 1 Input yzyz Output 2 -----Note----- For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda". For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb". For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
{"inputs": ["y\n", "y\n", "x\n", "w\n", "v\n", "bbb\n", "aba\n", "aba\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "3\n", "3\n"]}
370
70
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Write a program to count the number of days between two dates. The two dates are given as strings, their format is YYYY-MM-DD as shown in the examples.   Please complete the following python code precisely: ```python class Solution: def daysBetweenDates(self, date1: str, date2: str) -> int: ```
{"functional": "def check(candidate):\n assert candidate(date1 = \"2019-06-29\", date2 = \"2019-06-30\") == 1\n assert candidate(date1 = \"2020-01-15\", date2 = \"2019-12-31\") == 15\n\n\ncheck(Solution().daysBetweenDates)"}
88
95
coding
Solve the programming task below in a Python markdown code block. It is said that a legendary treasure left by Mr. Yao is sleeping somewhere in Hachioji long ago. The treasure map, which is said to show its whereabouts, has been handed down by Yao's n descendants, divided into several pieces. Now, the descendants of Mr. Yao were trying to cooperate to obtain the treasure. However, the treasure cannot be found only by a part of the treasure map that points to the location of the treasure. Therefore, all the descendants of Mr. Yao gathered and tried to collect the map in one place. However, even if I tried to put it into practice, I couldn't get together because I couldn't meet the schedule. However, this information about the treasure is valuable information that has been secretly passed down in the clan. Considering the risk of leakage, exchanging maps using public communication means is out of the question. Therefore, I decided to collect the map for one descendant by repeating the process of meeting the descendants in person and handing over the map. There is no limit to the number of people that one person can meet in a day, but it is necessary that there is a schedule for each other. Your job is to write a program that asks for at least how many days it will take to collect a map from a list of open days on schedule for each offspring. By the way, the unity of the Yao clan is very tight. If the descendants who finally get the entire map betray the other descendants and take away the treasure, they will be sanctioned by the clan. The sanctions are so horrifying that it is virtually impossible for their descendants to actually carry away the treasure. Input The input consists of multiple datasets. Each dataset consists of multiple rows. The first line contains the integer n (1 <n <= 50), which represents the number of people with a piece of the map. The next n lines contain the schedule for each descendant. Line i represents the schedule of the i-th descendant, with some integers separated by a single character space. The first integer fi (0 <= fi <= 30) is an integer that represents the number of days that the descendant's schedule is free. The following fi integers represent dates when the schedule is free. These dates differ from each other and are all greater than or equal to 1 and less than or equal to 30. There is one line containing only 0 at the end of the input. Output Print one integer on one line for each dataset. If you can collect the map within 30 days, output the minimum number of days required to collect the map, otherwise output -1. Addendum: The above "minimum number of days required to collect maps" means the date when all maps are collected earliest starting from one day. Example Input 4 1 1 2 2 3 2 1 2 3 3 4 5 0 Output 3
{"inputs": ["4\n1 1\n2 2 3\n2 1 2\n3 4 4 5\n0", "4\n1 1\n2 2 5\n2 0 2\n3 1 4 5\n0", "4\n1 1\n2 2 3\n2 1 2\n3 1 4 5\n0", "4\n1 1\n2 1 3\n2 0 1\n3 1 4 5\n0", "4\n1 1\n2 2 3\n2 0 4\n3 1 4 2\n0", "4\n1 1\n2 2 3\n2 1 2\n3 4 4 0\n0", "4\n1 1\n2 2 3\n2 2 2\n3 3 4 5\n0", "4\n1 1\n1 2 3\n2 1 2\n3 4 4 0\n0"], "outputs": ["-1\n", "5\n", "2\n", "1\n", "4\n", "-1\n", "-1\n", "-1\n"]}
605
271
coding
Solve the programming task below in a Python markdown code block. Write a function that accepts two arguments: an array/list of integers and another integer (`n`). Determine the number of times where two integers in the array have a difference of `n`. For example: ``` [1, 1, 5, 6, 9, 16, 27], n=4 --> 3 # (1,5), (1,5), (5,9) [1, 1, 3, 3], n=2 --> 4 # (1,3), (1,3), (1,3), (1,3) ``` Also feel free to reuse/extend the following starter code: ```python def int_diff(arr, n): ```
{"functional": "_inputs = [[[1, 1, 5, 6, 9, 16, 27], 4], [[1, 1, 3, 3], 2], [[4, 8, 12, 12, 3, 6, 2], 6], [[1, 2, 3, 4, 5, 6, 7], 7], [[1, 6, 2, 3, 7, 8, 7], 0], [[1, 2, 3, 4], 0], [[1, 1, 1, 1], 0], [[], 3]]\n_outputs = [[3], [4], [3], [0], [1], [0], [6], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != 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(int_diff(*i), o[0])"}
172
322
coding
Solve the programming task below in a Python markdown code block. A message from humans to extraterrestrial intelligence was sent through the Arecibo radio telescope in Puerto Rico on the afternoon of Saturday November l6, l974. The message consisted of l679 bits and was meant to be translated to a rectangular picture with 23 × 73 pixels. Since both 23 and 73 are prime numbers, 23 × 73 is the unique possible size of the translated rectangular picture each edge of which is longer than l pixel. Of course, there was no guarantee that the receivers would try to translate the message to a rectangular picture. Even if they would, they might put the pixels into the rectangle incorrectly. The senders of the Arecibo message were optimistic. We are planning a similar project. Your task in the project is to find the most suitable width and height of the translated rectangular picture. The term ``most suitable'' is defined as follows. An integer m greater than 4 is given. A positive fraction a/b less than or equal to 1 is also given. The area of the picture should not be greater than m. Both of the width and the height of the translated picture should be prime numbers. The ratio of the width to the height should not be less than a/b nor greater than 1. You should maximize the area of the picture under these constraints. In other words, you will receive an integer m and a fraction a/b . It holds that m > 4 and 0 < a/b ≤ 1 . You should find the pair of prime numbers p, q such that pq ≤ m and a/b ≤ p/q ≤ 1 , and furthermore, the product pq takes the maximum value among such pairs of two prime numbers. You should report p and q as the "most suitable" width and height of the translated picture. Input The input is a sequence of at most 2000 triplets of positive integers, delimited by a space character in between. Each line contains a single triplet. The sequence is followed by a triplet of zeros, 0 0 0, which indicates the end of the input and should not be treated as data to be processed. The integers of each input triplet are the integer m, the numerator a, and the denominator b described above, in this order. You may assume 4 < m < 100000 and 1 ≤ a ≤ b ≤ 1000. Output The output is a sequence of pairs of positive integers. The i-th output pair corresponds to the i-th input triplet. The integers of each output pair are the width p and the height q described above, in this order. Each output line contains a single pair. A space character is put between the integers as a delimiter. No other characters should appear in the output. Example Input 5 1 2 99999 999 999 1680 5 16 1970 1 1 2002 4 11 0 0 0 Output 2 2 313 313 23 73 43 43 37 53
{"inputs": ["5 1 7\n99999 999 999\n103 5 21\n973 1 2\n3406 4 4\n0 0 0", "6 1 7\n99999 999 999\n103 5 21\n973 1 2\n3406 4 4\n0 0 0", "7 1 5\n99999 999 999\n710 5 14\n973 1 2\n771 4 11\n0 0 0", "8 1 5\n99999 999 999\n238 8 10\n973 1 2\n771 4 11\n0 0 0", "5 1 4\n99999 999 999\n1680 5 6\n973 1 2\n131 4 11\n0 0 0", "5 1 2\n99999 999 999\n107 5 11\n973 1 2\n940 4 11\n0 0 0", "5 1 2\n99999 999 999\n107 5 16\n973 1 2\n2002 4 11\n0 0 0", "5 1 4\n99999 999 999\n103 5 21\n973 1 2\n3406 4 11\n0 0 0"], "outputs": ["2 2\n313 313\n5 19\n31 31\n53 53\n", "2 3\n313 313\n5 19\n31 31\n53 53\n", "2 3\n313 313\n19 37\n31 31\n17 43\n", "2 3\n313 313\n13 13\n31 31\n17 43\n", "2 2\n313 313\n37 43\n31 31\n11 11\n", "2 2\n313 313\n7 13\n31 31\n29 31\n", "2 2\n313 313\n7 13\n31 31\n37 53\n", "2 2\n313 313\n5 19\n31 31\n41 83\n"]}
679
683
coding
Solve the programming task below in a Python markdown code block. Due to another of his misbehaved, the primary school's teacher of the young Gauß, Herr J.G. Büttner, to keep the bored and unruly young schoolboy Karl Friedrich Gauss busy for a good long time, while he teaching arithmetic to his mates, assigned him the problem of adding up all the whole numbers from 1 through a given number `n`. Your task is to help the young Carl Friedrich to solve this problem as quickly as you can; so, he can astonish his teacher and rescue his recreation interval. Here's, an example: ``` f(n=100) // returns 5050 ``` It's your duty to verify that n is a valid positive integer number. If not, please, return false (None for Python, null for C#). > **Note:** the goal of this kata is to invite you to think about some 'basic' mathematic formula and how you can do performance optimization on your code. > Advanced - experienced users should try to solve it in one line, without loops, or optimizing the code as much as they can. ----- **Credits:** this kata was inspired by the farzher's kata 'Sum of large ints' . In fact, it can be seen as a sort of prep kata for that one. Also feel free to reuse/extend the following starter code: ```python def f(n): ```
{"functional": "_inputs = [[100], [300], [303], [50000], ['n'], [3.14], [0], [-10]]\n_outputs = [[5050], [45150], [46056], [1250025000], [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(f(*i), o[0])"}
303
229
coding
Solve the programming task below in a Python markdown code block. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of n points (called vertices), some of which are connected using n - 1 line segments (edges) so that each pair of vertices is connected by a path (a sequence of one or more edges). To decipher the prophecy, Heidi needs to perform a number of steps. The first is counting the number of lifelines in the tree – these are paths of length 2, i.e., consisting of two edges. Help her! -----Input----- The first line of the input contains a single integer n – the number of vertices in the tree (1 ≤ n ≤ 10000). The vertices are labeled with the numbers from 1 to n. Then n - 1 lines follow, each describing one edge using two space-separated numbers a b – the labels of the vertices connected by the edge (1 ≤ a < b ≤ n). It is guaranteed that the input represents a tree. -----Output----- Print one integer – the number of lifelines in the tree. -----Examples----- Input 4 1 2 1 3 1 4 Output 3 Input 5 1 2 2 3 3 4 3 5 Output 4 -----Note----- In the second sample, there are four lifelines: paths between vertices 1 and 3, 2 and 4, 2 and 5, and 4 and 5.
{"inputs": ["2\n1 2\n", "2\n1 2\n", "2\n2 1\n", "3\n2 1\n3 2\n", "3\n2 1\n3 2\n", "3\n2 1\n3 1\n", "4\n1 2\n1 3\n1 4\n", "4\n1 2\n2 3\n1 4\n"], "outputs": ["0", "0\n", "0\n", "1", "1\n", "1\n", "3", "2\n"]}
364
127
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells). The island doesn't have "lakes", meaning the water inside isn't connected to the water around the island. One cell is a square with side length 1. The grid is rectangular, width and height don't exceed 100. Determine the perimeter of the island.   Please complete the following python code precisely: ```python class Solution: def islandPerimeter(self, grid: List[List[int]]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(grid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]) == 16\n assert candidate(grid = [[1]]) == 4\n assert candidate(grid = [[1,0]]) == 4\n\n\ncheck(Solution().islandPerimeter)"}
179
90
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Consider an ordered tree with N vertices. Your task is to calculate the expected value of the number of vertices having exactly one child in such tree assuming that it is uniformly chosen from the set of all ordered trees of size N. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. Each testcase contains a single integer N for which you should calculate the answer. ------ Output ------ For each test case, output a single line containing two integers, which are explained below. Consider the answer to be a proper fraction P/Q, where gcd(P, Q) = 1. Then your task is to output two integers PQ^{-1} mod 10^{9}+7 and PQ^{-1} mod 10^{9}+9. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $It is guaranteed that Q will be invertible with respect to both the modulos.$ ------ Subtasks ------ Subtask #1 (10 points) $1 ≤ N ≤ 10^{3}$ Subtask #2 (20 points) $1 ≤ N ≤ 10^{6}$ Subtask #3 (30 points) $1 ≤ N ≤ 10^{9}$ Subtask #4 (40 points) $1 ≤ N ≤ 10^{18}$ ----- Sample Input 1 ------ 4 1 2 3 4 ----- Sample Output 1 ------ 0 0 1 1 1 1 400000004 200000003 ----- explanation 1 ------ You can see every possible tree with 1, 2, 3 or 4 vertices on the diagram below. From this you can see that answers for these inputs are 0/1 = 0, 1/1 = 1, (2+0)/2 = 1 and (3+1+1+1+0)/5 = 6/5 correspondingly.
{"inputs": ["4\n1\n2\n3\n4"], "outputs": ["0 0\n1 1\n1 1\n400000004 200000003"]}
466
50
coding
Solve the programming task below in a Python markdown code block. Given a board of `NxN`, distributed with tiles labeled `0` to `N² - 1`(inclusive): A solved grid will have the tiles in order of label, left to right, top to bottom. Return `true` if the board state is currently solved, and `false` if the board state is unsolved. Input will always be a square 2d array. For example, a 2x2 solved grid: ``` [ [0, 1], [2, 3] ] ``` A 2x2 unsolved grid: ``` [ [2, 1], [0, 3] ] ``` Also feel free to reuse/extend the following starter code: ```python def is_solved(board): ```
{"functional": "_inputs = [[[[1, 0], [3, 2]]], [[[1, 0, 4], [3, 2, 7], [8, 5, 6]]], [[[6, 7, 8], [0, 1, 2], [3, 4, 5]]]]\n_outputs = [[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(is_solved(*i), o[0])"}
173
228
coding
Solve the programming task below in a Python markdown code block. You are given N integer sequences A1, A2, ..., AN. Each of these sequences contains N elements. You should pick N elements, one from each sequence; let's denote the element picked from sequence Ai by Ei. For each i (2 ≤ i ≤ N), Ei should be strictly greater than Ei-1. Compute the maximum possible value of E1 + E2 + ... + EN. If it's impossible to pick the elements E1, E2, ..., EN, print -1 instead. -----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 N space-separated integers Ai1, Ai2, ..., AiN denoting the elements of the sequence Ai. -----Output----- For each test case, print a single line containing one integer — the maximum sum of picked elements. -----Constraints----- - 1 ≤ T ≤ 10 - 1 ≤ N ≤ 700 - 1 ≤ sum of N in all test-cases ≤ 3700 - 1 ≤ Aij ≤ 109 for each valid i, j -----Subtasks----- Subtask #1 (18 points): 1 ≤ Aij ≤ N for each valid i, j Subtask #2 (82 points): original constraints -----Example----- Input: 1 3 1 2 3 4 5 6 7 8 9 Output: 18 -----Explanation----- Example case 1: To maximise the score, pick 3 from the first row, 6 from the second row and 9 from the third row. The resulting sum is E1+E2+E3 = 3+6+9 = 18.
{"inputs": ["1\n3\n1 2 3\n4 5 6\n7 8 9"], "outputs": ["18"]}
417
33
coding
Solve the programming task below in a Python markdown code block. Consider the following expansion: ```Haskell solve("3(ab)") = "ababab" -- "ab" repeats 3 times solve("2(a3(b))" = "abbbabbb" -- "a3(b)" == "abbb" repeats twice. ``` Given a string, return the expansion of that string. Input will consist of only lowercase letters and numbers (1 to 9) in valid parenthesis. There will be no letters or numbers after the last closing parenthesis. More examples in test cases. Good luck! Please also try [Simple time difference](https://www.codewars.com/kata/5b76a34ff71e5de9db0000f2) Also feel free to reuse/extend the following starter code: ```python def solve(st): ```
{"functional": "_inputs = [['3(ab)'], ['2(a3(b))'], ['3(b(2(c)))'], ['k(a3(b(a2(c))))']]\n_outputs = [['ababab'], ['abbbabbb'], ['bccbccbcc'], ['kabaccbaccbacc']]\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])"}
187
203
coding
Solve the programming task below in a Python markdown code block. Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates greatly, it puts a strain on the body and it is easy to catch a cold. The day you should be careful about is the day when the difference between the maximum temperature and the minimum temperature is the largest. When the maximum and minimum temperatures of a day are given for 7 days, create a program that outputs the value obtained by subtracting the minimum temperature from the maximum temperature for each day. input Input data is given in the following format. a1 b1 a2 b2 :: a7 b7 The input consists of 7 lines, and line i is given an integer representing the maximum temperature ai (-40 ≤ ai ≤ 40) and the minimum temperature bi (-40 ≤ bi ≤ 40) on day i. On all days, the maximum temperature ai is always above the minimum temperature bi. output Output the temperature difference for 7 days in 7 lines. Example Input 30 19 39 20 19 18 25 20 22 21 23 10 10 -10 Output 11 19 1 5 1 13 20
{"inputs": ["42 25\n3 -2\n62 0\n2 30\n0 4\n0 0\n27 -2", "42 25\n3 -2\n62 0\n2 30\n0 2\n0 0\n27 -2", "42 25\n5 -1\n118 0\n2 9\n1 2\n-1 0\n5 -2", "42 25\n5 -1\n118 0\n2 9\n1 2\n-2 0\n5 -2", "42 25\n5 -1\n142 0\n2 9\n1 2\n-2 0\n5 -2", "42 25\n5 -1\n142 0\n2 9\n1 2\n-2 0\n5 -4", "42 25\n5 -1\n142 0\n2 9\n1 3\n-2 0\n5 -4", "42 25\n5 -1\n142 0\n2 9\n0 3\n-2 0\n5 -4"], "outputs": ["17\n5\n62\n-28\n-4\n0\n29\n", "17\n5\n62\n-28\n-2\n0\n29\n", "17\n6\n118\n-7\n-1\n-1\n7\n", "17\n6\n118\n-7\n-1\n-2\n7\n", "17\n6\n142\n-7\n-1\n-2\n7\n", "17\n6\n142\n-7\n-1\n-2\n9\n", "17\n6\n142\n-7\n-2\n-2\n9\n", "17\n6\n142\n-7\n-3\n-2\n9\n"]}
301
454
coding
Solve the programming task below in a Python markdown code block. The purpose of this series is developing understanding of stastical problems in AS and A level maths. Let's get started with a simple concept in statistics: Mutually exclusive events. The probability of an OR event is calculated by the following rule: `P(A || B) = P(A) + P(B) - P(A && B)` The probability of event A or event B happening is equal to the probability of event A plus the probability of event B minus the probability of event A and event B happening simultaneously. Mutually exclusive events are events that cannot happen at the same time. For example, the head and tail results of a toin coss are mutually exclusive because they can't both happen at once. Thus, the above example for a coin toss would look like this: `P(H || T) = P(H) + P(T) - P(H && T)` Note that the probaility of tossing a coin and the result being both head and tails is 0. `P(H || T) = (0.5) + (0.5) - (0)` `P(H || T) = 1` Thus the probability of a coin toss result being a heads or a tails is 1, in other words: certain. Your task: You are going to have to work out the probability of one roll of a die returning two given outcomes, or rolls. Given that dice rolls are mutually exclusive, you will have to implement the above forumala. To make this interesting (this is a coding challenge after all), these dice are not fair and thus the probabilites of receiving each roll is different. You will be given a two-dimensional array containing the number each of the results (1-6) of the die and the probability of that roll for example `[1 , 0.23]` as well as the two rolls for example `1` and `5`. Given the two roll probabilities to calculate, return the probability of a single roll of the die returning either. If the total probability of the six rolls doesn't add up to one, there is a problem with the die; in this case, return null. Return your result as a string to two decimal places. Example below: `1 : 1/6` `2 : 1/6` `3 : 1/6` `4 : 1/6` `5 : 1/6` `6 : 1/6` If asked for the rolls `1` and `2` then you would need to sum the probabilities, both `1/6` therefore `2/6` and return this. As above, you will need to return it as a decimal and not a fraction. Also feel free to reuse/extend the following starter code: ```python def mutually_exclusive(dice, call1, call2): ```
{"functional": "_inputs = [[[[3, 0.4], [4, 0.1], [1, 0.01], [2, 0.09], [5, 0.2], [6, 0.1]], 1, 6], [[[1, 0.1], [2, 0.14], [3, 0.16], [4, 0.2], [5, 0.15], [6, 0.25]], 1, 4], [[[1, 0.6], [2, 0.1001], [3, 0.0999], [4, 0.1], [5, 0.05], [6, 0.05]], 3, 4], [[[6, 0.25], [1, 0.1], [3, 0.16], [2, 0.14], [5, 0.15], [4, 0.2]], 1, 6], [[[3, 0.4], [4, 0.1], [1, 0.01], [2, 0.09], [5, 0.2], [6, 0.2]], 1, 6]]\n_outputs = [[None], ['0.30'], ['0.20'], ['0.35'], ['0.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(mutually_exclusive(*i), o[0])"}
601
468
coding
Solve the programming task below in a Python markdown code block. JJ found a balanced parenthesis sequence. He does not like balanced parentheses so he will make the parenthesis sequence unbalanced by swapping adjacent characters in the sequence. JJ is lazy and wants to know minimum number of adjacent swaps required to make the given balanced parenthesis sequence unbalanced. A parenthesis sequence is called balanced if one can turn it into a valid mathematical expression by adding characters + and 1. Sequences such as (())() and ()() are balanced whereas sequences such as ())( and )() are unbalanced. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains S - a balanced parenthesis sequence. ------ Output Format ------ For each test case, output the minimum number of adjacent swaps required to make the parenthesis sequence unbalanced. ------ Constraints ------ $1 ≤ T ≤ 5\cdot10^{4}$ $2 ≤ |S| ≤ 10^{5}$ - Sum of $S$ does not exceeds $10^{6}$ over all test cases $S$ is a balanced parentheses sequence ----- Sample Input 1 ------ 4 () (()) ()() ((()))(()) ----- Sample Output 1 ------ 1 2 1 2 ----- explanation 1 ------ - Test case $1$: Swap the first and second character to get the unbalanced sequence )(. - Test case $2$: Swap the second and third character first to obtain the bracket sequence ()(). Now you can swap the first and second character to obtain the sequence )(() which is unbalanced.
{"inputs": ["4\n()\n(())\n()()\n((()))(())\n"], "outputs": ["1\n2\n1\n2\n"]}
343
35
coding
Solve the programming task below in a Python markdown code block. There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls. First, Snuke will arrange the N balls in a row from left to right. Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible. How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K. -----Constraints----- - 1 \leq K \leq N \leq 2000 -----Input----- Input is given from Standard Input in the following format: N K -----Output----- Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7. -----Sample Input----- 5 3 -----Sample Output----- 3 6 1 There are three ways to arrange the balls so that Takahashi will need exactly one move: (B, B, B, R, R), (R, B, B, B, R), and (R, R, B, B, B). (R and B stands for red and blue, respectively). There are six ways to arrange the balls so that Takahashi will need exactly two moves: (B, B, R, B, R), (B, B, R, R, B), (R, B, B, R, B), (R, B, R, B, B), (B, R, B, B, R), and (B, R, R, B, B). There is one way to arrange the balls so that Takahashi will need exactly three moves: (B, R, B, R, B).
{"inputs": ["7 3", "7 5", "5 5", "7 4", "7 2", "5 2", "3 3", "2 3"], "outputs": ["5\n20\n10\n", "3\n12\n6\n0\n0\n", "1\n0\n0\n0\n0\n", "4\n18\n12\n1\n", "6\n15\n", "4\n6\n", "1\n0\n0\n", "0\n0\n0\n"]}
465
122
coding
Solve the programming task below in a Python markdown code block. In this problem, you will be given a polynomial, you have to print what it becomes after differentiation. Following are the rules for differentiation: - For a polynomial f(x), its differentiation is defined as f'(x). - If a is a constant, then differentiation of af(x) is af'(x). - If f(x) = h(x) + g(x) , then f'(x) = h'(x) + g'(x) - If f(x) = x n, then f'(x) = nxn-1. This is true for all n ≠ 0 . - If f(x) = c, where c is a constant, f'(x) = 0. If you are still uncomfortable with differentiation, please read the following: - Link to Wikihow page - Link to Wikipedia entry. -----Input----- First line contains T, the number of test cases to follow. Each test case contains the follows, the first line contains N, the number of non zero terms in the polynomial. Then N lines follow, each line contains a pair of integer which denotes a term in the polynomial, where the first element denotes the coefficient (a) and the second denotes the exponent (p) of the term. -----Output----- Print the polynomial after differentiation in the desired format as described below. - If the coefficient of a term in the output polynomial is 3, and the corresponding exponent is 2, print it as 3x^2 - Print " + " (with single space on both side) between each output term. - Print the terms in decreasing value of exponent. - For the constant term (if any), you have to just print the coefficient. You should not print x^0. -----Constraints----- - 1 ≤ T ≤ 10 - Subtask 1 (20 points) - 1 ≤ N ≤ 3 - 1 ≤ a ≤ 10 - 0 ≤ p ≤ 10 - Subtask 2 (80 points) - 1 ≤ N ≤ 10000 - 1 ≤ a ≤ 100000000 - 0 ≤ p ≤ 100000000 - No two inputs in a test case will have the same exponent. -----Example----- Input: 2 1 1 2 3 1 3 1 1 1 0 Output: 2x^1 3x^2 + 1
{"inputs": ["2\n1\n1 2\n3\n1 3\n1 1\n1 0"], "outputs": ["2x^1\n3x^2 + 1"]}
538
43
coding
Solve the programming task below in a Python markdown code block. William has a favorite bracket sequence. Since his favorite sequence is quite big he provided it to you as a sequence of positive integers $c_1, c_2, \dots, c_n$ where $c_i$ is the number of consecutive brackets "(" if $i$ is an odd number or the number of consecutive brackets ")" if $i$ is an even number. For example for a bracket sequence "((())()))" a corresponding sequence of numbers is $[3, 2, 1, 3]$. You need to find the total number of continuous subsequences (subsegments) $[l, r]$ ($l \le r$) of the original bracket sequence, which are regular bracket sequences. A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, sequences "(())()", "()" and "(()(()))" are regular, while ")(", "(()" and "(()))(" are not. -----Input----- The first line contains a single integer $n$ $(1 \le n \le 1000)$, the size of the compressed sequence. The second line contains a sequence of integers $c_1, c_2, \dots, c_n$ $(1 \le c_i \le 10^9)$, the compressed sequence. -----Output----- Output a single integer — the total number of subsegments of the original bracket sequence, which are regular bracket sequences. It can be proved that the answer fits in the signed 64-bit integer data type. -----Examples----- Input 5 4 1 2 3 1 Output 5 Input 6 1 3 2 1 2 4 Output 6 Input 6 1 1 1 1 2 2 Output 7 -----Note----- In the first example a sequence (((()(()))( is described. This bracket sequence contains $5$ subsegments which form regular bracket sequences: Subsequence from the $3$rd to $10$th character: (()(())) Subsequence from the $4$th to $5$th character: () Subsequence from the $4$th to $9$th character: ()(()) Subsequence from the $6$th to $9$th character: (()) Subsequence from the $7$th to $8$th character: () In the second example a sequence ()))(()(()))) is described. In the third example a sequence ()()(()) is described.
{"inputs": ["1\n6\n", "1\n6\n", "1\n7\n", "2\n49 1\n", "2\n49 1\n", "2\n15 1\n", "3\n1 2 39\n", "3\n1 2 39\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
544
105
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. For an array $B$, while it has more than one element, you can apply an operation on it - you choose any two elements $x,y$ (they may be the same value, but they should have different indices), delete them, and add an element $g(x, y)$ instead. Here $g(x, y)$ denotes the highest set bit in $x \oplus y$, or $0$ if they are equal. In other words, $g(x, y) = \max 2^{k}$, such that $2^{k} ≤ (x \oplus y)$ for $x \neq y$, and $g(x,y)=0$ if $x = y$. For example, $g(1,1) = 0, g(1,2) = 2, g(2,4)=4, g(13,17)=16$. Given an array $B$, we try to apply the operations repeatedly in such a way that when we are left with only one element at the end, that element is as small as possible. Let's denote this smallest possible value of the element at the end as $f(B)$. You are given an array $A$ with $N$ elements, you need to find the sum of $f(A_{l \ldots r})$ among all subsegments $1 ≤ l ≤ r ≤ N$. The answer may be large, so you need to find it modulo $998\,244\,353$. ------ Input: ------ The first line contains one integer $N$. The second line contains $N$ integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output: ------ In a single line, print the sum, modulo $998\,244\,353$. ------ Constraints ------ $1 ≤ N ≤ 300\,000$ $0 ≤ A_{i} < 2^{30}$ ------ Subtasks ------ 10 points : $1 ≤ N ≤ 10$ 10 points : $1 ≤ N ≤ 500$ 10 points : $1 ≤ N ≤ 5000$ 70 points : $1 ≤ N ≤ 300\,000$ ----- Sample Input 1 ------ 10 0 1 2 3 4 5 6 7 8 9 ----- Sample Output 1 ------ 160
{"inputs": ["10 \n0 1 2 3 4 5 6 7 8 9"], "outputs": ["160"]}
580
37
coding
Solve the programming task below in a Python markdown code block. Two people are playing Nimble! The rules of the game are: The game is played on a line of $n$ squares, indexed from $\mbox{0}$ to $n-1$. Each square $\boldsymbol{i}$ (where $0\leq i<n$) contains $c_i$ coins. For example: The players move in alternating turns. During each move, the current player must remove exactly $\mbox{1}$ coin from square $\boldsymbol{i}$ and move it to square $j$ if and only if $0\leq j<i$. The game ends when all coins are in square $\mbox{0}$ and nobody can make a move. The first player to have no available move loses the game. Given the value of $n$ and the number of coins in each square, determine whether the person who wins the game is the first or second person to move. Assume both players move optimally. Input Format The first line contains an integer, $\mathbf{T}$, denoting the number of test cases. Each of the $2T$ subsequent lines defines a test case. Each test case is described over the following two lines: An integer, $n$, denoting the number of squares. $n$ space-separated integers, $c_0,c_1,\ldots,c_{n-1}$, where each $c_i$ describes the number of coins at square $\boldsymbol{i}$. Constraints $1\leq T\leq10^4$ $1\leq n\leq100$ $0\leq c_i\leq10^9$ Output Format For each test case, print the name of the winner on a new line (i.e., either $\textbf{First}$ or $\textbf{Second}$). Sample Input 2 5 0 2 3 0 6 4 0 0 0 0 Sample Output First Second Explanation Explanation for $1^{st}$ testcase: The first player will shift one coin from $\textit{square}_2$ to $\textit{square}_0$. Hence, the second player is left with the squares $[1,2,2,0,6]$. Now whatever be his/her move is, the first player can always nullify the change by shifting a coin to the same square where he/she shifted it. Hence the last move is always played by the first player, so he wins. Exlanation for $2^{nd}$ testcase: There are no coins in any of the squares so the first player cannot make any move, hence second player wins.
{"inputs": ["2\n5\n0 2 3 0 6\n4\n0 0 0 0\n"], "outputs": ["First\nSecond\n"]}
573
38
coding
Solve the programming task below in a Python markdown code block. There is a sequence whose $n^{\text{th}}$ term is $T_n=n^2-(n-1)^2$ Evaluate the series $S_n=T_1+T_2+T_3+\cdots+T_n$ Find $S_n\:\text{mod}\:(10^9+7)$. Example $n=3$ The series is $1^2-0^2+2^2-1^2+3^2-2^2=1+3+5=9$. Function Description Complete the summingSeries function in the editor below. summingSeries has the following parameter(s): int n: the inclusive limit of the range to sum Returns int: the sum of the sequence, modulo $(10^9+7)$ Input Format The first line of input contains $\boldsymbol{\boldsymbol{t}}$, the number of test cases. Each test case consists of one line containing a single integer $n$. Constraints $1\leq t\leq10$ $1\leq n\leq10^{16}$ Sample Input 0 2 2 1 Sample Output 0 4 1 Explanation 0 Case 1: We have $4=1+3$ Case 2: We have $1=1$
{"inputs": ["2\n2\n1\n"], "outputs": ["4\n1\n"]}
312
20
coding
Solve the programming task below in a Python markdown code block. In this kata, you have to define a function named **func** that will take a list as input. You must try and guess the pattern how we get the output number and return list - **[output number,binary representation,octal representation,hexadecimal representation]**, but **you must convert that specific number without built-in : bin,oct and hex functions.** Examples : ```python func([12,13,6,3,6,45,123]) returns - [29,'11101','35','1d'] func([1,9,23,43,65,31,63,99]) returns - [41,'101001','51','29'] func([2,4,6,8,10,12,14,16,18,19]) returns - [10,'1010','12','a'] ``` Also feel free to reuse/extend the following starter code: ```python def func(l): ```
{"functional": "_inputs = [[[1, 4, 9, 16, 25, 36, 49]], [[2, 31, 3, 56, 46, 3, 467, 33]], [[9, 99, 999, 9999]], [[1, 12, 123, 1234, 12345]], [[1, 2, 6, 3, 1, 577, 12]]]\n_outputs = [[[20, '10100', '24', '14']], [[80, '1010000', '120', '50']], [[2776, '101011011000', '5330', 'ad8']], [[2743, '101010110111', '5267', 'ab7']], [[86, '1010110', '126', '56']]]\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(func(*i), o[0])"}
243
393
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a sentence that consists of some words separated by a single space, and a searchWord, check if searchWord is a prefix of any word in sentence. Return the index of the word in sentence (1-indexed) where searchWord is a prefix of this word. If searchWord is a prefix of more than one word, return the index of the first word (minimum index). If there is no such word return -1. A prefix of a string s is any leading contiguous substring of s.   Please complete the following python code precisely: ```python class Solution: def isPrefixOfWord(self, sentence: str, searchWord: str) -> int: ```
{"functional": "def check(candidate):\n assert candidate(sentence = \"i love eating burger\", searchWord = \"burg\") == 4\n assert candidate(sentence = \"this problem is an easy problem\", searchWord = \"pro\") == 2\n assert candidate(sentence = \"i am tired\", searchWord = \"you\") == -1\n\n\ncheck(Solution().isPrefixOfWord)"}
156
85
coding
Solve the programming task below in a Python markdown code block. You are given two integer arrays a_0, a_1, ..., a_{N - 1} and b_0, b_1, ..., b_{M - 1}. Calculate the array c_0, c_1, ..., c_{(N - 1) + (M - 1)}, defined by c_i = \sum_{j = 0}^i a_j b_{i - j} \bmod 998244353. Constraints * 1 \leq N, M \leq 524288 * 0 \leq a_i, b_i < 998244353 * All values in Input are integer. Input Input is given from Standard Input in the following format: N M a_0 a_1 ... a_{N-1} b_0 b_1 ... b_{M-1} Output Print the answer in the following format: c_0 c_1 ... c_{(N - 1) + (M - 1)} Output Print the answer in the following format: c_0 c_1 ... c_{(N - 1) + (M - 1)} Examples Input 4 5 1 2 3 4 5 6 7 8 9 Output 5 16 34 60 70 70 59 36 Input 1 1 10000000 10000000 Output 871938225
{"inputs": ["1 1\n10000000\n10100000", "1 1\n10001000\n10100000", "4 5\n1 2 3 4\n5 6 7 4 9", "1 1\n10001000\n10110000", "4 5\n1 1 3 4\n5 6 7 4 9", "1 1\n10001000\n00110000", "4 5\n1 2 3 8\n5 6 7 8 9", "1 1\n10010000\n10100000"], "outputs": ["631096519\n", "748652989\n", "5 16 34 56 62 58 43 36\n", "934217689\n", "5 11 28 49 58 49 43 36\n", "44722994\n", "5 16 34 80 94 98 91 72\n", "808416866\n"]}
361
324
coding
Solve the programming task below in a Python markdown code block. Build a function `sumNestedNumbers`/`sum_nested_numbers` that finds the sum of all numbers in a series of nested arrays raised to the power of their respective nesting levels. Numbers in the outer most array should be raised to the power of 1. For example, should return `1 + 2*2 + 3 + 4*4 + 5*5*5 === 149` Also feel free to reuse/extend the following starter code: ```python def sum_nested_numbers(a, depth=1): ```
{"functional": "_inputs = [[[0]], [[1, 2, 3, 4, 5]], [[1, [2], 3, [4, [5]]]], [[6, [5], [[4]], [[[3]]], [[[[2]]]], [[[[[1]]]]]]], [[1, [-1], [[1]], [[[-1]]], [[[[1]]]]]]]\n_outputs = [[0], [15], [149], [209], [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(sum_nested_numbers(*i), o[0])"}
126
249
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer num, return the number of digits in num that divide num. An integer val divides nums if nums % val == 0.   Please complete the following python code precisely: ```python class Solution: def countDigits(self, num: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(num = 7) == 1\n assert candidate(num = 121) == 2\n assert candidate(num = 1248) == 4\n\n\ncheck(Solution().countDigits)"}
76
60
coding
Solve the programming task below in a Python markdown code block. Chef has with him an array A of length N. In one move, he can delete any element from A. Find the minimum number of deletions Chef must make so that the following condition holds: Let B denote the resulting array, and M be the length of B. Then, B_{i} \oplus B_{j} ≤ 1 for every 1 ≤ i, j ≤ M. Here, \oplus denotes the [bitwise XOR] operation. For example, [3, 3, 3] and [6, 7, 6, 7] are valid final arrays, while [1, 2] and [6, 7, 8] are not (because 1 \oplus 2 = 3 and 7\oplus 8 = 15, respectively). ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains a single integer N, denoting the length of array A. - The second line contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} — the elements of array A. ------ Output Format ------ For each test case, output on a new line the answer: the minimum number of deletions required so that the given condition is satisfied. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 3\cdot 10^{5}$ $0 ≤ A_{i} ≤ N$ - The sum of $N$ over all test cases won't exceed $3\cdot 10^{5}$. ----- Sample Input 1 ------ 4 4 2 2 2 2 5 3 4 3 4 4 5 1 2 3 4 0 6 5 5 5 6 6 6 ----- Sample Output 1 ------ 0 2 3 3 ----- explanation 1 ------ Test case $1$: The given array already satisfies the condition, no deletions need to be done. Test case $2$: Chef can delete both the $3$'s to make the array $[4, 4, 4]$, which satisfies the condition. Test case $3$: Chef can use three moves as follows: - Delete the $1$, the array is now $[2, 3, 4, 0]$. - Delete the $4$, the array is now $[2, 3, 0]$. - Delete the $0$, the array is now $[2, 3]$ which satisfies the condition. It can be verified that using two or less deletions cannot give an array that satisfies the condition. Test case $4$: Chef must either delete all the $5$'s or all the $6$'s.
{"inputs": ["4\n4\n2 2 2 2\n5\n3 4 3 4 4\n5\n1 2 3 4 0\n6\n5 5 5 6 6 6\n"], "outputs": ["0\n2\n3\n3\n"]}
635
68
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given n points on a 2D plane, find if there is such a line parallel to the y-axis that reflects the given points symmetrically. In other words, answer whether or not if there exists a line that after reflecting all points over the given line, the original points' set is the same as the reflected ones. Note that there can be repeated points.   Please complete the following python code precisely: ```python class Solution: def isReflected(self, points: List[List[int]]) -> bool: ```
{"functional": "def check(candidate):\n assert candidate(points = [[1,1],[-1,1]]) == True\n assert candidate(points = [[1,1],[-1,-1]]) == False\n\n\ncheck(Solution().isReflected)"}
124
54
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
Solve the programming task below in a Python markdown code block. You have an array $a$ of length $n$. You can exactly once select an integer $len$ between $1$ and $n - 1$ inclusively, and then sort in non-decreasing order the prefix of the array of length $len$ and the suffix of the array of length $n - len$ independently. For example, if the array is $a = [3, 1, 4, 5, 2]$, and you choose $len = 2$, then after that the array will be equal to $[1, 3, 2, 4, 5]$. Could it be that after performing this operation, the array will not be sorted in non-decreasing order? -----Input----- There are several test cases in the input data. The first line contains a single integer $t$ ($1 \leq t \leq 100$) — the number of test cases. This is followed by the test cases description. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^4$) — the length of the array. The second line of the test case contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the array elements. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^4$. -----Output----- For each test case of input data, output "YES" (without quotes), if the array may be not sorted in non-decreasing order, output "NO" (without quotes) otherwise. You can output each letter in any case (uppercase or lowercase). -----Examples----- Input 3 3 2 2 1 4 3 1 2 1 5 1 2 2 4 4 Output YES YES NO -----Note----- In the first test case, it's possible to select $len = 1$, then after operation, the array will not be sorted in non-decreasing order and will be equal to $[2, 1, 2]$. In the second test case, it's possible to select $len = 3$, then after operation, the array will not be sorted in non-decreasing order and will be equal to $[1, 2, 3, 1]$. In the third test case, the array will be sorted in non-decreasing order for every possible $len$.
{"inputs": ["1\n4\n1 3 2 4\n", "1\n7\n1 2 3 5 4 6 7\n", "3\n3\n2 2 1\n4\n3 1 2 1\n5\n1 2 2 4 4\n"], "outputs": ["YES\n", "YES\n", "YES\nYES\nNO\n"]}
552
90
coding
Solve the programming task below in a Python markdown code block. Takahashi became a pastry chef and opened a shop La Confiserie d'ABC to celebrate AtCoder Beginner Contest 100. The shop sells N kinds of cakes. Each kind of cake has three parameters "beauty", "tastiness" and "popularity". The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the popularity of z_i. These values may be zero or negative. Ringo has decided to have M pieces of cakes here. He will choose the set of cakes as follows: - Do not have two or more pieces of the same kind of cake. - Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity). Find the maximum possible value of (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) for the set of cakes that Ringo chooses. -----Constraints----- - N is an integer between 1 and 1 \ 000 (inclusive). - M is an integer between 0 and N (inclusive). - x_i, y_i, z_i \ (1 \leq i \leq N) are integers between -10 \ 000 \ 000 \ 000 and 10 \ 000 \ 000 \ 000 (inclusive). -----Input----- Input is given from Standard Input in the following format: N M x_1 y_1 z_1 x_2 y_2 z_2 : : x_N y_N z_N -----Output----- Print the maximum possible value of (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) for the set of cakes that Ringo chooses. -----Sample Input----- 5 3 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 -----Sample Output----- 56 Consider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty, tastiness and popularity will be as follows: - Beauty: 1 + 3 + 9 = 13 - Tastiness: 5 + 5 + 7 = 17 - Popularity: 9 + 8 + 9 = 26 The value (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) here is 13 + 17 + 26 = 56. This is the maximum value.
{"inputs": ["5 3\n3 1 4\n1 5 9\n2 6 5\n3 5 8\n9 6 9", "5 3\n3 1 4\n1 5 9\n2 6 5\n3 5 1\n7 7 9", "5 3\n3 1 4\n1 5 9\n2 6 5\n3 5 8\n9 7 9", "5 3\n3 1 4\n1 5 9\n2 6 5\n3 5 8\n9 7 9\n", "5 3\n3 0 4\n1 5 18\n2 6 5\n3 5 8\n7 7 9", "5 3\n3 0 4\n1 5 18\n2 6 5\n3 5 4\n7 7 9", "5 5\n1 -2 4\n0 5 -6\n7 -8 -16\n-10 7 -12\n13 -3 15", "5 5\n1 -2 4\n-4 5 -9\n7 -8 -16\n-10 7 -12\n13 -3 15"], "outputs": ["55\n", "51\n", "56", "56\n", "63\n", "60\n", "27\n", "26\n"]}
611
341
coding
Solve the programming task below in a Python markdown code block. Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher suspected that Amr is sleeping and asked him a question to make sure he wasn't. First he gave Amr two positive integers n and k. Then he asked Amr, how many integer numbers x > 0 exist such that: Decimal representation of x (without leading zeroes) consists of exactly n digits; There exists some integer y > 0 such that: $y \operatorname{mod} k = 0$; decimal representation of y is a suffix of decimal representation of x. As the answer to this question may be pretty huge the teacher asked Amr to output only its remainder modulo a number m. Can you help Amr escape this embarrassing situation? -----Input----- Input consists of three integers n, k, m (1 ≤ n ≤ 1000, 1 ≤ k ≤ 100, 1 ≤ m ≤ 10^9). -----Output----- Print the required number modulo m. -----Examples----- Input 1 2 1000 Output 4 Input 2 2 1000 Output 45 Input 5 3 1103 Output 590 -----Note----- A suffix of a string S is a non-empty string that can be obtained by removing some number (possibly, zero) of first characters from S.
{"inputs": ["1 1 1\n", "1 2 2\n", "1 2 2\n", "1 1 1\n", "1 4 2\n", "1 2 1000\n", "2 2 1000\n", "5 3 1103\n"], "outputs": ["0", "0", "0\n", "0\n", "0\n", "4", "45", "590"]}
319
109
coding
Solve the programming task below in a Python markdown code block. # Introduction The ragbaby cipher is a substitution cipher that encodes/decodes a text using a keyed alphabet and their position in the plaintext word they are a part of. To encrypt the text `This is an example.` with the key `cipher`, first construct a keyed alphabet: ``` c i p h e r a b d f g j k l m n o q s t u v w x y z ``` Then, number the letters in the text as follows: ``` T h i s i s a n e x a m p l e . 1 2 3 4 1 2 1 2 1 2 3 4 5 6 7 ``` To obtain the encoded text, replace each character of the word with the letter in the keyed alphabet the corresponding number of places to the right of it (wrapping if necessary). Non-alphabetic characters are preserved to mark word boundaries. Our ciphertext is then `Urew pu bq rzfsbtj.` # Task Wirate functions `encode` and `decode` which accept 2 parameters: - `text` - string - a text to encode/decode - `key` - string - a key # Notes - handle lower and upper case in `text` string - `key` consists of only lowercase characters Also feel free to reuse/extend the following starter code: ```python def encode(text, key): ```
{"functional": "_inputs = [['cipher', 'cipher'], ['cipher', 'cccciiiiippphheeeeerrrrr']]\n_outputs = [['ihrbfj'], ['ihrbfj']]\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(encode(*i), o[0])"}
371
182
coding
Solve the programming task below in a Python markdown code block. This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced. Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each. As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball. The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies? Polycarp can throw his fire ball into an archer if the latter is already killed. Input The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has. Output In the first line print t — the required minimum amount of fire balls. In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order. Examples Input 3 2 1 2 2 2 Output 3 2 2 2 Input 4 3 1 1 4 1 1 Output 4 2 2 3 3
{"inputs": ["3 5 3\n3 2 2\n", "3 5 3\n1 2 1\n", "3 5 2\n9 3 6\n", "3 5 3\n1 4 1\n", "3 2 1\n2 2 2\n", "3 5 3\n10 9 7\n", "3 5 1\n1 9 10\n", "3 5 3\n12 9 7\n"], "outputs": ["2\n2 2 ", "1\n2 ", "5\n2 2 2 2 2 ", "1\n2 ", "3\n2 2 2 ", "4\n2 2 2 2 ", "11\n2 2 2 2 2 2 2 2 2 2 2 ", "5\n2 2 2 2 2 "]}
493
211
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string "". The testcases will be generated such that the answer is unique.   Please complete the following python code precisely: ```python class Solution: def minWindow(self, s: str, t: str) -> str: ```
{"functional": "def check(candidate):\n assert candidate(s = \"ADOBECODEBANC\", t = \"ABC\") == \"BANC\"\n assert candidate(s = \"a\", t = \"a\") == \"a\"\n\n\ncheck(Solution().minWindow)"}
113
61
coding
Solve the programming task below in a Python markdown code block. Ilya lives in a beautiful city of Chordalsk. There are $n$ houses on the street Ilya lives, they are numerated from $1$ to $n$ from left to right; the distance between every two neighboring houses is equal to $1$ unit. The neighboring houses are $1$ and $2$, $2$ and $3$, ..., $n-1$ and $n$. The houses $n$ and $1$ are not neighboring. The houses are colored in colors $c_1, c_2, \ldots, c_n$ so that the $i$-th house is colored in the color $c_i$. Everyone knows that Chordalsk is not boring, so there are at least two houses colored in different colors. Ilya wants to select two houses $i$ and $j$ so that $1 \leq i < j \leq n$, and they have different colors: $c_i \neq c_j$. He will then walk from the house $i$ to the house $j$ the distance of $(j-i)$ units. Ilya loves long walks, so he wants to choose the houses so that the distance between them is the maximum possible. Help Ilya, find this maximum possible distance. -----Input----- The first line contains a single integer $n$ ($3 \leq n \leq 300\,000$) — the number of cities on the street. The second line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \leq c_i \leq n$) — the colors of the houses. It is guaranteed that there is at least one pair of indices $i$ and $j$ so that $1 \leq i < j \leq n$ and $c_i \neq c_j$. -----Output----- Print a single integer — the maximum possible distance Ilya can walk. -----Examples----- Input 5 1 2 3 2 3 Output 4 Input 3 1 2 1 Output 1 Input 7 1 1 3 1 1 1 1 Output 4 -----Note----- In the first example the optimal way is to walk from the first house to the last one, where Ilya can walk the distance of $5-1 = 4$ units. In the second example the optimal way is to either walk from the first house to the second or from the second to the third. Both these ways have the distance of $1$ unit. In the third example the optimal way is to walk from the third house to the last one, where Ilya can walk the distance of $7-3 = 4$ units.
{"inputs": ["3\n1 2 1\n", "3\n1 1 3\n", "3\n1 1 3\n", "3\n1 0 3\n", "3\n1 2 2\n", "3\n0 0 3\n", "3\n1 3 2\n", "3\n1 2 1\n"], "outputs": ["1\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "1\n"]}
601
118
coding
Solve the programming task below in a Python markdown code block. Ohana Matsumae is trying to clean a room, which is divided up into an n by n grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean. She wants to sweep some columns of the room to maximize the number of rows that are completely clean. It is not allowed to sweep over the part of the column, Ohana can only sweep the whole column. Return the maximum number of rows that she can make completely clean. -----Input----- The first line of input will be a single integer n (1 ≤ n ≤ 100). The next n lines will describe the state of the room. The i-th line will contain a binary string with n characters denoting the state of the i-th row of the room. The j-th character on this line is '1' if the j-th square in the i-th row is clean, and '0' if it is dirty. -----Output----- The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean. -----Examples----- Input 4 0101 1000 1111 0101 Output 2 Input 3 111 111 111 Output 3 -----Note----- In the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean. In the second sample, everything is already clean, so Ohana doesn't need to do anything.
{"inputs": ["1\n1\n", "1\n0\n", "1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "2\n10\n01\n", "2\n10\n01\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1", "1", "1\n", "1"]}
378
91
coding
Solve the programming task below in a Python markdown code block. Write a function called "filterEvenLengthWords". Given an array of strings, "filterEvenLengthWords" returns an array containing only the elements of the given array whose length is an even number. var output = filterEvenLengthWords(['word', 'words', 'word', 'words']); console.log(output); // --> ['word', 'word'] Also feel free to reuse/extend the following starter code: ```python def filter_even_length_words(words): ```
{"functional": "_inputs = [[['Hello', 'World']], [['One', 'Two', 'Three', 'Four']]]\n_outputs = [[[]], [['Four']]]\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(filter_even_length_words(*i), o[0])"}
107
177
coding
Solve the programming task below in a Python markdown code block. Your task is to construct a building which will be a pile of n cubes. The cube at the bottom will have a volume of n^3, the cube above will have volume of (n-1)^3 and so on until the top which will have a volume of 1^3. You are given the total volume m of the building. Being given m can you find the number n of cubes you will have to build? The parameter of the function findNb `(find_nb, find-nb, findNb)` will be an integer m and you have to return the integer n such as n^3 + (n-1)^3 + ... + 1^3 = m if such a n exists or -1 if there is no such n. ## Examples: ``` findNb(1071225) --> 45 findNb(91716553919377) --> -1 ``` Also feel free to reuse/extend the following starter code: ```python def find_nb(m): ```
{"functional": "_inputs = [[4183059834009], [24723578342962], [135440716410000], [40539911473216], [26825883955641], [41364076483082], [9541025211025], [112668204662785], [79172108332642], [1788719004901], [131443152397956], [1801879360282], [18262169777476], [11988186060816], [826691919076], [36099801072722], [171814395026], [637148782657], [6759306226], [33506766981009], [108806345136785], [14601798712901], [56454575667876], [603544088161], [21494785321], [1025292944081385001], [10252519345963644753025], [10252519345963644753026], [102525193459636447530260], [4], [16]]\n_outputs = [[2022], [-1], [4824], [3568], [3218], [-1], [2485], [-1], [-1], [-1], [4788], [-1], [2923], [2631], [1348], [-1], [-1], [-1], [-1], [3402], [-1], [-1], [3876], [1246], [541], [45001], [450010], [-1], [-1], [-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(find_nb(*i), o[0])"}
239
777
coding
Solve the programming task below in a Python markdown code block. You are given a string $s$ consisting of lowercase letters of the English alphabet. You must perform the following algorithm on $s$: Let $x$ be the length of the longest prefix of $s$ which occurs somewhere else in $s$ as a contiguous substring (the other occurrence may also intersect the prefix). If $x = 0$, break. Otherwise, remove the first $x$ characters of $s$, and repeat. A prefix is a string consisting of several first letters of a given string, without any reorders. An empty prefix is also a valid prefix. For example, the string "abcd" has 5 prefixes: empty string, "a", "ab", "abc" and "abcd". For instance, if we perform the algorithm on $s =$ "abcabdc", Initially, "ab" is the longest prefix that also appears somewhere else as a substring in $s$, so $s =$ "cabdc" after $1$ operation. Then, "c" is the longest prefix that also appears somewhere else as a substring in $s$, so $s =$ "abdc" after $2$ operations. Now $x=0$ (because there are no non-empty prefixes of "abdc" that also appear somewhere else as a substring in $s$), so the algorithm terminates. Find the final state of the string after performing the algorithm. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. This is followed by $t$ lines, each containing a description of one test case. Each line contains a string $s$. The given strings consist only of lowercase letters of the English alphabet and have lengths between $1$ and $2 \cdot 10^5$ inclusive. It is guaranteed that the sum of the lengths of $s$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, print a single line containing the string $s$ after executing the algorithm. It can be shown that such string is non-empty. -----Examples----- Input 6 abcabdc a bbbbbbbbbb codeforces cffcfccffccfcffcfccfcffccffcfccf zyzyzwxxyyxxyyzzyzzxxwzxwywxwzxxyzzw Output abdc a b deforces cf xyzzw -----Note----- The first test case is explained in the statement. In the second test case, no operations can be performed on $s$. In the third test case, Initially, $s =$ "bbbbbbbbbb". After $1$ operation, $s =$ "b". In the fourth test case, Initially, $s =$ "codeforces". After $1$ operation, $s =$ "odeforces". After $2$ operations, $s =$ "deforces".
{"inputs": ["6\nabcabdc\na\nbbbbbbbbbb\ncodeforces\ncffcfccffccfcffcfccfcffccffcfccf\nzyzyzwxxyyxxyyzzyzzxxwzxwywxwzxxyzzw\n"], "outputs": ["abdc\na\nb\ndeforces\ncf\nxyzzw\n"]}
630
83
coding
Solve the programming task below in a Python markdown code block. You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom. Constraints * 1 \leq w \leq |S| \leq 1000 * S consists of lowercase English letters. * w is an integer. Input Input is given from Standard Input in the following format: S w Output Print the desired string in one line. Examples Input abcdefgh 3 Output adg Input lllll 1 Output lllll Input souuundhound 2 Output suudon
{"inputs": ["lllll\n2", "llmll\n2", "llmll\n4", "llmll\n6", "llmll\n1", "mlmll\n2", "mlmll\n4", "llmlm\n4"], "outputs": ["lll\n", "lml\n", "ll\n", "l\n", "llmll\n", "mml\n", "ml\n", "lm\n"]}
168
99
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer num, return a string of its base 7 representation.   Please complete the following python code precisely: ```python class Solution: def convertToBase7(self, num: int) -> str: ```
{"functional": "def check(candidate):\n assert candidate(num = 100) == \"202\"\n assert candidate(num = -7) == \"-10\"\n\n\ncheck(Solution().convertToBase7)"}
64
53
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image. To flip an image horizontally means that each row of the image is reversed. For example, flipping [1,1,0] horizontally results in [0,1,1]. To invert an image means that each 0 is replaced by 1, and each 1 is replaced by 0. For example, inverting [0,1,1] results in [1,0,0].   Please complete the following python code precisely: ```python class Solution: def flipAndInvertImage(self, image: List[List[int]]) -> List[List[int]]: ```
{"functional": "def check(candidate):\n assert candidate(image = [[1,1,0],[1,0,1],[0,0,0]]) == [[1,0,0],[0,1,0],[1,1,1]]\n assert candidate(image = [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]) == [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]\n\n\ncheck(Solution().flipAndInvertImage)"}
160
142
coding
Solve the programming task below in a Python markdown code block. In a class of N students, a class test was held. The i^{th} student scored A_{i} marks. It is also known that the scores of all students were distinct. A student passes the test if their score is strictly greater than the passing mark. Given that exactly X students pass in the test, find the maximum value of the passing mark of the test. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains two space-separated integers N and X — the number of students in the class and the number of students that passed in the test. - The next line contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}, where the i^{th} integer denotes the marks of the i^{th} student. ------ Output Format ------ For each test case, output on a new line, the maximum value of the passing mark of the test. ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ N ≤ 100$ $1 ≤ X ≤ N$ $1 ≤ A_{i} ≤ 100$ - All elements of array $A$ are distinct. ----- Sample Input 1 ------ 3 2 2 5 1 4 1 5 1 7 4 4 3 15 70 100 31 ----- Sample Output 1 ------ 0 6 30 ----- explanation 1 ------ Test case $1$: Since both students pass the test, both students scored greater than passing marks. The maximum value of passing marks can be $0$, as both students have marks greater than $0$. Test case $2$: Only one student passes the test. Thus, the third student has passed the test by scoring $7$ marks. The passing marks of the test is $6$. Test case $3$: Since three students pass the test, students $2, 3,$ and $4$ scored greater than passing marks. The maximum value of passing marks can be $30$, three students have marks greater than $30$.
{"inputs": ["3\n2 2\n5 1\n4 1\n5 1 7 4\n4 3\n15 70 100 31\n"], "outputs": ["0\n6\n30\n"]}
486
56
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are playing the Bulls and Cows game with your friend. You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info: The number of "bulls", which are digits in the guess that are in the correct position. The number of "cows", which are digits in the guess that are in your secret number but are located in the wrong position. Specifically, the non-bull digits in the guess that could be rearranged such that they become bulls. Given the secret number secret and your friend's guess guess, return the hint for your friend's guess. The hint should be formatted as "xAyB", where x is the number of bulls and y is the number of cows. Note that both secret and guess may contain duplicate digits.   Please complete the following python code precisely: ```python class Solution: def getHint(self, secret: str, guess: str) -> str: ```
{"functional": "def check(candidate):\n assert candidate(secret = \"1807\", guess = \"7810\") == \"1A3B\"\n assert candidate(secret = \"1123\", guess = \"0111\") == \"1A1B\"\n\n\ncheck(Solution().getHint)"}
223
73
coding
Solve the programming task below in a Python markdown code block. There are $n$ piles of sand where the $i$-th pile has $a_i$ blocks of sand. The $i$-th pile is called too tall if $1 < i < n$ and $a_i > a_{i-1} + a_{i+1}$. That is, a pile is too tall if it has more sand than its two neighbours combined. (Note that piles on the ends of the array cannot be too tall.) You are given an integer $k$. An operation consists of picking $k$ consecutive piles of sand and adding one unit of sand to them all. Formally, pick $1 \leq l,r \leq n$ such that $r-l+1=k$. Then for all $l \leq i \leq r$, update $a_i \gets a_i+1$. What is the maximum number of piles that can simultaneously be too tall after some (possibly zero) operations? -----Input----- The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $n$ and $k$ ($3 \leq n \leq 2 \cdot 10^5$; $1 \leq k \leq n$) — the number of piles of sand and the size of the operation, respectively. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — the sizes of the piles. 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 single integer — the maximum number of piles that are simultaneously too tall after some (possibly zero) operations. -----Examples----- Input 3 5 2 2 9 2 4 1 4 4 1 3 2 1 3 1 1 3 1 Output 2 0 1 -----Note----- In the first test case, we can perform the following three operations: Add one unit of sand to piles $1$ and $2$: $[{3}, {10}, 2, 4, 1]$. Add one unit of sand to piles $4$ and $5$: $[3, 10, 2, {5}, {2}]$. Add one unit of sand to piles $3$ and $4$: $[3, 10, {3}, {6}, 2]$. Now piles $2$ and $4$ are too tall, so in this case the answer is $2$. It can be shown that it is impossible to make more than $2$ piles too tall. In the second test case, any operation will increase all piles by $1$ unit, so the number of too tall piles will always be $0$. In the third test case, we can increase any pile by $1$ unit of sand. It can be shown that the maximum number of too tall piles is $1$.
{"inputs": ["3\n5 2\n2 9 2 4 1\n4 4\n1 3 2 1\n3 1\n1 3 1\n"], "outputs": ["2\n0\n1\n"]}
711
54
coding
Solve the programming task below in a Python markdown code block. You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. -----Constraints----- - -100≤A,B,C≤100 - A, B and C are all integers. -----Input----- Input is given from Standard Input in the following format: A B C -----Output----- If the condition is satisfied, print Yes; otherwise, print No. -----Sample Input----- 1 3 2 -----Sample Output----- Yes C=2 is not less than A=1 and not greater than B=3, and thus the output should be Yes.
{"inputs": ["7 5 4", "2 0 2", "1 0 2", "7 5 3", "1 1 2", "7 3 3", "1 1 0", "7 1 3"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
144
94
coding
Solve the programming task below in a Python markdown code block. In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi? -----Constraints----- - a is an integer between 1 and 12 (inclusive). - b is an integer between 1 and 31 (inclusive). - 2018-a-b is a valid date in Gregorian calendar. -----Input----- Input is given from Standard Input in the following format: a b -----Output----- Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi. -----Sample Input----- 5 5 -----Sample Output----- 5 There are five days that are Takahashi: 1-1, 2-2, 3-3, 4-4 and 5-5.
{"inputs": ["9 5", "4 0", "6 5", "8 5", "5 2", "6 9", "2 0", "4 1"], "outputs": ["8\n", "3\n", "5\n", "7\n", "4\n", "6\n", "1\n", "3\n"]}
291
78
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a positive integer n, you can apply one of the following operations: If n is even, replace n with n / 2. If n is odd, replace n with either n + 1 or n - 1. Return the minimum number of operations needed for n to become 1.   Please complete the following python code precisely: ```python class Solution: def integerReplacement(self, n: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(n = 8) == 3\n assert candidate(n = 7) == 4\n assert candidate(n = 4) == 2\n\n\ncheck(Solution().integerReplacement)"}
110
55
coding
Solve the programming task below in a Python markdown code block. Write a function, `persistence`, that takes in a positive parameter `num` and returns its multiplicative persistence, which is the number of times you must multiply the digits in `num` until you reach a single digit. For example: ```python persistence(39) => 3 # Because 3*9 = 27, 2*7 = 14, 1*4=4 # and 4 has only one digit. persistence(999) => 4 # Because 9*9*9 = 729, 7*2*9 = 126, # 1*2*6 = 12, and finally 1*2 = 2. persistence(4) => 0 # Because 4 is already a one-digit number. ``` ```python persistence(39) # returns 3, because 3*9=27, 2*7=14, 1*4=4 # and 4 has only one digit persistence(999) # returns 4, because 9*9*9=729, 7*2*9=126, # 1*2*6=12, and finally 1*2=2 persistence(4) # returns 0, because 4 is already a one-digit number ``` Also feel free to reuse/extend the following starter code: ```python def persistence(n): ```
{"functional": "_inputs = [[39], [4], [25], [999], [444]]\n_outputs = [[3], [0], [2], [4], [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(persistence(*i), o[0])"}
336
184
coding
Solve the programming task below in a Python markdown code block. We want an array, but not just any old array, an array with contents! Write a function that produces an array with the numbers `0` to `N-1` in it. For example, the following code will result in an array containing the numbers `0` to `4`: ``` arr(5) // => [0,1,2,3,4] ``` Also feel free to reuse/extend the following starter code: ```python def arr(n=0): ```
{"functional": "_inputs = [[4], [0]]\n_outputs = [[[0, 1, 2, 3]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(arr(*i), o[0])"}
117
167
coding
Solve the programming task below in a Python markdown code block. # Task In ChessLand there is a small but proud chess bishop with a recurring dream. In the dream the bishop finds itself on an `n × m` chessboard with mirrors along each edge, and it is not a bishop but a ray of light. This ray of light moves only along diagonals (the bishop can't imagine any other types of moves even in its dreams), it never stops, and once it reaches an edge or a corner of the chessboard it reflects from it and moves on. Given the initial position and the direction of the ray, find its position after `k` steps where a step means either moving from one cell to the neighboring one or reflecting from a corner of the board. # Example For `boardSize = [3, 7], initPosition = [1, 2], initDirection = [-1, 1] and k = 13,` the output should be `[0, 1]`. Here is the bishop's path: ``` [1, 2] -> [0, 3] -(reflection from the top edge) -> [0, 4] -> [1, 5] -> [2, 6] -(reflection from the bottom right corner) -> [2, 6] ->[1, 5] -> [0, 4] -(reflection from the top edge) -> [0, 3] ->[1, 2] -> [2, 1] -(reflection from the bottom edge) -> [2, 0] -(reflection from the left edge) -> [1, 0] -> [0, 1]``` ![](https://codefightsuserpics.s3.amazonaws.com/tasks/chessBishopDream/img/example.png?_tm=1472324389202) # Input/Output - `[input]` integer array `boardSize` An array of two integers, the number of `rows` and `columns`, respectively. Rows are numbered by integers from `0 to boardSize[0] - 1`, columns are numbered by integers from `0 to boardSize[1] - 1` (both inclusive). Constraints: `1 ≤ boardSize[i] ≤ 20.` - `[input]` integer array `initPosition` An array of two integers, indices of the `row` and the `column` where the bishop initially stands, respectively. Constraints: `0 ≤ initPosition[i] < boardSize[i]`. - `[input]` integer array `initDirection` An array of two integers representing the initial direction of the bishop. If it stands in `(a, b)`, the next cell he'll move to is `(a + initDirection[0], b + initDirection[1])` or whichever it'll reflect to in case it runs into a mirror immediately. Constraints: `initDirection[i] ∈ {-1, 1}`. - `[input]` integer `k` Constraints: `1 ≤ k ≤ 1000000000`. - `[output]` an integer array The position of the bishop after `k` steps. Also feel free to reuse/extend the following starter code: ```python def chess_bishop_dream(board_size, init_position, init_direction, k): ```
{"functional": "_inputs = [[[3, 7], [1, 2], [-1, 1], 13], [[1, 2], [0, 0], [1, 1], 6], [[2, 2], [1, 0], [1, 1], 12], [[1, 1], [0, 0], [1, -1], 1000000000], [[2, 3], [1, 2], [-1, -1], 41], [[17, 19], [14, 8], [1, -1], 239239], [[17, 19], [16, 18], [1, 1], 239239239]]\n_outputs = [[[0, 1]], [[0, 1]], [[1, 0]], [[0, 0]], [[0, 2]], [[4, 17]], [[10, 2]]]\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(chess_bishop_dream(*i), o[0])"}
720
375
coding
Solve the programming task below in a Python markdown code block. ## Witamy! You are in Poland and want to order a drink. You need to ask "One beer please": "Jedno piwo poprosze" ``` java Translator.orderingBeers(1) = "Jedno piwo poprosze" ``` But let's say you are really thirsty and want several beers. Then you need to count in Polish. And more difficult, you need to understand the Polish grammar and cases (nominative, genitive, accustative and more). ## The grammar In English, the plural of "beer" is simply "beers", with an "s". In Polish, the plural of "piwo" (nominative singular) is "piw" (genitive plural) or "piwa" (nominative plural). It depends! The rules: * usually the plural is genitive: "piw" * but after the numerals 2, 3, 4, and compound numbers ending with them (e.g. 22, 23, 24), the noun is plural and takes the same case as the numeral, so nominative: "piwa" * and exception to the exception: for 12, 13 and 14, it's the genitive plural again: "piw" (yes, I know, it's crazy!) ## The numbers From 0 to 9: "zero", "jeden", "dwa", "trzy", "cztery", "piec", "szesc" , "siedem", "osiem", "dziewiec" From 10 to 19 it's nearly the same, with "-ascie" at the end: "dziesiec", "jedenascie", "dwanascie", "trzynascie", "czternascie", "pietnascie", "szesnascie", "siedemnascie", "osiemnascie", "dziewietnascie" Tens from 10 to 90 are nearly the same, with "-ziesci" or "ziesiat" at the end: "dziesiec", "dwadziescia", "trzydziesci", "czterdziesci", "piecdziesiat", "szescdziesiat", "siedemdziesiat", "osiemdziesiat", "dziewiecdziesiat" Compound numbers are constructed similarly to English: tens + units. For example, 22 is "dwadziescia dwa". "One" could be male ("Jeden"), female ("Jedna") or neuter ("Jedno"), which is the case for "beer" (piwo). But all other numbers are invariant, even if ending with "jeden". Ah, and by the way, if you don't want to drink alcohol (so no beers are ordered), ask for mineral water instead: "Woda mineralna". Note: if the number of beers is outside your (limited) Polish knowledge (0-99), raise an error! --- More about the crazy polish grammar: https://en.wikipedia.org/wiki/Polish_grammar Also feel free to reuse/extend the following starter code: ```python def ordering_beers(beers): ```
{"functional": "_inputs = [[0], [1], [2], [3], [4], [5], [8], [10], [11], [12], [13], [14], [15], [16], [20], [21], [22], [28], [33], [44], [55], [98], [99]]\n_outputs = [['Woda mineralna poprosze'], ['Jedno piwo poprosze'], ['Dwa piwa poprosze'], ['Trzy piwa poprosze'], ['Cztery piwa poprosze'], ['Piec piw poprosze'], ['Osiem piw poprosze'], ['Dziesiec piw poprosze'], ['Jedenascie piw poprosze'], ['Dwanascie piw poprosze'], ['Trzynascie piw poprosze'], ['Czternascie piw poprosze'], ['Pietnascie piw poprosze'], ['Szesnascie piw poprosze'], ['Dwadziescia piw poprosze'], ['Dwadziescia jeden piw poprosze'], ['Dwadziescia dwa piwa poprosze'], ['Dwadziescia osiem piw poprosze'], ['Trzydziesci trzy piwa poprosze'], ['Czterdziesci cztery piwa poprosze'], ['Piecdziesiat piec piw poprosze'], ['Dziewiecdziesiat osiem piw poprosze'], ['Dziewiecdziesiat dziewiec piw poprosze']]\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(ordering_beers(*i), o[0])"}
722
516
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 2D integer array rectangles where rectangles[i] = [li, hi] indicates that ith rectangle has a length of li and a height of hi. You are also given a 2D integer array points where points[j] = [xj, yj] is a point with coordinates (xj, yj). The ith rectangle has its bottom-left corner point at the coordinates (0, 0) and its top-right corner point at (li, hi). Return an integer array count of length points.length where count[j] is the number of rectangles that contain the jth point. The ith rectangle contains the jth point if 0 <= xj <= li and 0 <= yj <= hi. Note that points that lie on the edges of a rectangle are also considered to be contained by that rectangle.   Please complete the following python code precisely: ```python class Solution: def countRectangles(self, rectangles: List[List[int]], points: List[List[int]]) -> List[int]: ```
{"functional": "def check(candidate):\n assert candidate(rectangles = [[1,2],[2,3],[2,5]], points = [[2,1],[1,4]]) == [2,1]\n assert candidate(rectangles = [[1,1],[2,2],[3,3]], points = [[1,3],[1,1]]) == [1,3]\n\n\ncheck(Solution().countRectangles)"}
228
94
coding
Solve the programming task below in a Python markdown code block. problem A city in Canada where JOI lives is divided into a grid pattern by w roads that extend straight in the north-south direction and h roads that extend straight in the east-west direction. The w roads in the north-south direction are numbered 1, 2, ..., w in order from the west. In addition, h roads in the east-west direction are numbered 1, 2, ..., h in order from the south. The intersection of the i-th north-south road from the west and the j-th east-west road from the south is represented by (i, j). JOI lives near the intersection (1, 1) and drives to a company near the intersection (w, h). Cars can only move along the road. JOI travels only to the east or north to shorten his commute time. The city also has the following traffic rules to reduce traffic accidents: * A car that turns at an intersection cannot turn at the intersection immediately after that. That is, it is not permissible to go one block after turning at an intersection and turn again. At this time, how many possible commuting routes for Mr. JOI? Given w and h, create a program that outputs the remainder of JOI's number of commuting routes divided by 100000. input The input consists of multiple datasets. Each dataset consists of one line, and two integers w, h (2 ≤ w ≤ 100, 2 ≤ h ≤ 100) are written, separated by a blank. w represents the number of roads in the north-south direction, and h represents the number of roads in the east-west direction. When both w and h are 0, it indicates the end of input. The number of data sets does not exceed 5. output For each data set, the remainder of JOI's number of commuting routes divided by 100000 is output on one line. Example Input 3 4 15 15 0 0 Output 5 43688
{"inputs": ["1 4\n7 16\n0 0", "1 6\n7 31\n0 0", "2 6\n7 31\n0 0", "2 4\n9 34\n0 0", "4 4\n8 40\n0 0", "4 2\n7 34\n0 0", "6 2\n7 65\n0 0", "2 7\n7 32\n0 0"], "outputs": ["1\n1102\n", "1\n6912\n", "2\n6912\n", "2\n96567\n", "8\n47890\n", "2\n8938\n", "2\n55345\n", "2\n7550\n"]}
440
193
coding
Solve the programming task below in a Python markdown code block. *After getting lost in Hollywood, ibti decided to give you yet another problem related to permutations.* Consider a permutation P of length 2\cdot N. An array A of size N is generated using the permutation P, such that the i^{th} element of the array is a pair having value, A_{i} = (P_{i} \bmod N, P_{(i+N)} \bmod N). The permutation P (of length 2\cdot N) is called N-beautiful, if, all elements of the array A are distinct. Given integers K and M, your task is to count the number of i-beautiful permutations for each 1 ≤ i ≤ K. Since the answers can be large, print them modulo M. ------ Input Format ------ The first and only line of the input contains two space-separated integers K, M - the parameters defined in the statement. ------ Output Format ------ Print K space-separated integers, the i^{th} integer will denote the number of i-beautiful permutations modulo M. ------ Constraints ------ $1 ≤K ≤2 \cdot 10^{5}$ $10^{7} + 19 ≤M ≤10^{9}+7$ - It is guaranteed that $M$ is a prime number. ------ subtasks ------ Subtask 1 (50 points): $1 ≤ K ≤ 10^{3}$ Subtask 2 (50 points): No further constraints. ----- Sample Input 1 ------ 8 269696969 ----- Sample Output 1 ------ 2 16 576 34560 3110400 142258231 78756849 13872609 ----- explanation 1 ------ - All permutations of length $2$ are $1$-beautiful, thus the first value we print is $2! = 2$. - There are $16$ $2$-beautiful permutations out of the $24$ possible permutations. The $8$ non-beautiful permutations are: $\{1, 3, 2, 4\}, \{1, 3, 4, 2\}, \{2, 4, 1, 3\}, \{2, 4, 3, 1\}, \{3, 1, 2, 4\}, \{3, 1, 4, 2\}, \{4, 2, 1, 3\}, \{4, 2, 3, 1\}$ For example, the permutation $\{1, 3, 2, 4\}$ is not beautiful as $A = [(1 \bmod 2, 2 \bmod 2), (3 \bmod 2, 4 \bmod 2)] = [(1, 0), (1, 0)]$. Both elements of the array $A$ are same.
{"inputs": ["8 269696969"], "outputs": ["2 16 576 34560 3110400 142258231 78756849 13872609"]}
663
71
coding
Solve the programming task below in a Python markdown code block. There are total N friends went to Chef's Pizza shop. There they bought a pizza. Chef divided the pizza into K equal slices. Now you have to check whether these K pizza slices can be distributed equally among the friends. Also given that every person should get at least one slice. If the above conditions are possible then print "YES" otherwise print "NO". -----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 integers N. The second line of each test case contains K. -----Output:----- For each test case, print a single line containing "YES" if the given conditions are true else "NO" if the given conditions are false. -----Constraints----- 1<=T<=10 1<=N<=10^6 1<=K<=10^6 -----Sample Input:----- 2 10 20 12 5 -----Sample Output:----- YES NO -----EXPLANATION:----- Explanation case 1: since there are 10 friends and 20 pizza slice, so each can get 2 slices, so "YES". Explanation case 2: Since there are 12 friends and only 5 pizza slice, so there is no way pizza slices can be distributed equally and each friend gets at least one pizza slice, so "NO".
{"inputs": ["2\n10\n20\n12\n5"], "outputs": ["YES\nNO"]}
309
25
coding
Solve the programming task below in a Python markdown code block. Your retro heavy metal band, VÄxën, originally started as kind of a joke, just because why would anyone want to use the crappy foosball table in your startup's game room when they could be rocking out at top volume in there instead? Yes, a joke, but now all the top tech companies are paying you top dollar to play at their conferences and big product-release events. And just as how in the early days of the Internet companies were naming everything "i"-this and "e"-that, now that VÄxënmänïä has conquered the tech world, any company that doesn't use Hëävÿ Mëtäl Ümläüts in ëvëry pössïblë pläcë is looking hopelessly behind the times. Well, with great power chords there must also come great responsibility! You need to help these companies out by writing a function that will guarantee that their web sites and ads and everything else will RÖCK ÄS MÜCH ÄS PÖSSÏBLË! Just think about it -- with the licensing fees you'll be getting from Gööglë, Fäcëböök, Äpplë, and Ämäzön alone, you'll probably be able to end world hunger, make college and Marshall stacks free to all, and invent self-driving bumper cars. Sö lët's gët röckïng and röllïng! Pëdal tö thë MËTÄL! Here's a little cheatsheet that will help you write your function to replace the so-last-year letters a-e-i-o-u-and-sometimes-y with the following totally rocking letters: ``` A = Ä = \u00c4 E = Ë = \u00cb I = Ï = \u00cf O = Ö = \u00d6 U = Ü = \u00dc Y = Ÿ = \u0178 a = ä = \u00e4 e = ë = \u00eb i = ï = \u00ef o = ö = \u00f6 u = ü = \u00fc y = ÿ = \u00ff ``` ### Python issues First, Python in the Codewars environment has some codec/encoding issues with extended ASCII codes like the umlaut-letters required above. With Python 2.7.6, when writing your solution you can just copy the above umlaut-letters (instead of the unicode sequences) and paste them into your code, but I haven't found something yet that will work for *both* 2.7.6 and 3.4.3 -- hopefully I will find something soon (answers/suggestions are welcome!), and hopefully that part will also be easier with other languages when I add them. Second, along the same lines, don't bother trying to use string translate() and maketrans() to solve this in Python 2.7.6, because maketrans will see the character-mapping strings as being different lengths. Use a different approach instead. Also feel free to reuse/extend the following starter code: ```python def heavy_metal_umlauts(boring_text): ```
{"functional": "_inputs = [['Announcing the Macbook Air Guitar'], ['Facebook introduces new heavy metal reaction buttons'], [\"Strong sales of Google's VR Metalheadsets send tech stock prices soaring\"], ['Vegan Black Metal Chef hits the big time on Amazon TV']]\n_outputs = [['\u00c4nn\u00f6\u00fcnc\u00efng th\u00eb M\u00e4cb\u00f6\u00f6k \u00c4\u00efr G\u00fc\u00eft\u00e4r'], ['F\u00e4c\u00ebb\u00f6\u00f6k \u00efntr\u00f6d\u00fcc\u00ebs n\u00ebw h\u00eb\u00e4v\u00ff m\u00ebt\u00e4l r\u00eb\u00e4ct\u00ef\u00f6n b\u00fctt\u00f6ns'], [\"Str\u00f6ng s\u00e4l\u00ebs \u00f6f G\u00f6\u00f6gl\u00eb's VR M\u00ebt\u00e4lh\u00eb\u00e4ds\u00ebts s\u00ebnd t\u00ebch st\u00f6ck pr\u00efc\u00ebs s\u00f6\u00e4r\u00efng\"], ['V\u00ebg\u00e4n Bl\u00e4ck M\u00ebt\u00e4l Ch\u00ebf h\u00efts th\u00eb b\u00efg t\u00efm\u00eb \u00f6n \u00c4m\u00e4z\u00f6n TV']]\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(heavy_metal_umlauts(*i), o[0])"}
712
605
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. For positive integers $a$ and $b$, we say that a fraction $\frac{a}{b}$ is *good* if it is equal to $\frac{m}{m+1}$ for some positive integer $m$. You are given an integer $N$. Find the number of pairs of integers $i, j$ such that $1 ≤ i, j ≤ N$ and the fraction $\frac{i}{i+1} \cdot \frac{j+1}{j}$ is good. ------ Input ------ The first and only line of the input contains a single integer $N$. ------ Output ------ Print a single line containing one integer ― the number of pairs of integers $i, j$ ($1 ≤ i, j ≤ N$) such that $\frac{i}{i + 1} \cdot \frac{j+1}{j}$ is good. ------ Constraints ------ $1 ≤ N ≤ 1,000,000$ ------ Subtasks ------ Subtask #1 (5 points): $1 ≤ N ≤ 2,000$ Subtask #2 (10 points): $1 ≤ N ≤ 100,000$ Subtask #3 (85 points): original constraints ----- Sample Input 1 ------ 5 ----- Sample Output 1 ------ 8 ----- explanation 1 ------ The following eight pairs $(i, j)$ give good fractions: $(1,2)$, $(1,3)$, $(2,3)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ and $(4,5)$.
{"inputs": ["5"], "outputs": ["8"]}
392
12
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n. You roll a fair 6-sided dice n times. Determine the total number of distinct sequences of rolls possible such that the following conditions are satisfied: The greatest common divisor of any adjacent values in the sequence is equal to 1. There is at least a gap of 2 rolls between equal valued rolls. More formally, if the value of the ith roll is equal to the value of the jth roll, then abs(i - j) > 2. Return the total number of distinct sequences possible. Since the answer may be very large, return it modulo 109 + 7. Two sequences are considered distinct if at least one element is different.   Please complete the following python code precisely: ```python class Solution: def distinctSequences(self, n: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(n = 4) == 184\n assert candidate(n = 2) == 22\n\n\ncheck(Solution().distinctSequences)"}
188
47
coding
Solve the programming task below in a Python markdown code block. There are N people, conveniently numbered 1 through N. We want to divide them into some number of groups, under the following two conditions: - Every group contains between A and B people, inclusive. - Let F_i be the number of the groups containing exactly i people. Then, for all i, either F_i=0 or C≤F_i≤D holds. Find the number of these ways to divide the people into groups. Here, two ways to divide them into groups is considered different if and only if there exists two people such that they belong to the same group in exactly one of the two ways. Since the number of these ways can be extremely large, print the count modulo 10^9+7. -----Constraints----- - 1≤N≤10^3 - 1≤A≤B≤N - 1≤C≤D≤N -----Input----- The input is given from Standard Input in the following format: N A B C D -----Output----- Print the number of ways to divide the people into groups under the conditions, modulo 10^9+7. -----Sample Input----- 3 1 3 1 2 -----Sample Output----- 4 There are four ways to divide the people: - (1,2),(3) - (1,3),(2) - (2,3),(1) - (1,2,3) The following way to divide the people does not count: (1),(2),(3). This is because it only satisfies the first condition and not the second.
{"inputs": ["7 3 4 2 5", "8 2 3 1 3", "7 1 3 1 3", "7 1 6 2 5", "0 3 8 2 7", "2 1 3 1 2", "8 2 5 1 3", "4 2 7 1 2"], "outputs": ["0\n", "280\n", "595\n", "105\n", "1\n", "2\n", "581\n", "4\n"]}
336
134
coding
Solve the programming task below in a Python markdown code block. Finally, a COVID vaccine is out on the market and the Chefland government has asked you to form a plan to distribute it to the public as soon as possible. There are a total of $N$ people with ages $a_1, a_2, \ldots, a_N$. There is only one hospital where vaccination is done and it is only possible to vaccinate up to $D$ people per day. Anyone whose age is $\ge 80$ or $\le 9$ is considered to be at risk. On each day, you may not vaccinate both a person who is at risk and a person who is not at risk. Find the smallest number of days needed to vaccinate everyone. -----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 two space-separated integers $N$ and $D$. - 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 smallest required number of days. -----Constraints----- - $1 \le T \le 10$ - $1 \le N \le 10^4$ - $1 \le D \le 10^5$ - $1 \le a_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (100 points): original constraints -----Example Input----- 2 10 1 10 20 30 40 50 60 90 80 100 1 5 2 9 80 27 72 79 -----Example Output----- 10 3 -----Explanation----- Example case 1: We do not need to worry about how the people are grouped, since only one person can be vaccinated in a single day. We require as many days as there are people. Example case 2: There are two people at risk and three people who are not at risk. One optimal strategy is to vaccinate the two people at risk on day $1$ and the remaining three on the next $2$ days.
{"inputs": ["2\n10 1\n10 20 30 40 50 60 90 80 100 1\n5 2\n9 80 27 72 79"], "outputs": ["10\n3"]}
508
68
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, return the largest palindromic integer that can be represented as the product of two n-digits integers. Since the answer can be very large, return it modulo 1337.   Please complete the following python code precisely: ```python class Solution: def largestPalindrome(self, n: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(n = 2) == 987\n assert candidate(n = 1) == 9\n\n\ncheck(Solution().largestPalindrome)"}
91
46
coding
Solve the programming task below in a Python markdown code block. Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. It is guaranteed that all the values are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$). Polycarp wants to know answers on $q$ queries. The $j$-th query is described as integer number $b_j$. The answer to the query is the minimum number of coins that is necessary to obtain the value $b_j$ using some subset of coins (Polycarp can use only coins he has). If Polycarp can't obtain the value $b_j$, the answer to the $j$-th query is -1. The queries are independent (the answer on the query doesn't affect Polycarp's coins). -----Input----- The first line of the input contains two integers $n$ and $q$ ($1 \le n, q \le 2 \cdot 10^5$) — the number of coins and the number of queries. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ — values of coins ($1 \le a_i \le 2 \cdot 10^9$). It is guaranteed that all $a_i$ are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$). The next $q$ lines contain one integer each. The $j$-th line contains one integer $b_j$ — the value of the $j$-th query ($1 \le b_j \le 10^9$). -----Output----- Print $q$ integers $ans_j$. The $j$-th integer must be equal to the answer on the $j$-th query. If Polycarp can't obtain the value $b_j$ the answer to the $j$-th query is -1. -----Example----- Input 5 4 2 4 8 2 4 8 5 14 10 Output 1 -1 3 2
{"inputs": ["3 3\n1 1 1\n1\n2\n3\n", "3 3\n1 1 1\n1\n2\n3\n", "3 3\n1 1 1\n1\n4\n3\n", "3 3\n1 2 1\n1\n4\n3\n", "3 3\n1 4 1\n1\n4\n3\n", "3 3\n1 4 1\n1\n6\n3\n", "3 3\n1 4 2\n1\n6\n3\n", "3 3\n1 4 2\n1\n6\n2\n"], "outputs": ["1\n2\n3\n", "1\n2\n3\n", "1\n-1\n3\n", "1\n3\n2\n", "1\n1\n-1\n", "1\n3\n-1\n", "1\n2\n2\n", "1\n2\n1\n"]}
476
217
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A string is called a happy prefix if is a non-empty prefix which is also a suffix (excluding itself). Given a string s, return the longest happy prefix of s. Return an empty string "" if no such prefix exists.   Please complete the following python code precisely: ```python class Solution: def longestPrefix(self, s: str) -> str: ```
{"functional": "def check(candidate):\n assert candidate(s = \"level\") == \"l\"\n assert candidate(s = \"ababab\") == \"abab\"\n\n\ncheck(Solution().longestPrefix)"}
93
49
coding
Solve the programming task below in a Python markdown code block. For every good kata idea there seem to be quite a few bad ones! In this kata you need to check the provided 2 dimensional array (x) for good ideas 'good' and bad ideas 'bad'. If there are one or two good ideas, return 'Publish!', if there are more than 2 return 'I smell a series!'. If there are no good ideas, as is often the case, return 'Fail!'. The sub arrays may not be the same length. The solution should be case insensitive (ie good, GOOD and gOOd all count as a good idea). All inputs may not be strings. Also feel free to reuse/extend the following starter code: ```python def well(arr): ```
{"functional": "_inputs = [[[['bad', 'bAd', 'bad'], ['bad', 'bAd', 'bad'], ['bad', 'bAd', 'bad']]], [[['gOOd', 'bad', 'BAD', 'bad', 'bad'], ['bad', 'bAd', 'bad'], ['GOOD', 'bad', 'bad', 'bAd']]], [[['gOOd', 'bAd', 'BAD', 'bad', 'bad', 'GOOD'], ['bad'], ['gOOd', 'BAD']]]]\n_outputs = [['Fail!'], ['Publish!'], ['I smell a series!']]\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(well(*i), o[0])"}
161
271
coding
Solve the programming task below in a Python markdown code block. # Kata Task Given a list of random integers, return the Three Amigos. These are 3 numbers that live next to each other in the list, and who have the **most** in common with each other by these rules: * lowest statistical range * same parity # Notes * The list will contain at least 3 numbers * If there is more than one answer then return the first one found (reading the list left to right) * If there is no answer (e.g. no 3 adjacent numbers with same parity) then return an empty list. # Examples * ex1 * Input = ```[1, 2, 34, 2, 1, 5, 3, 5, 7, 234, 2, 1]``` * Result = ```[5,3,5]``` * ex2 * Input = ```[2, 4, 6, 8, 10, 2, 2, 2, 1, 1, 1, 5, 3]``` * Result = ```[2,2,2]``` * ex3 * Input = ```[2, 4, 5, 3, 6, 3, 1, 56, 7, 6, 3, 12]``` * Result = ```[]``` Also feel free to reuse/extend the following starter code: ```python def three_amigos(numbers): ```
{"functional": "_inputs = [[[1, 2, 34, 2, 1, 5, 3, 5, 7, 234, 2, 1]], [[2, 4, 6, 8, 10, 2, 2, 2, 1, 1, 1, 5, 3]], [[2, 4, 5, 3, 6, 3, 1, 56, 7, 6, 3, 12]], [[1, 3, 5]], [[1, 3, 2]], [[1, 3, 5, 7, 9, 11, 13, 15]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 3, 5]], [[-5, -4, -2, 0, 1, 2, 3, 4, 5]], [[-8, -25, 21, -7, -5]], [[8, 5, 20, 17, -18, -11, 19, 5]], [[6, 9, -18, -19, -14, -10, -24]], [[0, -1, -1, 1, -1, -1, -3]], [[-8, -2, 0, 2, 4, 6, 8]]]\n_outputs = [[[5, 3, 5]], [[2, 2, 2]], [[]], [[1, 3, 5]], [[]], [[1, 3, 5]], [[1, 3, 5]], [[-4, -2, 0]], [[21, -7, -5]], [[-11, 19, 5]], [[-14, -10, -24]], [[-1, -1, 1]], [[-2, 0, 2]]]\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(three_amigos(*i), o[0])"}
338
606
coding
Solve the programming task below in a Python markdown code block. The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single line of input, one integer $K$. -----Output:----- For each test case, output as the pattern. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq K \leq 100$ -----Sample Input:----- 3 2 3 4 -----Sample Output:----- 21 1 123 21 1 4321 123 21 1 -----EXPLANATION:----- No need, else pattern can be decode easily.
{"inputs": ["3\n2\n3\n4"], "outputs": ["21\n1\n123\n21\n1\n4321\n123\n21\n1"]}
202
44
coding
Solve the programming task below in a Python markdown code block. The elections in which three candidates participated have recently ended. The first candidate received $a$ votes, the second one received $b$ votes, the third one received $c$ votes. For each candidate, solve the following problem: how many votes should be added to this candidate so that he wins the election (i.e. the number of votes for this candidate was strictly greater than the number of votes for any other candidate)? Please note that for each candidate it is necessary to solve this problem independently, i.e. the added votes for any candidate do not affect the calculations when getting the answer for the other two candidates. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow. Each test case consists of one line containing three integers $a$, $b$, and $c$ ($0 \le a,b,c \le 10^9$). -----Output----- For each test case, output in a separate line three integers $A$, $B$, and $C$ ($A, B, C \ge 0$) separated by spaces — the answers to the problem for the first, second, and third candidate, respectively. -----Examples----- Input 5 0 0 0 10 75 15 13 13 17 1000 0 0 0 1000000000 0 Output 1 1 1 66 0 61 5 5 0 0 1001 1001 1000000001 0 1000000001 -----Note----- None
{"inputs": ["1\n47 74 4774\n", "5\n0 0 0\n10 75 15\n13 13 17\n1000 0 0\n0 1000000000 0\n"], "outputs": ["4728 4701 0\n", "1 1 1\n66 0 61\n5 5 0\n0 1001 1001\n1000000001 0 1000000001\n"]}
390
145
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. You are wandering in the explorer space of the 2050 Conference. The explorer space can be viewed as an undirected weighted grid graph with size n× m. The set of vertices is \{(i, j)|1≤ i≤ n, 1≤ j≤ m\}. Two vertices (i_1,j_1) and (i_2, j_2) are connected by an edge if and only if |i_1-i_2|+|j_1-j_2|=1. At each step, you can walk to any vertex connected by an edge with your current vertex. On each edge, there are some number of exhibits. Since you already know all the exhibits, whenever you go through an edge containing x exhibits, your boredness increases by x. For each starting vertex (i, j), please answer the following question: What is the minimum possible boredness if you walk from (i, j) and go back to it after exactly k steps? You can use any edge for multiple times but the boredness on those edges are also counted for multiple times. At each step, you cannot stay on your current vertex. You also cannot change direction while going through an edge. Before going back to your starting vertex (i, j) after k steps, you can visit (i, j) (or not) freely. Input The first line contains three integers n, m and k (2≤ n, m≤ 500, 1≤ k≤ 20). The j-th number (1≤ j ≤ m - 1) in the i-th line of the following n lines is the number of exibits on the edge between vertex (i, j) and vertex (i, j+1). The j-th number (1≤ j≤ m) in the i-th line of the following n-1 lines is the number of exibits on the edge between vertex (i, j) and vertex (i+1, j). The number of exhibits on each edge is an integer between 1 and 10^6. Output Output n lines with m numbers each. The j-th number in the i-th line, answer_{ij}, should be the minimum possible boredness if you walk from (i, j) and go back to it after exactly k steps. If you cannot go back to vertex (i, j) after exactly k steps, answer_{ij} should be -1. Examples Input 3 3 10 1 1 1 1 1 1 1 1 1 1 1 1 Output 10 10 10 10 10 10 10 10 10 Input 2 2 4 1 3 4 2 Output 4 4 10 6 Input 2 2 3 1 2 3 4 Output -1 -1 -1 -1 Note In the first example, the answer is always 10 no matter how you walk. In the second example, answer_{21} = 10, the path is (2,1) → (1,1) → (1,2) → (2,2) → (2,1), the boredness is 4 + 1 + 2 + 3 = 10.
{"inputs": ["2 2 3\n1\n3\n4 2\n", "2 2 4\n1\n2\n1 4\n", "2 2 4\n1\n4\n4 2\n", "2 2 4\n2\n2\n1 4\n", "2 2 6\n1\n4\n4 2\n", "2 2 4\n1\n2\n2 4\n", "2 2 6\n1\n4\n4 0\n", "2 2 4\n1\n4\n2 4\n"], "outputs": ["-1 -1\n-1 -1\n", "4 4\n4 6\n", "4 4\n10 6\n", "4 6\n4 6\n", "6 6\n12 8\n", "4 4\n6 8\n", "2 0\n8 0\n", "4 4\n6 10\n"]}
730
219
coding
Solve the programming task below in a Python markdown code block. Many years ago, Roman numbers were defined by only `4` digits: `I, V, X, L`, which represented `1, 5, 10, 50`. These were the only digits used. The value of a sequence was simply the sum of digits in it. For instance: ``` IV = VI = 6 IX = XI = 11 XXL = LXX = XLX = 70 ``` It is easy to see that this system is ambiguous, and some numbers could be written in many different ways. Your goal is to determine how many distinct integers could be represented by exactly `n` Roman digits grouped together. For instance: ```Perl solve(1) = 4, because groups of 1 are [I, V, X, L]. solve(2) = 10, because the groups of 2 are [II, VI, VV, XI, XV, XX, IL, VL, XL, LL] corresponding to [2,6,10,11,15,20,51,55,60,100]. solve(3) = 20, because groups of 3 start with [III, IIV, IVV, ...etc] ``` `n <= 10E7` More examples in test cases. Good luck! Also feel free to reuse/extend the following starter code: ```python def solve(n): ```
{"functional": "_inputs = [[1], [2], [3], [4], [5], [6], [10], [10000000]]\n_outputs = [[4], [10], [20], [35], [56], [83], [244], [489999753]]\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])"}
322
219
coding
Solve the programming task below in a Python markdown code block. Chef's phone has a total storage of S MB. Also, Chef has 2 apps already installed on his phone which occupy X MB and Y MB respectively. He wants to install another app on his phone whose memory requirement is Z MB. For this, he might have to delete the apps already installed on his phone. Determine the minimum number of apps he has to delete from his phone so that he has enough memory to install the third app. ------ Input Format ------ - The first line contains a single integer T — the number of test cases. Then the test cases follow. - The first and only line of each test case contains four integers S, X, Y and Z — the total memory of Chef's phone, the memory occupied by the two already installed apps and the memory required by the third app. ------ Output Format ------ For each test case, output the minimum number of apps Chef has to delete from his phone so that he can install the third app. ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤ S ≤ 500$ $1 ≤X ≤Y ≤S$ $X + Y ≤S$ $Z ≤S$ ----- Sample Input 1 ------ 4 10 1 2 3 9 4 5 1 15 5 10 15 100 20 30 75 ----- Sample Output 1 ------ 0 1 2 1 ----- explanation 1 ------ Test Case 1: The unused memory in the phone is $7$ MB. Therefore Chef can install the $3$ MB app without deleting any app. Test Case 2: There is no unused memory in the phone. Chef has to first delete one of the apps from the phone and then only he can install the $1$ MB app. Test Case 3: There is no unused memory in the phone. Chef has to first delete both the apps from the phone and then only he can install the $15$ MB app. Test Case 4: The unused memory in the phone is $50$ MB. Chef has to first delete the $30$ MB app from the phone and then only he can install the $75$ MB app.
{"inputs": ["4\n10 1 2 3\n9 4 5 1\n15 5 10 15\n100 20 30 75\n"], "outputs": ["0\n1\n2\n1\n"]}
483
61
coding
Solve the programming task below in a Python markdown code block. For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ldots, P_{1}). You are given a positive integer N. You need to output a permutation P of length N such that L(P) = L(P^{R}), or say that none exist. Note: P is said to be a permutation of length N if P is a sequence of length N consisting of N distinct integers between 1 and N. For example, (3, 1, 2) is a permutation of length 3, but (1, 4, 2), (2, 2, 3) and (2, 1) are not. ------ 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. - Each test case consists of a single line containing one integer N — the length of the permutation to be constructed. ------ Output Format ------ For each test case, output on a new line "YES" if there exists a valid permutation, and "NO" if there doesn't. If you outputted "YES", on the next line, output a valid permutation P as N space-separated integers, the i^{th} of which is P_{i}. You can print each letter of the string in any case (upper or lower) (for instance, strings YES, yEs, and yes will be considered identical). ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ - The sum of $N$ across all test cases does not exceed $2 \cdot 10^{5}$ ----- Sample Input 1 ------ 2 2 3 ----- Sample Output 1 ------ NO YES 1 3 2 ----- explanation 1 ------ Test Case $1$: There are two permutations of length $2$ — $(1, 2)$ and $(2, 1)$. The length of the LIS of $(1, 2)$ is $2$ and the length of the LIS of $(2, 1)$ is $1$. Since these permutations are reverses of each other and have unequal LIS lengths, there is no valid permutation of length $2$. Test Case $2$: The length of the LIS of $(1, 3, 2)$ is $2$, and the length of the LIS of its reverse, $(2, 3, 1)$, is also $2$. Therefore, this is a valid permutation of length $3$.
{"inputs": ["2\n2\n3"], "outputs": ["NO\nYES\n1 3 2"]}
645
24
coding
Solve the programming task below in a Python markdown code block. You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $x$ that occurs in the array $2$ or more times. Take the first two occurrences of $x$ in this array (the two leftmost occurrences). Remove the left of these two occurrences, and the right one is replaced by the sum of this two values (that is, $2 \cdot x$). Determine how the array will look after described operations are performed. For example, consider the given array looks like $[3, 4, 1, 2, 2, 1, 1]$. It will be changed in the following way: $[3, 4, 1, 2, 2, 1, 1]~\rightarrow~[3, 4, 2, 2, 2, 1]~\rightarrow~[3, 4, 4, 2, 1]~\rightarrow~[3, 8, 2, 1]$. If the given array is look like $[1, 1, 3, 1, 1]$ it will be changed in the following way: $[1, 1, 3, 1, 1]~\rightarrow~[2, 3, 1, 1]~\rightarrow~[2, 3, 2]~\rightarrow~[3, 4]$. -----Input----- The first line contains a single integer $n$ ($2 \le n \le 150\,000$) — the number of elements in the array. The second line contains a sequence from $n$ elements $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^{9}$) — the elements of the array. -----Output----- In the first line print an integer $k$ — the number of elements in the array after all the performed operations. In the second line print $k$ integers — the elements of the array after all the performed operations. -----Examples----- Input 7 3 4 1 2 2 1 1 Output 4 3 8 2 1 Input 5 1 1 3 1 1 Output 2 3 4 Input 5 10 40 20 50 30 Output 5 10 40 20 50 30 -----Note----- The first two examples were considered in the statement. In the third example all integers in the given array are distinct, so it will not change.
{"inputs": ["5\n1 1 3 1 1\n", "5\n1 1 5 1 1\n", "5\n1 1 3 1 1\n", "5\n1 1 30 34 11\n", "7\n3 4 1 2 2 1 1\n", "7\n1 4 1 2 2 1 1\n", "7\n1 4 1 2 1 1 1\n", "7\n1 4 1 3 1 1 1\n"], "outputs": ["2\n3 4 \n", "2\n5 4 ", "2\n3 4 ", "4\n2 30 34 11 ", "4\n3 8 2 1 \n", "2\n8 4 ", "3\n8 2 1 ", "3\n3 8 1 "]}
592
213
coding
Solve the programming task below in a Python markdown code block. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it a_{k}) and delete it, at that all elements equal to a_{k} + 1 and a_{k} - 1 also must be deleted from the sequence. That step brings a_{k} points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. -----Input----- The first line contains integer n (1 ≤ n ≤ 10^5) that shows how many numbers are in Alex's sequence. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5). -----Output----- Print a single integer — the maximum number of points that Alex can earn. -----Examples----- Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 -----Note----- Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
{"inputs": ["2\n1 2\n", "2\n1 3\n", "2\n1 1\n", "2\n1 4\n", "2\n2 4\n", "2\n1 2\n", "3\n1 2 3\n", "3\n1 2 6\n"], "outputs": ["2\n", "4\n", "2\n", "5\n", "6\n", "2\n", "4\n", "8\n"]}
362
106
coding
Solve the programming task below in a Python markdown code block. _Based on [Project Euler problem 35](https://projecteuler.net/problem=35)_ A circular prime is a prime in which every circular permutation of that number is also prime. Circular permutations are created by rotating the digits of the number, for example: `197, 971, 719`. One-digit primes are circular primes by definition. Complete the function that dertermines if a number is a circular prime. There are 100 random tests for numbers up to 10000. Also feel free to reuse/extend the following starter code: ```python def circular_prime(n): ```
{"functional": "_inputs = [[197], [179], [971], [222], [9377], [7], [213], [35], [1]]\n_outputs = [[True], [False], [True], [False], [True], [True], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if 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(circular_prime(*i), o[0])"}
148
217
coding
Solve the programming task below in a Python markdown code block. You are given undirected weighted graph. Find the length of the shortest cycle which starts from the vertex 1 and passes throught all the edges at least once. Graph may contain multiply edges between a pair of vertices and loops (edges from the vertex to itself). Input The first line of the input contains two integers n and m (1 ≤ n ≤ 15, 0 ≤ m ≤ 2000), n is the amount of vertices, and m is the amount of edges. Following m lines contain edges as a triples x, y, w (1 ≤ x, y ≤ n, 1 ≤ w ≤ 10000), x, y are edge endpoints, and w is the edge length. Output Output minimal cycle length or -1 if it doesn't exists. Examples Input 3 3 1 2 1 2 3 1 3 1 1 Output 3 Input 3 2 1 2 3 2 3 4 Output 14
{"inputs": ["2 0\n", "1 0\n", "5 0\n", "3 0\n", "6 0\n", "15 0\n", "2 1\n1 1 3\n", "7 1\n3 4 4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "3\n", "-1\n"]}
230
99
coding
Solve the programming task below in a Python markdown code block. Compute A \times B, truncate its fractional part, and print the result as an integer. -----Constraints----- - 0 \leq A \leq 10^{15} - 0 \leq B < 10 - A is an integer. - B is a number with two digits after the decimal point. -----Input----- Input is given from Standard Input in the following format: A B -----Output----- Print the answer as an integer. -----Sample Input----- 198 1.10 -----Sample Output----- 217 We have 198 \times 1.10 = 217.8. After truncating the fractional part, we have the answer: 217.
{"inputs": ["2 0.01", "4 1.10", "2 1.10", "3 1.10", "1 0.01", "1 0.01\n", "0 9.98\n", "74 1.10"], "outputs": ["0\n", "4\n", "2\n", "3\n", "0", "0\n", "0\n", "81\n"]}
169
105
coding
Solve the programming task below in a Python markdown code block. ## Task Write a method `remainder` which takes two integer arguments, `dividend` and `divisor`, and returns the remainder when dividend is divided by divisor. Do NOT use the modulus operator (%) to calculate the remainder! #### Assumption Dividend will always be `greater than or equal to` divisor. #### Notes Make sure that the implemented `remainder` function works exactly the same as the `Modulus operator (%)`. ```if:java `SimpleInteger` is a tiny and immutable implementation of an integer number. Its interface is a very small subset of the `java.math.BigInteger` API: * `#add(SimpleInteger val)` * `#subtract(SimpleInteger val)` * `#multiply(SimpleInteger val)` * `#divide(SimpleInteger val)` * `#compareTo(SimpleInteger val)` ``` Also feel free to reuse/extend the following starter code: ```python def remainder(dividend, divisor): ```
{"functional": "_inputs = [[3, 2], [19, 2], [10, 2], [34, 7], [27, 5]]\n_outputs = [[1], [1], [0], [6], [2]]\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(remainder(*i), o[0])"}
208
197
coding
Solve the programming task below in a Python markdown code block. An uppercase or lowercase English letter \alpha will be given as input. If \alpha is uppercase, print A; if it is lowercase, print a. -----Constraints----- - \alpha is an uppercase (A - Z) or lowercase (a - z) English letter. -----Input----- Input is given from Standard Input in the following format: α -----Output----- If \alpha is uppercase, print A; if it is lowercase, print a. -----Sample Input----- B -----Sample Output----- A B is uppercase, so we should print A.
{"inputs": ["b", "C", "`", "D", "c", "E", "d", "F"], "outputs": ["a\n", "A\n", "a\n", "A\n", "a\n", "A\n", "a\n", "A\n"]}
126
61
coding
Solve the programming task below in a Python markdown code block. We need a function ```count_sel()``` that receives an array or list of integers (positive and negative) and may give us the following information in the order and structure presented bellow: ```[(1), (2), (3), [[(4)], 5]]``` (1) - Total amount of received integers. (2) - Total amount of different values the array has. (3) - Total amount of values that occur only once. (4) and (5) both in a list (4) - It is (or they are) the element(s) that has (or have) the maximum occurrence. If there are more than one, the elements should be sorted (by their value obviously) (5) - Maximum occurrence of the integer(s) Let's see some cases ```python ____ count_sel([-3, -2, -1, 3, 4, -5, -5, 5, -1, -5]) ----> [10, 7, 5, [[-5], 3]] (1) - The list has ten elements (10 numbers) (2) - We have seven different values: -5, -3, -2, -1, 3, 4, 5 (7 values) (3) - The numbers that occur only once: -3, -2, 3, 4, 5 (5 values) (4) and (5) - The number -5 occurs three times (3 occurrences) ____ count_sel([4, 4, 2, -3, 1, 4, 3, 2, 0, -5, 2, -2, -2, -5]) ----> [14, 8, 4, [[2, 4], 3]] ``` Enjoy it and happy coding!! Also feel free to reuse/extend the following starter code: ```python def count_sel(lst): ```
{"functional": "_inputs = [[[-3, -2, -1, 3, 4, -5, -5, 5, -1, -5]], [[5, -1, 1, -1, -2, 5, 0, -2, -5, 3]], [[-2, 4, 4, -2, -2, -1, 3, 5, -5, 5]], [[4, -5, 1, -5, 2, 4, -1, 4, -1, 1]], [[4, 4, 2, -3, 1, 4, 3, 2, 0, -5, 2, -2, -2, -5]]]\n_outputs = [[[10, 7, 5, [[-5], 3]]], [[10, 7, 4, [[-2, -1, 5], 2]]], [[10, 6, 3, [[-2], 3]]], [[10, 5, 1, [[4], 3]]], [[14, 8, 4, [[2, 4], 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(count_sel(*i), o[0])"}
425
409
coding
Solve the programming task below in a Python markdown code block. There is a special offer in Vasya's favourite supermarket: if the customer buys $a$ chocolate bars, he or she may take $b$ additional bars for free. This special offer can be used any number of times. Vasya currently has $s$ roubles, and he wants to get as many chocolate bars for free. Each chocolate bar costs $c$ roubles. Help Vasya to calculate the maximum possible number of chocolate bars he can get! -----Input----- The first line contains one integer $t$ ($1 \le t \le 100$) — the number of testcases. Each of the next $t$ lines contains four integers $s, a, b, c~(1 \le s, a, b, c \le 10^9)$ — the number of roubles Vasya has, the number of chocolate bars you have to buy to use the special offer, the number of bars you get for free, and the cost of one bar, respectively. -----Output----- Print $t$ lines. $i$-th line should contain the maximum possible number of chocolate bars Vasya can get in $i$-th test. -----Example----- Input 2 10 3 1 1 1000000000 1 1000000000 1 Output 13 1000000001000000000 -----Note----- In the first test of the example Vasya can buy $9$ bars, get $3$ for free, buy another bar, and so he will get $13$ bars. In the second test Vasya buys $1000000000$ bars and gets $1000000000000000000$ for free. So he has $1000000001000000000$ bars.
{"inputs": ["1\n709551 1 1 1\n", "1\n754851 1 1 1\n", "1\n6713132 1 0 1\n", "1\n4 8980272 0 4\n", "1\n9085944 1 0 1\n", "1\n4 8980272 0 1\n", "1\n4 8980272 0 2\n", "1\n4 8980272 0 3\n"], "outputs": ["1419102\n", "1509702\n", "6713132\n", "1\n", "9085944\n", "4\n", "2\n", "1\n"]}
444
204
coding
Solve the programming task below in a Python markdown code block. You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle. A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t. Input The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000). Output Print a single integer — the answer to a problem. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 10 12345 Output 6 Input 16 439873893693495623498263984765 Output 40
{"inputs": ["1\n0\n", "0\n0\n", "0\n1\n", "1\n1\n", "0\n2\n", "2\n5\n", "1\n00\n", "0\n01\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "0\n", "0\n", "0\n", "5\n"]}
272
88
coding
Solve the programming task below in a Python markdown code block. We have an integer sequence A, whose length is N. Find the number of the non-empty contiguous subsequences of A whose sums are 0. Note that we are counting the ways to take out subsequences. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. Constraints * 1 \leq N \leq 2 \times 10^5 * -10^9 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Find the number of the non-empty contiguous subsequences of A whose sum is 0. Examples Input 6 1 3 -4 2 2 -2 Output 3 Input 7 1 -1 1 -1 1 -1 1 Output 12 Input 5 1 -2 3 -4 5 Output 0
{"inputs": ["5\n0 0 2 0 8", "5\n0 0 3 0 8", "5\n0 0 3 1 8", "5\n1 0 6 -2 5", "5\n1 0 8 -2 5", "5\n2 0 8 -2 5", "5\n2 0 8 -2 9", "5\n2 0 2 -2 5"], "outputs": ["4\n", "4\n", "3\n", "1\n", "1\n", "1\n", "1\n", "3\n"]}
241
142
coding
Solve the programming task below in a Python markdown code block. Harry is a bright student. To prepare thoroughly for exams, he completes all the exercises in his book! Now that the exams are approaching fast, he is doing book exercises day and night. He writes down and keeps updating the remaining number of exercises on the back cover of each book. Harry has a lot of books messed on the floor. Therefore, he wants to pile up the books that still have some remaining exercises into a single pile. He will grab the books one-by-one and add the books that still have remaining exercises to the top of the pile. Whenever he wants to do a book exercise, he will pick the book with the minimum number of remaining exercises from the pile. In order to pick the book, he has to remove all the books above it. Therefore, if there are more than one books with the minimum number of remaining exercises, he will take the one which requires the least number of books to remove. The removed books are returned to the messy floor. After he picks the book, he will do all the remaining exercises and trash the book. Since number of books is rather large, he needs your help to tell him the number of books he must remove, for picking the book with the minimum number of exercises. Note that more than one book can have the same name. -----Input----- The first line contains a single integer N denoting the number of actions. Then N lines follow. Each line starts with an integer. If the integer is -1, that means Harry wants to do a book exercise. Otherwise, the integer is number of the remaining exercises in the book he grabs next. This is followed by a string denoting the name of the book. -----Output----- For each -1 in the input, output a single line containing the number of books Harry must remove, followed by the name of the book that Harry must pick. -----Constraints----- 1 < N ≤ 1,000,000 0 ≤ (the number of remaining exercises of each book) < 100,000 The name of each book consists of between 1 and 15 characters 'a' - 'z'. Whenever he wants to do a book exercise, there is at least one book in the pile. -----Example----- Input: 6 9 english 6 mathematics 8 geography -1 3 graphics -1 Output: 1 mathematics 0 graphics
{"inputs": ["6\n9 english\n6 mathematics\n8 geography\n-1\n3 graphics\n-1"], "outputs": ["1 mathematics\n0 graphics"]}
500
34