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. Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12
{"inputs": ["1\n7 9 7\n1 7 8\n2 1\n2 2 1\n0", "1\n7 4 2\n1 9 8\n2 1\n9 2 1\n0", "1\n7 3 4\n1 7 8\n2 1\n3 3 1\n0", "1\n7 9 7\n1 7 2\n2 1\n2 2 1\n0", "1\n7 4 2\n1 9 8\n2 1\n1 2 1\n0", "1\n7 1 7\n7 7 8\n8 1\n3 1 2\n0", "1\n7 9 7\n2 7 2\n2 1\n2 2 1\n0", "1\n7 4 2\n1 9 8\n2 1\n2 2 1\n0"], "outputs": ["11\n0\n16\n13\n15\n", "11\n13\n18\n13\n12\n", "11\n14\n16\n13\n17\n", "11\n0\n20\n13\n15\n", "11\n13\n18\n13\n14\n", "11\n15\n0\n19\n16\n", "11\n0\n11\n13\n15\n", "11\n13\n18\n13\n15\n"]}
380
354
coding
Solve the programming task below in a Python markdown code block. Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number $q = \frac{\sqrt{5} + 1}{2}$, in particular that q^2 = q + 1, and she thinks it would make a good base for her new unique system. She called it "golden system". In golden system the number is a non-empty string containing 0's and 1's as digits. The decimal value of expression a_0a_1...a_{n} equals to $\sum_{i = 0}^{n} a_{i} \cdot q^{n - i}$. Soon Piegirl found out that this system doesn't have same properties that integer base systems do and some operations can not be performed on it. She wasn't able to come up with a fast way of comparing two numbers. She is asking for your help. Given two numbers written in golden system notation, determine which of them has larger decimal value. -----Input----- Input consists of two lines — one for each number. Each line contains non-empty string consisting of '0' and '1' characters. The length of each string does not exceed 100000. -----Output----- Print ">" if the first number is larger, "<" if it is smaller and "=" if they are equal. -----Examples----- Input 1000 111 Output < Input 00100 11 Output = Input 110 101 Output > -----Note----- In the first example first number equals to $((\sqrt{5} + 1) / 2)^{3} \approx 1.618033988^{3} \approx 4.236$, while second number is approximately 1.618033988^2 + 1.618033988 + 1 ≈ 5.236, which is clearly a bigger number. In the second example numbers are equal. Each of them is ≈ 2.618.
{"inputs": ["0\n0\n", "0\n1\n", "1\n0\n", "1\n1\n", "1\n1\n", "0\n1\n", "0\n0\n", "1\n0\n"], "outputs": ["=\n", "<\n", ">\n", "=\n", "=", "<", "=", ">"]}
464
76
coding
Solve the programming task below in a Python markdown code block. The students of Codechef Middle School are visiting an amusement park. The children want to go on a ride, however, there is a minimum height requirement of $X$ cm. Determine if the children are eligible to go on the ride. Print "Yes" if they are eligible, "No" otherwise. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains of a single line of input, two integers $H$ which is a child's height in cm and $X$ which is the minimum permissible height. -----Output:----- For each testcase, output in a single line $"Yes"$ or $"No"$. You cannot give your answer as "YeS", "YES", "yes" or any other variation. -----Constraints----- - $1 \leq T \leq 10^4$ - $50 \leq H \leq 200$ - $50 \leq X \leq 200$ -----Sample Input:----- 2 120 100 90 100 -----Sample Output:----- Yes No -----EXPLANATION:----- The first child has height more than minimum permissible height, so he can go on the ride while the other person cannot!
{"inputs": ["2\n120 100\n90 100"], "outputs": ["Yes\nNo"]}
290
29
coding
Solve the programming task below in a Python markdown code block. Create a function finalGrade, which calculates the final grade of a student depending on two parameters: a grade for the exam and a number of completed projects. This function should take two arguments: exam - grade for exam (from 0 to 100); projects - number of completed projects (from 0 and above); This function should return a number (final grade). There are four types of final grades: - 100, if a grade for the exam is more than 90 or if a number of completed projects more than 10. - 90, if a grade for the exam is more than 75 and if a number of completed projects is minimum 5. - 75, if a grade for the exam is more than 50 and if a number of completed projects is minimum 2. - 0, in other cases Examples: ~~~if-not:nasm ```python final_grade(100, 12) # 100 final_grade(99, 0) # 100 final_grade(10, 15) # 100 final_grade(85, 5) # 90 final_grade(55, 3) # 75 final_grade(55, 0) # 0 final_grade(20, 2) # 0 ``` ~~~ *Use Comparison and Logical Operators. Also feel free to reuse/extend the following starter code: ```python def final_grade(exam, projects): ```
{"functional": "_inputs = [[100, 12], [99, 0], [10, 15], [85, 5], [55, 3], [55, 0], [20, 2]]\n_outputs = [[100], [100], [100], [90], [75], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(final_grade(*i), o[0])"}
350
229
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. On a 2D plane, there are n points with integer coordinates points[i] = [xi, yi]. Return the minimum time in seconds to visit all the points in the order given by points. You can move according to these rules: In 1 second, you can either: move vertically by one unit, move horizontally by one unit, or move diagonally sqrt(2) units (in other words, move one unit vertically then one unit horizontally in 1 second). You have to visit the points in the same order as they appear in the array. You are allowed to pass through points that appear later in the order, but these do not count as visits.   Please complete the following python code precisely: ```python class Solution: def minTimeToVisitAllPoints(self, points: List[List[int]]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(points = [[1,1],[3,4],[-1,0]]) == 7\n assert candidate(points = [[3,2],[-2,2]]) == 5\n\n\ncheck(Solution().minTimeToVisitAllPoints)"}
192
63
coding
Solve the programming task below in a Python markdown code block. Let $n$ be a fixed integer. A permutation is a bijection from the set $\{1,2,\ldots,n\}$ to itself. A cycle of length ${k}$ ($k\geq2$) is a permutation $\mbox{f}$ where different integers exist $i_1,\ldots,i_k$ such that $f(i_1)=i_2,f(i_2)=i_3,...,f(i_k)=i_1$ and, for all $\boldsymbol{x}$ not in $\{i_1,\ldots,i_k\}$, $f(x)=x$. The composition of $m$ permutations $f_1,\ldots,f_m$, written $f_1\circ f_2\circ\ldots\circ f_m$, is their composition as functions. Steve has some cycles $f_1,f_2,\ldots,f_m$. He knows the length of cycle $f_i$ is $\mathbf{l}_i$, but he does not know exactly what the cycles are. He finds that the composition $f_1\circ f_2\circ\ldots\circ f_m$ of the cycles is a cycle of length $n$. He wants to know how many possibilities of $f_1,\ldots,f_m$ exist. Input Format The first line contains ${T}$, the number of test cases. Each test case contains the following information: The first line of each test case contains two space separated integers, $n$ and $m$. The second line of each test case contains $m$ integers, $l_1,\ldots,l_m$. Constraints $n\geq2$ Sum of $n\leqslant1000$ $2\leq l_i\leq n$ Sum of $m\leq10^{6}$ Output Format Output ${T}$ lines. Each line contains a single integer, the answer to the corresponding test case. Since the answers may be very large, output them modulo $(10^9+7)$. Sample Input 1 3 2 2 2 Sample Output 6 Explanation There are three cycles of length $2$. The composition of two cycles of length $2$ is a cycle of length $3$ if, and only if, the two cycles are different. So, there are $3\cdot2=6$ possibilities.
{"inputs": ["1\n3 2\n2 2\n"], "outputs": ["6\n"]}
528
22
coding
Solve the programming task below in a Python markdown code block. You are given an array that of arbitrary depth that needs to be nearly flattened into a 2 dimensional array. The given array's depth is also non-uniform, so some parts may be deeper than others. All of lowest level arrays (most deeply nested) will contain only integers and none of the higher level arrays will contain anything but other arrays. All arrays given will be at least 2 dimensional. All lowest level arrays will contain at least one element. Your solution should be an array containing all of the lowest level arrays and only these. The sub-arrays should be ordered by the smallest element within each, so `[1,2]` should preceed `[3,4,5]`. Note: integers will not be repeated. For example: If you receive `[[[1,2,3],[4,5]],[6,7]]`, your answer should be `[[1,2,3],[4,5],[6,7]]`. Also feel free to reuse/extend the following starter code: ```python def near_flatten(nested): ```
{"functional": "_inputs = [[[[1]]], [[[1, 2, 3], [4, 5, 6]]], [[[1, 2, 3], [[4, 5], [[6], [7, 8]]]]], [[[[1, 2, 3], [9, 10]], [[4, 5], [6, 7, 8]]]]]\n_outputs = [[[[1]]], [[[1, 2, 3], [4, 5, 6]]], [[[1, 2, 3], [4, 5], [6], [7, 8]]], [[[1, 2, 3], [4, 5], [6, 7, 8], [9, 10]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(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(near_flatten(*i), o[0])"}
231
314
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are three stones in different positions on the X-axis. You are given three integers a, b, and c, the positions of the stones. In one move, you pick up a stone at an endpoint (i.e., either the lowest or highest position stone), and move it to an unoccupied position between those endpoints. Formally, let's say the stones are currently at positions x, y, and z with x < y < z. You pick up the stone at either position x or position z, and move that stone to an integer position k, with x < k < z and k != y. The game ends when you cannot make any more moves (i.e., the stones are in three consecutive positions). Return an integer array answer of length 2 where: answer[0] is the minimum number of moves you can play, and answer[1] is the maximum number of moves you can play.   Please complete the following python code precisely: ```python class Solution: def numMovesStones(self, a: int, b: int, c: int) -> List[int]: ```
{"functional": "def check(candidate):\n assert candidate(a = 1, b = 2, c = 5) == [1, 2]\n assert candidate(a = 4, b = 3, c = 2) == [0, 0]\n\n\ncheck(Solution().numMovesStones)"}
246
73
coding
Solve the programming task below in a Python markdown code block. Problem statement There is a positive integer sequence $ a_1, a_2, \ ldots, a_N $ of length $ N $. Consider the following game, which uses this sequence and is played by $ 2 $ players on the play and the play. * Alternately select one of the following operations for the first move and the second move. * Select a positive term in the sequence for $ 1 $ and decrement its value by $ 1 $. * When all terms in the sequence are positive, decrement the values ​​of all terms by $ 1 $. The one who cannot operate first is the loser. When $ 2 $ players act optimally, ask for the first move or the second move. Constraint * $ 1 \ leq N \ leq 2 \ times 10 ^ 5 $ * $ 1 \ leq a_i \ leq 10 ^ 9 $ * All inputs are integers * * * input Input is given from standard input in the following format. $ N $ $ a_1 $ $ a_2 $ $ ... $ $ a_N $ output Output `First` when the first move wins, and output` Second` when the second move wins. * * * Input example 1 2 1 2 Output example 1 First The first move has to reduce the value of the $ 1 $ term by $ 1 $ first, and then the second move has to reduce the value of the $ 2 $ term by $ 1 $. If the first move then decrements the value of the $ 2 $ term by $ 1 $, the value of all terms in the sequence will be $ 0 $, and the second move will not be able to perform any operations. * * * Input example 2 Five 3 1 4 1 5 Output example 2 Second * * * Input example 3 8 2 4 8 16 32 64 128 256 Output example 3 Second * * * Input example 4 3 999999999 1000000000 1000000000 Output example 4 First Example Input 2 1 2 Output First
{"inputs": ["2\n0 2", "2\n0 4", "2\n0 1", "2\n1 0", "2\n0 7", "2\n2 0", "2\n4 0", "2\n5 0"], "outputs": ["Second\n", "Second\n", "First\n", "First\n", "First\n", "Second\n", "Second\n", "First\n"]}
517
94
coding
Solve the programming task below in a Python markdown code block. There's a chessboard of size $n \times n$. $m$ rooks are placed on it in such a way that: no two rooks occupy the same cell; no two rooks attack each other. A rook attacks all cells that are in its row or column. Is it possible to move exactly one rook (you can choose which one to move) into a different cell so that no two rooks still attack each other? A rook can move into any cell in its row or column if no other rook stands on its path. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 2000$) — the number of testcases. The first line of each testcase contains two integers $n$ and $m$ ($1 \le n, m \le 8$) — the size of the chessboard and the number of the rooks. The $i$-th of the next $m$ lines contains two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n$) — the position of the $i$-th rook: $x_i$ is the row and $y_i$ is the column. No two rooks occupy the same cell. No two rooks attack each other. -----Output----- For each testcase, print "YES" if it's possible to move exactly one rook into a different cell so that no two rooks still attack each other. Otherwise, print "NO". -----Examples----- Input 2 2 2 1 2 2 1 3 1 2 2 Output NO YES -----Note----- In the first testcase, the rooks are in the opposite corners of a $2 \times 2$ board. Each of them has a move into a neighbouring corner, but moving there means getting attacked by another rook. In the second testcase, there's a single rook in a middle of a $3 \times 3$ board. It has $4$ valid moves, and every move is fine because there's no other rook to attack it.
{"inputs": ["2\n2 2\n1 2\n2 1\n3 1\n2 2\n", "3\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n", "17\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n8 1\n1 1\n", "17\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n"], "outputs": ["NO\nYES\n", "NO\nNO\nNO\n", "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n", "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n"]}
465
426
coding
Solve the programming task below in a Python markdown code block. The chef is trying to decode 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:----- 4 1 2 3 4 -----Sample Output:----- 1 10 10 101 101 101 1010 1010 1010 1010 -----EXPLANATION:----- No need, else pattern can be decode easily.
{"inputs": ["4\n1\n2\n3\n4"], "outputs": ["1\n10\n10\n101\n101\n101\n1010\n1010\n1010\n1010"]}
216
58
coding
Solve the programming task below in a Python markdown code block. There are N people standing in a queue from west to east. Given is a string S of length N representing the directions of the people. The i-th person from the west is facing west if the i-th character of S is L, and east if that character of S is R. A person is happy if the person in front of him/her is facing the same direction. If no person is standing in front of a person, however, he/she is not happy. You can perform the following operation any number of times between 0 and K (inclusive): Operation: Choose integers l and r such that 1 \leq l \leq r \leq N, and rotate by 180 degrees the part of the queue: the l-th, (l+1)-th, ..., r-th persons. That is, for each i = 0, 1, ..., r-l, the (l + i)-th person from the west will stand the (r - i)-th from the west after the operation, facing east if he/she is facing west now, and vice versa. What is the maximum possible number of happy people you can have? -----Constraints----- - N is an integer satisfying 1 \leq N \leq 10^5. - K is an integer satisfying 1 \leq K \leq 10^5. - |S| = N - Each character of S is L or R. -----Input----- Input is given from Standard Input in the following format: N K S -----Output----- Print the maximum possible number of happy people after at most K operations. -----Sample Input----- 6 1 LRLRRL -----Sample Output----- 3 If we choose (l, r) = (2, 5), we have LLLRLL, where the 2-nd, 3-rd, and 6-th persons from the west are happy.
{"inputs": ["1 99999\nL\n", "6 2\nLRLRRL", "6 0\nLRRLRL", "6 1\nRRLLRL", "6 0\nRRLLRL", "6 0\nLRLRLR", "6 4\nLRLRRL", "6 1\nLRRLRL"], "outputs": ["0\n", "5\n", "1\n", "4\n", "2\n", "0\n", "5\n", "3\n"]}
413
116
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, consider all duplicated substrings: (contiguous) substrings of s that occur 2 or more times. The occurrences may overlap. Return any duplicated substring that has the longest possible length. If s does not have a duplicated substring, the answer is "".   Please complete the following python code precisely: ```python class Solution: def longestDupSubstring(self, s: str) -> str: ```
{"functional": "def check(candidate):\n assert candidate(s = \"banana\") == \"ana\"\n assert candidate(s = \"abcd\") == \"\"\n\n\ncheck(Solution().longestDupSubstring)"}
109
46
coding
Solve the programming task below in a Python markdown code block. ## Task Create a function that given a sequence of strings, groups the elements that can be obtained by rotating others, ignoring upper or lower cases. In the event that an element appears more than once in the input sequence, only one of them will be taken into account for the result, discarding the rest. ## Input Sequence of strings. Valid characters for those strings are uppercase and lowercase characters from the alphabet and whitespaces. ## Output Sequence of elements. Each element is the group of inputs that can be obtained by rotating the strings. Sort the elements of each group alphabetically. Sort the groups descendingly by size and in the case of a tie, by the first element of the group alphabetically. ## Examples ```python ['Tokyo', 'London', 'Rome', 'Donlon', 'Kyoto', 'Paris', 'Okyot'] --> [['Kyoto', 'Okyot', 'Tokyo'], ['Donlon', 'London'], ['Paris'], ['Rome']] ['Rome', 'Rome', 'Rome', 'Donlon', 'London'] --> [['Donlon', 'London'], ['Rome']] [] --> [] ``` Also feel free to reuse/extend the following starter code: ```python def group_cities(seq): ```
{"functional": "_inputs = [[['Tokyo', 'London', 'Rome', 'Donlon', 'Kyoto', 'Paris', 'Okyot']], [['Tokyo', 'London', 'Rome', 'Donlon']], [['Rome', 'Rome', 'Rome', 'Donlon', 'London']], [['Ab', 'Aa']], [[]]]\n_outputs = [[[['Kyoto', 'Okyot', 'Tokyo'], ['Donlon', 'London'], ['Paris'], ['Rome']]], [[['Donlon', 'London'], ['Rome'], ['Tokyo']]], [[['Donlon', 'London'], ['Rome']]], [[['Aa'], ['Ab']]], [[]]]\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(group_cities(*i), o[0])"}
282
290
coding
Solve the programming task below in a Python markdown code block. Write a function that removes every lone 9 that is inbetween 7s. ```python seven_ate9('79712312') => '7712312' seven_ate9('79797') => '777' ``` Input: String Output: String Also feel free to reuse/extend the following starter code: ```python def seven_ate9(str_): ```
{"functional": "_inputs = [['165561786121789797'], ['797'], ['7979797'], ['16797'], ['77'], ['7927'], ['1779'], ['a779'], ['17797a'], ['797 9 7']]\n_outputs = [['16556178612178977'], ['77'], ['7777'], ['1677'], ['77'], ['7927'], ['1779'], ['a779'], ['1777a'], ['77 9 7']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(seven_ate9(*i), o[0])"}
108
303
coding
Solve the programming task below in a Python markdown code block. # The Problem Dan, president of a Large company could use your help. He wants to implement a system that will switch all his devices into offline mode depending on his meeting schedule. When he's at a meeting and somebody texts him, he wants to send an automatic message informing that he's currently unavailable and the time when he's going to be back. # What To Do Your task is to write a helper function `checkAvailability` that will take 2 arguments: * schedule, which is going to be a nested array with Dan's schedule for a given day. Inside arrays will consist of 2 elements - start and finish time of a given appointment, * *currentTime* - is a string with specific time in hh:mm 24-h format for which the function will check availability based on the schedule. * If no appointments are scheduled for `currentTime`, the function should return `true`. If there are no appointments for the day, the output should also be `true` * If Dan is in the middle of an appointment at `currentTime`, the function should return a string with the time he's going to be available. # Examples `checkAvailability([["09:30", "10:15"], ["12:20", "15:50"]], "11:00");` should return `true` `checkAvailability([["09:30", "10:15"], ["12:20", "15:50"]], "10:00");` should return `"10:15"` If the time passed as input is *equal to the end time of a meeting*, function should also return `true`. `checkAvailability([["09:30", "10:15"], ["12:20", "15:50"]], "15:50");` should return `true` *You can expect valid input for this kata* Also feel free to reuse/extend the following starter code: ```python def check_availability(schedule, current_time): ```
{"functional": "_inputs = [[[['09:30', '10:15'], ['12:20', '15:50']], '10:00'], [[['09:30', '10:15'], ['12:20', '15:50']], '11:00'], [[['09:30', '10:15'], ['12:20', '15:50']], '10:15'], [[], '10:15'], [[['12:13', '23:50']], '10:15'], [[['12:13', '23:50']], '23:55'], [[['12:13', '23:50']], '17:43']]\n_outputs = [['10:15'], [True], [True], [True], [True], [True], ['23:50']]\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(check_availability(*i), o[0])"}
450
361
coding
Solve the programming task below in a Python markdown code block. A palindrome is a word that reads the same forward and backward. Given a string s, you need to make it a palindrome by adding 0 or more characters to the end of s, and remember, we want the palindrome to be as short as possible. INPUT First line is T, the number of test cases. T strings follow, every string s needs to be converted to palindrome. OUTPUT Print the shortest possible length of a palindrome that John can generate. CONSTRAINTS 1 ≤ T ≤ 50 s will contain between 1 and 50 characters, inclusive, palindrome can be larger in length. Each character of s will be a lowercase letter ('a' - 'z'). SAMPLE INPUT 3 abab abacaba qwerty SAMPLE OUTPUT 5 7 11 Explanation CASE 1: "ababa" is the shortest palindrome that we can get. CASE 2: Already a palindrome. CASE 3: All characters are different.
{"inputs": ["6\nabdfhdyrbdbsdfghjkllkjhgfds\nzazazazazazazazazazazazazazazazazazazazazazazazaza\nbacba\na\nadwuaaxcnleegluqvsczaguujoppchwecusmevz\nkoikijiikmmkmonkiinnjlijmiimnniokikimikkkkjkmiinii"], "outputs": ["38\n51\n9\n1\n77\n95"]}
219
120
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have a cubic storeroom where the width, length, and height of the room are all equal to n units. You are asked to place n boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes: You can place the boxes anywhere on the floor. If box x is placed on top of the box y, then each side of the four vertical sides of the box y must either be adjacent to another box or to a wall. Given an integer n, return the minimum possible number of boxes touching the floor.   Please complete the following python code precisely: ```python class Solution: def minimumBoxes(self, n: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(n = 3) == 3\n assert candidate(n = 4) == 3\n assert candidate(n = 10) == 6\n\n\ncheck(Solution().minimumBoxes)"}
165
56
coding
Solve the programming task below in a Python markdown code block. Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or all) cards and flip them, then he will calculate the [bitwise AND] of all the numbers currently in a face-up manner. Now Chef wonders what is the *maximum* bitwise AND that he can achieve and what is the *minimum* number of cards he has to flip to achieve this value. Can you help him find it? ------ Input Format ------ - The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. - Each test case contains three lines of input. - The first line contains a single integer N - the number of cards. - The second line contains N space-separated integers A_{1}, A_{2},..., A_{N} - the numbers on the front face of the cards - The third line contains N space-separated integers B_{1}, B_{2},..., B_{N} - the numbers on the back face of the cards ------ Output Format ------ For each test case, print a single line containing two space-separated integers, first denoting the maximum bitwise AND possible and second denoting the minimum number of flips required to achieve it. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} ≤ 2^{30} - 1$ $0 ≤ B_{i} ≤ 2^{30} - 1$ - Sum of $N$ over all testcases does not exceeds $10^{5}$. ----- Sample Input 1 ------ 3 3 4 6 8 2 1 2 3 0 2 0 2 0 8 3 1 2 1 2 3 6 ----- Sample Output 1 ------ 2 2 0 0 2 2 ----- explanation 1 ------ Test case $1$: The maximum AND is obtained after flipping the first and third cards achieving a configuration of $[2, 6, 2]$ which yields a bitwise AND of $2$. Test case $2$: Every possible configuration of the cards yields a bitwise AND equal to $0$. So to ensure the minimum number of operations, Chef performs no flip.
{"inputs": ["3\n3\n4 6 8\n2 1 2\n3\n0 2 0\n2 0 8\n3\n1 2 1\n2 3 6"], "outputs": ["2 2\n0 0\n2 2"]}
568
64
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements. Your task is to find the smallest possible length of a (contiguous) subarray of nums, that has the same degree as nums.   Please complete the following python code precisely: ```python class Solution: def findShortestSubArray(self, nums: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,2,3,1]) == 2\n assert candidate(nums = [1,2,2,3,1,4,2]) == 6\n\n\ncheck(Solution().findShortestSubArray)"}
108
66
coding
Solve the programming task below in a Python markdown code block. It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts. There are N houses along TopCoDeer street. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses. Find the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions. -----Constraints----- - 1 ≤ N ≤ 100 - 0 ≤ a_i ≤ 1000 - a_i is an integer. -----Input----- Input is given from Standard Input in the following format: N a_1 a_2 ... a_N -----Output----- Print the minimum distance to be traveled. -----Sample Input----- 4 2 3 7 9 -----Sample Output----- 7 The travel distance of 7 can be achieved by starting at coordinate 9 and traveling straight to coordinate 2. It is not possible to do with a travel distance of less than 7, and thus 7 is the minimum distance to be traveled.
{"inputs": ["4\n2 3 9 9", "4\n4 4 8 9", "4\n0 4 8 9", "4\n2 3 7 9", "4\n2 3 7 9\n", "4\n2 3 13 9", "4\n4 4 13 9", "4\n0 4 8 18"], "outputs": ["7\n", "5\n", "9\n", "7", "7\n", "11\n", "9\n", "18\n"]}
237
131
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums (0-indexed). In one operation, you can choose an element of the array and increment it by 1. For example, if nums = [1,2,3], you can choose to increment nums[1] to make nums = [1,3,3]. Return the minimum number of operations needed to make nums strictly increasing. An array nums is strictly increasing if nums[i] < nums[i+1] for all 0 <= i < nums.length - 1. An array of length 1 is trivially strictly increasing.   Please complete the following python code precisely: ```python class Solution: def minOperations(self, nums: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(nums = [1,1,1]) == 3\n assert candidate(nums = [1,5,2,4,1]) == 14\n assert candidate(nums = [8]) == 0\n\n\ncheck(Solution().minOperations)"}
166
68
coding
Solve the programming task below in a Python markdown code block. Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined as a sequence of continuous elements Ai, Ai+1, ..., Aj where 0 ≤ i ≤ j ≤ N−1. The function foo, when applied to an array, returns the minimum of all the elements in the array. For example, foo returns 5 when it is applied to the array [7, 5, 10, 7, 5, 8]. Please note that the subarrays Ai, Ai+1, ..., Aj and Ak, Ak+1, ..., Al are different if and only if i ≠ k or j ≠ l in this problem. -----Input----- The first line of input contains N, denoting the size of the array. The next line contains N space separated integers A0, A1, ..., AN−1, denoting the array. Then the next line contains Q, denoting the number of queries. Each query consists of one integer per line, denoting K. -----Output----- For each query, print the required number of subarrays. -----Constraints----- - 1 ≤ N ≤ 50 - 1 ≤ Ai ≤ 1000000 (106) - 1 ≤ Q ≤ 10 - 1 ≤ K ≤ 1000000 (106) -----Example----- Input: 5 4 1 2 3 4 4 3 4 6 1 Output: 2 2 0 8 -----Explanation----- Query 1. Only the two subarrays [3, 4] and [3] satisfy. Query 2. Again only the two subarrays [4] and [4] satisfy. Please note that these subarrays (A0 and A4) are considered different. Query 3. No subarray satisfies. Query 4. The eight subarrays [4, 1], [4, 1, 2], [4, 1, 2, 3], [4, 1, 2, 3, 4], [1], [1, 2], [1, 2, 3] and [1, 2, 3, 4] satisfy.
{"inputs": ["5\n4 0 2 3 4\n4\n3\n4\n6\n1", "5\n4 0 2 3 4\n4\n5\n4\n6\n1", "5\n4 1 2 3 4\n4\n5\n4\n6\n1", "5\n4 1 2 6 4\n4\n5\n4\n6\n1", "5\n4 1 2 3 4\n4\n3\n7\n6\n1", "5\n4 0 2 3 4\n1\n3\n4\n6\n1", "5\n4 0 2 3 0\n4\n5\n4\n6\n1", "5\n4 1 2 3 4\n3\n5\n4\n6\n1"], "outputs": ["2\n2\n0\n0\n", "0\n2\n0\n0\n", "0\n2\n0\n8\n", "0\n3\n1\n8\n", "2\n0\n0\n8\n", "2\n", "0\n1\n0\n0\n", "0\n2\n0\n"]}
545
262
coding
Solve the programming task below in a Python markdown code block. Kajaria has an empty bag and 2 types of tiles - tiles of type $1$ have the number $X$ written and those of type $2$ have the number $Y$ written on them. He has an infinite supply of both type of tiles. In one move, Kajaria adds exactly $1$ tile to the bag. He adds a tile of type $1$ with probability $p$ and a tile of type $2$ with probability $(1 - p)$. If $2$ tiles in the bag have the same number written on them (say $Z$), they are merged into a single tile of twice that number ($2Z$). Find the expected number of moves to reach the first tile with number $S$ written on it. Notes on merging: - Consider that the bag contains tiles $(5, 10, 20, 40)$ and if the new tile added is $5$, then it would merge with the existing $5$ and the bag would now contain $(10, 10, 20, 40)$. The tiles $10$ (already present) and $10$ (newly formed) would then merge in the same move to form $(20, 20, 40)$, and that will form $(40, 40)$, which will form $(80)$. Kajaria guarantees that: - $X$ and $Y$ are not divisible by each other. - A tile with number $S$ can be formed. -----Input----- - First line contains a single integer $T$ - the total no. of testcases - Each testcase is described by $2$ lines: - $X, Y, S$ - $3$ space-separated natural numbers - $u, v$ - $2$ space-separated natural numbers describing the probability $p$ The value of $p$ is provided as a fraction in its lowest form $u/v$ ($u$ and $v$ are co-prime) -----Output----- - For each testcase, if the expected number of moves can be expressed as a fraction $p/q$ in its lowest form, print $(p * q^{-1})$ modulo $10^9 + 7$, where $q^{-1}$ denotes the modular inverse of $q$ wrt $10^9 + 7$. -----Constraints----- - $1 \leq T \leq 10^5$ - $2 \leq X, Y \leq 5 * 10^{17}$ - $1 \leq S \leq 10^{18}$ - $1 \leq u < v \leq 10^{9}$ -----Sample Input----- 1 5 3 96 1 3 -----Sample Output----- 48
{"inputs": ["1\n5 3 96\n1 3"], "outputs": ["48"]}
616
24
coding
Solve the programming task below in a Python markdown code block. You are given an unordered array of unique integers incrementing from $\mbox{1}$. You can swap any two elements a limited number of times. Determine the largest lexicographical value array that can be created by executing no more than the limited number of swaps. Example $arr=[1,2,3,4]$ $k=1$ The following arrays can be formed by swapping the $\mbox{I}$ with the other elements: [2,1,3,4] [3,2,1,4] [4,2,3,1] The highest value of the four (including the original) is $[4,2,3,1]$. If $k\geq2$, we can swap to the highest possible value: $[4,3,2,1]$. Function Description Complete the largestPermutation function in the editor below. It must return an array that represents the highest value permutation that can be formed. largestPermutation has the following parameter(s): int k: the maximum number of swaps int arr[n]: an array of integers Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{\mbox{k}}$, the length of $\textbf{arr}$ and the maximum swaps that can be performed. The second line contains $n$ distinct space-separated integers from $\mbox{1}$ to $n$ as $arr\left[i\right]$ where $1\leq ar r[i]\leq n$. Constraints $1\leq n\leq10^5$ $1\leq k\leq10^9$ Output Format Print the lexicographically largest permutation you can make with at most $\boldsymbol{\mbox{k}}$ swaps. Sample Input 0 STDIN Function ----- -------- 5 1 n = 5, k = 1 4 2 3 5 1 arr = [4, 2, 3, 5, 1] Sample Output 0 5 2 3 4 1 Explanation 0 You can swap any two numbers in $[4,2,3,5,1]$ and see the largest permutation is $[5,2,3,4,1]$ Sample Input 1 3 1 2 1 3 Sample Output 1 3 1 2 Explanation 1 With 1 swap we can get $[1,2,3]$, $[3,1,2]$ and $[2,3,1]$. Of these, $[3,1,2]$ is the largest permutation. Sample Input 2 2 1 2 1 Sample Output 2 2 1 Explanation 2 We can see that $[2,1]$ is already the largest permutation. We don't make any swaps.
{"inputs": ["2 1\n2 1\n", "3 1\n2 1 3\n"], "outputs": ["2 1\n", "3 1 2\n"]}
640
42
coding
Solve the programming task below in a Python markdown code block. There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote. Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions on what should be the outcome of the vote. The voting procedure is rather complicated: Each of n employees makes a statement. They make statements one by one starting from employees 1 and finishing with employee n. If at the moment when it's time for the i-th employee to make a statement he no longer has the right to vote, he just skips his turn (and no longer takes part in this voting). When employee makes a statement, he can do nothing or declare that one of the other employees no longer has a right to vote. It's allowed to deny from voting people who already made the statement or people who are only waiting to do so. If someone is denied from voting he no longer participates in the voting till the very end. When all employees are done with their statements, the procedure repeats: again, each employees starting from 1 and finishing with n who are still eligible to vote make their statements. The process repeats until there is only one employee eligible to vote remaining and he determines the outcome of the whole voting. Of course, he votes for the decision suitable for his fraction. You know the order employees are going to vote and that they behave optimal (and they also know the order and who belongs to which fraction). Predict the outcome of the vote. -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of employees. The next line contains n characters. The i-th character is 'D' if the i-th employee is from depublicans fraction or 'R' if he is from remocrats. -----Output----- Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win. -----Examples----- Input 5 DDRRR Output D Input 6 DDRRRR Output R -----Note----- Consider one of the voting scenarios for the first sample: Employee 1 denies employee 5 to vote. Employee 2 denies employee 3 to vote. Employee 3 has no right to vote and skips his turn (he was denied by employee 2). Employee 4 denies employee 2 to vote. Employee 5 has no right to vote and skips his turn (he was denied by employee 1). Employee 1 denies employee 4. Only employee 1 now has the right to vote so the voting ends with the victory of depublicans.
{"inputs": ["1\nD\n", "1\nR\n", "1\nR\n", "1\nD\n", "2\nDR\n", "2\nDR\n", "3\nRDD\n", "3\nDRD\n"], "outputs": ["D\n", "R\n", "R\n", "D\n", "D\n", "D\n", "D\n", "D\n"]}
588
87
coding
Solve the programming task below in a Python markdown code block. You have $n$ barrels lined up in a row, numbered from left to right from one. Initially, the $i$-th barrel contains $a_i$ liters of water. You can pour water from one barrel to another. In one act of pouring, you can choose two different barrels $x$ and $y$ (the $x$-th barrel shouldn't be empty) and pour any possible amount of water from barrel $x$ to barrel $y$ (possibly, all water). You may assume that barrels have infinite capacity, so you can pour any amount of water in each of them. Calculate the maximum possible difference between the maximum and the minimum amount of water in the barrels, if you can pour water at most $k$ times. Some examples: if you have four barrels, each containing $5$ liters of water, and $k = 1$, you may pour $5$ liters from the second barrel into the fourth, so the amounts of water in the barrels are $[5, 0, 5, 10]$, and the difference between the maximum and the minimum is $10$; if all barrels are empty, you can't make any operation, so the difference between the maximum and the minimum amount is still $0$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases. The first line of each test case contains two integers $n$ and $k$ ($1 \le k < n \le 2 \cdot 10^5$) — the number of barrels and the number of pourings you can make. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^{9}$), where $a_i$ is the initial amount of water the $i$-th barrel has. It's guaranteed that the total sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the maximum possible difference between the maximum and the minimum amount of water in the barrels, if you can pour water at most $k$ times. -----Example----- Input 2 4 1 5 5 5 5 3 2 0 0 0 Output 10 0
{"inputs": ["2\n4 1\n5 5 5 5\n3 2\n0 0 0\n", "2\n4 2\n5 5 5 5\n3 2\n0 0 0\n", "2\n4 2\n5 5 5 5\n3 2\n0 0 1\n", "2\n4 3\n5 5 2 5\n3 2\n0 1 0\n", "2\n4 3\n5 5 2 1\n3 2\n0 1 0\n", "2\n4 3\n5 1 2 1\n3 2\n0 1 0\n", "2\n4 2\n2 5 5 0\n3 2\n0 0 0\n", "2\n4 3\n5 1 2 2\n3 2\n0 1 0\n"], "outputs": ["10\n0\n", "15\n0\n", "15\n1\n", "17\n1\n", "13\n1\n", "9\n1\n", "12\n0\n", "10\n1\n"]}
525
269
coding
Solve the programming task below in a Python markdown code block. Given an integer N, find a permutation P = P_{1}, P_{2}, \ldots, P_{N} of length N that satisfies the following two conditions: P_{i} \neq i (1 ≤ i ≤ N); Consider the set which contains P_{i} \% i for all 1 ≤ i ≤ N. This set should have the minimum number of distinct integers possible, over all permutations P. Note that a permutation of length N is an array containing every integer from 1 to N exactly once. ------ Input Format ------ - The first line will contain T, number of test cases. Then the test cases follow. - Each test case consists of a single line of input, an integer N, the length of the required permutation. ------ Output Format ------ For each test case, output on a new line, N space-separated integers, denoting the permutation P of length N satisfying the above conditions. ------ Constraints ------ $1 ≤ T ≤ 700$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): $1 ≤ M ≤ 10$ Subtask 2 (20 points): The sum of $N$ across all test cases won't exceed $20$. Subtask 3 (70 points): No further constraints. ----- Sample Input 1 ------ 2 2 3 ----- Sample Output 1 ------ 2 1 2 3 1 ----- explanation 1 ------ Test case $1$: The possible permutations of length $2$ are $[1,2]$ and $[2,1]$. The only permutation that satisfies the conditions is $[2,1]$. The values $P_{i}$ $\%$ $i$ are $[2\%1, 1\%2] = [0, 1]$. Thus there are $2$ distinct values of $P_{i}$ $\%$ $i$, which is the minimum possible. Test case $2$: There are $6$ possible permutations of length $3$ out of which $[2,3,1]$ satisfies the above conditions. The values $P_{i}$ $\%$ $i$ are $[2\%1, 3\%2, 1\%3] = [0, 1, 1]$. Thus there are $2$ distinct values of $P_{i}$ $\%$ $i$, which is the minimum possible.
{"inputs": ["2\n2\n3\n"], "outputs": ["2 1\n2 3 1"]}
562
25
coding
Solve the programming task below in a Python markdown code block. Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. Input The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. Output Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. Examples Input 1 1 Output 1 Input 1 2 Output 0 Input 3 5 6 7 Output 13
{"inputs": ["1\n0\n", "1\n2\n", "1\n1\n", "1\n31\n", "1\n44\n", "1\n33\n", "1\n64\n", "1\n11\n"], "outputs": ["0\n", "0\n", "1\n", "31\n", "0\n", "33\n", "0\n", "11\n"]}
321
94
coding
Solve the programming task below in a Python markdown code block. Lot of junior developer can be stuck when they need to change the access permission to a file or a directory in an Unix-like operating systems. To do that they can use the `chmod` command and with some magic trick they can change the permissionof a file or a directory. For more information about the `chmod` command you can take a look at the [wikipedia page](https://en.wikipedia.org/wiki/Chmod). `chmod` provides two types of syntax that can be used for changing permissions. An absolute form using octal to denote which permissions bits are set e.g: 766. Your goal in this kata is to define the octal you need to use in order to set yout permission correctly. Here is the list of the permission you can set with the octal representation of this one. - User - read (4) - write (2) - execute (1) - Group - read (4) - write (2) - execute (1) - Other - read (4) - write (2) - execute (1) The method take a hash in argument this one can have a maximum of 3 keys (`owner`,`group`,`other`). Each key will have a 3 chars string to represent the permission, for example the string `rw-` say that the user want the permission `read`, `write` without the `execute`. If a key is missing set the permission to `---` **Note**: `chmod` allow you to set some special flags too (`setuid`, `setgid`, `sticky bit`) but to keep some simplicity for this kata we will ignore this one. Also feel free to reuse/extend the following starter code: ```python def chmod_calculator(perm): ```
{"functional": "_inputs = [[{'user': 'rwx', 'group': 'r-x', 'other': 'r-x'}], [{'user': 'rwx', 'group': 'r--', 'other': 'r--'}], [{'user': 'r-x', 'group': 'r-x', 'other': '---'}], [{'group': 'rwx'}], [{}]]\n_outputs = [['755'], ['744'], ['550'], ['070'], ['000']]\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(chmod_calculator(*i), o[0])"}
383
252
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an integer array nums that consists of n unique elements, but you have forgotten it. However, you do remember every pair of adjacent elements in nums. You are given a 2D integer array adjacentPairs of size n - 1 where each adjacentPairs[i] = [ui, vi] indicates that the elements ui and vi are adjacent in nums. It is guaranteed that every adjacent pair of elements nums[i] and nums[i+1] will exist in adjacentPairs, either as [nums[i], nums[i+1]] or [nums[i+1], nums[i]]. The pairs can appear in any order. Return the original array nums. If there are multiple solutions, return any of them.   Please complete the following python code precisely: ```python class Solution: def restoreArray(self, adjacentPairs: List[List[int]]) -> List[int]: ```
{"functional": "def check(candidate):\n assert candidate(adjacentPairs = [[2,1],[3,4],[3,2]]) == [1,2,3,4]\n assert candidate(adjacentPairs = [[4,-2],[1,4],[-3,1]]) == [-2,4,1,-3]\n assert candidate(adjacentPairs = [[100000,-100000]]) == [100000,-100000]\n\n\ncheck(Solution().restoreArray)"}
194
120
coding
Solve the programming task below in a Python markdown code block. You are given a fair coin and two integers X and N. You repeatedly flip the coin and perform the following operation based on the result: If it lands on heads, then X will increase by 1. However, if X = N then X will not change. If it lands on tails, X will decrease by 1. You stop as soon as the value of X becomes 1. Find the expected number of coin flips. Note that it is guaranteed that under the given constraints, the answer is an integer and does not exceed 2 \cdot 10^{18} ------ 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 two space separated integers X and N. ------ Output Format ------ For each testcase, output the expected number of coin flips. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ X ≤ N ≤ 10^{9}$ ----- Sample Input 1 ------ 4 1 3 2 2 12 12 568 57800 ----- Sample Output 1 ------ 0 2 132 65223144 ----- explanation 1 ------ In the first test case, $X$ is already $1$. So, the expected number of coin flip in this case is $0$. In the second test case, if the coin lands on head, $X$ will not change because $X$ is equal to $N$ here. Whenever the coin lands on tail, $X$ will decrease by $1$ and the game ends as $X$ becomes $1$. The expected number of coin flips to get the first tail is $2$. So, the answer for the case is $2$.
{"inputs": ["4\n1 3\n2 2\n12 12\n568 57800"], "outputs": ["0\n2\n132\n65223144\n"]}
403
52
coding
Solve the programming task below in a Python markdown code block. There is data of up to 100 characters per line, consisting of half-width alphabetic character strings. Some lines are symmetric (same whether read from the left edge or the right edge). Create a program that reads this data and outputs the number of symmetric strings in it. Note that lines consisting of only one character are symmetrical. Input Multiple strings are given over multiple lines. One string is given for each line. The number of strings does not exceed 50. Output Outputs the number of symmetric strings on one line. Example Input abcba sx abcddcba rttrd Output 2
{"inputs": ["abcba\nsx\nabcddcba\nrstrd", "abcca\nsw\nabcddcba\nrstrd", "abcca\nxt\nadcbdcba\nrdsrt", "abcba\nsw\nabcddcba\nrstrd", "accba\nsw\nabcddcba\nrstrd", "accba\nsx\nabcddcba\nrstrd", "accba\ntx\nabcddcba\nrstrd", "accba\ntx\nabcddcba\nrsdrt"], "outputs": ["2\n", "1\n", "0\n", "2\n", "1\n", "1\n", "1\n", "1\n"]}
143
153
coding
Solve the programming task below in a Python markdown code block. Alice and Bob were having an argument about which of them is taller than the other. Charlie got irritated by the argument, and decided to settle the matter once and for all. Charlie measured the heights of Alice and Bob, and got to know that Alice's height is X centimeters and Bob's height is Y centimeters. Help Charlie decide who is taller. It is guaranteed that X \neq Y. ------ Input Format ------ - The first line of input will contain an integer T — the number of test cases. The description of T test cases follows. - The first and only line of each test case contains two integers X and Y, as described in the problem statement. ------ Output Format ------ For each test case, output on a new line \texttt{A} if Alice is taller than Bob, else output \texttt{B}. The output is case insensitive, i.e, both \texttt{A} and \texttt{a} will be accepted as correct answers when Alice is taller. ------ Constraints ------ $1 ≤ T ≤ 1000$ $100 ≤ X, Y ≤ 200$ $X \neq Y$ ----- Sample Input 1 ------ 2 150 160 160 150 ----- Sample Output 1 ------ B A ----- explanation 1 ------ Test case $1$: In this case, $150 < 160$ so Bob is taller than Alice. Test case $2$: In this case, $160 > 150$ so Alice is taller than Bob.
{"inputs": ["2\n150 160\n160 150"], "outputs": ["B\nA"]}
352
30
coding
Solve the programming task below in a Python markdown code block. =====Function Descriptions===== mean The mean tool computes the arithmetic mean along the specified axis. import numpy my_array = numpy.array([ [1, 2], [3, 4] ]) print numpy.mean(my_array, axis = 0) #Output : [ 2. 3.] print numpy.mean(my_array, axis = 1) #Output : [ 1.5 3.5] print numpy.mean(my_array, axis = None) #Output : 2.5 print numpy.mean(my_array) #Output : 2.5 By default, the axis is None. Therefore, it computes the mean of the flattened array. var The var tool computes the arithmetic variance along the specified axis. import numpy my_array = numpy.array([ [1, 2], [3, 4] ]) print numpy.var(my_array, axis = 0) #Output : [ 1. 1.] print numpy.var(my_array, axis = 1) #Output : [ 0.25 0.25] print numpy.var(my_array, axis = None) #Output : 1.25 print numpy.var(my_array) #Output : 1.25 By default, the axis is None. Therefore, it computes the variance of the flattened array. std The std tool computes the arithmetic standard deviation along the specified axis. import numpy my_array = numpy.array([ [1, 2], [3, 4] ]) print numpy.std(my_array, axis = 0) #Output : [ 1. 1.] print numpy.std(my_array, axis = 1) #Output : [ 0.5 0.5] print numpy.std(my_array, axis = None) #Output : 1.118033988749895 print numpy.std(my_array) #Output : 1.118033988749895 By default, the axis is None. Therefore, it computes the standard deviation of the flattened array. =====Problem Statement===== You are given a 2-D array of size NXM. Your task is to find: The mean along axis 1 The var along axis 0 The std along axis None =====Input Format===== The first line contains the space separated values of N and M. The next N lines contains M space separated integers. =====Output Format===== First, print the mean. Second, print the var. Third, print the std. Also feel free to reuse/extend the following starter code: ```python import numpy ```
{"inputs": ["2 2\n1 2\n3 4"], "outputs": ["[1.5 3.5]\n[1. 1.]\n1.118033988749895"]}
580
56
coding
Solve the programming task below in a Python markdown code block. Complete the solution so that it takes the object (JavaScript/CoffeeScript) or hash (ruby) passed in and generates a human readable string from its key/value pairs. The format should be "KEY = VALUE". Each key/value pair should be separated by a comma except for the last pair. **Example:** ```python solution({"a": 1, "b": '2'}) # should return "a = 1,b = 2" ``` Also feel free to reuse/extend the following starter code: ```python def solution(pairs): ```
{"functional": "_inputs = [[{'a': 1, 'b': 2}], [{'a': 'b', 'b': 'a'}], [{'0': 'a', 'b': 2}], [{'b': 1, 'c': 2, 'e': 3}], [{}]]\n_outputs = [['a = 1,b = 2'], ['a = b,b = a'], ['0 = a,b = 2'], ['b = 1,c = 2,e = 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(solution(*i), o[0])"}
129
249
coding
Solve the programming task below in a Python markdown code block. You're given a sequence of N distinct integers. You need to find a subsequence of length K with the maximum possible median. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is selected. For example, if the sequence is [3, 4, 2, 1, 5], then the median is 3 since after sorting, it will look like [1, 2, 3, 4, 5] and 3 is the only middle element. The median of [4, 2, 1, 5] is 2 since after sorting, the value 2 is the left of the two middle elements 2 and 4. A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. For example, if the sequence is [2, 1, 4, 5, 7], then [1, 5, 7], [2, 1, 4], [5] are some valid subsequences but [4, 1, 2], [1, 6, 7] are not. ------ Input Format ------ - The first line will contain T, the number of test cases. The description of test cases follow. - The first line of each test case consists of two space-separated integers N, the length of the sequence, and K, the length of the subsequence to be found. - The second line of each test case consists of N distinct space-separated integers A_{i}, the elements of the sequence. ------ Output Format ------ - For each test case, output two lines. - The first line should consist of the median of the subsequence with the maximum median. - The second line should consist of K space-separated integers, representing a subsequence with that median. If there are multiple such subsequences, print any. ------ Constraints ------ $1 ≤ T ≤ 30$ $1 ≤ K ≤ N ≤ 2 \times 10^{5}$ $1 ≤ A_{i} ≤ 10^{9}$ - Sum of $N$ over all test cases won't exceed $5 \times 10^{5}$ ----- Sample Input 1 ------ 1 5 3 1 4 3 6 5 ----- Sample Output 1 ------ 5 1 6 5
{"inputs": ["1\n5 3\n1 4 3 6 5"], "outputs": ["5\n1 6 5"]}
542
32
coding
Solve the programming task below in a Python markdown code block. Two integers are coprimes if the their only greatest common divisor is 1. ## Task In this kata you'll be given a number ```n >= 2``` and output a list with all positive integers less than ```gcd(n, k) == 1```, with ```k``` being any of the output numbers. The list cannot include duplicated entries and has to be sorted. ## Examples ``` 2 -> [1] 3 -> [1, 2] 6 -> [1, 5] 10 -> [1, 3, 7, 9] 20 -> [1, 3, 7, 9, 11, 13, 17, 19] 25 -> [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 30 -> [1, 7, 11, 13, 17, 19, 23, 29] ``` Also feel free to reuse/extend the following starter code: ```python def coprimes(n): ```
{"functional": "_inputs = [[2], [3], [6], [10], [20], [25], [30]]\n_outputs = [[[1]], [[1, 2]], [[1, 5]], [[1, 3, 7, 9]], [[1, 3, 7, 9, 11, 13, 17, 19]], [[1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24]], [[1, 7, 11, 13, 17, 19, 23, 29]]]\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(coprimes(*i), o[0])"}
296
331
coding
Solve the programming task below in a Python markdown code block. Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly a_{i} calories on touching the i-th strip. You've got a string s, describing the process of the game and numbers a_1, a_2, a_3, a_4. Calculate how many calories Jury needs to destroy all the squares? -----Input----- The first line contains four space-separated integers a_1, a_2, a_3, a_4 (0 ≤ a_1, a_2, a_3, a_4 ≤ 10^4). The second line contains string s (1 ≤ |s| ≤ 10^5), where the і-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. -----Output----- Print a single integer — the total number of calories that Jury wastes. -----Examples----- Input 1 2 3 4 123214 Output 13 Input 1 5 3 2 11221 Output 13
{"inputs": ["4 3 2 1\n2\n", "0 0 0 0\n1\n", "1 2 3 4\n4\n", "1 2 3 4\n4\n", "4 3 2 1\n2\n", "0 0 0 0\n1\n", "0 2 3 4\n4\n", "0 3 2 1\n2\n"], "outputs": ["3\n", "0\n", "4\n", "4\n", "3\n", "0\n", "4\n", "3\n"]}
361
134
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese here ------ Problem Statement ------ Maxim likes dividers of the numbers. Also Maxim is fond of lucky numbers of small elephant from Lviv city.   If you remember, lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky, 5, 17, 467 — aren't.   Now Maxim is interested in the next information: what is the number of the integer positive dividers of number n, which are overlucky.   We call number overlucky if it is possible to remove some, but not all, digits and during bonding the remaining digits we will receive a lucky number. For example, number 72344 — overlucky, because it is possible to remove digits 2 and 3, and get number 744, which is lucky. Number 223 isn't overlucky.  ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. Single line of each test case contains an integer n.  ------ Output ------ For each test case on different lines print the answer to the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ n ≤ 10^{9}$   ----- Sample Input 1 ------ 10 1 2 3 4 5 6 7 8 9 10 ----- Sample Output 1 ------ 0 0 0 1 0 0 1 1 0 0
{"inputs": ["10\n2\n4\n2\n7\n5\n6\n7\n8\n9\n2", "10\n2\n2\n2\n4\n5\n8\n1\n2\n9\n5", "10\n2\n2\n1\n4\n5\n6\n3\n8\n9\n4", "10\n2\n3\n2\n5\n5\n4\n1\n2\n9\n5", "10\n2\n2\n1\n6\n5\n6\n3\n8\n9\n4", "10\n2\n4\n2\n7\n4\n6\n7\n8\n9\n2", "10\n2\n5\n4\n5\n5\n4\n1\n2\n9\n2", "10\n3\n4\n2\n9\n4\n6\n7\n8\n9\n2"], "outputs": ["0\n1\n0\n1\n0\n0\n1\n1\n0\n0\n", "0\n0\n0\n1\n0\n1\n0\n0\n0\n0\n", "0\n0\n0\n1\n0\n0\n0\n1\n0\n1\n", "0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n", "0\n0\n0\n0\n0\n0\n0\n1\n0\n1\n", "0\n1\n0\n1\n1\n0\n1\n1\n0\n0\n", "0\n0\n1\n0\n0\n1\n0\n0\n0\n0\n", "0\n1\n0\n0\n1\n0\n1\n1\n0\n0\n"]}
370
374
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 grid of size m x n, where each cell contains a positive integer. A cornered path is defined as a set of adjacent cells with at most one turn. More specifically, the path should exclusively move either horizontally or vertically up to the turn (if there is one), without returning to a previously visited cell. After the turn, the path will then move exclusively in the alternate direction: move vertically if it moved horizontally, and vice versa, also without returning to a previously visited cell. The product of a path is defined as the product of all the values in the path. Return the maximum number of trailing zeros in the product of a cornered path found in grid. Note: Horizontal movement means moving in either the left or right direction. Vertical movement means moving in either the up or down direction.   Please complete the following python code precisely: ```python class Solution: def maxTrailingZeros(self, grid: List[List[int]]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(grid = [[23,17,15,3,20],[8,1,20,27,11],[9,4,6,2,21],[40,9,1,10,6],[22,7,4,5,3]]) == 3\n assert candidate(grid = [[4,3,2],[7,6,1],[8,8,8]]) == 0\n\n\ncheck(Solution().maxTrailingZeros)"}
222
121
coding
Solve the programming task below in a Python markdown code block. A core idea of several left-wing ideologies is that the wealthiest should *support* the poorest, no matter what and that is exactly what you are called to do using this kata (which, on a side note, was born out of the necessity to redistribute the width of `div`s into a given container). You will be given two parameters, `population` and `minimum`: your goal is to give to each one according to his own needs (which we assume to be equal to `minimum` for everyone, no matter what), taking from the richest (bigger numbers) first. For example, assuming a population `[2,3,5,15,75]` and `5` as a minimum, the expected result should be `[5,5,5,15,70]`. Let's punish those filthy capitalists, as we all know that being rich has to be somehow a fault and a shame! If you happen to have few people as the richest, just take from the ones with the lowest index (the closest to the left, in few words) in the array first, on a 1:1 based heroic proletarian redistribution, until everyone is satisfied. To clarify this rule, assuming a population `[2,3,5,45,45]` and `5` as `minimum`, the expected result should be `[5,5,5,42,43]`. If you want to see it in steps, consider removing `minimum` from every member of the population, then iteratively (or recursively) adding 1 to the poorest while removing 1 from the richest. Pick the element most at left if more elements exist with the same level of minimal poverty, as they are certainly even more aligned with the party will than other poor people; similarly, it is ok to take from the richest one on the left first, so they can learn their lesson and be more kind, possibly giving more *gifts* to the inspectors of the State! In steps: ``` [ 2, 3, 5,45,45] becomes [-3,-2, 0,40,40] that then becomes [-2,-2, 0,39,40] that then becomes [-1,-2, 0,39,39] that then becomes [-1,-1, 0,38,39] that then becomes [ 0,-1, 0,38,38] that then becomes [ 0, 0, 0,37,38] that then finally becomes (adding the minimum again, as no value is no longer under the poverty threshold [ 5, 5, 5,42,43] ``` If giving `minimum` is unfeasable with the current resources (as it often comes to be the case in socialist communities...), for example if the above starting population had set a goal of giving anyone at least `30`, just return an empty array `[]`. Also feel free to reuse/extend the following starter code: ```python def socialist_distribution(population, minimum): ```
{"functional": "_inputs = [[[2, 3, 5, 15, 75], 5], [[2, 3, 5, 15, 75], 20], [[2, 3, 5, 45, 45], 5], [[2, 3, 5, 45, 45], 30], [[24, 48, 22, 19, 37], 30]]\n_outputs = [[[5, 5, 5, 15, 70]], [[20, 20, 20, 20, 20]], [[5, 5, 5, 42, 43]], [[]], [[30, 30, 30, 30, 30]]]\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(socialist_distribution(*i), o[0])"}
669
332
coding
Solve the programming task below in a Python markdown code block. Given a string and an array of integers representing indices, capitalize all letters at the given indices. For example: * `capitalize("abcdef",[1,2,5]) = "aBCdeF"` * `capitalize("abcdef",[1,2,5,100]) = "aBCdeF"`. There is no index 100. The input will be a lowercase string with no spaces and an array of digits. Good luck! Be sure to also try: [Alternate capitalization](https://www.codewars.com/kata/59cfc000aeb2844d16000075) [String array revisal](https://www.codewars.com/kata/59f08f89a5e129c543000069) Also feel free to reuse/extend the following starter code: ```python def capitalize(s,ind): ```
{"functional": "_inputs = [['abcdef', [1, 2, 5]], ['abcdef', [1, 2, 5, 100]], ['codewars', [1, 3, 5, 50]], ['abracadabra', [2, 6, 9, 10]], ['codewarriors', [5]], ['indexinglessons', [0]]]\n_outputs = [['aBCdeF'], ['aBCdeF'], ['cOdEwArs'], ['abRacaDabRA'], ['codewArriors'], ['Indexinglessons']]\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(capitalize(*i), o[0])"}
214
269
coding
Solve the programming task below in a Python markdown code block. ## Task: You have to write a function `pattern` which returns the following Pattern (See Pattern & Examples) upto `n` number of rows. * Note: `Returning` the pattern is not the same as `Printing` the pattern. ### Rules/Note: * If `n < 1` then it should return "" i.e. empty string. * There are `no whitespaces` in the pattern. ### Pattern: (n)(n-1)(n-2)...4321 (n)(n-1)(n-2)...432 (n)(n-1)(n-2)...43 (n)(n-1)(n-2)...4 ............... .............. (n)(n-1)(n-2) (n)(n-1) (n) ### Examples: * pattern(4): 4321 432 43 4 * pattern(11): 1110987654321 111098765432 11109876543 1110987654 111098765 11109876 1110987 111098 11109 1110 11 ~~~if-not:cfml * Hint: Use \n in string to jump to next line ~~~ ~~~if:cfml * Hint: Use chr(10) in string to jump to next line ~~~ [List of all my katas]("http://www.codewars.com/users/curious_db97/authored") Also feel free to reuse/extend the following starter code: ```python def pattern(n): ```
{"functional": "_inputs = [[1], [2], [5], [0], [-25]]\n_outputs = [['1'], ['21\\n2'], ['54321\\n5432\\n543\\n54\\n5'], [''], ['']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, 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(pattern(*i), o[0])"}
448
202
coding
Solve the programming task below in a Python markdown code block. Your task is to calculate the distance between two $n$ dimensional vectors $x = \\{x_1, x_2, ..., x_n\\}$ and $y = \\{y_1, y_2, ..., y_n\\}$. The Minkowski's distance defined below is a metric which is a generalization of both the Manhattan distance and the Euclidean distance. \\[ D_{xy} = (\sum_{i=1}^n |x_i - y_i|^p)^{\frac{1}{p}} \\] It can be the Manhattan distance \\[ D_{xy} = |x_1 - y_1| + |x_2 - y_2| + ... + |x_n - y_n| \\] where $p = 1 $. It can be the Euclidean distance \\[ D_{xy} = \sqrt{(|x_1 - y_1|)^{2} + (|x_2 - y_2|)^{2} + ... + (|x_n - y_n|)^{2}} \\] where $p = 2 $. Also, it can be the Chebyshev distance \\[ D_{xy} = max_{i=1}^n (|x_i - y_i|) \\] where $p = \infty$ Write a program which reads two $n$ dimensional vectors $x$ and $y$, and calculates Minkowski's distance where $p = 1, 2, 3, \infty$ respectively. Constraints * $1 \leq n \leq 100$ * $0 \leq x_i, y_i \leq 1000$ Input In the first line, an integer $n$ is given. In the second and third line, $x = \\{x_1, x_2, ... x_n\\}$ and $y = \\{y_1, y_2, ... y_n\\}$ are given respectively. The elements in $x$ and $y$ are given in integers. Output Print the distance where $p = 1, 2, 3$ and $\infty$ in a line respectively. The output should not contain an absolute error greater than 10-5. Example Input 3 1 2 3 2 0 4 Output 4.000000 2.449490 2.154435 2.000000
{"inputs": ["3\n2 2 3\n2 0 4", "3\n1 2 3\n2 0 4", "3\n2 2 3\n2 -1 4", "3\n2 4 5\n2 -1 4", "3\n3 4 5\n2 -1 4", "3\n6 4 5\n2 -1 4", "3\n6 5 5\n2 -1 4", "3\n6 5 5\n2 -1 3"], "outputs": ["3.000000\n2.236068\n2.080084\n2.000000\n", "4.000000\n2.449490\n2.154435\n2.000000", "4.000000\n3.162278\n3.036589\n3.000000\n", "6.000000\n5.099020\n5.013298\n5.000000\n", "7.000000\n5.196152\n5.026526\n5.000000\n", "10.000000\n6.480741\n5.748897\n5.000000\n", "11.000000\n7.280110\n6.549912\n6.000000\n", "12.000000\n7.483315\n6.603854\n6.000000\n"]}
554
432
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, return the number of substrings that have only one distinct letter.   Please complete the following python code precisely: ```python class Solution: def countLetters(self, s: str) -> int: ```
{"functional": "def check(candidate):\n assert candidate(s = \"aaaba\") == 8\n assert candidate(s = \"aaaaaaaaaa\") == 55\n\n\ncheck(Solution().countLetters)"}
65
46
coding
Solve the programming task below in a Python markdown code block. It’s the company's 3^rd anniversary, and everyone is super-excited about it. There is a tradition in the company, that the interns decide the seating arrangement of all the members. The requirements of this order are: The CEO of the company must sit in the middle. (In case of even number of team members, he can sit on either central position.) The CTO and the COO must sit on the ends of the row. The sum of the absolute height difference of adjacent members should be minimum. Bhargav wants to steal the show by coming up with the minimum sum of absolute height difference of the heights of all the members while satisfying first 2 conditions. Since he is a product management intern, he does not know anything about computer programs. Please help him before a software engineer intern solves this. Input Format: ceo_height coo_height cto_height total number of team members (excluding above three) height_array (excluding above three) Output Format: Minimum sum of absolute height difference Constraints: 1 ≤ number of team members ≤ 20 1 ≤ heights ≤ 100 SAMPLE INPUT 13 17 11 2 12 10 SAMPLE OUTPUT 10 Explanation Optimal order: 11 10 13 12 17 -> 1+3+1+5 = 10
{"inputs": ["80 82 81\n3\n50 90 65"], "outputs": ["79"]}
304
31
coding
Solve the programming task below in a Python markdown code block. # Your Task The city of Darkishland has a strange hotel with infinite rooms. The groups that come to this hotel follow the following rules: * At the same time only members of one group can rent the hotel. * Each group comes in the morning of the check-in day and leaves the hotel in the evening of the check-out day. * Another group comes in the very next morning after the previous group has left the hotel. * A very important property of the incoming group is that it has one more member than its previous group unless it is the starting group. You will be given the number of members of the starting group. * A group with n members stays for n days in the hotel. For example, if a group of four members comes on 1st August in the morning, it will leave the hotel on 4th August in the evening and the next group of five members will come on 5th August in the morning and stay for five days and so on. Given the initial group size you will have to find the group size staying in the hotel on a specified day. # Input S denotes the initial size of the group and D denotes that you will have to find the group size staying in the hotel on D-th day (starting from 1). A group size S means that on the first day a group of S members comes to the hotel and stays for S days. Then comes a group of S + 1 members according to the previously described rules and so on. Also feel free to reuse/extend the following starter code: ```python def group_size(S, D): ```
{"functional": "_inputs = [[1, 6], [3, 10], [3, 14], [10, 1000], [1, 1000], [5, 4], [5, 7], [10000, 1000000000000000], [2, 20000000000000], [10, 900000000000000000], [34545, 565], [234234, 6577], [10, 10]]\n_outputs = [[3], [5], [6], [46], [45], [5], [6], [44721361], [6324555], [1341640786], [34545], [234234], [10]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(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(group_size(*i), o[0])"}
341
374
coding
Solve the programming task below in a Python markdown code block. Most football fans love it for the goals and excitement. Well, this Kata doesn't. You are to handle the referee's little notebook and count the players who were sent off for fouls and misbehavior. The rules: Two teams, named "A" and "B" have 11 players each; players on each team are numbered from 1 to 11. Any player may be sent off the field by being given a red card. A player can also receive a yellow warning card, which is fine, but if he receives another yellow card, he is sent off immediately (no need for a red card in that case). If one of the teams has less than 7 players remaining, the game is stopped immediately by the referee, and the team with less than 7 players loses. A `card` is a string with the team's letter ('A' or 'B'), player's number, and card's color ('Y' or 'R') - all concatenated and capitalized. e.g the card `'B7Y'` means player #7 from team B received a yellow card. The task: Given a list of cards (could be empty), return the number of remaining players on each team at the end of the game (as a tuple of 2 integers, team "A" first). If the game was terminated by the referee for insufficient number of players, you are to stop the game immediately, and ignore any further possible cards. Note for the random tests: If a player that has already been sent off receives another card - ignore it. Also feel free to reuse/extend the following starter code: ```python def men_still_standing(cards): ```
{"functional": "_inputs = [[[]], [['A4Y', 'A4Y']], [['A4Y', 'A4R']], [['A4Y', 'A5R', 'B5R', 'A4Y', 'B6Y']], [['A4R', 'A4R', 'A4R']], [['A4R', 'A2R', 'A3R', 'A6R', 'A8R', 'A10R', 'A11R']]]\n_outputs = [[[11, 11]], [[10, 11]], [[10, 11]], [[9, 10]], [[10, 11]], [[6, 11]]]\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(men_still_standing(*i), o[0])"}
358
299
coding
Solve the programming task below in a Python markdown code block. Polycarp has a poor memory. Each day he can remember no more than $3$ of different letters. Polycarp wants to write a non-empty string of $s$ consisting of lowercase Latin letters, taking minimum number of days. In how many days will he be able to do it? Polycarp initially has an empty string and can only add characters to the end of that string. For example, if Polycarp wants to write the string lollipops, he will do it in $2$ days: on the first day Polycarp will memorize the letters l, o, i and write lolli; On the second day Polycarp will remember the letters p, o, s, add pops to the resulting line and get the line lollipops. If Polycarp wants to write the string stringology, he will do it in $4$ days: in the first day will be written part str; on day two will be written part ing; on the third day, part of olog will be written; on the fourth day, part of y will be written. For a given string $s$, print the minimum number of days it will take Polycarp to write it. -----Input----- The first line of input data contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Each test case consists of a non-empty string $s$ consisting of lowercase Latin letters (the length of the string $s$ does not exceed $2 \cdot 10^5$) — the string Polycarp wants to construct. It is guaranteed that the sum of string lengths $s$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, print a single number — minimum number of days it will take Polycarp to write the string $s$ from memory. -----Examples----- Input 6 lollipops stringology abracadabra codeforces test f Output 2 4 3 4 1 1 -----Note----- None
{"inputs": ["1\nvdjisjifreo\n", "6\nlollipops\nstringology\nabracadabra\ncodeforces\ntest\nf\n"], "outputs": ["4\n", "2\n4\n3\n4\n1\n1\n"]}
459
60
coding
Solve the programming task below in a Python markdown code block. Chef gets confused between mean and median very often, and as a result, he has developed a dislike of arrays whose mean and median are not equal. Chef has an array A of N elements. He can perform the following operation on it: Pick an index 1 ≤ i ≤ N and increase A_{i} by 1. He would like to obtain an array whose mean and median are equal. Determine the minimum number of operations required to achieve this. Note: The median of an array A of length N is defined as follows: Sort the array A. Then, If N is even, the median is the (\frac{N}{2})^{\text{th}} element If N is odd, the median is the (\frac{N + 1}{2})^{\text{th}} element For example, the median of the array [3,4,1,2] is 2 and the median of the array [3,4,1] is 3. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of testcases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}. ------ Output Format ------ For each test case, print a single line containing one integer — the minimum number of operations Chef needs to perform to make the mean and median equal. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $2 ≤ N ≤ 3 \cdot 10^{5}$ $1 ≤ A_{i} ≤ 10^{9}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$ ----- Sample Input 1 ------ 3 3 1 2 3 4 1 1 3 3 5 1 1000000000 1 1000000000 1 ----- Sample Output 1 ------ 0 4 500000002 ----- explanation 1 ------ Test Case $1$: The mean and median of the array are both $2$. They are already equal, so no operations are required. Test Case $2$: It is optimal to apply the operation on $1^{st}$ and $2^{nd}$ index twice each. The array after applying these operations will be $[3, 3, 3, 3]$, which has both mean and median $3$.
{"inputs": ["3\n3\n1 2 3\n4\n1 1 3 3\n5\n1 1000000000 1 1000000000 1\n"], "outputs": ["0\n4\n500000002\n"]}
579
74
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n integer matrix grid where each cell is either 0 (empty) or 1 (obstacle). You can move up, down, left, or right from and to an empty cell in one step. Return the minimum number of steps to walk from the upper left corner (0, 0) to the lower right corner (m - 1, n - 1) given that you can eliminate at most k obstacles. If it is not possible to find such walk return -1.   Please complete the following python code precisely: ```python class Solution: def shortestPath(self, grid: List[List[int]], k: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate( grid = [[0,0,0],[1,1,0],[0,0,0],[0,1,1],[0,0,0]], k = 1) == 6\n assert candidate(grid = [[0,1,1],[1,1,1],[1,0,0]], k = 1) == -1\n\n\ncheck(Solution().shortestPath)"}
159
99
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums representing the strength of some heroes. The power of a group of heroes is defined as follows: Let i0, i1, ... ,ik be the indices of the heroes in a group. Then, the power of this group is max(nums[i0], nums[i1], ... ,nums[ik])2 * min(nums[i0], nums[i1], ... ,nums[ik]). Return the sum of the power of all non-empty groups of heroes possible. Since the sum could be very large, return it modulo 109 + 7.   Please complete the following python code precisely: ```python class Solution: def sumOfPower(self, nums: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(nums = [2,1,4]) == 141\n assert candidate(nums = [1,1,1]) == 7\n\n\ncheck(Solution().sumOfPower)"}
174
54
coding
Solve the programming task below in a Python markdown code block. Every now and then people in the office moves teams or departments. Depending what people are doing with their time they can become more or less boring. Time to assess the current team. ```if-not:java You will be provided with an object(staff) containing the staff names as keys, and the department they work in as values. ``` ```if:java You will be provided with an array of `Person` objects with each instance containing the name and department for a staff member. ~~~java public class Person { public final String name; // name of the staff member public final String department; // department they work in } ~~~ ``` Each department has a different boredom assessment score, as follows: accounts = 1 finance = 2 canteen = 10 regulation = 3 trading = 6 change = 6 IS = 8 retail = 5 cleaning = 4 pissing about = 25 Depending on the cumulative score of the team, return the appropriate sentiment: <=80: 'kill me now' < 100 & > 80: 'i can handle this' 100 or over: 'party time!!' The Office I - Outed The Office III - Broken Photocopier The Office IV - Find a Meeting Room The Office V - Find a Chair Also feel free to reuse/extend the following starter code: ```python def boredom(staff): ```
{"functional": "_inputs = [[{'tim': 'change', 'jim': 'accounts', 'randy': 'canteen', 'sandy': 'change', 'andy': 'change', 'katie': 'IS', 'laura': 'change', 'saajid': 'IS', 'alex': 'trading', 'john': 'accounts', 'mr': 'finance'}], [{'tim': 'IS', 'jim': 'finance', 'randy': 'pissing about', 'sandy': 'cleaning', 'andy': 'cleaning', 'katie': 'cleaning', 'laura': 'pissing about', 'saajid': 'regulation', 'alex': 'regulation', 'john': 'accounts', 'mr': 'canteen'}], [{'tim': 'accounts', 'jim': 'accounts', 'randy': 'pissing about', 'sandy': 'finance', 'andy': 'change', 'katie': 'IS', 'laura': 'IS', 'saajid': 'canteen', 'alex': 'pissing about', 'john': 'retail', 'mr': 'pissing about'}]]\n_outputs = [['kill me now'], ['i can handle this'], ['party time!!']]\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(boredom(*i), o[0])"}
330
411
coding
Solve the programming task below in a Python markdown code block. The city of Hackerland has formed a new football club and wants to participate in the upcoming Football League of their country. The coach is worried that they will not be able to qualify because they don't have a famous footballer in their team. The assistant coach suggests that the team should buy Cristiano Ronaldo as he can single-handedly get their team qualified. On day 1, today, the club has to pay 'A' HackerCoins in order to buy Ronaldo. After each passing day, the price of buying Ronaldo becomes A times the price on the previous day. Any normal person would buy him on the 1^{st} day itself as the price will be the lowest but since the coach always failed in high school Mathematics, he wants 'B' days to think before making him an offer. As the coach doesn't know how to calculate the price of Ronaldo on the B^{th} day, he has asked for your help. Your task is to tell the price of Ronaldo on the B^{th} day. Since, the price can be a very large number, please tell him the price modulo 10^{9} + 7. Input Format The first line contains an integer T, the number of testcases. It's followed by T lines. Each testcase will contain two integers A & B separated by a space. Output Format Output T lines, each corresponding to the answer of the testcase. Constraints 1 <= T <= 10 1 <= A,B <= 10100000 A % (10^{9} + 7) != 0 Note Both integers will have a maximum of 100000 digits. Sample Input #00: 5 3 2 4 5 7 4 34534985349875439875439875349875 93475349759384754395743975349573495 34543987529435983745230948023948 3498573497543987543985743989120393097595572309482304 Sample Output #00: 9 1024 2401 735851262 985546465 Explanation #00: As value of 3^{2} = 9, So output for first case will be 9. Similarly 4^{5} modulo (10^{9} + 7) = 1024 Similarly 7^{4} modulo (10^{9} + 7) = 2401 Similarly we can do for others.
{"inputs": ["5\n3 2\n4 5\n7 4\n34534985349875439875439875349875 93475349759384754395743975349573495\n34543987529435983745230948023948 3498573497543987543985743989120393097595572309482304\n"], "outputs": ["9\n1024\n2401\n735851262\n985546465\n"]}
665
211
coding
Solve the programming task below in a Python markdown code block. There is an array of $n$ integers. There are also $2$ disjoint sets, $\mbox{A}$ and $\mbox{B}$, each containing $m$ integers. You like all the integers in set $\mbox{A}$ and dislike all the integers in set $\mbox{B}$. Your initial happiness is $\mbox{o}$. For each $\boldsymbol{i}$ integer in the array, if $i\in A$, you add $\mbox{I}$ to your happiness. If $i\in B$, you add $-1$ to your happiness. Otherwise, your happiness does not change. Output your final happiness at the end. Note: Since $\mbox{A}$ and $\mbox{B}$ are sets, they have no repeated elements. However, the array might contain duplicate elements. Constraints $1\leq n\leq10^5$ $1\leq m\leq10^5$ $1\leq\textit{Any integer in the input}\leq10^9$ Input Format The first line contains integers $n$ and $m$ separated by a space. The second line contains $n$ integers, the elements of the array. The third and fourth lines contain $m$ integers, $\mbox{A}$ and $\mbox{B}$, respectively. Output Format Output a single integer, your total happiness. Sample Input 3 2 1 5 3 3 1 5 7 Sample Output 1 Explanation You gain $\mbox{I}$ unit of happiness for elements $3$ and $\mbox{I}$ in set $\mbox{A}$. You lose $\mbox{I}$ unit for $5$ in set $\mbox{B}$. The element $7$ in set $\mbox{B}$ does not exist in the array so it is not included in the calculation. Hence, the total happiness is $2-1=1$.
{"inputs": ["3 2\n1 5 3\n3 1\n5 7\n"], "outputs": ["1\n"]}
446
30
coding
Solve the programming task below in a Python markdown code block. We define a magic square to be an $n\times n$ matrix of distinct positive integers from $\mbox{1}$ to $n^2$ where the sum of any row, column, or diagonal of length $n$ is always equal to the same number: the magic constant. You will be given a $3\times3$ matrix $\boldsymbol{\mathrm{~S~}}$ of integers in the inclusive range $[1,9]$. We can convert any digit $\boldsymbol{a}$ to any other digit $\boldsymbol{b}$ in the range $[1,9]$ at cost of $\left|a-b\right|$. Given $\boldsymbol{\mathrm{~S~}}$, convert it into a magic square at minimal cost. Print this cost on a new line. Note: The resulting magic square must contain distinct integers in the inclusive range $[1,9]$. Example $s = [[5, 3, 4], [1, 5, 8], [6, 4, 2]]$ The matrix looks like this: 5 3 4 1 5 8 6 4 2 We can convert it to the following magic square: 8 3 4 1 5 9 6 7 2 This took three replacements at a cost of $|5-8|+|8-9|+|4-7|=7$. Function Description Complete the formingMagicSquare function in the editor below. formingMagicSquare has the following parameter(s): int s[3][3]: a $3\times3$ array of integers Returns int: the minimal total cost of converting the input square to a magic square Input Format Each of the $3$ lines contains three space-separated integers of row $s[i]$. Constraints $s[i][j]\in[1,9]$ Sample Input 0 4 9 2 3 5 7 8 1 5 Sample Output 0 1 Explanation 0 If we change the bottom right value, $s[2][2]$, from $5$ to $\boldsymbol{6}$ at a cost of $|6-5|=1$, $\boldsymbol{\mathrm{~S~}}$ becomes a magic square at the minimum possible cost. Sample Input 1 4 8 2 4 5 7 6 1 6 Sample Output 1 4 Explanation 1 Using 0-based indexing, if we make $s[0][1]$->$\mbox{9}$ at a cost of $|9-8|=1$ $s[\mathbf{1}][\mathbf{0}]$->$3$ at a cost of $|3-4|=1$ $s[2][0]$->$8$ at a cost of $|8-6|=2$, then the total cost will be $1+1+2=4$.
{"inputs": ["4 9 2\n3 5 7\n8 1 5\n", "4 8 2\n4 5 7\n6 1 6\n"], "outputs": ["1\n", "4\n"]}
650
54
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums. Each element in nums is 1, 2 or 3. In each operation, you can remove an element from nums. Return the minimum number of operations to make nums non-decreasing.   Please complete the following python code precisely: ```python class Solution: def minimumOperations(self, nums: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(nums = [2,1,3,2,1]) == 3\n assert candidate(nums = [1,3,2,1,3,3]) == 2\n assert candidate(nums = [2,2,2,2,3,3]) == 0\n\n\ncheck(Solution().minimumOperations)"}
96
83
coding
Solve the programming task below in a Python markdown code block. You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains two space-separated integers $L$ and $R$. -----Output----- For each test case, print a single line containing one integer — the sum $S$ modulo $10^9+7$. -----Constraints----- - $1 \le T \le 10^5$ - $1 \le L \le R \le 10^{18}$ -----Example Input----- 2 1 4 4 10 -----Example Output----- 1 16 -----Explanation----- Example case 1: The sum is 1 + 1 AND 2 + 1 AND 2 AND 3 + 1 AND 2 AND 3 AND 4 = 1 + 0 + 0 + 0 = 1. Example case 2: The sum is 4 + 4 AND 5 + 4 AND 5 AND 6 + 4 AND 5 AND 6 AND 7 + … + 4 AND 5 AND … AND 10 = 4 + 4 + … + 0 = 16.
{"inputs": ["2\n1 4\n4 10"], "outputs": ["1\n16"]}
407
24
coding
Solve the programming task below in a Python markdown code block. Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message. -----Input----- First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. -----Output----- Print a line that contains the original message. -----Examples----- Input R s;;upimrrfod;pbr Output allyouneedislove
{"inputs": ["L\nq\n", "L\no\n", "L\n,\n", "L\nz\n", "R\n.\n", "R\no\n", "R\nw\n", "R\nx\n"], "outputs": ["w\n", "p\n", ".\n", "x\n", ",\n", "i\n", "q\n", "z\n"]}
282
86
coding
Solve the programming task below in a Python markdown code block. Find the edit distance between given two words s1 and s2. The disntace is the minimum number of single-character edits required to change one word into the other. The edits including the following operations: * insertion: Insert a character at a particular position. * deletion: Delete a character at a particular position. * substitution: Change the character at a particular position to a different character Constraints * 1 ≤ length of s1 ≤ 1000 * 1 ≤ length of s2 ≤ 1000 Input s1 s2 Two words s1 and s2 are given in the first line and the second line respectively. The words will consist of lower case characters. Output Print the edit distance in a line. Examples Input acac acm Output 2 Input icpc icpc Output 0
{"inputs": ["`cac\nacm", "`cad\nacm", "`cac\nbcm", "`cac\nmcb", "`cab\nmcb", "`cab\nbcm", "_cac\nmcb", "_cca\nmcb"], "outputs": ["3\n", "3\n", "3\n", "3\n", "2\n", "3\n", "3\n", "3\n"]}
195
85
coding
Solve the programming task below in a Python markdown code block. The R2 company has n employees working for it. The work involves constant exchange of ideas, sharing the stories of success and upcoming challenging. For that, R2 uses a famous instant messaging program Spyke. R2 has m Spyke chats just to discuss all sorts of issues. In each chat, some group of employees exchanges messages daily. An employee can simultaneously talk in multiple chats. If some employee is in the k-th chat, he can write messages to this chat and receive notifications about messages from this chat. If an employee writes a message in the chat, all other participants of the chat receive a message notification. The R2 company is conducting an audit. Now the specialists study effective communication between the employees. For this purpose, they have a chat log and the description of chat structure. You, as one of audit specialists, are commissioned to write a program that will use this data to determine the total number of message notifications received by each employee. -----Input----- The first line contains three space-separated integers n, m and k (2 ≤ n ≤ 2·10^4; 1 ≤ m ≤ 10; 1 ≤ k ≤ 2·10^5) — the number of the employees, the number of chats and the number of events in the log, correspondingly. Next n lines contain matrix a of size n × m, consisting of numbers zero and one. The element of this matrix, recorded in the j-th column of the i-th line, (let's denote it as a_{ij}) equals 1, if the i-th employee is the participant of the j-th chat, otherwise the element equals 0. Assume that the employees are numbered from 1 to n and the chats are numbered from 1 to m. Next k lines contain the description of the log events. The i-th line contains two space-separated integers x_{i} and y_{i} (1 ≤ x_{i} ≤ n; 1 ≤ y_{i} ≤ m) which mean that the employee number x_{i} sent one message to chat number y_{i}. It is guaranteed that employee number x_{i} is a participant of chat y_{i}. It is guaranteed that each chat contains at least two employees. -----Output----- Print in the single line n space-separated integers, where the i-th integer shows the number of message notifications the i-th employee receives. -----Examples----- Input 3 4 5 1 1 1 1 1 0 1 1 1 1 0 0 1 1 3 1 1 3 2 4 3 2 Output 3 3 1 Input 4 3 4 0 1 1 1 0 1 1 1 1 0 0 0 1 2 2 1 3 1 1 3 Output 0 2 3 0
{"inputs": ["2 1 1\n1\n1\n1 1\n", "2 1 1\n1\n1\n1 1\n", "2 1 1\n1\n1\n2 1\n", "2 1 1\n1\n1\n1 1\n", "2 1 1\n1\n1\n2 1\n", "2 1 1\n1\n0\n1 1\n", "3 1 2\n1\n1\n0\n1 1\n2 1\n", "3 1 2\n1\n0\n1\n1 1\n3 1\n"], "outputs": ["0 1 ", "0 1 ", "1 0 ", "0 1 \n", "1 0 \n", "0 0", "1 1 0 ", "1 0 1 "]}
624
195
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are several squares being dropped onto the X-axis of a 2D plane. You are given a 2D integer array positions where positions[i] = [lefti, sideLengthi] represents the ith square with a side length of sideLengthi that is dropped with its left edge aligned with X-coordinate lefti. Each square is dropped one at a time from a height above any landed squares. It then falls downward (negative Y direction) until it either lands on the top side of another square or on the X-axis. A square brushing the left/right side of another square does not count as landing on it. Once it lands, it freezes in place and cannot be moved. After each square is dropped, you must record the height of the current tallest stack of squares. Return an integer array ans where ans[i] represents the height described above after dropping the ith square.   Please complete the following python code precisely: ```python class Solution: def fallingSquares(self, positions: List[List[int]]) -> List[int]: ```
{"functional": "def check(candidate):\n assert candidate(positions = [[1,2],[2,3],[6,1]]) == [2,5,5]\n assert candidate(positions = [[100,100],[200,100]]) == [100,100]\n\n\ncheck(Solution().fallingSquares)"}
229
83
coding
Solve the programming task below in a Python markdown code block. The polar bears are going fishing. They plan to sail from (s_{x}, s_{y}) to (e_{x}, e_{y}). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x, y). If the wind blows to the east, the boat will move to (x + 1, y). If the wind blows to the south, the boat will move to (x, y - 1). If the wind blows to the west, the boat will move to (x - 1, y). If the wind blows to the north, the boat will move to (x, y + 1). Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (x, y). Given the wind direction for t seconds, what is the earliest time they sail to (e_{x}, e_{y})? -----Input----- The first line contains five integers t, s_{x}, s_{y}, e_{x}, e_{y} (1 ≤ t ≤ 10^5, - 10^9 ≤ s_{x}, s_{y}, e_{x}, e_{y} ≤ 10^9). The starting location and the ending location will be different. The second line contains t characters, the i-th character is the wind blowing direction at the i-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north). -----Output----- If they can reach (e_{x}, e_{y}) within t seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). -----Examples----- Input 5 0 0 1 1 SESNW Output 4 Input 10 5 3 3 6 NENSWESNEE Output -1 -----Note----- In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4. In the second sample, they cannot sail to the destination.
{"inputs": ["1 5 5 5 6\nE\n", "1 5 5 5 6\nE\n", "1 5 3 5 6\nE\n", "1 5 8 5 6\nE\n", "1 0 0 0 -1\nS\n", "1 0 0 0 -1\nS\n", "1 5 3 5 12\nE\n", "1 -2 0 0 0\nS\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "1\n", "1\n", "-1\n", "-1\n"]}
489
152
coding
Solve the programming task below in a Python markdown code block. Chef loves cooking. Also, he is very hygienic. Hence, Chef grows his own vegetables in his mini kitchen garden. He has $M$ lanes in which he grows vegetables. The $ith$ lane has $Ai$ vegetables growing in it. Vegetables in $ith$ lane become edible on day $Di$ and day $Di+1$(that is, the vegetables are edible only on days $Di$ and $Di+1$,where $Di+1$ is the next day of $Di$). For Example, if $Di$ is 2, then vegetable is edible on day 2 and day 3 only. If not collected in these days, they cannot be cooked. Also, Chef is a lone worker. Hence, with respect to his capacity, he can collect only $V$ vegetables per day. But, Chef is a hard worker, and is willing to work every day, starting from day 1. Chef is busy sowing the seeds. So, he assigns you the task to find out the maximum number of vegetables he can collect, provided that he collects optimally. -----Input:----- - First line contains of 2 space separated integers $M$ and $V$, number of lanes and capacity of Chef. - Next $M$ lines follow - Each $ith$ line contains 2 space separated integers, $Di$ and $Ai$, the day when the vegetable of the $ith$ lane become edible and the number of vegetables in that lane. -----Output:----- For each testcase, output in a single integer, that is the maximum number of vegetables that can be cooked -----Constraints----- - $1 \leq M,V \leq 3000$ - $1 \leq Di,Ai \leq 3000$ -----Subtasks----- - 20 points : $1 \leq M \leq 100$ - 30 points : $1 \leq M \leq 1000$ - 50 points : $Original Constraints$ -----Sample Input 1:----- 2 4 1 6 2 5 -----Sample Output 1:----- 11 -----Sample Input 2:----- 3 3 1 4 6 2 5 3 -----Sample Output 2:----- 9 -----EXPLANATION:----- In the first sample, in order to obtain the optimal answer, you should do the following:- - On day 1, collect 4 vegetables from lane 1 - On day 2, collect 2 vegetables from lane 1 and 2 vegetables from lane 2 - On day 3, collect 3 vegetables from lane 2 In the first sample, in order to obtain the optimal answer, you should do the following:- - On day 1, collect 3 vegetables from lane 1 - On day 2, collect 1 vegetable from lane 1 - On day 5, collect 3 vegetables from lane 3 - On day 6, collect 2 vegetables from lane 2
{"inputs": ["2 4\n1 6\n2 5", "3 3\n1 4\n6 2\n5 3"], "outputs": ["11", "9"]}
662
43
coding
Solve the programming task below in a Python markdown code block. Given an array A having N elements, Chef wonders how many pairs (i, j) exists such that 1 ≤ i < j ≤ N, and A_{i} \cdot A_{j} is divisible by i \cdot j. Can you help Chef in finding the number of such pairs? ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of the T testcases follows. - The first line of each test case contains a single integer N denoting the number of elements in A. - The second line of each test case contains N space separated integers A_{1}, A_{2},..., A_{N}. ------ Output Format ------ For each test case, print a single line containing one integer denoting the number of pairs that satisfies the above condition. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i} ≤ 10^{5}$ - The sum of $N$ over all test cases does not exceed $10^{5}$ ----- Sample Input 1 ------ 3 3 1 2 3 4 2 3 5 6 5 3 9 14 6 10 ----- Sample Output 1 ------ 3 2 6 ----- explanation 1 ------ Test Case $1$: For all possible pairs of $\{i, j\}$, $A_{i} \cdot A_{j}$ is divisible by $i \cdot j$. Test Case $2$: The condition holds for the following two pairs of $\{i, j\}$: $\{1 , 2\}$, $\{1, 4\}$.
{"inputs": ["3\n3\n1 2 3\n4\n2 3 5 6\n5\n3 9 14 6 10\n"], "outputs": ["3\n2\n6\n"]}
390
50
coding
Solve the programming task below in a Python markdown code block. There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = W represents the ball is white; c_i = B represents the ball is black. Takahashi the human wants to achieve the following objective: - For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. - For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: - Swap two adjacent balls. Find the minimum number of operations required to achieve the objective. -----Constraints----- - 1 ≤ N ≤ 2000 - 1 ≤ a_i ≤ N - c_i = W or c_i = B. - If i ≠ j, (a_i,c_i) ≠ (a_j,c_j). -----Input----- Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N} -----Output----- Print the minimum number of operations required to achieve the objective. -----Sample Input----- 3 B 1 W 2 B 3 W 1 W 3 B 2 -----Sample Output----- 4 The objective can be achieved in four operations, for example, as follows: - Swap the black 3 and white 1. - Swap the white 1 and white 2. - Swap the black 3 and white 3. - Swap the black 3 and black 2.
{"inputs": ["1\nB 1\nW 1\n", "1\nB 1\nW 1\n", "1\nW 1\nB 1\n", "2\nW 2\nB 1\nW 1\nB 2\n", "3\nB 1\nW 1\nB 3\nW 2\nW 3\nB 2", "3\nB 1\nW 1\nB 2\nW 2\nW 3\nB 3", "3\nB 1\nW 1\nB 3\nW 3\nW 2\nB 2", "3\nB 1\nW 2\nB 2\nW 1\nW 3\nB 3"], "outputs": ["0\n", "0\n", "0\n", "2\n", "3", "0", "4", "2"]}
457
198
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string word and an array of strings forbidden. A string is called valid if none of its substrings are present in forbidden. Return the length of the longest valid substring of the string word. A substring is a contiguous sequence of characters in a string, possibly empty.   Please complete the following python code precisely: ```python class Solution: def longestValidSubstring(self, word: str, forbidden: List[str]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(word = \"cbaaaabc\", forbidden = [\"aaa\",\"cb\"]) == 4\n assert candidate(word = \"leetcode\", forbidden = [\"de\",\"le\",\"e\"]) == 4\n\n\ncheck(Solution().longestValidSubstring)"}
110
67
coding
Solve the programming task below in a Python markdown code block. It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent such three displays with indices $i < j < k$ that the font size increases if you move along the road in a particular direction. Namely, the condition $s_i < s_j < s_k$ should be held. The rent cost is for the $i$-th display is $c_i$. Please determine the smallest cost Maria Stepanovna should pay. -----Input----- The first line contains a single integer $n$ ($3 \le n \le 3\,000$) — the number of displays. The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^9$) — the font sizes on the displays in the order they stand along the road. The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \le c_i \le 10^8$) — the rent costs for each display. -----Output----- If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices $i < j < k$ such that $s_i < s_j < s_k$. -----Examples----- Input 5 2 4 5 4 10 40 30 20 10 40 Output 90 Input 3 100 101 100 2 4 5 Output -1 Input 10 1 2 3 4 5 6 7 8 9 10 10 13 11 14 15 12 13 13 18 13 Output 33 -----Note----- In the first example you can, for example, choose displays $1$, $4$ and $5$, because $s_1 < s_4 < s_5$ ($2 < 4 < 10$), and the rent cost is $40 + 10 + 40 = 90$. In the second example you can't select a valid triple of indices, so the answer is -1.
{"inputs": ["3\n1 2 3\n1 1 1\n", "3\n1 2 3\n1 1 1\n", "3\n1 3 3\n1 1 1\n", "3\n1 3 3\n1 0 1\n", "3\n1 0 3\n1 0 1\n", "3\n1 -1 3\n1 0 1\n", "3\n1 -1 3\n1 0 2\n", "3\n0 -1 3\n1 0 2\n"], "outputs": ["3\n", "3\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
594
166
coding
Solve the programming task below in a Python markdown code block. Kiteretsu goes to his Chemistry Lab to perform the perfect reaction. In his lab, he found N reagents numbered 1 to N. The i^{th} reagent has two properties - A_{i} and B_{i}. A reaction can be performed between the reagents i and j only if A_{i} ≤ j. If a reaction is performed between reagents i and j, i \cdot j amount of heat is produced. Out of this, D \cdot (B_{i} \oplus B_{j}) is absorbed and the rest heat is released. Here, \oplus denotes the [bitwise XOR] operation. More formally, in a reaction between reagents i and j, the heat released is given by: H(i,j)= i \cdot j - D \cdot (B_{i} \oplus B_{j}) Find the maximum possible heat which can be released in a reaction. Note: The input of this problem is large, so use fast input/output methods. ------ Input Format ------ - The first line will contain T - the number of test cases. Then the test cases follow. - First line of each test case contains two integers N, D. - Second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}. - Third line of each test case contains N integers B_{1}, B_{2}, \ldots, B_{N} ------ Output Format ------ For each test case, print a single line, a single integer denoting the maximum possible heat that can be released in a reaction. ------ Constraints ------ $1 ≤ T ≤ 10$ $2 ≤ N ≤ 10^{6}$ $1 ≤ D ≤ 2000$ $(i+1) ≤ A_{i} ≤ N$ $\forall$ $(1 ≤ i < N)$ $A_{N}=N+1$ $1 ≤ B_{i} ≤ N$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 5 2 2 4 5 5 6 1 3 2 2 5 2 3 2 3 1 2 ----- Sample Output 1 ------ 6 -7 ----- explanation 1 ------ Test Case $1$: Let us choose $i = 2$ and $j = 4$. Since $A_{2} ≤ 4$, a reaction can take place. The heat released in this reaction is $2\cdot 4 - 2\cdot (3 \oplus 2) = 8-2 \cdot 1 = 6$. It can be proven that for no other reaction, the heat released is greater than $6$. Some other reactions can take place between $(2, 5)$, $(3,5)$. Note that no reaction is possible between $(3,4)$ as $A_{3} \nleq 4$. Test Case $2$: The only possible reaction is between reagents $1$ and $2$. The heat released in this reaction is $1 \cdot 2 - 3\cdot (1 \oplus 2) = 2 - 3\cdot 3 = -7$.
{"inputs": ["2\n5 2\n2 4 5 5 6\n1 3 2 2 5\n2 3\n2 3\n1 2\n"], "outputs": ["6\n-7\n"]}
714
53
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree and an integer limit, delete all insufficient nodes in the tree simultaneously, and return the root of the resulting binary tree. A node is insufficient if every root to leaf path intersecting this node has a sum strictly less than limit. A leaf is a node with no children.   Please complete the following python code precisely: ```python # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def sufficientSubset(self, root: Optional[TreeNode], limit: int) -> Optional[TreeNode]: ```
{"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14]), limit = 1), tree_node([1,2,3,4,None,None,7,8,9,None,14]))\n assert is_same_tree(candidate(root = tree_node([5,4,8,11,None,17,4,7,1,None,None,5,3]), limit = 22), tree_node([5,4,8,11,None,17,4,7,None,None,None,5]))\n assert is_same_tree(candidate(root = tree_node([1,2,-3,-5,None,4,None]), limit = -1), tree_node([1,None,-3,4]))\n\n\ncheck(Solution().sufficientSubset)"}
168
208
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese , Russian and Vietnamese Chef likes to play table tennis. He found some statistics of matches which described who won the points in order. A game shall be won by the player first scoring 11 points except in the case when both players have 10 points each, then the game shall be won by the first player subsequently gaining a lead of 2 points. Could you please help the Chef find out who the winner was from the given statistics? (It is guaranteed that statistics represent always a valid, finished match.) ------ 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 test case consist a binary string S, which describes a match. '0' means Chef lose a point, whereas '1' means he won the point. ------ Output ------ For each test case, output on a separate line a string describing who won the match. If Chef won then print "WIN" (without quotes), otherwise print "LOSE" (without quotes). ------ Constraints ------ 1 ≤ T ≤ 1000 1 ≤ length(S) ≤ 100 ----- Sample Input 1 ------ 2 0101111111111 11100000000000 ----- Sample Output 1 ------ WIN LOSE ----- explanation 1 ------ Example case 1. Chef won the match 11:2, his opponent won just two points, the first and the third of the match. Example case 2. Chef lost this match 11:3, however he started very well the match, he won the first three points in a row, but maybe he got tired and after that lost 11 points in a row.
{"inputs": ["2\n0101111111111\n11100000000000\n"], "outputs": ["WIN\nLOSE"]}
395
44
coding
Solve the programming task below in a Python markdown code block. Given a string S of length N containing only numeric characters, find the number of Nice Pairs. A Nice Pair is a pair of indices - (i, j) such that 1 ≤ i < j ≤ N and j - i = |S_{j} - S_{i}|. ------ Input Format ------ - First line will contain T, number of testcases. Then the testcases follow. - The first line of each testcase contains a single integer, N, the length of the string - The second line of each testcase contains a string S of length N. The string contains only numeric characters [0-9] ------ Output Format ------ For each testcase, output a single integer - the number of nice pairs in the given string. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - String $S$ contains only numeric characters - The sum of $N$ over all test cases does not exceed $2\cdot10^{5}$ ----- Sample Input 1 ------ 3 3 123 5 13492 8 94241234 ----- Sample Output 1 ------ 3 2 9 ----- explanation 1 ------ Test Case $1$: There are $3$ nice pairs in the given string - $(1,2) , (1,3) , (2,3)$ Test Case $2$: There are $2$ nice pairs in the given string - $(2,3) , (3,5)$
{"inputs": ["3\n3\n123\n5\n13492\n8\n94241234\n"], "outputs": ["3\n2\n9\n"]}
343
43
coding
Solve the programming task below in a Python markdown code block. You should write a function that takes a string and a positive integer `n`, splits the string into parts of length `n` and returns them in an array. It is ok for the last element to have less than `n` characters. If `n` is not a valid size (`> 0`) (or is absent), you should return an empty array. If `n` is greater than the length of the string, you should return an array with the only element being the same string. Examples: ```python string_chunk('codewars', 2) # ['co', 'de', 'wa', 'rs'] string_chunk('thiskataeasy', 4) # ['this', 'kata', 'easy'] string_chunk('hello world', 3) # ['hel', 'lo ', 'wor', 'ld'] string_chunk('sunny day', 0) # [] ``` Also feel free to reuse/extend the following starter code: ```python def string_chunk(string, n=0): ```
{"functional": "_inputs = [['codewars', 2]]\n_outputs = [[['co', 'de', 'wa', 'rs']]]\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(string_chunk(*i), o[0])"}
226
170
coding
Solve the programming task below in a Python markdown code block. Chef calls a pair of integers (A, B) *equivalent* if there exist some positive integers X and Y such that A^{X} = B^{Y}. Given A and B, determine whether the pair is *equivalent* or not. ------ 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 space-separated integers A and B, as mentioned in statement. ------ Output Format ------ For each test case, output YES if (A, B) is an *equivalent* pair, NO otherwise. The output is case-insensitive. Thus, the strings Yes, YES, yes, and yeS are all considered identical. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ A, B ≤ 10^{6}$ ----- Sample Input 1 ------ 3 2 3 8 4 12 24 ----- Sample Output 1 ------ NO YES NO ----- explanation 1 ------ Test case $1$: There are no positive integers $X$ and $Y$ which satisfy $A^{X} = B^{Y}$. Test case $2$: Let $X = 2$ and $Y = 3$. Thus, $A^{X} = 8^{2} = 64$ and $B^{Y} = 4^{3} = 64$. Thus, the pair $(8, 4)$ is *equivalent*. Test case $3$: There are no positive integers $X$ and $Y$ which satisfy $A^{X} = B^{Y}$.
{"inputs": ["3\n2 3\n8 4\n12 24\n"], "outputs": ["NO\nYES\nNO\n"]}
367
32
coding
Solve the programming task below in a Python markdown code block. It's Friday night, and Chuck is bored. He's already run 1,000 miles, stopping only to eat a family sized bag of Heatwave Doritos and a large fistful of M&Ms. He just can't stop thinking about kicking something! There is only one thing for it, Chuck heads down to his local MMA gym and immediately challenges every fighter there to get in the cage and try and take him down... AT THE SAME TIME! You are provided an array of strings that represent the cage and Chuck's opponents. Your task, in traditional Chuck style, is to take their heads off!! Throw punches, kicks, headbutts (or more likely - regex or iteration...) but whatever you do, remove their heads. Return the same array of strings, but with the heads ('O') removed and replaced with a space (' '). If the provided array is empty, or is an empty string, return 'Gym is empty'. If you are given an array of numbers, return 'This isn't the gym!!'. FIGHT!! *Original design of this kata was a much more beautiful thing - the test cases illustrate the idea, and the intended output. I am unable to make the actual output go over multiple lines so for now at least you will have to imagine the beauty!* Also feel free to reuse/extend the following starter code: ```python def head_smash(arr): ```
{"functional": "_inputs = [[['*****************************************', '** _O_ * _O_ * _O_ * _O_ **', '** /(.)J * C(.)J * /(.)J * C(.)J **', '** _| |_ * _| |_ * _( )_ * _( )_ *']], [['*** _O_ ** _O_ ** _O_ ** _O_ ***', '*** /(.)J ** /(.)J ** C(.)J ** C(.)J ***', '*** _| |_ ** _| |_ ** _| |_ ** _( )_ **']], [['*****************************************', '*********** _O_ * _O_ ***********', '** _O_ * /(.)J * /(.)J * _O_ **', '** /(.)J * _| |_ * _( )_ * /(.)J **', '** _( )_ ********************* _( )_ **', '******************* X ******************']], [['*****************************************', '*********** _O_ * _O_ ***********', '** _O_ * C(.)J * /(.)J * _O_ **', '** /(.)J * _| |_ * _/ )_ * C(.)J **', '** _/ )_ ********************* _/ |_ **', '******************* X *******************', '********************** _O_ ************', '** _O_ * _O_ * /(.)J * _O_ **', '** /(.)J * C(.)J * _/ )_ * C(.)J **', '** _( )_ * _| |_ *********** _/ |_ **', '****************************************']], [[]], [876], [''], [6], [509876251], [11111111111]]\n_outputs = [[['*****************************************', '** _ _ * _ _ * _ _ * _ _ **', '** /(.)J * C(.)J * /(.)J * C(.)J **', '** _| |_ * _| |_ * _( )_ * _( )_ *']], [['*** _ _ ** _ _ ** _ _ ** _ _ ***', '*** /(.)J ** /(.)J ** C(.)J ** C(.)J ***', '*** _| |_ ** _| |_ ** _| |_ ** _( )_ **']], [['*****************************************', '*********** _ _ * _ _ ***********', '** _ _ * /(.)J * /(.)J * _ _ **', '** /(.)J * _| |_ * _( )_ * /(.)J **', '** _( )_ ********************* _( )_ **', '******************* X ******************']], [['*****************************************', '*********** _ _ * _ _ ***********', '** _ _ * C(.)J * /(.)J * _ _ **', '** /(.)J * _| |_ * _/ )_ * C(.)J **', '** _/ )_ ********************* _/ |_ **', '******************* X *******************', '********************** _ _ ************', '** _ _ * _ _ * /(.)J * _ _ **', '** /(.)J * C(.)J * _/ )_ * C(.)J **', '** _( )_ * _| |_ *********** _/ |_ **', '****************************************']], ['Gym is empty'], [\"This isn't the gym!!\"], ['Gym is empty'], [\"This isn't the gym!!\"], [\"This isn't the gym!!\"], [\"This isn't the gym!!\"]]\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(head_smash(*i), o[0])"}
303
1,042
coding
Solve the programming task below in a Python markdown code block. The idea for this Kata came from 9gag today.[here](http://9gag.com/gag/amrb4r9) [screen]:("http://img-9gag-fun.9cache.com/photo/amrb4r9_700b.jpg") You'll have to translate a string to Pilot's alphabet (NATO phonetic alphabet) [wiki](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet). Like this: **Input:** `If, you can read?` **Output:** `India Foxtrot , Yankee Oscar Uniform Charlie Alfa November Romeo Echo Alfa Delta ?` **Notes** * The set of used punctuation is `.!?`. * Punctuation should be kept in your return string, but spaces should not. * __Xray__ should not have a dash within. * Every word and punctuation mark should be seperated by a space ' '. * There should be no trailing whitespace ~~~if:php Although the proper alphabet for j is `Juliett` you have to use `Juliet` here ~~~ Also feel free to reuse/extend the following starter code: ```python def to_nato(words): ```
{"functional": "_inputs = [['If you can read'], ['Did not see that coming']]\n_outputs = [['India Foxtrot Yankee Oscar Uniform Charlie Alfa November Romeo Echo Alfa Delta'], ['Delta India Delta November Oscar Tango Sierra Echo Echo Tango Hotel Alfa Tango Charlie Oscar Mike India November Golf']]\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(to_nato(*i), o[0])"}
263
202
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n integer matrix grid containing distinct positive integers. You have to replace each integer in the matrix with a positive integer satisfying the following conditions: The relative order of every two elements that are in the same row or column should stay the same after the replacements. The maximum number in the matrix after the replacements should be as small as possible. The relative order stays the same if for all pairs of elements in the original matrix such that grid[r1][c1] > grid[r2][c2] where either r1 == r2 or c1 == c2, then it must be true that grid[r1][c1] > grid[r2][c2] after the replacements. For example, if grid = [[2, 4, 5], [7, 3, 9]] then a good replacement could be either grid = [[1, 2, 3], [2, 1, 4]] or grid = [[1, 2, 3], [3, 1, 4]]. Return the resulting matrix. If there are multiple answers, return any of them.   Please complete the following python code precisely: ```python class Solution: def minScore(self, grid: List[List[int]]) -> List[List[int]]: ```
{"functional": "def check(candidate):\n assert candidate(grid = [[3,1],[2,5]]) == [[2,1],[1,2]]\n assert candidate(grid = [[10]]) == [[1]]\n\n\ncheck(Solution().minScore)"}
284
60
coding
Solve the programming task below in a Python markdown code block. You are given an empty grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). You should fill this grid with integers in a way that satisfies the following rules: - For any three cells $c_1$, $c_2$ and $c_3$ such that $c_1$ shares a side with $c_2$ and another side with $c_3$, the integers written in cells $c_2$ and $c_3$ are distinct. - Let's denote the number of different integers in the grid by $K$; then, each of these integers should lie between $1$ and $K$ inclusive. - $K$ should be minimum possible. Find the minimum value of $K$ and a resulting (filled) grid. If there are multiple solutions, you may find any one. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains two space-separated integers $N$ and $M$. -----Output----- - For each test case, print $N+1$ lines. - The first line should contain a single integer — the minimum $K$. - Each of the following $N$ lines should contain $M$ space-separated integers between $1$ and $K$ inclusive. For each valid $i, j$, the $j$-th integer on the $i$-th line should denote the number in the $i$-th row and $j$-th column of the grid. -----Constraints----- - $1 \le T \le 500$ - $1 \le N, M \le 50$ - the sum of $N \cdot M$ over all test cases does not exceed $7 \cdot 10^5$ -----Subtasks----- Subtask #1 (100 points): original constraints -----Example Input----- 2 1 1 2 3 -----Example Output----- 1 1 3 1 1 2 2 3 3 -----Explanation----- Example case 1: There is only one cell in the grid, so the only valid way to fill it is to write $1$ in this cell. Note that we cannot use any other integer than $1$. Example case 2: For example, the integers written in the neighbours of cell $(2, 2)$ are $1$, $2$ and $3$; all these numbers are pairwise distinct and the integer written inside the cell $(2, 2)$ does not matter. Note that there are pairs of neighbouring cells with the same integer written in them, but this is OK.
{"inputs": ["2\n1 1\n2 3"], "outputs": ["1\n1\n3\n1 1 2\n2 3 3"]}
604
36
coding
Solve the programming task below in a Python markdown code block. Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one. Ivan knows some information about the string s. Namely, he remembers, that string t_{i} occurs in string s at least k_{i} times or more, he also remembers exactly k_{i} positions where the string t_{i} occurs in string s: these positions are x_{i}, 1, x_{i}, 2, ..., x_{i}, k_{i}. He remembers n such strings t_{i}. You are to reconstruct lexicographically minimal string s such that it fits all the information Ivan remembers. Strings t_{i} and string s consist of small English letters only. -----Input----- The first line contains single integer n (1 ≤ n ≤ 10^5) — the number of strings Ivan remembers. The next n lines contain information about the strings. The i-th of these lines contains non-empty string t_{i}, then positive integer k_{i}, which equal to the number of times the string t_{i} occurs in string s, and then k_{i} distinct positive integers x_{i}, 1, x_{i}, 2, ..., x_{i}, k_{i} in increasing order — positions, in which occurrences of the string t_{i} in the string s start. It is guaranteed that the sum of lengths of strings t_{i} doesn't exceed 10^6, 1 ≤ x_{i}, j ≤ 10^6, 1 ≤ k_{i} ≤ 10^6, and the sum of all k_{i} doesn't exceed 10^6. The strings t_{i} can coincide. It is guaranteed that the input data is not self-contradictory, and thus at least one answer always exists. -----Output----- Print lexicographically minimal string that fits all the information Ivan remembers. -----Examples----- Input 3 a 4 1 3 5 7 ab 2 1 5 ca 1 4 Output abacaba Input 1 a 1 3 Output aaa Input 3 ab 1 1 aba 1 3 ab 2 3 5 Output ababab
{"inputs": ["1\na 1 3\n", "1\na 1 4\n", "1\na 1 2\n", "1\nb 1 2\n", "1\nc 1 2\n", "1\nc 1 3\n", "1\nc 1 4\n", "1\na 1 3\n"], "outputs": ["aaa\n", "aaaa", "aa", "ab", "ac", "aac", "aaac", "aaa\n"]}
517
113
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The hash of a 0-indexed string s of length k, given integers p and m, is computed using the following function: hash(s, p, m) = (val(s[0]) * p0 + val(s[1]) * p1 + ... + val(s[k-1]) * pk-1) mod m. Where val(s[i]) represents the index of s[i] in the alphabet from val('a') = 1 to val('z') = 26. You are given a string s and the integers power, modulo, k, and hashValue. Return sub, the first substring of s of length k such that hash(sub, power, modulo) == hashValue. The test cases will be generated such that an answer always exists. A substring is a contiguous non-empty sequence of characters within a string.   Please complete the following python code precisely: ```python class Solution: def subStrHash(self, s: str, power: int, modulo: int, k: int, hashValue: int) -> str: ```
{"functional": "def check(candidate):\n assert candidate(s = \"leetcode\", power = 7, modulo = 20, k = 2, hashValue = 0) == \"ee\"\n assert candidate(s = \"fbxzaad\", power = 31, modulo = 100, k = 3, hashValue = 32) == \"fbx\"\n\n\ncheck(Solution().subStrHash)"}
238
97
coding
Solve the programming task below in a Python markdown code block. Eshag has an array $a$ consisting of $n$ integers. Eshag can perform the following operation any number of times: choose some subsequence of $a$ and delete every element from it which is strictly larger than $AVG$, where $AVG$ is the average of the numbers in the chosen subsequence. For example, if $a = [1 , 4 , 3 , 2 , 4]$ and Eshag applies the operation to the subsequence containing $a_1$, $a_2$, $a_4$ and $a_5$, then he will delete those of these $4$ elements which are larger than $\frac{a_1+a_2+a_4+a_5}{4} = \frac{11}{4}$, so after the operation, the array $a$ will become $a = [1 , 3 , 2]$. Your task is to find the maximum number of elements Eshag can delete from the array $a$ by applying the operation described above some number (maybe, zero) times. A sequence $b$ is a subsequence of an array $c$ if $b$ can be obtained from $c$ by deletion of several (possibly, zero or all) elements. -----Input----- The first line contains an integer $t$ $(1\le t\le 100)$ — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $n$ $(1\le n\le 100)$ — the length of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1\le a_i \le 100)$ — the elements of the array $a$. -----Output----- For each test case print a single integer — the maximum number of elements Eshag can delete from the array $a$. -----Examples----- Input 3 6 1 1 1 2 2 3 6 9 9 9 9 9 9 6 6 4 1 1 4 1 Output 3 0 3 -----Note----- Consider the first test case. Initially $a = [1, 1, 1, 2, 2, 3]$. In the first operation, Eshag can choose the subsequence containing $a_1$, $a_5$ and $a_6$, their average is equal to $\frac{a_1 + a_5 + a_6}{3} = \frac{6}{3} = 2$. So $a_6$ will be deleted. After this $a = [1, 1, 1, 2, 2]$. In the second operation, Eshag can choose the subsequence containing the whole array $a$, the average of all its elements is equal to $\frac{7}{5}$. So $a_4$ and $a_5$ will be deleted. After this $a = [1, 1, 1]$. In the second test case, Eshag can't delete any element.
{"inputs": ["1\n2\n1 2\n", "1\n2\n1 2\n", "1\n2\n0 2\n", "1\n2\n1 1\n", "1\n2\n1 4\n", "1\n2\n0 4\n", "1\n2\n1 6\n", "1\n2\n0 3\n"], "outputs": ["1\n", "1\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n"]}
701
118
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Sometimes mysteries happen. Chef found a directed graph with N vertices and M edges in his kitchen! The evening was boring and chef has nothing else to do, so to entertain himself, Chef thought about a question "What is the minimum number of edges he needs to reverse in order to have at least one path from vertex 1 to vertex N, where the vertices are numbered from 1 to N. ------ Input ------ Each test file contains only one test case. The first line of the input contains two space separated integers N and M, denoting the number of vertices and the number of edges in the graph respectively. The i^{th} line of the next M lines contains two space separated integers X_{i} and Y_{i}, denoting that the i^{th} edge connects vertices from X_{i} to Y_{i}. ------ Output ------ In a single line, print the minimum number of edges we need to revert. If there is no way of having at least one path from 1 to N, print -1. ------ Constraints ------ $1 ≤ N, M ≤ 100000 = 10^{5}$ $1 ≤ X_{i}, Y_{i} ≤ N$ $There can be multiple edges connecting the same pair of vertices, There can be self loops too i.e. X_{i} = Y_{i} $ ----- Sample Input 1 ------ 7 7 1 2 3 2 3 4 7 4 6 2 5 6 7 5 ----- Sample Output 1 ------ 2 ----- explanation 1 ------ We can consider two paths from 1 to 7: 1-2-3-4-7 1-2-6-5-7 In the first one we need to revert edges (3-2), (7-4). In the second one - (6-2), (5-6), (7-5). So the answer is min(2, 3) = 2.
{"inputs": ["7 7\n1 2 \n3 2\n3 4\n7 4\n6 2\n5 6\n7 5", "7 7\n1 2 \n4 2\n3 4\n7 4\n6 2\n5 6\n7 5", "9 7\n1 2 \n4 2\n3 4\n7 4\n6 2\n5 6\n7 5", "7 7\n1 2 \n3 2\n2 4\n7 4\n6 2\n5 6\n7 5", "7 7\n1 2 \n3 2\n2 4\n4 4\n6 2\n5 6\n7 5", "8 7\n1 4 \n2 2\n3 4\n7 4\n6 2\n4 8\n7 6", "7 7\n1 2 \n3 2\n3 4\n7 4\n6 2\n5 6\n5 5", "7 7\n1 2 \n3 2\n3 4\n7 4\n6 2\n5 3\n5 5"], "outputs": ["2", "2\n", "-1\n", "1\n", "3\n", "0\n", "2\n", "2\n"]}
451
309
coding
Solve the programming task below in a Python markdown code block. You have recently fallen through a hole and, after several hours of unconsciousness, have realized you are in an underground city. On one of your regular, daily walks through the unknown, you have encountered two unusually looking skeletons called Sanz and P’pairus, who decided to accompany you and give you some puzzles for seemingly unknown reasons. One day, Sanz has created a crossword for you. Not any kind of crossword, but a 1D crossword! You are given m words and a string of length n. You are also given an array p, which designates how much each word is worth — the i-th word is worth pi points. Whenever you find one of the m words in the string, you are given the corresponding number of points. Each position in the crossword can be used at most x times. A certain word can be counted at different places, but you cannot count the same appearance of a word multiple times. If a word is a substring of another word, you can count them both (presuming you haven’t used the positions more than x times). In order to solve the puzzle, you need to tell Sanz what’s the maximum achievable number of points in the crossword. There is no need to cover all postions, just get the maximal score! Crossword and words contain only lowercase English letters. Input The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the length of the crossword. The second line contains the crossword string. The third line contains a single integer m (1 ≤ m ≤ 100) — the number of given words, and next m lines contain description of words: each line will have a string representing a non-empty word (its length doesn't exceed the length of the crossword) and integer pi (0 ≤ pi ≤ 100). Last line of the input will contain x (1 ≤ x ≤ 100) — maximum number of times a position in crossword can be used. Output Output single integer — maximum number of points you can get. Example Input 6 abacba 2 aba 6 ba 3 3 Output 12 Note For example, with the string "abacba", words "aba" (6 points) and "ba" (3 points), and x = 3, you can get at most 12 points - the word "aba" appears once ("abacba"), while "ba" appears two times ("abacba"). Note that for x = 1, you could get at most 9 points, since you wouldn’t be able to count both "aba" and the first appearance of "ba".
{"inputs": ["6\nabacba\n2\naba 6\nba 3\n1\n", "6\nabacba\n2\naba 6\nba 3\n2\n", "6\nabacba\n2\naba 6\nba 4\n2\n", "6\nabacba\n2\naba 5\nba 4\n2\n", "6\nabacba\n2\naba 5\nba 0\n2\n", "6\nabacba\n2\nbaa 5\nab 0\n2\n", "6\nabacba\n2\nbaa 5\nba 1\n2\n", "6\nabacba\n2\nbaa 5\nba 2\n2\n"], "outputs": ["9\n", "12\n", "14\n", "13\n", "5\n", "0\n", "2\n", "4\n"]}
568
204
coding
Solve the programming task below in a Python markdown code block. Given is an integer N. Snuke will choose integers s_1, s_2, n_1, n_2, u_1, u_2, k_1, k_2, e_1, and e_2 so that all of the following six conditions will be satisfied: * 0 \leq s_1 < s_2 * 0 \leq n_1 < n_2 * 0 \leq u_1 < u_2 * 0 \leq k_1 < k_2 * 0 \leq e_1 < e_2 * s_1 + s_2 + n_1 + n_2 + u_1 + u_2 + k_1 + k_2 + e_1 + e_2 \leq N For every possible choice (s_1,s_2,n_1,n_2,u_1,u_2,k_1,k_2,e_1,e_2), compute (s_2 − s_1)(n_2 − n_1)(u_2 − u_1)(k_2 - k_1)(e_2 - e_1), and find the sum of all computed values, modulo (10^{9} +7). Solve this problem for each of the T test cases given. Constraints * All values in input are integers. * 1 \leq T \leq 100 * 1 \leq N \leq 10^{9} Input Input is given from Standard Input in the following format: T \mathrm{case}_1 \vdots \mathrm{case}_T Each case is given in the following format: N Output Print T lines. The i-th line should contain the answer to the i-th test case. Example Input 4 4 6 10 1000000000 Output 0 11 4598 257255556
{"inputs": ["4\n2\n6\n1\n1001000000", "4\n0\n6\n6\n1001000000", "4\n0\n0\n9\n1001000101", "4\n1\n0\n9\n1000000101", "4\n2\n1\n9\n1001000001", "4\n6\n2\n7\n0010010100", "4\n6\n2\n5\n0010010100", "4\n4\n6\n15\n1000000000"], "outputs": ["0\n11\n0\n475432620\n", "0\n11\n11\n475432620\n", "0\n0\n1346\n301343122\n", "0\n0\n1346\n497959914\n", "0\n0\n1346\n479280212\n", "11\n0\n71\n743338326\n", "11\n0\n1\n743338326\n", "0\n11\n563447\n257255556\n"]}
453
332
coding
Solve the programming task below in a Python markdown code block. Read problems statements [Hindi] , [Vietnamese] , [Mandarin Chinese] , [Russian] and [Bengali] as well. Oh, these difficult contests... In each contest, there are so many hard tasks Chef cannot solve. However, he knows that he can only become a successful coder if he works hard. Fortunately, he has a problem in mind for training. You are given two positive integers $a$ and $b$. You may apply the following magical operation any number of times (including zero): choose an arbitrary positive integer $d$ perform exactly one of the following actions: - add $d$ to $a$, add $d-1$ to $b$ - add $d-1$ to $a$, add $d$ to $b$ Chef is asking you to find out if it is possible to obtain $a = b$. Help him! ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each test case contains two space-separated integers $a$ and $b$. ------ Output ------ For each test case, print a single line containing the string "YES" if it is possible to obtain $a = b$ or "NO" if it is impossible. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ a, b ≤ 10^{9}$ ------ Subtasks ------ Subtaks #1 (100 points): original constraints ----- Sample Input 1 ------ 1 5 7 ----- Sample Output 1 ------ YES ----- explanation 1 ------ Example case 1: One possible strategy for Chef is: - choose $d = 10$, add $d-1=9$ to $a$ and $d=10$ to $b$; after this operation, $a = 14$ and $b = 17$ - choose $d = 10$, add $d=10$ to $a$ and $d-1=9$ to $b$; afterwards, $a = 24$ and $b = 26$ - choose $d = 9$, add $d=9$ to $a$ and $d-1=8$ to $b$; afterwards, $a = 33$ and $b = 34$ - choose $d = 9$, add $d$ to $a$ and $d-1$ to $b$; finally, we have $a = b = 42$
{"inputs": ["1\n5 7"], "outputs": ["YES"]}
576
16
coding
Solve the programming task below in a Python markdown code block. There is a new mobile game that starts with consecutively numbered clouds. Some of the clouds are thunderheads and others are cumulus. The player can jump on any cumulus cloud having a number that is equal to the number of the current cloud plus $\mbox{1}$ or $2$. The player must avoid the thunderheads. Determine the minimum number of jumps it will take to jump from the starting postion to the last cloud. It is always possible to win the game. For each game, you will get an array of clouds numbered $\mbox{0}$ if they are safe or $\mbox{1}$ if they must be avoided. Example $c=[0,1,0,0,0,1,0]$ Index the array from $\boldsymbol{0\ldots6}$. The number on each cloud is its index in the list so the player must avoid the clouds at indices $\mbox{I}$ and $5$. They could follow these two paths: $0\rightarrow2\rightarrow4\rightarrow6$ or $0\to2\to3\to4\to6$. The first path takes $3$ jumps while the second takes $\begin{array}{c}4\end{array}$. Return $3$. Function Description Complete the jumpingOnClouds function in the editor below. jumpingOnClouds has the following parameter(s): int c[n]: an array of binary integers Returns int: the minimum number of jumps required Input Format The first line contains an integer $n$, the total number of clouds. The second line contains $n$ space-separated binary integers describing clouds $c[i]$ where $0\leq i<n$. Constraints $2\leq n\leq100$ $c[i]\in\{0,1\}$ $c[0]=c[n-1]=0$ Output Format Print the minimum number of jumps needed to win the game. Sample Input 0 7 0 0 1 0 0 1 0 Sample Output 0 4 Explanation 0: The player must avoid $c[2]$ and $c\left[5\right]$. The game can be won with a minimum of $\begin{array}{c}4\end{array}$ jumps: Sample Input 1 6 0 0 0 0 1 0 Sample Output 1 3 Explanation 1: The only thundercloud to avoid is $c\left[4\right]$. The game can be won in $3$ jumps:
{"inputs": ["6\n0 0 0 0 1 0\n", "7\n0 0 1 0 0 1 0\n"], "outputs": ["3\n", "4\n"]}
572
48
coding
Solve the programming task below in a Python markdown code block. Sarthak and Anuradha are very good friends and are eager to participate in an event called *Equinox*. It is a game of words. In this game, $N$ strings $S_{1},\ldots, S_{N}$ are given. For each string $S_{i}$, if it starts with one of the letters of the word “EQUINOX”, Sarthak gets $A$ points and if not, Anuradha gets $B$ points. The one who has more points at the end of the game wins. If they both the same number of points, the game is a draw.. Print the winner of the game, if any, otherwise print “DRAW”. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. The first line of each test case contains three integers $N$, $A$, $B$. $N$ lines follow, each containing a string $S_{i}$. All strings are in UPPERCASE. ------ Output ------ For each test case, print “SARTHAK” (case insensitive) if he has more points than Anuradha, print “ANURADHA” (case insensitive) if she has more points than Sarthak, otherwise print “DRAW” (case insensitive), without the quotes. ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ N ≤ 100$ $1 ≤ A$, $B ≤ 10^{9}$ $1 ≤ |S_{i}\right| ≤ 100$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 2 4 1 3 ABBBCDDE EARTH INDIA UUUFFFDDD 2 5 7 SDHHD XOXOXOXO ----- Sample Output 1 ------ DRAW ANURADHA ----- explanation 1 ------ Test case $1$: The strings which start with one of the letters of the word EQUINOX are $\{$ EARTH, INDIA, UUUFFFDDD $\}$. Thus, Sarthak gets $1$ point for each of these strings. In total, Sarthak gets $3$ points. On the other hand, there is one string that does not start with one of the letters of the word EQUINOX. Thus, Anuradha gets $3$ points for that string. Finally, since both of them have equal points, the game results in DRAW. Test case $2$: There is only one string that starts with one of the letters of the word EQUINOX which is XOXOXOXO. Thus, Sarthak gets $5$ point for this string. There is one string that does not start with one of the letters of the word EQUINOX. Thus, Anuradha gets $7$ points for that string. Finally, Anuradha has the higher score. So she is the winner.
{"inputs": ["2\n4 1 3\nABBBCDDE\nEARTH\nINDIA\nUUUFFFDDD\n2 5 7\nSDHHD\nXOXOXOXO"], "outputs": ["DRAW\nANURADHA"]}
662
55
coding
Solve the programming task below in a Python markdown code block. Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Examples Input 3 3 4 6 Output 12 Input 4 1 2 3 5 Output 30
{"inputs": ["3\n3 4 3", "3\n3 7 3", "3\n4 6 5", "3\n4 6 7", "3\n4 4 7", "3\n5 4 7", "3\n9 4 3", "3\n9 2 6"], "outputs": ["12\n", "21\n", "60\n", "84\n", "28\n", "140\n", "36\n", "18\n"]}
156
119
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's college is conducting an online exam, where his camera will be monitored by one or more invigilators (supervisors). Once again, Chef failed to prepare for the exam on time and decided to google answers during it. The exam starts at time $0$ and ends at time $F$ minutes. Chef needs a total of $K$ minutes of googling during the exam in order to pass it. There are $N$ invigilators (numbered $1$ through $N$); for each valid $i$, the $i$-th invigilator monitors Chef's camera during the time interval starting at $S_{i}$ minutes since the start of the exam and ending at $E_{i}$ minutes (where $0 ≤ S_{i} ≤ E_{i} ≤ F$). He was resourceful enough to somehow get hold of these times and now he wants to know if he would be able to pass the exam if he googles the answers during the times when no one is looking at his camera. Note: The time of googling need not be continuous and there can be multiple invigilators at some interval of time. ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first line of each test case contains three space-separated integers $N$, $K$ and $F$. $N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $S_{i}$ and $E_{i}$. ------ Output ------ For each test case, print a single line containing the string "YES" if it is possible to pass the exam or "NO" if it is impossible. You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ F ≤ 10^{9}$ $0 ≤ K ≤ F$ $0 ≤ S_{i} ≤ E_{i} ≤ F$ for each valid $i$ the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$ ----- Sample Input 1 ------ 3 1 10 10 0 10 2 2 10 0 5 7 10 2 2 100 0 5 5 10 ----- Sample Output 1 ------ NO YES YES ----- explanation 1 ------ Example case 1: There is no point during the exam when Chef is not monitored, so he is unable to google even for a single second and will fail the exam. Example case 2: Chef can google for $2$ minutes (in the time interval $[5, 7]$, when he is not monitored) and hence will be able to pass the exam. Example case 3: Chef can google for $2$ minutes (in the time interval $[10, 12]$) and hence will be able to pass the exam.
{"inputs": ["3\n1 10 10\n0 10\n2 2 10\n0 5\n7 10\n2 2 100\n0 5\n5 10"], "outputs": ["NO\nYES\nYES"]}
736
62
coding
Solve the programming task below in a Python markdown code block. You are given $q$ queries in the following form: Given three integers $l_i$, $r_i$ and $d_i$, find minimum positive integer $x_i$ such that it is divisible by $d_i$ and it does not belong to the segment $[l_i, r_i]$. Can you answer all the queries? Recall that a number $x$ belongs to segment $[l, r]$ if $l \le x \le r$. -----Input----- The first line contains one integer $q$ ($1 \le q \le 500$) — the number of queries. Then $q$ lines follow, each containing a query given in the format $l_i$ $r_i$ $d_i$ ($1 \le l_i \le r_i \le 10^9$, $1 \le d_i \le 10^9$). $l_i$, $r_i$ and $d_i$ are integers. -----Output----- For each query print one integer: the answer to this query. -----Example----- Input 5 2 4 2 5 10 4 3 10 1 1 2 3 4 6 5 Output 6 4 1 3 10
{"inputs": ["1\n1 1 1\n", "1\n2 5 6\n", "1\n5 5 5\n", "1\n6 6 6\n", "1\n1 3 2\n", "1\n6 6 6\n", "1\n1 1 1\n", "1\n1 3 2\n"], "outputs": ["2\n", "6\n", "10\n", "12\n", "4\n", "12\n", "2\n", "4\n"]}
285
121
coding
Solve the programming task below in a Python markdown code block. Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift and decided to put some important facts to this array. Here are the first few of the facts: The highest mountain above sea level in the world is Mount Everest. Its peak rises to 8848 m. The largest board game tournament consisted of 958 participants playing chapaev. The largest online maths competition consisted of 12766 participants. The Nile is credited as the longest river in the world. From its farthest stream in Burundi, it extends 6695 km in length. While not in flood, the main stretches of the Amazon river in South America can reach widths of up to 1100 km at its widest points. Angel Falls is the highest waterfall. Its greatest single drop measures 807 m. The Hotel Everest View above Namche, Nepal — the village closest to Everest base camp – is at a record height of 31962 m Uranium is the heaviest of all the naturally occurring elements. Its most common isotope has a nucleus containing 146 neutrons. The coldest permanently inhabited place is the Siberian village of Oymyakon, where the temperature of -68°C was registered in the twentieth century. The longest snake held in captivity is over 25 feet long. Its name is Medusa. Colonel Meow holds the world record for longest fur on a cat — almost 134 centimeters. Sea otters can have up to 10000 hairs per square inch. This is the most dense fur in the animal kingdom. The largest state of USA is Alaska; its area is 663268 square miles Alaska has a longer coastline than all of the other 49 U.S. States put together: it is 154103 miles long. Lake Baikal is the largest freshwater lake in the world. It reaches 1642 meters in depth and contains around one-fifth of the world’s unfrozen fresh water. The most colorful national flag is the one of Turkmenistan, with 106 colors. -----Input----- The input will contain a single integer between 1 and 16. -----Output----- Output a single integer. -----Examples----- Input 1 Output 1 Input 7 Output 0
{"inputs": ["1\n", "7\n", "3\n", "8\n", "2\n", "5\n", "9\n", "4\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "0\n", "0\n", "1\n", "1\n"]}
545
70
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.   Please complete the following python code precisely: ```python class Solution: def maximalRectangle(self, matrix: List[List[str]]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(matrix = [[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]]) == 6\n assert candidate(matrix = [[\"0\"]]) == 0\n assert candidate(matrix = [[\"1\"]]) == 1\n\n\ncheck(Solution().maximalRectangle)"}
81
106
coding
Solve the programming task below in a Python markdown code block. You are given two strings $s$ and $t$. Both strings have length $n$ and consist of lowercase Latin letters. The characters in the strings are numbered from $1$ to $n$. You can successively perform the following move any number of times (possibly, zero): swap any two adjacent (neighboring) characters of $s$ (i.e. for any $i = \{1, 2, \dots, n - 1\}$ you can swap $s_i$ and $s_{i + 1})$. You can't apply a move to the string $t$. The moves are applied to the string $s$ one after another. Your task is to obtain the string $t$ from the string $s$. Find any way to do it with at most $10^4$ such moves. You do not have to minimize the number of moves, just find any sequence of moves of length $10^4$ or less to transform $s$ into $t$. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 50$) — the length of strings $s$ and $t$. The second line of the input contains the string $s$ consisting of $n$ lowercase Latin letters. The third line of the input contains the string $t$ consisting of $n$ lowercase Latin letters. -----Output----- If it is impossible to obtain the string $t$ using moves, print "-1". Otherwise in the first line print one integer $k$ — the number of moves to transform $s$ to $t$. Note that $k$ must be an integer number between $0$ and $10^4$ inclusive. In the second line print $k$ integers $c_j$ ($1 \le c_j < n$), where $c_j$ means that on the $j$-th move you swap characters $s_{c_j}$ and $s_{c_j + 1}$. If you do not need to apply any moves, print a single integer $0$ in the first line and either leave the second line empty or do not print it at all. -----Examples----- Input 6 abcdef abdfec Output 4 3 5 4 5 Input 4 abcd accd Output -1 -----Note----- In the first example the string $s$ changes as follows: "abcdef" $\rightarrow$ "abdcef" $\rightarrow$ "abdcfe" $\rightarrow$ "abdfce" $\rightarrow$ "abdfec". In the second example there is no way to transform the string $s$ into the string $t$ through any allowed moves.
{"inputs": ["1\nk\nk\n", "1\no\nk\n", "1\no\nk\n", "1\nk\nk\n", "1\no\nj\n", "1\nj\nk\n", "1\np\nk\n", "1\ni\nk\n"], "outputs": ["0\n\n", "-1\n", "-1", "0\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
587
102
coding
Solve the programming task below in a Python markdown code block. Takahashi will do a tap dance. The dance is described by a string S where each character is L, R, U, or D. These characters indicate the positions on which Takahashi should step. He will follow these instructions one by one in order, starting with the first character. S is said to be easily playable if and only if it satisfies both of the following conditions: - Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is R, U, or D. - Every character in an even position (2-nd, 4-th, 6-th, \ldots) is L, U, or D. Your task is to print Yes if S is easily playable, and No otherwise. -----Constraints----- - S is a string of length between 1 and 100 (inclusive). - Each character of S is L, R, U, or D. -----Input----- Input is given from Standard Input in the following format: S -----Output----- Print Yes if S is easily playable, and No otherwise. -----Sample Input----- RUDLUDR -----Sample Output----- Yes Every character in an odd position (1-st, 3-rd, 5-th, 7-th) is R, U, or D. Every character in an even position (2-nd, 4-th, 6-th) is L, U, or D. Thus, S is easily playable.
{"inputs": ["U\n", "L\n", "R\n", "D\n", "LLUD", "EULL", "EULM", "DULL"], "outputs": ["Yes\n", "No\n", "Yes\n", "Yes\n", "No\n", "No\n", "No\n", "No"]}
320
70
coding
Solve the programming task below in a Python markdown code block. Read problems statements [Hindi] , [Vietnamese] , [Mandarin Chinese] , [Russian] and [Bengali] as well. You are given a directed acyclic graph with $N$ vertices (numbered $1$ through $N$) and $M$ edges. You want to destroy it all! To destroy the graph, you should delete all of its vertices. In one step, you are allowed to delete at most two vertices; you may only delete a vertex when there is no edge from it to another (not yet deleted) vertex. You may not delete two vertices when there is an edge between them either. Find a way to destroy the graph in the minimum number of steps. ------ Input ------ The first line of the input contains two space-separated integers $N$ and $M$. Each of the next $M$ lines contains two space-separated integers $U$ and $V$ denoting an edge from vertex $U$ to vertex $V$. ------ Output ------ The first line of the output should contain a single integer $S$ denoting the minimum number of steps needed to destroy the graph. Each of the next $S$ lines should describe one step; it should contain an integer $K$ ($1 ≤ K ≤ 2$), followed by a space and $K$ space-separated integers denoting the numbers of vertices deleted in this step. ------ Constraints ------ $1 ≤ N, M ≤ 10^{6}$ the graph on the input does not contain any cycles or self-loops ------ Scoring ------ The score for each test file is $10 \cdot (C/S)^2$, where $C$ is the number of steps in which you deleted exactly $2$ vertices. The final score of your submission is equal to the sum of scores for each test file. There are twenty test cases. During the contest, the displayed score will account for exactly four test files, i.e. your score reflects your submission's performance on 20% (4/20) of the test files. However, if your program gets a non-AC verdict on any test file, your submission's verdict will be non-AC. In other words, an AC verdict denotes that your program runs successfully on all the test files. After the end of the contest, your score will be changed to include the sum of your program's scores over the other sixteen test files. ------ Example Input ------ 6 6 1 2 2 3 1 3 3 4 3 5 1 6 ------ Example Output ------ 4 2 4 5 2 6 3 1 2 1 1
{"inputs": ["6 6\n1 2\n2 3\n1 3\n3 4\n3 5\n1 6\n"], "outputs": ["4\n2 4 5\n2 6 3\n1 2\n1 1\n"]}
581
60
coding
Solve the programming task below in a Python markdown code block. Smart Beaver recently got interested in a new word game. The point is as follows: count the number of distinct good substrings of some string s. To determine if a string is good or not the game uses rules. Overall there are n rules. Each rule is described by a group of three (p, l, r), where p is a string and l and r (l ≤ r) are integers. We’ll say that string t complies with rule (p, l, r), if the number of occurrences of string t in string p lies between l and r, inclusive. For example, string "ab", complies with rules ("ab", 1, 2) and ("aab", 0, 1), but does not comply with rules ("cd", 1, 2) and ("abab", 0, 1). A substring s[l... r] (1 ≤ l ≤ r ≤ |s|) of string s = s_1s_2... s_{|}s| (|s| is a length of s) is string s_{l}s_{l} + 1... s_{r}. Consider a number of occurrences of string t in string p as a number of pairs of integers l, r (1 ≤ l ≤ r ≤ |p|) such that p[l... r] = t. We’ll say that string t is good if it complies with all n rules. Smart Beaver asks you to help him to write a program that can calculate the number of distinct good substrings of string s. Two substrings s[x... y] and s[z... w] are cosidered to be distinct iff s[x... y] ≠ s[z... w]. -----Input----- The first line contains string s. The second line contains integer n. Next n lines contain the rules, one per line. Each of these lines contains a string and two integers p_{i}, l_{i}, r_{i}, separated by single spaces (0 ≤ l_{i} ≤ r_{i} ≤ |p_{i}|). It is guaranteed that all the given strings are non-empty and only contain lowercase English letters. The input limits for scoring 30 points are (subproblem G1): 0 ≤ n ≤ 10. The length of string s and the maximum length of string p is ≤ 200. The input limits for scoring 70 points are (subproblems G1+G2): 0 ≤ n ≤ 10. The length of string s and the maximum length of string p is ≤ 2000. The input limits for scoring 100 points are (subproblems G1+G2+G3): 0 ≤ n ≤ 10. The length of string s and the maximum length of string p is ≤ 50000. -----Output----- Print a single integer — the number of good substrings of string s. -----Examples----- Input aaab 2 aa 0 0 aab 1 1 Output 3 Input ltntlnen 3 n 0 0 ttlneenl 1 4 lelllt 1 1 Output 2 Input a 0 Output 1 -----Note----- There are three good substrings in the first sample test: «aab», «ab» and «b». In the second test only substrings «e» and «t» are good.
{"inputs": ["a\n0\n", "b\n0\n", "a\n0\n", "aaab\n2\naa 0 0\naab 1 1\n", "aaab\n2\naa 0 0\nbaa 1 1\n", "aaab\n2\naa 0 0\naab 2 1\n", "aaab\n2\naa 1 0\naab 2 1\n", "aaab\n2\naa 1 1\naab 2 1\n"], "outputs": ["1\n", "1\n", "1\n", "3\n", "1\n", "0\n", "0\n", "0\n"]}
751
152
coding
Solve the programming task below in a Python markdown code block. “I am not in danger, Skyler. I am the danger. A guy opens his door and gets shot, and you think that of me? No! I am the one who knocks!” Skyler fears Walter and ponders escaping to Colorado. Walter wants to clean his lab as soon as possible and then go back home to his wife. In order clean his lab, he has to achieve cleaning level of lab as $Y$. The current cleaning level of the lab is $X$. He must choose one positive odd integer $a$ and one positive even integer $b$. Note that, he cannot change $a$ or $b$ once he starts cleaning. He can perform any one of the following operations for one round of cleaning: - Replace $X$ with $X+a$. - Replace $X$ with $X-b$. Find minimum number of rounds (possibly zero) to make lab clean. -----Input:----- - First line will contain $T$, number of test cases. $T$ testcases follow : - Each test case contains two space separated integers $X, Y$. -----Output:----- For each test case, output an integer denoting minimum number of rounds to clean the lab. -----Constraints----- - $1 \leq T \leq 10^5$ - $ |X|,|Y| \leq 10^9$ -----Sample Input:----- 3 0 5 4 -5 0 10000001 -----Sample Output:----- 1 2 1 -----EXPLANATION:----- - For the first testcase, you can convert $X$ to $Y$ by choosing $a=5$ and $b=2$. It will cost minimum of $1$ cleaning round. You can select any other combination of $a, b$ satisfying above condition but will take minimum of $1$ cleaning round in any case. - For the second testcase, you can convert $X$ to $Y$ by choosing $a=1$ and $b=10$. In first round they will replace $X$ to $X+a$ and then in second round replace to $X-b$. You can perform only one operation in one round.
{"inputs": ["3\n0 5\n4 -5\n0 10000001"], "outputs": ["1\n2\n1"]}
483
35
coding
Solve the programming task below in a Python markdown code block. Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he realized that Java is the best choice. The main argument in favor of choosing Java was that it has a very large integer data type, called BigInteger. But having attended several classes of the club, Petya realized that not all tasks require using the BigInteger type. It turned out that in some tasks it is much easier to use small data types. That's why a question arises: "Which integer type to use if one wants to store a positive integer n?" Petya knows only 5 integer types: 1) byte occupies 1 byte and allows you to store numbers from - 128 to 127 2) short occupies 2 bytes and allows you to store numbers from - 32768 to 32767 3) int occupies 4 bytes and allows you to store numbers from - 2147483648 to 2147483647 4) long occupies 8 bytes and allows you to store numbers from - 9223372036854775808 to 9223372036854775807 5) BigInteger can store any integer number, but at that it is not a primitive type, and operations with it are much slower. For all the types given above the boundary values are included in the value range. From this list, Petya wants to choose the smallest type that can store a positive integer n. Since BigInteger works much slower, Peter regards it last. Help him. Input The first line contains a positive number n. It consists of no more than 100 digits and doesn't contain any leading zeros. The number n can't be represented as an empty string. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). Output Print the first type from the list "byte, short, int, long, BigInteger", that can store the natural number n, in accordance with the data given above. Examples Input 127 Output byte Input 130 Output short Input 123456789101112131415161718192021222324 Output BigInteger
{"inputs": ["6\n", "9\n", "8\n", "71\n", "13\n", "16\n", "26\n", "19\n"], "outputs": ["byte\n", "byte\n", "byte\n", "byte\n", "byte\n", "byte\n", "byte\n", "byte\n"]}
561
75
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The pair sum of a pair (a,b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs. For example, if we have pairs (1,5), (2,3), and (4,4), the maximum pair sum would be max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8. Given an array nums of even length n, pair up the elements of nums into n / 2 pairs such that: Each element of nums is in exactly one pair, and The maximum pair sum is minimized. Return the minimized maximum pair sum after optimally pairing up the elements.   Please complete the following python code precisely: ```python class Solution: def minPairSum(self, nums: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(nums = [3,5,2,3]) == 7\n assert candidate(nums = [3,5,4,2,4,6]) == 8\n\n\ncheck(Solution().minPairSum)"}
198
60