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. Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the only criteria, so two bishops may attack each other (according to Wet Shark) even if there is another bishop located between them. Now Wet Shark wants to count the number of pairs of bishops that attack each other. -----Input----- The first line of the input contains n (1 ≀ n ≀ 200 000)Β β€” the number of bishops. Each of next n lines contains two space separated integers x_{i} and y_{i} (1 ≀ x_{i}, y_{i} ≀ 1000)Β β€” the number of row and the number of column where i-th bishop is positioned. It's guaranteed that no two bishops share the same position. -----Output----- Output one integerΒ β€” the number of pairs of bishops which attack each other. -----Examples----- Input 5 1 1 1 5 3 3 5 1 5 5 Output 6 Input 3 1 1 2 3 3 5 Output 0 -----Note----- In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal.
{"inputs": ["1\n6 3\n", "1\n1 1\n", "1\n1 1\n", "1\n6 3\n", "1\n0 1\n", "1\n6 6\n", "1\n9 6\n", "1\n9 11\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
401
103
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. English description is not available for the problem. Please switch to Chinese. Β  Please complete the following python code precisely: ```python class Solution: def game(self, guess: List[int], answer: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(guess = [1,2,3], answer = [1,2,3]) == 3\n assert candidate(guess = [2,2,3], answer = [3,2,1]) == 1\n\n\ncheck(Solution().game)"}
67
68
coding
Solve the programming task below in a Python markdown code block. Compute A + B. Constraints * -1000 ≀ A, B ≀ 1000 Input The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF. Output For each pair of input integers A and B, you must output the sum of A and B in one line. Example Input 1 2 10 5 100 20 Output 3 15 120
{"inputs": ["1 2\n0 6\n011 1", "2 2\n0 6\n011 1", "2 4\n0 6\n011 1", "2 4\n0 2\n011 1", "2 6\n0 2\n011 1", "3 6\n0 2\n011 1", "3 6\n0 2\n011 0", "3 6\n0 4\n011 0"], "outputs": ["3\n6\n12\n", "4\n6\n12\n", "6\n6\n12\n", "6\n2\n12\n", "8\n2\n12\n", "9\n2\n12\n", "9\n2\n11\n", "9\n4\n11\n"]}
128
198
coding
Solve the programming task below in a Python markdown code block. You are the principal of the Cake school in chefland and today is your birthday. You want to treat each of the children with a small cupcake which is made by you. But there is a problem, You don't know how many students are present today. The students have gathered of the morning assembly in $R$ rows and $C$ columns. Now you have to calculate how many cakes you have to make such that each child gets a cupcake. -----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, two integers $R$ and $C$. -----Output:----- For each test case, output number of cupcakes you have to make. -----Constraints----- - $1 \leq T \leq 1000$ - $2 \leq R,C \leq 10^6$ -----Sample Input:----- 1 5 10 -----Sample Output:----- 50
{"inputs": ["1\n5 10"], "outputs": ["50"]}
227
18
coding
Solve the programming task below in a Python markdown code block. Cooking Examinations Authority (C.E.A.) is conducting an Ordinary Cooking Level (O.C.L.) test, which tests the candidate skills on three different aspects - Appearance, Flavor and Texture. Chef is planning to appear in this coveted test. O.C.L. is a 240 \textbf{minute} test consisting of 20 \textbf{problems} on \textbf{each aspect} (and hence total 60 problems). Chef figured out that for \textbf{each} problem on Appearance, Flavor and Texture He requires A, B and C minutes respectively to correctly solve that problem. He will be awarded X, Y and Z points respectively when correctly solved that problem. Chef wonders what are the maximum points P that he can get in O.C.L.? Can you help the Chef? ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of testcases. The description of the T testcases follows. - The first line of each testcase contains 3 space separated integers A, B and C. - The second line of each testcase contains 3 space separated integers X, Y and Z. ------ Output Format ------ For each testcase, output a single line containing an integer P, which denotes the maximum points that the Chef can score in O.C.L. ------ Constraints ------ $1 ≀ T ≀ 100$ $1 ≀ A, B, C ≀ 10$ $1 ≀ X, Y, Z ≀ 10^{6}$ ----- Sample Input 1 ------ 3 4 4 4 5 5 5 5 5 5 10 8 6 5 6 7 5 6 7 ----- Sample Output 1 ------ 300 408 240 ----- explanation 1 ------ Test Case $1$: Chef can correctly solve all the problems within the time limit, resulting in total $300$ points. Test Case $2$: Chef can correctly solve $20$ problems on Appearance, $20$ problems on Flavor and $8$ problems on Texture, resulting in total $408$ points. We can prove that the Chef cannot get more than $408$ points.
{"inputs": ["3\n4 4 4\n5 5 5\n5 5 5\n10 8 6\n5 6 7\n5 6 7\n"], "outputs": ["300\n408\n240\n"]}
491
61
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a string that may have mixed uppercase and lowercase letters and your task is to convert that string to either lowercase only or uppercase only based on: * make as few changes as possible. * if the string contains equal number of uppercase and lowercase letters, convert the string to lowercase. For example: ```Haskell solve("coDe") = "code". Lowercase characters > uppercase. Change only the "D" to lowercase. solve("CODe") = "CODE". Uppercase characters > lowecase. Change only the "e" to uppercase. solve("coDE") = "code". Upper == lowercase. Change all to lowercase. ``` More examples in test cases. Good luck! Please also try: [Simple time difference](https://www.codewars.com/kata/5b76a34ff71e5de9db0000f2) [Simple remove duplicates](https://www.codewars.com/kata/5ba38ba180824a86850000f7) Also feel free to reuse/extend the following starter code: ```python def solve(s): ```
{"functional": "_inputs = [['code'], ['CODe'], ['COde'], ['Code']]\n_outputs = [['code'], ['CODE'], ['code'], ['code']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(solve(*i), o[0])"}
267
174
coding
Solve the programming task below in a Python markdown code block. There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get? -----Constraints----- - All values in input are integers. - 3 \leq A, B \leq 20 -----Input----- Input is given from Standard Input in the following format: A B -----Output----- Print the maximum number of coins you can get. -----Sample Input----- 5 3 -----Sample Output----- 9 You can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this is the maximum result.
{"inputs": ["6 4", "4 3", "9 2", "2 3", "2 1", "2 2", "1 1", "1 0"], "outputs": ["11\n", "7\n", "17\n", "5\n", "3\n", "4\n", "2\n", "1\n"]}
184
80
coding
Solve the programming task below in a Python markdown code block. Write a function that checks if all the letters in the second string are present in the first one at least once, regardless of how many times they appear: ``` ["ab", "aaa"] => true ["trances", "nectar"] => true ["compadres", "DRAPES"] => true ["parses", "parsecs"] => false ``` Function should not be case sensitive, as indicated in example #2. Note: both strings are presented as a **single argument** in the form of an array. Also feel free to reuse/extend the following starter code: ```python def letter_check(arr): ```
{"functional": "_inputs = [[['abcd', 'aaa']], [['trances', 'nectar']], [['THE EYES', 'they see']], [['assert', 'staring']], [['arches', 'later']], [['dale', 'caller']], [['parses', 'parsecs']], [['replays', 'adam']], [['mastering', 'streaming']], [['drapes', 'compadres']], [['deltas', 'slated']], [['deltas', '']], [['', 'slated']]]\n_outputs = [[True], [True], [True], [False], [False], [False], [False], [False], [True], [False], [True], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(letter_check(*i), o[0])"}
154
284
coding
Solve the programming task below in a Python markdown code block. ## Task Given an array of strings, reverse them and their order in such way that their length stays the same as the length of the original inputs. ### Example: ``` Input: {"I", "like", "big", "butts", "and", "I", "cannot", "lie!"} Output: {"!", "eilt", "onn", "acIdn", "ast", "t", "ubgibe", "kilI"} ``` Good luck! Also feel free to reuse/extend the following starter code: ```python def reverse(a): ```
{"functional": "_inputs = [[['I', 'like', 'big', 'butts', 'and', 'I', 'cannot', 'lie!']], [['?kn', 'ipnr', 'utotst', 'ra', 'tsn', 'iksr', 'uo', 'yer', 'ofebta', 'eote', 'vahu', 'oyodpm', 'ir', 'hsyn', 'amwoH']]]\n_outputs = [[['!', 'eilt', 'onn', 'acIdn', 'ast', 't', 'ubgibe', 'kilI']], [['How', 'many', 'shrimp', 'do', 'you', 'have', 'to', 'eat', 'before', 'your', 'skin', 'starts', 'to', 'turn', 'pink?']]]\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(reverse(*i), o[0])"}
134
313
coding
Solve the programming task below in a Python markdown code block. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010" is an unique substring of s, because l = 2 is the only one suitable number. But, for example t = "10" isn't a unique substring of s, because l = 1 and l = 3 are suitable. And for example t ="00" at all isn't a substring of s, because there is no suitable l. Today Vasya solved the following problem at the informatics lesson: given a string consisting of symbols "0" and "1", the task is to find the length of its minimal unique substring. He has written a solution to this problem and wants to test it. He is asking you to help him. You are given 2 positive integers n and k, such that (n mod 2) = (k mod 2), where (x mod 2) is operation of taking remainder of x by dividing on 2. Find any string s consisting of n symbols "0" or "1", such that the length of its minimal unique substring is equal to k. Input The first line contains two integers n and k, separated by spaces (1 ≀ k ≀ n ≀ 100 000, (k mod 2) = (n mod 2)). Output Print a string s of length n, consisting of symbols "0" and "1". Minimal length of the unique substring of s should be equal to k. You can find any suitable string. It is guaranteed, that there exists at least one such string. Examples Input 4 4 Output 1111 Input 5 3 Output 01010 Input 7 3 Output 1011011 Note In the first test, it's easy to see, that the only unique substring of string s = "1111" is all string s, which has length 4. In the second test a string s = "01010" has minimal unique substring t ="101", which has length 3. In the third test a string s = "1011011" has minimal unique substring t ="110", which has length 3.
{"inputs": ["3 3\n", "6 4\n", "3 1\n", "7 3\n", "6 2\n", "1 1\n", "6 6\n", "5 1\n"], "outputs": ["111", "010101", "010", "0010010", "001001", "1", "111111", "00100"]}
585
107
coding
Solve the programming task below in a Python markdown code block. You have a list of numbers from $1$ to $n$ written from left to right on the blackboard. You perform an algorithm consisting of several steps (steps are $1$-indexed). On the $i$-th step you wipe the $i$-th number (considering only remaining numbers). You wipe the whole number (not one digit). $\left. \begin{array}{r}{1234567 \ldots} \\{234567 \ldots} \\{24567 \ldots} \end{array} \right.$ When there are less than $i$ numbers remaining, you stop your algorithm. Now you wonder: what is the value of the $x$-th remaining number after the algorithm is stopped? -----Input----- The first line contains one integer $T$ ($1 \le T \le 100$) β€” the number of queries. The next $T$ lines contain queries β€” one per line. All queries are independent. Each line contains two space-separated integers $n$ and $x$ ($1 \le x < n \le 10^{9}$) β€” the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least $x$ numbers. -----Output----- Print $T$ integers (one per query) β€” the values of the $x$-th number after performing the algorithm for the corresponding queries. -----Example----- Input 3 3 1 4 2 69 6 Output 2 4 12
{"inputs": ["1\n4271 0\n", "1\n3916 0\n", "1\n33777 1\n", "1\n33777 0\n", "1\n54843 1\n", "1\n21874 1\n", "1\n21874 2\n", "1\n42601 2\n"], "outputs": ["0\n", "0\n", "2\n", "0\n", "2\n", "2\n", "4\n", "4\n"]}
355
132
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a rectangular cake of size h x w and two arrays of integers horizontalCuts and verticalCuts where: horizontalCuts[i] is the distance from the top of the rectangular cake to the ith horizontal cut and similarly, and verticalCuts[j] is the distance from the left of the rectangular cake to the jth vertical cut. Return the maximum area of a piece of cake after you cut at each horizontal and vertical position provided in the arrays horizontalCuts and verticalCuts. Since the answer can be a large number, return this modulo 109 + 7. Β  Please complete the following python code precisely: ```python class Solution: def maxArea(self, h: int, w: int, horizontalCuts: List[int], verticalCuts: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(h = 5, w = 4, horizontalCuts = [1,2,4], verticalCuts = [1,3]) == 4 \n assert candidate(h = 5, w = 4, horizontalCuts = [3,1], verticalCuts = [1]) == 6\n assert candidate(h = 5, w = 4, horizontalCuts = [3], verticalCuts = [3]) == 9\n\n\ncheck(Solution().maxArea)"}
187
121
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Can you solve it without sorting? Β  Please complete the following python code precisely: ```python class Solution: def findKthLargest(self, nums: List[int], k: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(nums = [3,2,1,5,6,4], k = 2) == 5\n assert candidate(nums = [3,2,3,1,2,4,5,5,6], k = 4) == 4\n\n\ncheck(Solution().findKthLargest)"}
103
82
coding
Solve the programming task below in a Python markdown code block. You are walking through a parkway near your house. The parkway has $n+1$ benches in a row numbered from $1$ to $n+1$ from left to right. The distance between the bench $i$ and $i+1$ is $a_i$ meters. Initially, you have $m$ units of energy. To walk $1$ meter of distance, you spend $1$ unit of your energy. You can't walk if you have no energy. Also, you can restore your energy by sitting on benches (and this is the only way to restore the energy). When you are sitting, you can restore any integer amount of energy you want (if you sit longer, you restore more energy). Note that the amount of your energy can exceed $m$. Your task is to find the minimum amount of energy you have to restore (by sitting on benches) to reach the bench $n+1$ from the bench $1$ (and end your walk). You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 100$) β€” the number of test cases. Then $t$ test cases follow. The first line of the test case contains two integers $n$ and $m$ ($1 \le n \le 100$; $1 \le m \le 10^4$). The second line of the test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the distance between benches $i$ and $i+1$. -----Output----- For each test case, print one integer β€” the minimum amount of energy you have to restore (by sitting on benches) to reach the bench $n+1$ from the bench $1$ (and end your walk) in the corresponding test case. -----Examples----- Input 3 3 1 1 2 1 4 5 3 3 5 2 5 16 1 2 3 4 5 Output 3 8 0 -----Note----- In the first test case of the example, you can walk to the bench $2$, spending $1$ unit of energy, then restore $2$ units of energy on the second bench, walk to the bench $3$, spending $2$ units of energy, restore $1$ unit of energy and go to the bench $4$. In the third test case of the example, you have enough energy to just go to the bench $6$ without sitting at all.
{"inputs": ["1\n1 1\n3\n", "1\n1 1\n2\n", "1\n1 1\n69\n", "1\n2 1\n99 99\n", "1\n5 3\n1 91 99 80 5\n", "1\n5 100\n1 99 99 80 5\n", "1\n5 100\n1 91 99 80 5\n", "3\n3 1\n1 2 1\n4 5\n3 3 5 2\n5 16\n1 2 3 4 5\n"], "outputs": ["2\n", "1\n", "68\n", "197\n", "273\n", "184\n", "176\n", "3\n8\n0\n"]}
583
204
coding
Solve the programming task below in a Python markdown code block. You are given an array B of length 2N . You have an unknown array A which is sorted and contains *distinct* elements. You need to find out the array A. B contains all the medians of each prefix and suffix of the array A. A median is the middle element in a sorted array . [1,2,3,4] has median 2 and [1,3,4] has 3 as median. Determine whether B is a valid array of some array A. If yes find the array A else print -1. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains an integer N. - The second line of each test case contains 2N space-separated integers B_{1}, B_{2}, \dots, B_{N}. ------ Output Format ------ For each testcase, output the valid array A or -1 if not possible. ------ Constraints ------ $1 ≀ T ≀ 1000$ $1 ≀ N ≀ 10^{5}$ $1 ≀B_{i} ≀10^{6}$ - Sum of N overall testcases won't exceed $2*10^{5}$. ------ subtasks ------ 100 points : Original Constraints ----- Sample Input 1 ------ 2 3 6 5 5 7 6 6 3 1 2 1 4 2 4 ----- Sample Output 1 ------ 5 6 7 -1 ----- explanation 1 ------ - Test case $1$: Assume the array $A$ be $[5,6,7]$. The medians of the prefix arrays of $A$ are - $[5]$ = $5$ - $[5,6]$ = $5$ - $[5,6,7]$ = $6$ The medians of the suffix arrays of $A$ are - $[7]$ = $7$ - $[6,7]$ = $6$ - $[5,6,7]$ = $6$ Hence $B$ contains all the medians above with the element $5$ repeating exactly $2$ times, $6$ repeating exactly $3$ times and $7$ repeating only once. - Test case $2$: no valid array $A$ can be found.
{"inputs": ["2\n3\n6 5 5 7 6 6\n3\n1 2 1 4 2 4"], "outputs": ["5 6 7\n-1"]}
528
47
coding
Solve the programming task below in a Python markdown code block. You are given a colored permutation $p_1, p_2, \dots, p_n$. The $i$-th element of the permutation has color $c_i$. Let's define an infinite path as infinite sequence $i, p[i], p[p[i]], p[p[p[i]]] \dots$ where all elements have same color ($c[i] = c[p[i]] = c[p[p[i]]] = \dots$). We can also define a multiplication of permutations $a$ and $b$ as permutation $c = a \times b$ where $c[i] = b[a[i]]$. Moreover, we can define a power $k$ of permutation $p$ as $p^k=\underbrace{p \times p \times \dots \times p}_{k \text{ times}}$. Find the minimum $k > 0$ such that $p^k$ has at least one infinite path (i.e. there is a position $i$ in $p^k$ such that the sequence starting from $i$ is an infinite path). It can be proved that the answer always exists. -----Input----- The first line contains single integer $T$ ($1 \le T \le 10^4$) β€” the number of test cases. Next $3T$ lines contain test cases β€” one per three lines. The first line contains single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the size of the permutation. The second line contains $n$ integers $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$, $p_i \neq p_j$ for $i \neq j$) β€” the permutation $p$. The third line contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le n$) β€” the colors of elements of the permutation. It is guaranteed that the total sum of $n$ doesn't exceed $2 \cdot 10^5$. -----Output----- Print $T$ integers β€” one per test case. For each test case print minimum $k > 0$ such that $p^k$ has at least one infinite path. -----Example----- Input 3 4 1 3 4 2 1 2 2 3 5 2 3 4 5 1 1 2 3 4 5 8 7 4 5 6 1 8 3 2 5 3 6 4 7 5 8 4 Output 1 5 2 -----Note----- In the first test case, $p^1 = p = [1, 3, 4, 2]$ and the sequence starting from $1$: $1, p[1] = 1, \dots$ is an infinite path. In the second test case, $p^5 = [1, 2, 3, 4, 5]$ and it obviously contains several infinite paths. In the third test case, $p^2 = [3, 6, 1, 8, 7, 2, 5, 4]$ and the sequence starting from $4$: $4, p^2[4]=8, p^2[8]=4, \dots$ is an infinite path since $c_4 = c_8 = 4$.
{"inputs": ["3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 3 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4\n", "3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 3 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 8 7 5 8 4\n", "3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 5 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4\n", "3\n4\n1 3 4 2\n1 1 2 3\n5\n2 3 4 5 1\n1 2 5 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4\n", "3\n4\n1 3 4 2\n1 1 2 3\n5\n2 3 4 5 1\n1 2 5 4 4\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4\n", "3\n4\n1 3 4 2\n1 1 2 3\n5\n2 3 4 5 1\n1 2 0 4 4\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4\n", "3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 3 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 5 7 5 8 4\n", "3\n4\n1 3 4 2\n1 2 2 0\n5\n2 3 4 5 1\n1 2 3 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 8 7 5 8 4\n"], "outputs": ["1\n5\n2\n", "1\n5\n4\n", "1\n5\n2\n", "1\n5\n2\n", "1\n5\n2\n", "1\n5\n2\n", "1\n5\n4\n", "1\n5\n4\n"]}
757
694
coding
Solve the programming task below in a Python markdown code block. Kabir Singh is playing a game on the non-negative side of x-axis. It takes him $1 second$ to reach from Pth position to (Pβˆ’1)th position or (P+1)th position. Kabir never goes to the negative side and also doesn't stop at any moment of time. The movement can be defined as : - At the beginning he is at $x=0$ , at time $0$ - During the first round, he moves towards $x=1$ and comes back to the $x=0$ position. - In the second round, he moves towards the $x=2$ and comes back again to $x=0$. - So , at $Kth$ round , he moves to $x=K$ and comes back to $x=0$ So in this way game goes ahead. For Example, the path of Kabir for $3rd$ round is given below. $0βˆ’1βˆ’2βˆ’3βˆ’2βˆ’1βˆ’0$ The overall path followed by Kabir would look somewhat like this: $0βˆ’1βˆ’0βˆ’1βˆ’2βˆ’1βˆ’0βˆ’1βˆ’2βˆ’3βˆ’2βˆ’1βˆ’0βˆ’1βˆ’2βˆ’3βˆ’4βˆ’3βˆ’β€¦$ Now the task is , You are given Two Non-Negative integers $N$ , $K$ . You have to tell the time at which Kabir arrives at $x=N$ for the $Kth$ time. Note - Kabir visits all the points , he can not skip or jump over one point. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains of a single line of input, two integers $N, K$. -----Output:----- For each testcase, output in a single line answer i.e Time Taken by Kabir Singh modulo 1000000007. -----Constraints----- - $1 \leq T \leq 10^5$ - $0 \leq N \leq 10^9$ - $1 \leq K \leq 10^9$ -----Sample Input:----- 4 0 1 1 1 1 3 4 6 -----Sample Output:----- 0 1 5 46 -----EXPLANATION:----- Test Case 1: Kabir starts the journey from the $N=0$ at time $t=0$ and it's the first time$ (K=1)$, he is here. So, the answer is $0$. Test Case 3: The path followed by Kabir to reach 1 for the third time is given below. $0βˆ’1βˆ’0βˆ’1βˆ’2βˆ’1$ He reaches $1$ for the third time at $ t=5$.
{"inputs": ["4\n0 1\n1 1\n1 3\n4 6"], "outputs": ["0\n1\n5\n46"]}
619
35
coding
Solve the programming task below in a Python markdown code block. In your garden, there is a long and narrow flowerbed that stretches infinitely to the east. You have decided to plant N kinds of flowers in this empty flowerbed. For convenience, we will call these N kinds of flowers Flower 1, 2, …, N. Also, we will call the position that is p centimeters from the west end of the flowerbed Position p. You will plant Flower i (1 ≀ i ≀ N) as follows: first, plant one at Position w_i, then plant one every d_i centimeters endlessly toward the east. That is, Flower i will be planted at the positions w_i, w_i + d_i, w_i + 2 d_i, … Note that more than one flower may be planted at the same position. Find the position at which the K-th flower from the west is planted. If more than one flower is planted at the same position, they are counted individually. Constraints * 1 ≀ N ≀ 10^5 * 1 ≀ K ≀ 10^9 * 1 ≀ w_i ≀ 10^{18} * 1 ≀ d_i ≀ 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N K w_1 d_1 : w_N d_N Output When the K-th flower from the west is planted at Position X, print the value of X. (The westmost flower is counted as the 1-st flower.) Examples Input 2 6 20 10 25 15 Output 50 Input 3 9 10 10 10 10 10 10 Output 30 Input 1 1000000000 1000000000000000000 1000000000 Output 1999999999000000000
{"inputs": ["2 5\n38 9\n25 15", "2 5\n38 9\n39 15", "2 5\n38 9\n17 15", "2 10\n26 9\n1 15", "2 5\n20 3\n25 10", "1 5\n38 9\n25 15", "2 5\n20 10\n25 15", "2 5\n20 16\n25 15"], "outputs": ["55\n", "56\n", "47\n", "62\n", "29\n", "74\n", "40\n", "52\n"]}
450
176
coding
Solve the programming task below in a Python markdown code block. There is a horizontal row of $n$ cubes. The length of each cube is given. You need to create a new vertical pile of cubes. The new pile should follow these directions: if $cube[i]$ is on top of $cube[j]$ then $side Length[j]\geq side Length[i]$. When stacking the cubes, you can only pick up either the leftmost or the rightmost cube each time. Print Yes if it is possible to stack the cubes. Otherwise, print No. Example $blocks=[1,2,3,8,7]$ Result: No After choosing the rightmost element, $7$, choose the leftmost element, $\mbox{I}$. After than, the choices are $2$ and $8$. These are both larger than the top block of size $\mbox{I}$. $blocks=[1,2,3,7,8]$ Result: Yes Choose blocks from right to left in order to successfully stack the blocks. Input Format The first line contains a single integer $\mathbf{T}$, the number of test cases. For each test case, there are $2$ lines. The first line of each test case contains $n$, the number of cubes. The second line contains $n$ space separated integers, denoting the sideLengths of each cube in that order. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $1\leq side Length<2^{31}$ Output Format For each test case, output a single line containing either Yes or No. Sample Input STDIN Function ----- -------- 2 T = 2 6 blocks[] size n = 6 4 3 2 1 3 4 blocks = [4, 3, 2, 1, 3, 4] 3 blocks[] size n = 3 1 3 2 blocks = [1, 3, 2] Sample Output Yes No Explanation In the first test case, pick in this order: left - $\begin{array}{c}A\end{array}$, right - $\begin{array}{c}A\end{array}$, left - $3$, right - $3$, left - $2$, right - $\mbox{I}$. In the second test case, no order gives an appropriate arrangement of vertical cubes. $3$ will always come after either $\mbox{I}$ or $2$.
{"inputs": ["2\n6\n4 3 2 1 3 4\n3\n1 3 2\n"], "outputs": ["Yes\nNo\n"]}
562
38
coding
Solve the programming task below in a Python markdown code block. Chef is a really nice and respectful person, in sharp contrast to his little brother, who is a very nasty and disrespectful person. Chef always sends messages to his friends in all small letters, whereas the little brother sends messages in all capital letters. You just received a message given by a string s. You don't know whether this message is sent by Chef or his brother. Also, the communication channel through which you received the message is erroneous and hence can flip a letter from uppercase to lowercase or vice versa. However, you know that this channel can make at most K such flips. Determine whether the message could have been sent only by Chef, only by the little brother, by both or by none. -----Input----- - The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains two space-separated integers N and K denoting the length of the string s and the maximum number of flips that the erroneous channel can make. - The second line contains a single string s denoting the message you received. -----Output----- For each test case, output a single line containing one string β€” "chef", "brother", "both" or "none". -----Constraints----- - 1 ≀ T ≀ 1000 - 1 ≀ N ≀ 100 - 0 ≀ K ≀ N - s consists only of (lowercase and uppercase) English letters -----Example----- Input 4 5 1 frauD 5 1 FRAUD 4 4 Life 10 4 sTRAWBerry Output chef brother both none -----Explanation----- Example case 1: Only one flip is possible. So it is possible that Chef sent "fraud" and the channel flipped the last character to get "frauD". However, it is not possible for the brother to have sent "FRAUD", because then it would need 4 flips. Hence the answer is "chef". Example case 2: Only one flip is possible. So it is possible that the brother sent "FRAUD" and the channel didn't flip anything. However, it is not possible for Chef to have sent "fraud", because then it would need 5 flips. Hence the answer is "brother". Example case 3: Four flips are allowed. It is possible that Chef sent "life" and the channel flipped the first character to get "Life". It is also possible that the brother sent "LIFE" and the channel flipped the last three characters to get "Life". Hence the answer is "both". Example case 4: Four flips are allowed. It is not possible that Chef sent "strawberry", because it would need five flips to get "sTRAWBerry". It is also not possible that the brother sent "STRAWBERRY", because that would also need five flips. Hence the answer is "none".
{"inputs": ["4\n5 1\nfrauD\n5 1\nFRAUD\n4 4\nLife\n10 4\nsTRAWBerry"], "outputs": ["chef\nbrother\nboth\nnone"]}
630
50
coding
Solve the programming task below in a Python markdown code block. Today, Chef decided to cook some delicious meals from the ingredients in his kitchen. There are $N$ ingredients, represented by strings $S_1, S_2, \ldots, S_N$. Chef took all the ingredients, put them into a cauldron and mixed them up. In the cauldron, the letters of the strings representing the ingredients completely mixed, so each letter appears in the cauldron as many times as it appeared in all the strings in total; now, any number of times, Chef can take one letter out of the cauldron (if this letter appears in the cauldron multiple times, it can be taken out that many times) and use it in a meal. A complete meal is the string "codechef". Help Chef find the maximum number of complete meals he can make! -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - $N$ lines follow. For each $i$ ($1 \le i \le N$), the $i$-th of these lines contains a single string $S_i$. -----Output----- For each test case, print a single line containing one integer β€” the maximum number of complete meals Chef can create. -----Constraints----- - $1 \le T \le 100$ - $1 \le N \le 100$ - $|S_1| + |S_2| + \ldots + |S_N| \le 1,000$ - each string contains only lowercase English letters -----Example Input----- 3 6 cplusplus oscar deck fee hat near 5 code hacker chef chaby dumbofe 5 codechef chefcode fehcedoc cceeohfd codechef -----Example Output----- 1 2 5 -----Explanation----- Example case 1: After mixing, the cauldron contains the letter 'c' 3 times, the letter 'e' 4 times, and each of the letters 'o', 'd', 'h' and 'f' once. Clearly, this is only enough for one "codechef" meal. Example case 2: After mixing, the cauldron contains the letter 'c' 4 times, 'o' 2 times, 'd' 2 times, 'e' 4 times, 'h' 3 times and 'f' 2 times, which is enough to make 2 meals.
{"inputs": ["3\n6\ncplusplus\noscar\ndeck\nfee\nhat\nnear\n5\ncode\nhacker\nchef\nchaby\ndumbofe\n5\ncodechef\nchefcode\nfehcedoc\ncceeohfd\ncodechef"], "outputs": ["1\n2\n5"]}
570
73
coding
Solve the programming task below in a Python markdown code block. Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number a, the second player wrote number b. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins? -----Input----- The single line contains two integers a and b (1 ≀ a, b ≀ 6)Β β€” the numbers written on the paper by the first and second player, correspondingly. -----Output----- Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. -----Examples----- Input 2 5 Output 3 0 3 Input 2 4 Output 2 1 3 -----Note----- The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number a is closer to number x than number b, if |a - x| < |b - x|.
{"inputs": ["2 5\n", "2 4\n", "5 3\n", "1 6\n", "5 1\n", "6 3\n", "2 3\n", "5 6\n"], "outputs": ["3 0 3\n", "2 1 3\n", "2 1 3\n", "3 0 3\n", "3 1 2\n", "2 0 4\n", "2 0 4\n", "5 0 1\n"]}
284
118
coding
Solve the programming task below in a Python markdown code block. Consider the following $4 \times 4$ pattern: 1 2 4 7 3 5 8 11 6 9 12 14 10 13 15 16 You are given an integer $N$. Print the $N \times N$ pattern of the same kind (containing integers $1$ through $N^2$). -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains a single integer $N$. -----Output----- For each test case, print $N$ lines; each of them should contain $N$ space-separated integers. -----Constraints----- - $1 \le T \le 10$ - $1 \le N \le 100$ -----Subtasks----- Subtask #1 (100 points): Original constraints -----Example Input----- 1 4 -----Example Output----- 1 2 4 7 3 5 8 11 6 9 12 14 10 13 15 16 -----Explanation-----
{"inputs": ["1\n4"], "outputs": ["1 2 4 7\n3 5 8 11\n6 9 12 14\n10 13 15 16"]}
283
51
coding
Solve the programming task below in a Python markdown code block. You are the best freelancer in the city. Everybody knows you, but what they don't know, is that you are actually offloading your work to other freelancers and and you rarely need to do any work. You're living the life! To make this process easier you need to write a method called workNeeded to figure out how much time you need to contribute to a project. Giving the amount of time in `minutes` needed to complete the project and an array of pair values representing other freelancers' time in `[Hours, Minutes]` format ie. `[[2, 33], [3, 44]]` calculate how much time **you** will need to contribute to the project (if at all) and return a string depending on the case. * If we need to contribute time to the project then return `"I need to work x hour(s) and y minute(s)"` * If we don't have to contribute any time to the project then return `"Easy Money!"` Also feel free to reuse/extend the following starter code: ```python def work_needed(projectMinutes, freeLancers): ```
{"functional": "_inputs = [[60, [[1, 0]]], [60, [[0, 0]]]]\n_outputs = [['Easy Money!'], ['I need to work 1 hour(s) and 0 minute(s)']]\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(work_needed(*i), o[0])"}
244
192
coding
Solve the programming task below in a Python markdown code block. This is the hard version of Problem F. The only difference between the easy version and the hard version is the constraints. We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and "++-+--" are balanced, and strings "+--", "--" and "" are not balanced. We will call a string promising if the string can be made balanced by several (possibly zero) uses of the following operation: replace two adjacent minus signs with one plus sign. In particular, every balanced string is promising. However, the converse is not true: not every promising string is balanced. For example, the string "-+---" is promising, because you can replace two adjacent minuses with plus and get a balanced string "-++-", or get another balanced string "-+-+". How many non-empty substrings of the given string $s$ are promising? Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. Recall that a substring is a sequence of consecutive characters of the string. For example, for string "+-+" its substring are: "+-", "-+", "+", "+-+" (the string is a substring of itself) and some others. But the following strings are not its substring: "--", "++", "-++". -----Input----- The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) β€”the number of test cases in the test. Then the descriptions of test cases follow. Each test case of input data consists of two lines. The first line consists of the number $n$ ($1 \le n \le 2 \cdot 10^5$): the length of $s$. The second line of the test case contains the string $s$ of length $n$, consisting only of characters "+" and "-". It is guaranteed that the sum of values $n$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, print a single number: the number of the promising non-empty substrings of string $s$. Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. -----Examples----- Input 5 3 +-+ 5 -+--- 4 ---- 7 --+---+ 6 +++--- Output 2 4 2 7 4 -----Note----- The following are the promising substrings for the first three test cases in the example: $s[1 \dots 2]$="+-", $s[2 \dots 3]$="-+"; $s[1 \dots 2]$="-+", $s[2 \dots 3]$="+-", $s[1 \dots 5]$="-+---", $s[3 \dots 5]$="---"; $s[1 \dots 3]$="---", $s[2 \dots 4]$="---".
{"inputs": ["5\n3\n+-+\n5\n-+---\n4\n----\n7\n--+---+\n6\n+++---\n"], "outputs": ["2\n4\n2\n7\n4\n"]}
640
51
coding
Solve the programming task below in a Python markdown code block. For two positive integers a and b, let g(a, b) = [gcd] (a, b) + [lcm](a, b). For a positive integer N, let f(N) denote the minimum value of g(a, b) over all the pairs of positive integers (a, b) such that a+b = N. Find out the number of ordered pairs (a, b) such that a+b = N and g(a, b) = f(N). ------ 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 a positive integer N. ------ Output Format ------ For each test case, output the number of ordered pairs (a, b) such that a+b = N and g(a, b) = f(N). ------ Constraints ------ $1 ≀ T ≀ 100$ $2 ≀ N ≀ 10^{9}$ ----- Sample Input 1 ------ 2 4 105 ----- Sample Output 1 ------ 3 14 ----- explanation 1 ------ Test case $1$: - For the pair $(1, 3)$, $g(1, 3) = gcd(1,3)+lcm(1,3)=1+3=4$. - For the pair $(2, 2)$, $g(2, 2) = gcd(2,2)+lcm(2,2)=2+2=4$. - For the pair $(3, 1)$, $g(3, 1) = gcd(3,1)+lcm(3,1)=1+3=4$. Hence, $f(4) = 4$. There are three pairs $(a, b)$ satisfying $a+b = N$ and $g(a, b) = f(N)$.
{"inputs": ["2\n4\n105"], "outputs": ["3\n14\n"]}
422
22
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n flower seeds. Every seed must be planted first before it can begin to grow, then bloom. Planting a seed takes time and so does the growth of a seed. You are given two 0-indexed integer arrays plantTime and growTime, of length n each: plantTime[i] is the number of full days it takes you to plant the ith seed. Every day, you can work on planting exactly one seed. You do not have to work on planting the same seed on consecutive days, but the planting of a seed is not complete until you have worked plantTime[i] days on planting it in total. growTime[i] is the number of full days it takes the ith seed to grow after being completely planted. After the last day of its growth, the flower blooms and stays bloomed forever. From the beginning of day 0, you can plant the seeds in any order. Return the earliest possible day where all seeds are blooming. Β  Please complete the following python code precisely: ```python class Solution: def earliestFullBloom(self, plantTime: List[int], growTime: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(plantTime = [1,4,3], growTime = [2,3,1]) == 9\n assert candidate(plantTime = [1,2,3,2], growTime = [2,1,2,1]) == 9\n assert candidate(plantTime = [1], growTime = [1]) == 2\n\n\ncheck(Solution().earliestFullBloom)"}
253
102
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, return the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root. The length of a path between two nodes is represented by the number of edges between them. Β  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 diameterOfBinaryTree(self, root: Optional[TreeNode]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,4,5])) == 3\n assert candidate(root = tree_node([1,2])) == 1\n\n\ncheck(Solution().diameterOfBinaryTree)"}
170
60
coding
Solve the programming task below in a Python markdown code block. For a rooted tree, find the lowest common ancestor of two nodes u and v. The given tree consists of n nodes and every node has a unique ID from 0 to n-1 where 0 is the root. Constraints * 1 ≀ n ≀ 100000 * 1 ≀ q ≀ 100000 Input n k0 c1 c2 ... ck0 k1 c1 c2 ... ck1 : kn-1 c1 c2 ... ckn-1 q u1 v1 u2 v2 : uq vq The first line of the input includes an integer n, the number of nodes of the tree. In the next n lines, the information of node i is given. ki is the number of children of node i, and c1, ... cki are node IDs of 1st, ... kth child of node i. In the next line, the number of queryies q is given. In the next q lines, pairs of u and v are given as the queries. Output For each query, print the LCA of u and v in a line. Example Input 8 3 1 2 3 2 4 5 0 0 0 2 6 7 0 0 4 4 6 4 7 4 3 5 2 Output 1 1 0 0
{"inputs": ["8\n3 1 2 3\n2 4 5\n0\n0\n0\n2 6 7\n0\n0\n4\n4 6\n4 0\n2 3\n7 3", "8\n3 1 2 3\n2 4 5\n0\n0\n0\n2 6 7\n0\n0\n4\n4 6\n4 7\n2 3\n3 3", "8\n3 1 2 3\n2 4 5\n0\n0\n0\n2 6 7\n0\n0\n4\n4 6\n4 7\n3 3\n5 2", "8\n3 1 2 3\n2 4 5\n0\n0\n0\n2 6 7\n0\n0\n4\n6 6\n4 7\n2 2\n7 3", "8\n3 1 2 3\n2 4 5\n0\n0\n0\n2 6 7\n0\n0\n4\n6 6\n7 0\n2 3\n7 3", "8\n3 1 2 3\n2 4 5\n0\n0\n0\n2 6 7\n0\n0\n4\n4 6\n4 7\n5 3\n5 2", "8\n3 1 2 3\n2 4 5\n0\n0\n0\n2 6 7\n0\n0\n4\n4 6\n4 7\n2 3\n5 2", "8\n3 1 2 3\n2 4 5\n0\n0\n0\n2 6 7\n0\n0\n4\n4 6\n4 7\n2 3\n5 3"], "outputs": ["1\n0\n0\n0\n", "1\n1\n0\n3\n", "1\n1\n3\n0\n", "6\n1\n2\n0\n", "6\n0\n0\n0\n", "1\n1\n0\n0\n", "1\n1\n0\n0\n", "1\n1\n0\n0\n"]}
322
494
coding
Solve the programming task below in a Python markdown code block. Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 * d_1 \times d_{10} = m Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D. In Takahashi Calendar, how many Product Days does a year have? Constraints * All values in input are integers. * 1 \leq M \leq 100 * 1 \leq D \leq 99 Input Input is given from Standard Input in the following format: M D Output Print the number of Product Days in a year in Takahashi Calender. Examples Input 15 40 Output 10 Input 12 31 Output 5 Input 1 1 Output 0
{"inputs": ["0 1", "0 0", "1 0", "2 0", "9 1", "9 0", "2 1", "4 0"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
301
78
coding
Solve the programming task below in a Python markdown code block. You have a team of N people. For a particular task, you can pick any non-empty subset of people. The cost of having x people for the task is x^{k}. Output the sum of costs over all non-empty subsets of people. -----Input----- Only line of input contains two integers N (1 ≀ N ≀ 10^9) representing total number of people and k (1 ≀ k ≀ 5000). -----Output----- Output the sum of costs for all non empty subsets modulo 10^9 + 7. -----Examples----- Input 1 1 Output 1 Input 3 2 Output 24 -----Note----- In the first example, there is only one non-empty subset {1} with cost 1^1 = 1. In the second example, there are seven non-empty subsets. - {1} with cost 1^2 = 1 - {2} with cost 1^2 = 1 - {1, 2} with cost 2^2 = 4 - {3} with cost 1^2 = 1 - {1, 3} with cost 2^2 = 4 - {2, 3} with cost 2^2 = 4 - {1, 2, 3} with cost 3^2 = 9 The total cost is 1 + 1 + 4 + 1 + 4 + 4 + 9 = 24.
{"inputs": ["1 1\n", "3 2\n", "5 3\n", "5 3\n", "7 5\n", "3 3\n", "4 8\n", "1 1\n"], "outputs": ["1\n", "24\n", "800\n", "800\n", "181888", "54", "93320", "1\n"]}
333
98
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the number of combinations that make up that amount. If that amount of money cannot be made up by any combination of the coins, return 0. You may assume that you have an infinite number of each kind of coin. The answer is guaranteed to fit into a signed 32-bit integer. Β  Please complete the following python code precisely: ```python class Solution: def change(self, amount: int, coins: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(amount = 5, coins = [1, 2, 5]) == 4\n assert candidate(amount = 3, coins = [2]) == 0\n assert candidate(amount = 10, coins = [10] ) == 1\n\n\ncheck(Solution().change)"}
136
78
coding
Solve the programming task below in a Python markdown code block. Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 10^9. In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbersΒ β€” the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different). Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists. -----Input----- The first line of the input contains a positive integer n (1 ≀ n ≀ 200 000)Β β€” the number of scientists. The second line contains n positive integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where a_{i} is the index of a language, which the i-th scientist knows. The third line contains a positive integer m (1 ≀ m ≀ 200 000)Β β€” the number of movies in the cinema. The fourth line contains m positive integers b_1, b_2, ..., b_{m} (1 ≀ b_{j} ≀ 10^9), where b_{j} is the index of the audio language of the j-th movie. The fifth line contains m positive integers c_1, c_2, ..., c_{m} (1 ≀ c_{j} ≀ 10^9), where c_{j} is the index of subtitles language of the j-th movie. It is guaranteed that audio languages and subtitles language are different for each movie, that is b_{j} β‰  c_{j}. -----Output----- Print the single integerΒ β€” the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists. If there are several possible answers print any of them. -----Examples----- Input 3 2 3 2 2 3 2 2 3 Output 2 Input 6 6 3 1 1 3 7 5 1 2 3 4 5 2 3 4 5 1 Output 1 -----Note----- In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied. In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied.
{"inputs": ["1\n8\n1\n10\n3\n", "1\n8\n1\n17\n3\n", "1\n10\n1\n10\n3\n", "2\n1 6\n1\n6\n1\n", "1\n10\n1\n10\n3\n", "2\n1 6\n1\n6\n1\n", "1\n19\n1\n10\n3\n", "2\n1 6\n1\n3\n1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
730
148
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. It's the soccer match finals in Chefland and as always it has reached the penalty shotouts. Each team is given 5 shots to make and the team scoring a goal on the maximum number of shots wins the game. If both the teams' scores are equal, then the game is considered a draw and we would have 2 champions. Given ten integers A_{1}, A_{2}, \ldots, A_{10}, where the odd indexed integers(A_{1}, A_{3}, A_{5}, A_{7}, A_{9}) represent the outcome of the shots made by team 1 and even indexed integers(A_{2}, A_{4}, A_{6}, A_{8}, A_{10}) represent the outcome of the shots made by team 2 (here A_{i} = 1 indicates that it's a goal and A_{i} = 0 indicates a miss), determine the winner or find if the game ends in a draw. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first and only line of each test case contains ten space-separated integers A_{1}, A_{2}, \ldots, A_{10}. ------ Output Format ------ For each test case, print a single line containing one integer - 0 if the game ends in a draw or 1 if the first team wins or 2 if the second team wins. ------ Constraints ------ $1 ≀ T ≀ 1024$ $0 ≀ A_{i} ≀ 1$ ----- Sample Input 1 ------ 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 ----- Sample Output 1 ------ 0 2 1 1 ----- explanation 1 ------ Test case $1$: No team scores any goal, so the game ends in a draw. Test case $2$: The second team is able to score in their final shot, while the first team has scored 0 goals and hence the second team wins. Test case $3$: The first team is successfully able to make their first $2$ shots count and whereas the second team has not scored any goals. Therefore the first team wins. Test case $4$: Team $2$ misses their final shot and hence team $1$ wins the game with the final score of $5 - 4$.
{"inputs": ["4\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 1\n1 0 1 0 0 0 0 0 0 0 \n1 1 1 1 1 1 1 1 1 0"], "outputs": ["0\n2\n1\n1"]}
610
99
coding
Solve the programming task below in a Python markdown code block. There is a string S consisting of digits 1, 2, ..., 9. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.) The master's favorite number is 753. The closer to this number, the better. What is the minimum possible (absolute) difference between X and 753? -----Constraints----- - S is a string of length between 4 and 10 (inclusive). - Each character in S is 1, 2, ..., or 9. -----Input----- Input is given from Standard Input in the following format: S -----Output----- Print the minimum possible difference between X and 753. -----Sample Input----- 1234567876 -----Sample Output----- 34 Taking out the seventh to ninth characters results in X = 787, and the difference between this and 753 is 787 - 753 = 34. The difference cannot be made smaller, no matter where X is taken from. Note that the digits cannot be rearranged. For example, taking out 567 and rearranging it to 765 is not allowed. We cannot take out three digits that are not consecutive from S, either. For example, taking out the seventh digit 7, the ninth digit 7 and the tenth digit 6 to obtain 776 is not allowed.
{"inputs": ["820", "708", "792", "571", "2761", "5306", "1537", "1801"], "outputs": ["67\n", "45\n", "39\n", "182\n", "8\n", "223\n", "216\n", "48\n"]}
335
92
coding
Solve the programming task below in a Python markdown code block. Learn, learn and learn again β€” Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite that Valera is one of the best students, he failed to manage with the new homework. That's why he asks for your help. He has the following task. A sequence of n numbers is given. A prefix of a sequence is the part of the sequence (possibly empty), taken from the start of the sequence. A suffix of a sequence is the part of the sequence (possibly empty), taken from the end of the sequence. It is allowed to sequentially make two operations with the sequence. The first operation is to take some prefix of the sequence and multiply all numbers in this prefix by - 1. The second operation is to take some suffix and multiply all numbers in it by - 1. The chosen prefix and suffix may intersect. What is the maximum total sum of the sequence that can be obtained by applying the described operations? Input The first line contains integer n (1 ≀ n ≀ 105) β€” amount of elements in the sequence. The second line contains n integers ai ( - 104 ≀ ai ≀ 104) β€” the sequence itself. Output The first and the only line of the output should contain the answer to the problem. Examples Input 3 -1 -2 -3 Output 6 Input 5 -4 2 0 5 0 Output 11 Input 5 -1 10 -5 10 -2 Output 18
{"inputs": ["1\n2\n", "1\n4\n", "1\n0\n", "1\n-3\n", "2\n0 3\n", "2\n0 0\n", "1\n7500\n", "1\n5507\n"], "outputs": ["2\n", "4\n", "0\n", "3\n", "3\n", "0\n", "7500\n", "5507\n"]}
374
103
coding
Solve the programming task below in a Python markdown code block. Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase. Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then β€” zero or more lowercase letters. To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions. Input The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105. Output Print a single number β€” the least number of actions needed to make the message fancy. Examples Input PRuvetSTAaYA Output 5 Input OYPROSTIYAOPECHATALSYAPRIVETSTASYA Output 0 Input helloworld Output 0
{"inputs": ["P\n", "t\n", "O\n", "s\n", "N\n", "r\n", "M\n", "q\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
289
70
coding
Solve the programming task below in a Python markdown code block. # Task Your Informatics teacher at school likes coming up with new ways to help you understand the material. When you started studying numeral systems, he introduced his own numeral system, which he's convinced will help clarify things. His numeral system has base 26, and its digits are represented by English capital letters - `A for 0, B for 1, and so on`. The teacher assigned you the following numeral system exercise: given a one-digit `number`, you should find all unordered pairs of one-digit numbers whose values add up to the `number`. # Example For `number = 'G'`, the output should be `["A + G", "B + F", "C + E", "D + D"]` Translating this into the decimal numeral system we get: number = 6, so it is `["0 + 6", "1 + 5", "2 + 4", "3 + 3"]`. # Input/Output - `[input]` string(char in C#) `number` A character representing a correct one-digit number in the new numeral system. Constraints: `'A' ≀ number ≀ 'Z'.` - `[output]` a string array An array of strings in the format "letter1 + letter2", where "letter1" and "letter2" are correct one-digit numbers in the new numeral system. The strings should be sorted by "letter1". Note that "letter1 + letter2" and "letter2 + letter1" are equal pairs and we don't consider them to be different. Also feel free to reuse/extend the following starter code: ```python def new_numeral_system(number): ```
{"functional": "_inputs = [['G'], ['A'], ['D'], ['E'], ['O']]\n_outputs = [[['A + G', 'B + F', 'C + E', 'D + D']], [['A + A']], [['A + D', 'B + C']], [['A + E', 'B + D', 'C + C']], [['A + O', 'B + N', 'C + M', 'D + L', 'E + K', 'F + J', 'G + I', 'H + H']]]\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(new_numeral_system(*i), o[0])"}
367
257
coding
Solve the programming task below in a Python markdown code block. There is a 10 \times 10 grid with rows numbered 1 to 10 from top to bottom, and columns 1 to 10 from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c. If Chef's current location is (a,b), then in one move Chef can go to (c,d) if both of the following are satisfied: a \neq c b \neq d Determine the minimum number of moves required to go from (s_{x}, s_{y}) to (e_{x}, e_{y}). ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first and only line of each test case contains four integer s_{x}, s_{y}, e_{x}, e_{y} β€” the coordinates of the starting and ending cells. ------ Output Format ------ For each testcase, output the minimum number of moves required to go from (s_{x}, s_{y}) to (e_{x}, e_{y}). ------ Constraints ------ $1 ≀ T ≀ 1000$ $1 ≀ s_{x}, s_{y}, e_{x}, e_{y} ≀ 10$ $(s_{x},s_{y}) \neq (e_{x},e_{y})$ ----- Sample Input 1 ------ 4 1 2 9 8 5 5 5 7 8 6 6 8 3 10 8 10 ----- Sample Output 1 ------ 1 2 1 2 ----- explanation 1 ------ Test case 1: Chef can go from $(1, 2)$ to $(9, 8)$ in one move since $1 \neq 9$ and $2 \neq 8$. Test case 2: Chef will require at least two moves. One such sequence of moves is $(5, 5) \rightarrow (2, 3) \rightarrow (5, 7)$.
{"inputs": ["4\n1 2 9 8\n5 5 5 7\n8 6 6 8\n3 10 8 10\n"], "outputs": ["1\n2\n1\n2\n"]}
470
54
coding
Solve the programming task below in a Python markdown code block. You're given an undirected graph with $n$ nodes and $m$ edges. Nodes are numbered from $1$ to $n$. The graph is considered harmonious if and only if the following property holds: For every triple of integers $(l, m, r)$ such that $1 \le l < m < r \le n$, if there exists a path going from node $l$ to node $r$, then there exists a path going from node $l$ to node $m$. In other words, in a harmonious graph, if from a node $l$ we can reach a node $r$ through edges ($l < r$), then we should able to reach nodes $(l+1), (l+2), \ldots, (r-1)$ too. What is the minimum number of edges we need to add to make the graph harmonious? -----Input----- The first line contains two integers $n$ and $m$ ($3 \le n \le 200\ 000$ and $1 \le m \le 200\ 000$). The $i$-th of the next $m$ lines contains two integers $u_i$ and $v_i$ ($1 \le u_i, v_i \le n$, $u_i \neq v_i$), that mean that there's an edge between nodes $u$ and $v$. It is guaranteed that the given graph is simple (there is no self-loop, and there is at most one edge between every pair of nodes). -----Output----- Print the minimum number of edges we have to add to the graph to make it harmonious. -----Examples----- Input 14 8 1 2 2 7 3 4 6 3 5 7 3 8 6 8 11 12 Output 1 Input 200000 3 7 9 9 8 4 5 Output 0 -----Note----- In the first example, the given graph is not harmonious (for instance, $1 < 6 < 7$, node $1$ can reach node $7$ through the path $1 \rightarrow 2 \rightarrow 7$, but node $1$ can't reach node $6$). However adding the edge $(2, 4)$ is sufficient to make it harmonious. In the second example, the given graph is already harmonious.
{"inputs": ["3 1\n1 3\n", "3 1\n1 3\n", "5 1\n1 3\n", "4 1\n1 3\n", "200000 1\n1 200000\n", "200000 1\n1 200000\n", "200000 3\n7 9\n9 8\n4 5\n", "200000 3\n4 9\n9 8\n4 5\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "199998\n", "199998\n", "0\n", "2\n"]}
538
174
coding
Solve the programming task below in a Python markdown code block. Create a function that takes a string and an integer (`n`). The function should return a string that repeats the input string `n` number of times. If anything other than a string is passed in you should return `"Not a string"` ## Example ``` "Hi", 2 --> "HiHi" 1234, 5 --> "Not a string" ``` Also feel free to reuse/extend the following starter code: ```python def repeat_it(string,n): ```
{"functional": "_inputs = [['*', 3], ['Hello', 11], ['243624', 22], [[], 3], [24, 3], [True, 3], ['Hello', 0]]\n_outputs = [['***'], ['HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello'], ['243624243624243624243624243624243624243624243624243624243624243624243624243624243624243624243624243624243624243624243624243624243624'], ['Not a string'], ['Not a string'], ['Not a string'], ['']]\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(repeat_it(*i), o[0])"}
115
364
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The factorial of a positive integer n is the product of all positive integers less than or equal to n. For example, factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1. We make a clumsy factorial using the integers in decreasing order by swapping out the multiply operations for a fixed rotation of operations with multiply '*', divide '/', add '+', and subtract '-' in this order. For example, clumsy(10) = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1. However, these operations are still applied using the usual order of operations of arithmetic. We do all multiplication and division steps before any addition or subtraction steps, and multiplication and division steps are processed left to right. Additionally, the division that we use is floor division such that 10 * 9 / 8 = 90 / 8 = 11. Given an integer n, return the clumsy factorial of n. Β  Please complete the following python code precisely: ```python class Solution: def clumsy(self, n: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(4) == 7\n assert candidate(10) == 12\n\n\ncheck(Solution().clumsy)"}
271
42
coding
Solve the programming task below in a Python markdown code block. In 2020, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education. One day, there was an exam where a one-year-old child must write a program that prints Hello World, and a two-year-old child must write a program that receives integers A, B and prints A+B. Takahashi, who is taking this exam, suddenly forgets his age. He decides to write a program that first receives his age N (1 or 2) as input, then prints Hello World if N=1, and additionally receives integers A, B and prints A+B if N=2. Write this program for him. -----Constraints----- - N is 1 or 2. - A is an integer between 1 and 9 (inclusive). - B is an integer between 1 and 9 (inclusive). -----Input----- Input is given from Standard Input in one of the following formats: 1 2 A B -----Output----- If N=1, print Hello World; if N=2, print A+B. -----Sample Input----- 1 -----Sample Output----- Hello World As N=1, Takahashi is one year old. Thus, we should print Hello World.
{"inputs": ["1", "1\n", "2\n4\n5", "2\n4\n9", "2\n2\n9", "2\n4\n4", "2\n8\n4", "2\n6\n4"], "outputs": ["Hello World", "Hello World\n", "9\n", "13\n", "11\n", "8\n", "12\n", "10\n"]}
281
92
coding
Solve the programming task below in a Python markdown code block. There are $n$ persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends. We want to plan a trip for every evening of $m$ days. On each trip, you have to select a group of people that will go on the trip. For every person, one of the following should hold: Either this person does not go on the trip, Or at least $k$ of his friends also go on the trip. Note that the friendship is not transitive. That is, if $a$ and $b$ are friends and $b$ and $c$ are friends, it does not necessarily imply that $a$ and $c$ are friends. For each day, find the maximum number of people that can go on the trip on that day. -----Input----- The first line contains three integers $n$, $m$, and $k$ ($2 \leq n \leq 2 \cdot 10^5, 1 \leq m \leq 2 \cdot 10^5$, $1 \le k < n$)Β β€” the number of people, the number of days and the number of friends each person on the trip should have in the group. The $i$-th ($1 \leq i \leq m$) of the next $m$ lines contains two integers $x$ and $y$ ($1\leq x, y\leq n$, $x\ne y$), meaning that persons $x$ and $y$ become friends on the morning of day $i$. It is guaranteed that $x$ and $y$ were not friends before. -----Output----- Print exactly $m$ lines, where the $i$-th of them ($1\leq i\leq m$) contains the maximum number of people that can go on the trip on the evening of the day $i$. -----Examples----- Input 4 4 2 2 3 1 2 1 3 1 4 Output 0 0 3 3 Input 5 8 2 2 1 4 2 5 4 5 2 4 3 5 1 4 1 3 2 Output 0 0 0 3 3 4 4 5 Input 5 7 2 1 5 3 2 2 5 3 4 1 2 5 3 1 3 Output 0 0 0 0 3 4 4 -----Note----- In the first example, $1,2,3$ can go on day $3$ and $4$. In the second example, $2,4,5$ can go on day $4$ and $5$. $1,2,4,5$ can go on day $6$ and $7$. $1,2,3,4,5$ can go on day $8$. In the third example, $1,2,5$ can go on day $5$. $1,2,3,5$ can go on day $6$ and $7$.
{"inputs": ["2 1 1\n2 1\n", "2 1 1\n2 1\n", "2 1 2\n2 1\n", "2 1 3\n2 1\n", "4 4 2\n2 3\n1 2\n1 3\n1 4\n", "4 4 2\n2 3\n1 2\n1 3\n1 4\n", "5 7 2\n1 5\n3 2\n2 5\n3 4\n1 2\n5 3\n1 3\n", "9 7 2\n1 5\n3 2\n2 5\n3 4\n1 2\n5 3\n1 3\n"], "outputs": ["2\n", "2\n", "0\n", "0\n", "0\n0\n3\n3\n", "0\n0\n3\n3\n", "0\n0\n0\n0\n3\n4\n4\n", "0\n0\n0\n0\n3\n4\n4\n"]}
704
242
coding
Solve the programming task below in a Python markdown code block. We have the first value of a certain sequence, we will name it ```initVal```. We define pattern list, ```patternL```, an array that has the differences between contiguous terms of the sequence. ``` E.g: patternL = [k1, k2, k3, k4]``` The terms of the sequence will be such values that: ```python term1 = initVal term2 - term1 = k1 term3 - term2 = k2 term4 - term3 = k3 term5 - term4 = k4 term6 - term5 = k1 term7 - term6 = k2 term8 - term7 = k3 term9 - term8 = k4 .... - ..... = ... .... - ..... = ... ``` So the values of the differences between contiguous terms are cyclical and are repeated as the differences values of the pattern list stablishes. Let's see an example with numbers: ```python initVal = 10 patternL = [2, 1, 3] term1 = 10 term2 = 12 term3 = 13 term4 = 16 term5 = 18 term6 = 19 term7 = 22 # and so on... ``` We can easily obtain the next terms of the sequence following the values in the pattern list. We see that the sixth term of the sequence, ```19```, has the sum of its digits ```10```. Make a function ```sumDig_nthTerm()```, that receives three arguments in this order ```sumDig_nthTerm(initVal, patternL, nthTerm(ordinal number of the term in the sequence)) ``` This function will output the sum of the digits of the n-th term of the sequence. Let's see some cases for this function: ```python sumDig_nthTerm(10, [2, 1, 3], 6) -----> 10 # because the sixth term is 19 sum of Dig = 1 + 9 = 10. The sequence up to the sixth-Term is: 10, 12, 13, 16, 18, 19 sumDig_nthTerm(10, [1, 2, 3], 15) ----> 10 # 37 is the 15-th term, and 3 + 7 = 10 ``` Enjoy it and happy coding!! Also feel free to reuse/extend the following starter code: ```python def sumDig_nthTerm(initVal, patternL, nthTerm): ```
{"functional": "_inputs = [[10, [2, 1, 3], 6], [10, [2, 1, 3], 15], [10, [2, 1, 3], 50], [10, [2, 1, 3], 78], [10, [2, 1, 3], 157], [10, [2, 2, 5, 8], 6], [10, [2, 2, 5, 8], 15], [10, [2, 2, 5, 8], 50], [10, [2, 2, 5, 8], 78], [10, [2, 2, 5, 8], 157], [100, [2, 2, 5, 8], 6], [100, [2, 2, 5, 8], 15], [100, [2, 2, 5, 8], 50], [100, [2, 2, 5, 8], 78], [100, [2, 2, 5, 8], 157], [1000, [2, 2, 5, 8], 2550], [1000, [2, 2, 5, 8], 25500]]\n_outputs = [[10], [10], [9], [10], [7], [11], [11], [9], [11], [16], [11], [11], [9], [11], [16], [14], [26]]\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(sumDig_nthTerm(*i), o[0])"}
585
553
coding
Solve the programming task below in a Python markdown code block. To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible. The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following: * aij β€” the cost of buying an item; * bij β€” the cost of selling an item; * cij β€” the number of remaining items. It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind. Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get. Input The first line contains three space-separated integers n, m and k (2 ≀ n ≀ 10, 1 ≀ m, k ≀ 100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow n blocks describing each planet. The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≀ bij < aij ≀ 1000, 0 ≀ cij ≀ 100) β€” the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces. It is guaranteed that the names of all planets are different. Output Print a single number β€” the maximum profit Qwerty can get. Examples Input 3 3 10 Venus 6 5 3 7 6 5 8 6 10 Earth 10 9 0 8 6 4 10 9 3 Mars 4 3 0 8 4 12 7 2 5 Output 16 Note In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case.
{"inputs": ["2 1 5\nA\n6 5 5\nB\n10 9 0\n", "2 1 5\nA\n6 3 5\nB\n10 9 0\n", "2 1 5\nA\n6 3 2\nB\n10 9 0\n", "2 1 5\nA\n10 3 2\nB\n10 9 0\n", "2 1 5\nA\n10 3 2\nB\n10 9 1\n", "2 1 1\nG\n2 1 9\nRdepya\n2 1 8\n", "2 1 1\nG\n2 1 9\nRdepyb\n2 1 8\n", "2 1 1\nG\n1 1 9\nRdepyb\n2 1 4\n"], "outputs": ["15\n", "15\n", "6\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
728
248
coding
Solve the programming task below in a Python markdown code block. Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K. -----Constraints----- - 2 \leq K \leq 10^5 - K is an integer. -----Input----- Input is given from Standard Input in the following format: K -----Output----- Print the smallest possible sum of the digits in the decimal notation of a positive multiple of K. -----Sample Input----- 6 -----Sample Output----- 3 12=6Γ—2 yields the smallest sum.
{"inputs": ["9", "8", "4", "3", "5", "2", "7", "6"], "outputs": ["9\n", "1\n", "1\n", "3\n", "1\n", "1\n", "2\n", "3"]}
118
61
coding
Solve the programming task below in a Python markdown code block. You can perform the following operations on the string, $a$: Capitalize zero or more of $a$'s lowercase letters. Delete all of the remaining lowercase letters in $a$. Given two strings, $a$ and $\boldsymbol{b}$, determine if it's possible to make $a$ equal to $\boldsymbol{b}$ as described. If so, print YES on a new line. Otherwise, print NO. For example, given $a=\textbf{AbcDE}$ and $b=\textbf{ABDE}$, in $a$ we can convert $\mbox{b}$ and delete $\textbf{C}$ to match $\boldsymbol{b}$. If $a=\textbf{AbcDE}$ and $b=\textbf{AFDE}$, matching is not possible because letters may only be capitalized or discarded, not changed. Function Description Complete the function $abbreviation$ in the editor below. It must return either $YES$ or $\mathrm{NO}$. abbreviation has the following parameter(s): a: the string to modify b: the string to match Input Format The first line contains a single integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ pairs of lines is as follows: - The first line of each query contains a single string, $a$. - The second line of each query contains a single string, $\boldsymbol{b}$. Constraints $1\leq q\leq10$ $1\le|a|,|b|\le1000$ String $a$ consists only of uppercase and lowercase English letters, ascii[A-Za-z]. String $\boldsymbol{b}$ consists only of uppercase English letters, ascii[A-Z]. Output Format For each query, print YES on a new line if it's possible to make string $a$ equal to string $\boldsymbol{b}$. Otherwise, print NO. Sample Input 1 daBcd ABC Sample Output YES Explanation We have $\boldsymbol{a}=$ daBcd and $b=$ ABC. We perform the following operation: Capitalize the letters a and c in $\boldsymbol{\alpha}$ so that $\boldsymbol{a}=$ dABCd. Delete all the remaining lowercase letters in $a$ so that $\boldsymbol{a}=$ ABC. Because we were able to successfully convert $a$ to $\boldsymbol{b}$, we print YES on a new line.
{"inputs": ["1\ndaBcd\nABC\n"], "outputs": ["YES\n"]}
551
20
coding
Solve the programming task below in a Python markdown code block. Petya's friends made him a birthday present β€” a bracket sequence. Petya was quite disappointed with his gift, because he dreamed of correct bracket sequence, yet he told his friends nothing about his dreams and decided to fix present himself. To make everything right, Petya is going to move at most one bracket from its original place in the sequence to any other position. Reversing the bracket (e.g. turning "(" into ")" or vice versa) isn't allowed. We remind that bracket sequence $s$ is called correct if: $s$ is empty; $s$ is equal to "($t$)", where $t$ is correct bracket sequence; $s$ is equal to $t_1 t_2$, i.e. concatenation of $t_1$ and $t_2$, where $t_1$ and $t_2$ are correct bracket sequences. For example, "(()())", "()" are correct, while ")(" and "())" are not. Help Petya to fix his birthday present and understand whether he can move one bracket so that the sequence becomes correct. -----Input----- First of line of input contains a single number $n$ ($1 \leq n \leq 200\,000$)Β β€” length of the sequence which Petya received for his birthday. Second line of the input contains bracket sequence of length $n$, containing symbols "(" and ")". -----Output----- Print "Yes" if Petya can make his sequence correct moving at most one bracket. Otherwise print "No". -----Examples----- Input 2 )( Output Yes Input 3 (() Output No Input 2 () Output Yes Input 10 )))))((((( Output No -----Note----- In the first example, Petya can move first bracket to the end, thus turning the sequence into "()", which is correct bracket sequence. In the second example, there is no way to move at most one bracket so that the sequence becomes correct. In the third example, the sequence is already correct and there's no need to move brackets.
{"inputs": ["1\n)\n", "1\n(\n", "1\n(\n", "1\n)\n", "2\n)(\n", "2\n()\n", "2\n((\n", "2\n((\n"], "outputs": ["No\n", "No\n", "No\n", "No\n", "Yes\n", "Yes\n", "No\n", "No\n"]}
466
89
coding
Solve the programming task below in a Python markdown code block. You are given an integer N. For two positive integers A and B, we will define F(A,B) as the larger of the following: the number of digits in the decimal notation of A, and the number of digits in the decimal notation of B. For example, F(3,11) = 2 since 3 has one digit and 11 has two digits. Find the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \times B. -----Constraints----- - 1 \leq N \leq 10^{10} - N is an integer. -----Input----- The input is given from Standard Input in the following format: N -----Output----- Print the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \times B. -----Sample Input----- 10000 -----Sample Output----- 3 F(A,B) has a minimum value of 3 at (A,B)=(100,100).
{"inputs": ["1\n", "56", "472", "010", "748", "395", "593", "101"], "outputs": ["1\n", "1\n", "2\n", "1\n", "2\n", "2\n", "3\n", "3\n"]}
238
76
coding
Solve the programming task below in a Python markdown code block. Tak performed the following action N times: rolling two dice. The result of the i-th roll is D_{i,1} and D_{i,2}. Check if doublets occurred at least three times in a row. Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold. -----Constraints----- - 3 \leq N \leq 100 - 1\leq D_{i,j} \leq 6 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: N D_{1,1} D_{1,2} \vdots D_{N,1} D_{N,2} -----Output----- Print Yes if doublets occurred at least three times in a row. Print No otherwise. -----Sample Input----- 5 1 2 6 6 4 4 3 3 3 2 -----Sample Output----- Yes From the second roll to the fourth roll, three doublets occurred in a row.
{"inputs": ["3\n1 2\n3 4\n5 6\n", "3\n1 1\n2 2\n3 3\n", "3\n1 2\n1 2\n3 3\n", "3\n1 1\n1 1\n1 1\n", "5\n1 2\n6 6\n4 4\n3 3\n3 3", "5\n1 2\n2 2\n3 4\n5 5\n6 6", "5\n1 2\n6 6\n4 1\n3 3\n3 2", "5\n1 2\n2 2\n3 4\n9 5\n6 6"], "outputs": ["No\n", "Yes\n", "No\n", "Yes\n", "Yes\n", "No\n", "No\n", "No\n"]}
277
194
coding
Solve the programming task below in a Python markdown code block. The goal of this exercise is to convert a string to a new string where each character in the new string is `"("` if that character appears only once in the original string, or `")"` if that character appears more than once in the original string. Ignore capitalization when determining if a character is a duplicate. ## Examples ``` "din" => "(((" "recede" => "()()()" "Success" => ")())())" "(( @" => "))((" ``` **Notes** Assertion messages may be unclear about what they display in some languages. If you read `"...It Should encode XXX"`, the `"XXX"` is the expected result, not the input! Also feel free to reuse/extend the following starter code: ```python def duplicate_encode(word): ```
{"functional": "_inputs = [['din'], ['recede'], ['Success'], ['CodeWarrior'], ['Supralapsarian'], ['iiiiii'], ['(( @'], [' ( ( )']]\n_outputs = [['((('], ['()()()'], [')())())'], ['()(((())())'], [')()))()))))()('], ['))))))'], ['))(('], [')))))(']]\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(duplicate_encode(*i), o[0])"}
183
225
coding
Solve the programming task below in a Python markdown code block. Return the century of the input year. The input will always be a 4 digit string, so there is no need for validation. ### Examples ``` "1999" --> "20th" "2011" --> "21st" "2154" --> "22nd" "2259" --> "23rd" "1124" --> "12th" "2000" --> "20th" ``` Also feel free to reuse/extend the following starter code: ```python def what_century(year): ```
{"functional": "_inputs = [['1999']]\n_outputs = [['20th']]\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(what_century(*i), o[0])"}
142
161
coding
Solve the programming task below in a Python markdown code block. You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types. * `0 u v`: Add an edge (u, v). * `1 u v`: Print 1 if u and v are in the same connected component, 0 otherwise. Constraints * 1 \leq N \leq 200,000 * 1 \leq Q \leq 200,000 * 0 \leq u_i, v_i \lt N Input Input is given from Standard Input in the following format: N Q t_1 u_1 v_1 t_2 u_2 v_2 : t_Q u_Q v_Q ε‡ΊεŠ› For each query of the latter type, print the answer. Example Input 4 7 1 0 1 0 0 1 0 2 3 1 0 1 1 1 2 0 0 2 1 1 3 Output 0 1 0 1
{"inputs": ["4 7\n1 0 1\n0 0 1\n0 2 3\n1 0 1\n1 1 2\n0 0 2\n1 0 3", "4 7\n1 0 1\n0 0 1\n0 2 3\n1 0 2\n1 1 2\n0 0 2\n1 1 3", "4 7\n1 0 1\n0 0 1\n0 2 3\n1 0 1\n1 1 2\n0 0 2\n0 0 3", "4 7\n1 0 1\n0 0 1\n0 2 3\n1 0 2\n1 1 2\n0 0 2\n0 1 3", "4 7\n1 1 1\n0 0 1\n0 2 3\n1 0 2\n1 0 2\n0 0 2\n0 1 3", "4 7\n1 0 1\n0 0 1\n0 2 3\n2 0 2\n1 0 1\n0 0 2\n0 1 3", "4 7\n0 0 1\n0 0 1\n0 2 3\n2 0 2\n1 0 1\n0 0 2\n0 1 3", "4 7\n1 0 1\n0 0 1\n0 2 3\n1 0 1\n1 2 2\n0 0 2\n2 0 3"], "outputs": ["0\n1\n0\n1\n", "0\n0\n0\n1\n", "0\n1\n0\n", "0\n0\n0\n", "1\n0\n0\n", "0\n0\n1\n", "0\n1\n", "0\n1\n1\n1\n"]}
247
450
coding
Solve the programming task below in a Python markdown code block. Codefortia is a small island country located somewhere in the West Pacific. It consists of $n$ settlements connected by $m$ bidirectional gravel roads. Curiously enough, the beliefs of the inhabitants require the time needed to pass each road to be equal either to $a$ or $b$ seconds. It's guaranteed that one can go between any pair of settlements by following a sequence of roads. Codefortia was recently struck by the financial crisis. Therefore, the king decided to abandon some of the roads so that: it will be possible to travel between each pair of cities using the remaining roads only, the sum of times required to pass each remaining road will be minimum possible (in other words, remaining roads must form minimum spanning tree, using the time to pass the road as its weight), among all the plans minimizing the sum of times above, the time required to travel between the king's residence (in settlement $1$) and the parliament house (in settlement $p$) using the remaining roads only will be minimum possible. The king, however, forgot where the parliament house was. For each settlement $p = 1, 2, \dots, n$, can you tell what is the minimum time required to travel between the king's residence and the parliament house (located in settlement $p$) after some roads are abandoned? -----Input----- The first line of the input contains four integers $n$, $m$, $a$ and $b$ ($2 \leq n \leq 70$, $n - 1 \leq m \leq 200$, $1 \leq a < b \leq 10^7$) β€” the number of settlements and gravel roads in Codefortia, and two possible travel times. Each of the following lines contains three integers $u, v, c$ ($1 \leq u, v \leq n$, $u \neq v$, $c \in \{a, b\}$) denoting a single gravel road between the settlements $u$ and $v$, which requires $c$ minutes to travel. You can assume that the road network is connected and has no loops or multiedges. -----Output----- Output a single line containing $n$ integers. The $p$-th of them should denote the minimum possible time required to travel from $1$ to $p$ after the selected roads are abandoned. Note that for each $p$ you can abandon a different set of roads. -----Examples----- Input 5 5 20 25 1 2 25 2 3 25 3 4 20 4 5 20 5 1 20 Output 0 25 60 40 20 Input 6 7 13 22 1 2 13 2 3 13 1 4 22 3 4 13 4 5 13 5 6 13 6 1 13 Output 0 13 26 39 26 13 -----Note----- The minimum possible sum of times required to pass each road in the first example is $85$ β€” exactly one of the roads with passing time $25$ must be abandoned. Note that after one of these roads is abandoned, it's now impossible to travel between settlements $1$ and $3$ in time $50$.
{"inputs": ["2 1 1 2\n2 1 1\n", "2 1 1 2\n2 1 1\n", "2 1 1 4\n2 1 1\n", "2 1 185269 10000000\n1 2 10000000\n", "2 1 9999999 10000000\n1 2 10000000\n", "2 1 9999999 10000000\n1 2 10000000\n", "2 1 12099651 10000000\n1 2 10000000\n", "3 2 509529 96762\n1 2 509529\n3 2 509529\n"], "outputs": ["0 1\n", "0 1\n", "0 1 ", "0 10000000 ", "0 10000000\n", "0 10000000\n", "0 10000000 ", "0 509529 1019058 "]}
751
325
coding
Solve the programming task below in a Python markdown code block. Define a "prime prime" number to be a rational number written as one prime number over another prime number: `primeA / primeB` (e.g. `7/31`) Given a whole number `N`, generate the number of "prime prime" rational numbers less than 1, using only prime numbers between `0` and `N` (non inclusive). Return the count of these "prime primes", and the integer part of their sum. ## Example ```python N = 6 # The "prime primes" less than 1 are: 2/3, 2/5, 3/5 # count: 3 2/3 + 2/5 + 3/5 = 1.6667 # integer part: 1 Thus, the function should return 3 and 1. ``` Also feel free to reuse/extend the following starter code: ```python def prime_primes(N): ```
{"functional": "_inputs = [[6], [4], [10], [65], [0], [1000], [666]]\n_outputs = [[[3, 1]], [[1, 0]], [[6, 3]], [[153, 63]], [[0, 0]], [[14028, 6266]], [[7260, 3213]]]\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(prime_primes(*i), o[0])"}
217
236
coding
Solve the programming task below in a Python markdown code block. Chef has an array of N integers. Chef can rearrange this array in any manner. Chef doesn’t like the array if any two adjacent elements are equal. Determine whether there exists a rearrangement of the array that Chef likes. ------ 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 a single integer N - size of the array A. - Second line of each test case contains N space-separated integers - denoting the elements of array A. ------ Output Format ------ For each test case, if Chef can like any rearrangement of the array print YES, otherwise print NO. You may print each character of the 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}$ $2 ≀ N ≀ 10^{5}$ $-10^{9} ≀ A_{i} ≀ 10^{9}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 1 1 1 1 1 3 3 3 4 ----- Sample Output 1 ------ No Yes ----- explanation 1 ------ Test case $1$: There exists no rearrangement of the array which Chef will like. Test case $2$: A rearrangement of the array that Chef likes is $[3, 4, 3]$. Note that in this rearrangement, no two adjacent elements are equal.
{"inputs": ["2\n5\n1 1 1 1 1\n3\n3 3 4\n"], "outputs": ["No\nYes\n"]}
363
36
coding
Solve the programming task below in a Python markdown code block. We consider two strings to be anagrams of each other if the first string's letters can be rearranged to form the second string. In other words, both strings must contain the same exact letters in the same exact frequency. For example, bacdc and dcbac are anagrams, but bacdc and dcbad are not. Alice is taking a cryptography class and finding anagrams to be very useful. She decides on an encryption scheme involving two large strings where encryption is dependent on the minimum number of character deletions required to make the two strings anagrams. Can you help her find this number? Given two strings, $\mbox{s1}$ and $\mbox{s2}$, that may not be of the same length, determine the minimum number of character deletions required to make $\mbox{s1}$ and $\mbox{s2}$ anagrams. Any characters can be deleted from either of the strings. Example. $\textit{s1}=\texttt{abc}$ $s2=\textbf{amnop}$ The only characters that match are the $\mbox{a}$'s so we have to remove $\mathbf{bc}$ from $\mbox{s1}$ and $\textbf{mnop}$ from $\mbox{s2}$ for a total of $\boldsymbol{6}$ deletions. Function Description Complete the makingAnagrams function in the editor below. makingAnagrams has the following parameter(s): string s1: a string string s2: a string Returns int: the minimum number of deletions needed Input Format The first line contains a single string, $\mbox{s1}$. The second line contains a single string, $\mbox{s2}$. Constraints $1\leq|s1|,|s2|\leq10^4$ It is guaranteed that $\mbox{s1}$ and $\mbox{s2}$ consist of lowercase English letters, ascii[a-z]. Sample Input cde abc Sample Output 4 Explanation Delete the following characters from our two strings to turn them into anagrams: Remove d and e from cde to get c. Remove a and b from abc to get c. $4$ characters have to be deleted to make both strings anagrams.
{"inputs": ["cde\nabc\n"], "outputs": ["4\n"]}
491
17
coding
Solve the programming task below in a Python markdown code block. Kristen loves playing with and comparing numbers. She thinks that if she takes two different positive numbers, the one whose digits sum to a larger number is better than the other. If the sum of digits is equal for both numbers, then she thinks the smaller number is better. For example, Kristen thinks that $13$ is better than $31$ and that $12$ is better than ${11}$. Given an integer, $n$, can you find the divisor of $n$ that Kristin will consider to be the best? Input Format A single integer denoting $n$. Constraints $0<n\leq10^5$ Output Format Print an integer denoting the best divisor of $n$. Sample Input 0 12 Sample Output 0 6 Explanation 0 The set of divisors of $12$ can be expressed as $\{1,2,3,4,6,12\}$. The divisor whose digits sum to the largest number is ${6}$ (which, having only one digit, sums to itself). Thus, we print ${6}$ as our answer.
{"inputs": ["12\n"], "outputs": ["6\n"]}
252
15
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array matches where matches[i] = [winneri, loseri] indicates that the player winneri defeated player loseri in a match. Return a list answer of size 2 where: answer[0] is a list of all players that have not lost any matches. answer[1] is a list of all players that have lost exactly one match. The values in the two lists should be returned in increasing order. Note: You should only consider the players that have played at least one match. The testcases will be generated such that no two matches will have the same outcome. Β  Please complete the following python code precisely: ```python class Solution: def findWinners(self, matches: List[List[int]]) -> List[List[int]]: ```
{"functional": "def check(candidate):\n assert candidate(matches = [[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]]) == [[1,2,10],[4,5,7,8]]\n assert candidate(matches = [[2,3],[1,3],[5,4],[6,4]]) == [[1,2,5,6],[]]\n\n\ncheck(Solution().findWinners)"}
175
122
coding
Solve the programming task below in a Python markdown code block. DNA is a biomolecule that carries genetic information. It is composed of four different building blocks, called nucleotides: adenine (A), thymine (T), cytosine (C) and guanine (G). Two DNA strands join to form a double helix, whereby the nucleotides of one strand bond to the nucleotides of the other strand at the corresponding positions. The bonding is only possible if the nucleotides are complementary: A always pairs with T, and C always pairs with G. Due to the asymmetry of the DNA, every DNA strand has a direction associated with it. The two strands of the double helix run in opposite directions to each other, which we refer to as the 'up-down' and the 'down-up' directions. Write a function `checkDNA` that takes in two DNA sequences as strings, and checks if they are fit to form a fully complementary DNA double helix. The function should return a Boolean `true` if they are complementary, and `false` if there is a sequence mismatch (Example 1 below). Note: - All sequences will be of non-zero length, and consisting only of `A`, `T`, `C` and `G` characters. - All sequences **will be given in the up-down direction**. - The two sequences to be compared can be of different length. If this is the case and one strand is entirely bonded by the other, and there is no sequence mismatch between the two (Example 2 below), your function should still return `true`. - If both strands are only partially bonded (Example 3 below), the function should return `false`. Example 1: Example 2: Example 3: --- #### If you enjoyed this kata, check out also my other DNA kata: [**Longest Repeated DNA Motif**](http://www.codewars.com/kata/longest-repeated-dna-motif) Also feel free to reuse/extend the following starter code: ```python def check_DNA(seq1, seq2): ```
{"functional": "_inputs = [['GTCTTAGTGTAGCTATGCATGC', 'GCATGCATAGCTACACTACGAC'], ['ATGCTACG', 'CGTAGCAT'], ['AGTCTGTATGCATCGTACCC', 'GGGTACGATGCATACAGACT'], ['TGCTACGTACGATCGACGATCCACGAC', 'GTCGTGGATCGTCGATCGTACGTAGCA'], ['ATGCCTACGGCCATATATATTTAG', 'CTAAATATGTATGGCCGTAGGCAT'], ['GTCACCGA', 'TCGGCTGAC'], ['TAATACCCGACTAATTCCCC', 'GGGGAATTTCGGGTATTA'], ['GCTAACTCGAAGCTATACGTTA', 'TAACGTATAGCTTCGAGGTTAGC'], ['GCGCTGCTAGCTGATCGA', 'ACGTACGATCGATCAGCTAGCAGCGCTAC'], ['GCTAGCACCCATTAGGAGATAC', 'CTCCTAATGGGTG'], ['TAGCATCGCCAAATTATGCGTCAGTCTGCCCG', 'GGGCA'], ['ACGACTACGTGCGCCGCTAATATT', 'GCACGGGTCGT'], ['CGATACGAACCCATAATCG', 'CTACACCGGCCGATTATGG'], ['CGACATCGAGGGGGCTCAGAAGTACTGA', 'CATGGCGTCAGTACTTCTGAGCC'], ['GAGCAGTTGGTAGTTT', 'GTATCGAAACTACCA'], ['TACGATCCAAGGCTACTCAGAG', 'GGGATACTCTGAGTAGCCTTGGAA'], ['ATGCTACG', 'CGTAGCAA']]\n_outputs = [[False], [True], [True], [True], [False], [False], [False], [False], [True], [True], [True], [False], [False], [False], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(check_DNA(*i), o[0])"}
437
604
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two positive integer arrays spells and potions, of length n and m respectively, where spells[i] represents the strength of the ith spell and potions[j] represents the strength of the jth potion. You are also given an integer success. A spell and potion pair is considered successful if the product of their strengths is at least success. Return an integer array pairs of length n where pairs[i] is the number of potions that will form a successful pair with the ith spell. Β  Please complete the following python code precisely: ```python class Solution: def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]: ```
{"functional": "def check(candidate):\n assert candidate(spells = [5,1,3], potions = [1,2,3,4,5], success = 7) == [4,0,3]\n assert candidate(spells = [3,1,2], potions = [8,5,8], success = 16) == [2,0,2]\n\n\ncheck(Solution().successfulPairs)"}
155
96
coding
Solve the programming task below in a Python markdown code block. Given a binary number (of $N$ bits) $X$. Find the highest power of 2 that divides this number. Note: If the binary number is "100" then the highest power of 2 that divides it is 2 (as $2^{2}$ = 4) ------ Input: ------ The first line contains N the number of bits in the number The next line contains a binary number of N bits ------ Output: ------ The first and only line contains the max power of 2 that divides the given number ------ Constraints: ------ $ $1 ≀ N ≀10^{5}$$ $ $1≀ X$$ ----- Sample Input 1 ------ 5 10100 ----- Sample Output 1 ------ 2
{"inputs": ["5\n10100"], "outputs": ["2"]}
175
18
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A complex number can be represented as a string on the form "real+imaginaryi" where: real is the real part and is an integer in the range [-100, 100]. imaginary is the imaginary part and is an integer in the range [-100, 100]. i2 == -1. Given two complex numbers num1 and num2 as strings, return a string of the complex number that represents their multiplications. Β  Please complete the following python code precisely: ```python class Solution: def complexNumberMultiply(self, num1: str, num2: str) -> str: ```
{"functional": "def check(candidate):\n assert candidate(num1 = \"1+1i\", num2 = \"1+1i\") == \"0+2i\"\n assert candidate(num1 = \"1+-1i\", num2 = \"1+-1i\") == \"0+-2i\"\n\n\ncheck(Solution().complexNumberMultiply)"}
151
78
coding
Solve the programming task below in a Python markdown code block. Kevin Sun wants to move his precious collection of n cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into k boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single box. Since Kevin wishes to minimize expenses, he is curious about the smallest size box he can use to pack his entire collection. Kevin is a meticulous cowbell collector and knows that the size of his i-th (1 ≀ i ≀ n) cowbell is an integer s_{i}. In fact, he keeps his cowbells sorted by size, so s_{i} - 1 ≀ s_{i} for any i > 1. Also an expert packer, Kevin can fit one or two cowbells into a box of size s if and only if the sum of their sizes does not exceed s. Given this information, help Kevin determine the smallest s for which it is possible to put all of his cowbells into k boxes of size s. -----Input----- The first line of the input contains two space-separated integers n and k (1 ≀ n ≀ 2Β·k ≀ 100 000), denoting the number of cowbells and the number of boxes, respectively. The next line contains n space-separated integers s_1, s_2, ..., s_{n} (1 ≀ s_1 ≀ s_2 ≀ ... ≀ s_{n} ≀ 1 000 000), the sizes of Kevin's cowbells. It is guaranteed that the sizes s_{i} are given in non-decreasing order. -----Output----- Print a single integer, the smallest s for which it is possible for Kevin to put all of his cowbells into k boxes of size s. -----Examples----- Input 2 1 2 5 Output 7 Input 4 3 2 3 5 9 Output 9 Input 3 2 3 5 7 Output 8 -----Note----- In the first sample, Kevin must pack his two cowbells into the same box. In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}. In the third sample, the optimal solution is {3, 5} and {7}.
{"inputs": ["1 1\n1\n", "1 1\n1\n", "1 2\n10\n", "1 2\n10\n", "1 1\n10\n", "2 1\n2 5\n", "2 2\n2 3\n", "2 2\n2 3\n"], "outputs": ["1\n", "1\n", "10\n", "10\n", "10\n", "7\n", "3\n", "3\n"]}
527
114
coding
Solve the programming task below in a Python markdown code block. There are N apple trees in a row. People say that one of them will bear golden apples. We want to deploy some number of inspectors so that each of these trees will be inspected. Each inspector will be deployed under one of the trees. For convenience, we will assign numbers from 1 through N to the trees. An inspector deployed under the i-th tree (1 \leq i \leq N) will inspect the trees with numbers between i-D and i+D (inclusive). Find the minimum number of inspectors that we need to deploy to achieve the objective. -----Constraints----- - All values in input are integers. - 1 \leq N \leq 20 - 1 \leq D \leq 20 -----Input----- Input is given from Standard Input in the following format: N D -----Output----- Print the minimum number of inspectors that we need to deploy to achieve the objective. -----Sample Input----- 6 2 -----Sample Output----- 2 We can achieve the objective by, for example, placing an inspector under Tree 3 and Tree 4.
{"inputs": ["0 3", "6 4", "4 0", "9 0", "2 7", "1 3", "1 4", "1 7"], "outputs": ["0\n", "1\n", "4\n", "9\n", "1\n", "1\n", "1\n", "1\n"]}
240
78
coding
Solve the programming task below in a Python markdown code block. We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right). Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target. Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed. -----Constraints----- - All values in input are integers. - 1 \leq H, W \leq 3 \times 10^5 - 1 \leq M \leq \min\left(H\times W, 3 \times 10^5\right) - 1 \leq h_i \leq H - 1 \leq w_i \leq W - \left(h_i, w_i\right) \neq \left(h_j, w_j\right) \left(i \neq j\right) -----Input----- Input is given from Standard Input in the following format: H W M h_1 w_1 \vdots h_M w_M -----Output----- Print the answer. -----Sample Input----- 2 3 3 2 2 1 1 1 3 -----Sample Output----- 3 We can destroy all the targets by placing the bomb at \left(1, 2\right).
{"inputs": ["2 3 3\n2 2\n1 1\n1 2", "2 3 3\n2 1\n1 1\n1 3", "2 3 3\n2 1\n1 1\n1 2", "2 4 3\n2 1\n1 1\n1 2", "2 3 3\n2 2\n2 1\n1 2", "4 3 3\n2 1\n1 1\n1 2", "4 3 3\n3 1\n1 1\n1 2", "8 3 3\n3 1\n1 1\n1 2"], "outputs": ["3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n"]}
347
190
coding
Solve the programming task below in a Python markdown code block. The only difference between this problem and D1 is the bound on the size of the tree. You are given an unrooted tree with $n$ vertices. There is some hidden vertex $x$ in that tree that you are trying to find. To do this, you may ask $k$ queries $v_1, v_2, \ldots, v_k$ where the $v_i$ are vertices in the tree. After you are finished asking all of the queries, you are given $k$ numbers $d_1, d_2, \ldots, d_k$, where $d_i$ is the number of edges on the shortest path between $v_i$ and $x$. Note that you know which distance corresponds to which query. What is the minimum $k$ such that there exists some queries $v_1, v_2, \ldots, v_k$ that let you always uniquely identify $x$ (no matter what $x$ is). Note that you don't actually need to output these queries. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 2\cdot10^5$) β€” the number of vertices in the tree. Each of the next $n-1$ lines contains two integers $x$ and $y$ ($1 \le x, y \le n$), meaning there is an edges between vertices $x$ and $y$ in the tree. It is guaranteed that the given edges form a tree. It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- For each test case print a single nonnegative integer, the minimum number of queries you need, on its own line. -----Examples----- Input 3 1 2 1 2 10 2 4 2 1 5 7 3 10 8 6 6 1 1 3 4 7 9 6 Output 0 1 2 -----Note----- In the first test case, there is only one vertex, so you don't need any queries. In the second test case, you can ask a single query about the node $1$. Then, if $x = 1$, you will get $0$, otherwise you will get $1$.
{"inputs": ["3\n1\n2\n1 2\n10\n2 4\n2 1\n5 7\n3 10\n8 6\n6 1\n1 3\n4 7\n9 6\n"], "outputs": ["0\n1\n2\n"]}
554
66
coding
Solve the programming task below in a Python markdown code block. You gave the twins Ai and Zu a program of games using strings. In this game, Ai and Zu each select a substring from the character string, compare them, and the person who chooses the smaller one will get points. The two competed and played the game many times. However, I got tired of playing games for the same string many times. So you decided to modify the program so that the strings change. Given a string U of length N and Q statements, write a program that processes the following instructions. * Replaces all characters in the specified range of string U with the specified characters. * Compares the two specified substrings S and T of the string U in lexicographical order and outputs their magnitude relations. Input The input is given in the following format. N U Q query1 query2 :: queryQ The string length N (1 ≀ N ≀ 200000) is given on the first line, and the string U (string containing only lowercase letters) is given on the second line. The number of instructions Q (1 ≀ Q ≀ 100000) is given on the third line. The following Q line is given the i-th instruction queryi. Each queryi is given in one of the following formats: set x y z Or comp a b c d set x y z means to replace the xth to yth characters of the string U with the specified character z. Where 1 ≀ x ≀ y ≀ N and z is lowercase. comp abcd is a string S and a string, where S is the substring from the a to b of the string U and T is the substring of the string U from the c to the d. Represents comparing T in lexical order. Where 1 ≀ a ≀ b ≀ N and 1 ≀ c ≀ d ≀ N. Output For each comp instruction, if S is smaller, "s" is output, if T is smaller, "t" is output, and if both match, "e" is output on one line. Example Input 13 aizualgorithm 9 comp 1 1 4 5 comp 2 6 1 5 set 9 12 b comp 9 9 10 10 comp 5 8 1 4 set 1 10 z set 11 13 x comp 8 10 1 5 comp 1 5 1 5 Output s t e t s e
{"inputs": ["13\naizualgorithm\n9\ncomp 1 1 4 5\ncomp 2 6 1 5\nset 9 12 b\ncomp 9 9 6 10\ncomp 5 8 1 3\nset 1 10 z\nset 11 6 x\ncomp 8 10 1 5\ncomp 1 5 2 5", "13\naozualgirithm\n9\ncomp 1 1 4 5\ncomp 2 6 1 5\nset 9 12 b\ncomp 9 9 6 10\ncomp 5 8 1 3\nset 1 10 z\nset 11 6 x\ncomp 8 10 1 5\ncomp 1 5 2 5", "13\naizualgorithm\n8\ncomp 1 1 4 5\ncomp 3 6 1 5\nset 9 12 b\ncomp 9 9 10 9\ncomp 5 8 1 4\nset 1 0 z\nset 11 13 x\ncomp 8 10 1 5\ncomp 0 5 0 0", "13\naizuaglorithm\n1\ncomp 1 1 4 5\ncomp 2 6 1 5\nset 15 12 b\ncomp 9 9 8 0\ncomp 3 8 1 4\nset 1 10 z\nset 11 4 x\ncomp 8 10 1 5\ncomp 1 5 1 5", "13\nmhtiroglauzia\n9\ncomp 1 1 4 5\ncomp 2 6 1 5\nset 4 12 b\ncomp 9 9 10 10\ncomp 5 8 1 3\nset 1 8 z\nset 11 6 x\ncomp 8 10 1 5\ncomp 1 5 2 5", "13\naizualgorithm\n9\ncomp 1 1 4 8\ncomp 2 5 2 5\nset 9 12 b\ncomp 9 9 18 10\ncomp 5 7 1 3\nset 1 6 z\nset 11 6 x\ncomp 8 10 1 6\ncomp 1 5 2 5", "13\naizualgorithm\n9\ncomp 1 1 4 5\ncomp 2 6 1 5\nset 9 12 b\ncomp 9 9 10 10\ncomp 5 8 1 3\nset 1 16 z\nset 2 6 x\ncomp 8 10 1 5\ncomp 1 5 2 5", "13\naizualgorithm\n9\ncomp 1 1 4 5\ncomp 2 6 1 5\nset 9 12 b\ncomp 9 9 10 10\ncomp 5 8 1 3\nset 1 8 z\nset 11 6 x\ncomp 8 10 1 5\ncomp 1 5 2 5"], "outputs": ["s\nt\ns\nt\ns\nt\n", "s\nt\ns\ns\ns\nt\n", "s\nt\nt\nt\nt\n", "s\n", "t\ns\ne\ns\ns\nt\n", "s\ne\nt\nt\ns\nt\n", "s\nt\ne\nt\nt\nt\n", "s\nt\ne\nt\ns\nt\n"]}
554
889
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. In one operation, select any non-negative integer x and an index i, then update nums[i] to be equal to nums[i] AND (nums[i] XOR x). Note that AND is the bitwise AND operation and XOR is the bitwise XOR operation. Return the maximum possible bitwise XOR of all elements of nums after applying the operation any number of times. Β  Please complete the following python code precisely: ```python class Solution: def maximumXOR(self, nums: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(nums = [3,2,4,6]) == 7\n assert candidate(nums = [1,2,3,9,2]) == 11\n\n\ncheck(Solution().maximumXOR)"}
132
59
coding
Solve the programming task below in a Python markdown code block. Complete the solution. It should try to retrieve the value of the array at the index provided. If the index is out of the array's max bounds then it should return the default value instead. Example: ```Haskell solution [1..3] 1 1000 `shouldBe` 2 solution [1..5] (10) 1000 `shouldBe` 1000 -- negative values work as long as they are not out of the length bounds solution [1..3] (-1) 1000 `shouldBe` 3 solution [1..3] (-5) 1000 `shouldBe` 1000 solution [1..3] (-3) 1000 `shouldBe` 1 solution [1..5] (-3) 1000 `shouldBe` 3 -- for Haskell default value will always be a (random) number, not a character. ``` ```python data = ['a', 'b', 'c'] solution(data, 1, 'd') # should == 'b' solution(data, 5, 'd') # should == 'd' # negative values work as long as they aren't out of the length bounds solution(data, -1, 'd') # should == 'c' solution(data, -5, 'd') # should == 'd' ``` Also feel free to reuse/extend the following starter code: ```python def solution(items, index, default_value): ```
{"functional": "_inputs = [[[None, None], 0, 'a']]\n_outputs = [[None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_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])"}
338
161
coding
Solve the programming task below in a Python markdown code block. Leha is a bright mathematician. Today he is investigating whether an integer is divisible by some square number or not. He has a positive integer X represented as a product of N integers a1, a2, .... aN. He has somehow figured out that there exists some integer P such that the number X is divisible by P2, but he is not able to find such P himself. Can you find it for him? If there are more than one possible values of P possible, you can print any one of them. -----Input----- The first line of the input contains an integer T denoting the number of test cases. T test cases follow. The first line of each test case contains one integer N denoting the number of intgers in presentation of X. The second line contains N space-separated integers a1, a2, .... aN. -----Output----- For each test case, output a single integer P deoting the answer for this test case. Note that P must be in range from 2 to 1018 inclusive. It's guaranteed that at least one answer exists. If there are more than one possible answers, print any. -----Constraints----- - 1 ≀ T ≀ 5 - 1 ≀ N ≀ 100 - 1 ≀ ai ≀ 1018 -----Subtasks----- - Subtask 1[19 points]: 1 ≀ a1*a2*...*aN ≀ 106 - Subtask 2[22 points]: 1 ≀ a1*a2*...*aN ≀ 1012 - Subtask 3[23 points]: 1 ≀ ai ≀ 1012 - Subtask 4[36 points]: no additional constraints -----Example----- Input: 1 3 21 11 6 Output: 3 -----Explanation----- Example case 1. X = 21 * 11 * 6 = 1386. It's divisible by 9 which is a square number, as 9 = 32. So P = 3.
{"inputs": ["1\n3\n21 11 6"], "outputs": ["3"]}
452
22
coding
Solve the programming task below in a Python markdown code block. Gru wanted to upgrade the quality of his minions' despicableness through his new base, The Volcano. Dave, desperately wanting the Minion of the Year award, rushed to The Volcano only to find out that he needs to solve a series of questions before he can unlock the gate and enter. Dave is given a prime $\mbox{P}$, and $N$ questions. In each question/query, Dave is given four integers $(A,B,C,D)$, and Dave needs to find the minimum possible value of $Ax+By$ among all positive integer pairs $(x,y)$ such that $\mbox{P}$ divides $|C^x-D^y|$. Unfortunately, the gate has a strict time limit, and if Dave is unable to answer all questions quickly and correctly, then a hidden freeze ray will zap him and he won't be able to move. Please help Dave answer all the questions so he can enter The Volcano and win the Minion of the Year award! Input Format The first line of input consists of an integer, $\mathbf{T}$, which is the number of test cases. The first line of each test case consists of two integers separated by a space, $\mbox{P}$ and $N$. The following $N$ lines contain the queries, each in a line. Each question consists of four integers separated by single spaces: $\mbox{A}$, $\mbox{B}$, $\mbox{C}$ and $\mbox{D}$. Output Format For each query, output a single line containing the minimum value of $Ax+By$, or output wala if no such pairs $(x,y)$ exist. Constraints $1\leq T\leq3$ $1\leq N\leq6000$ $2\leq P\leq10^{8}$ $0\leq A,B,C,D\leq10^8$ $\mbox{P}$ is prime Sample Input 2 7 2 1 1 1 5 7 8 8 7 11 5 1 1 1 1 0 1 2 3 3 2 1 0 9 8 7 6 0 0 1 1 Sample Output 7 wala 2 1 wala 33 0 Explanation For the first query, $P=7$, $(A,B,C,D)=(1,1,1,5)$, the minimum $1x+1y$ is $7$, which occurs at $(x,y)=(1,6)$ ($7$ divides $\left|1^1-5^6\right|=15624=7\cdot2232$). For the second query, no matter what $(x,y)$ you choose, $|8^x-7^y|$ will not by divisible by $7$, so the answer is wala.
{"inputs": ["2\n7 2\n1 1 1 5\n7 8 8 7\n11 5\n1 1 1 1\n0 1 2 3\n3 2 1 0\n9 8 7 6\n0 0 1 1\n"], "outputs": ["7\nwala\n2\n1\nwala\n33\n0\n"]}
644
94
coding
Solve the programming task below in a Python markdown code block. Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a_1, a_2, ..., a_{n} of n integer numbers β€” saturation of the color of each pencil. Now Mishka wants to put all the mess in the pack in order. He has an infinite number of empty boxes to do this. He would like to fill some boxes in such a way that: Each pencil belongs to exactly one box; Each non-empty box has at least k pencils in it; If pencils i and j belong to the same box, then |a_{i} - a_{j}| ≀ d, where |x| means absolute value of x. Note that the opposite is optional, there can be pencils i and j such that |a_{i} - a_{j}| ≀ d and they belong to different boxes. Help Mishka to determine if it's possible to distribute all the pencils into boxes. Print "YES" if there exists such a distribution. Otherwise print "NO". -----Input----- The first line contains three integer numbers n, k and d (1 ≀ k ≀ n ≀ 5Β·10^5, 0 ≀ d ≀ 10^9) β€” the number of pencils, minimal size of any non-empty box and maximal difference in saturation between any pair of pencils in the same box, respectively. The second line contains n integer numbers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9) β€” saturation of color of each pencil. -----Output----- Print "YES" if it's possible to distribute all the pencils into boxes and satisfy all the conditions. Otherwise print "NO". -----Examples----- Input 6 3 10 7 2 7 7 4 2 Output YES Input 6 2 3 4 5 3 13 4 10 Output YES Input 3 2 5 10 16 22 Output NO -----Note----- In the first example it is possible to distribute pencils into 2 boxes with 3 pencils in each with any distribution. And you also can put all the pencils into the same box, difference of any pair in it won't exceed 10. In the second example you can split pencils of saturations [4, 5, 3, 4] into 2 boxes of size 2 and put the remaining ones into another box.
{"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 1 0\n1\n", "3 2 2\n6 7 7\n", "3 2 2\n6 7 7\n", "3 2 3\n6 7 7\n", "4 2 3\n1 2 3 6\n", "4 2 1\n1 1 2 3\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
562
142
coding
Solve the programming task below in a Python markdown code block. In this kata you will have to change every letter in a given string to the next letter in the alphabet. You will write a function `nextLetter` to do this. The function will take a single parameter `s` (string). Examples: ``` "Hello" --> "Ifmmp" "What is your name?" --> "Xibu jt zpvs obnf?" "zoo" --> "app" "zzZAaa" --> "aaABbb" ``` Note: spaces and special characters should remain the same. Capital letters should transfer in the same way but remain capitilized. Also feel free to reuse/extend the following starter code: ```python def next_letter(s): ```
{"functional": "_inputs = [['Hello'], ['What is your name?'], ['zOo']]\n_outputs = [['Ifmmp'], ['Xibu jt zpvs obnf?'], ['aPp']]\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(next_letter(*i), o[0])"}
157
184
coding
Solve the programming task below in a Python markdown code block. Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off. Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b_1, b_2, ..., b_{m} (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button b_{i} is actually b_{i}, not i. Please, help Mashmokh, print these indices. -----Input----- The first line of the input contains two space-separated integers n and m (1 ≀ n, m ≀ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b_1, b_2, ..., b_{m}Β (1 ≀ b_{i} ≀ n). It is guaranteed that all lights will be turned off after pushing all buttons. -----Output----- Output n space-separated integers where the i-th number is index of the button that turns the i-th light off. -----Examples----- Input 5 4 4 3 1 2 Output 1 1 3 4 4 Input 5 5 5 4 3 2 1 Output 1 2 3 4 5 -----Note----- In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.
{"inputs": ["1 1\n1\n", "1 1\n1\n", "2 1\n1\n", "5 4\n4 3 1 2\n", "5 4\n2 3 4 1\n", "5 4\n2 3 4 1\n", "5 4\n3 3 4 1\n", "35 3\n6 1 11\n"], "outputs": ["1 \n", "1\n", "1 1 ", "1 1 3 4 4 \n", "1 2 2 2 2 \n", "1 2 2 2 2\n", "1 1 3 3 3 ", "1 1 1 1 1 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 "]}
507
235
coding
Solve the programming task below in a Python markdown code block. Consider the following series: `1, 2, 4, 8, 16, 22, 26, 38, 62, 74, 102, 104, 108, 116, 122` It is generated as follows: * For single digit integers, add the number to itself to get the next element. * For other integers, multiply all the non-zero digits and add the result to the original number to get the next element. For example: `16 + (6 * 1) = 22` and `104 + (4 * 1) = 108`. Let's begin the same series with a seed value of `3` instead of `1`: `3, 6, 12, 14, 18, 26, 38, 62, 74, 102, 104, 108, 116, 122` Notice that the two sequences converge at `26` and are identical therefter. We will call the series seeded by a value of `1` the "base series" and the other series the "test series". You will be given a seed value for the test series and your task will be to return the number of integers that have to be generated in the test series before it converges to the base series. In the case above: ```Python convergence(3) = 5, the length of [3, 6, 12, 14, 18]. ``` Good luck! If you like this Kata, please try: [Simple Prime Streaming](https://www.codewars.com/kata/5a908da30025e995880000e3) [Unique digit sequence](https://www.codewars.com/kata/599688d0e2800dda4e0001b0) [Divisor harmony](https://www.codewars.com/kata/59bf97cd4f98a8b1cd00007e) Also feel free to reuse/extend the following starter code: ```python def convergence(n): ```
{"functional": "_inputs = [[3], [5], [10], [15], [500], [5000]]\n_outputs = [[5], [6], [5], [2], [29], [283]]\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(convergence(*i), o[0])"}
515
194
coding
Solve the programming task below in a Python markdown code block. How many multiples of d are there among the integers between L and R (inclusive)? Constraints * All values in input are integers. * 1 \leq L \leq R \leq 100 * 1 \leq d \leq 100 Input Input is given from Standard Input in the following format: L R d Output Print the number of multiples of d among the integers between L and R (inclusive). Examples Input 5 10 2 Output 3 Input 6 20 7 Output 2 Input 1 100 1 Output 100
{"inputs": ["5 4 1", "2 4 1", "2 3 1", "2 8 1", "2 5 1", "5 4 2", "2 2 1", "9 20 7"], "outputs": ["0\n", "3\n", "2\n", "7\n", "4\n", "0\n", "1\n", "1\n"]}
153
95
coding
Solve the programming task below in a Python markdown code block. Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position). Inserting an element in the same position he was erased from is also considered moving. Can Vasya divide the array after choosing the right element to move and its new position? -----Input----- The first line contains single integer n (1 ≀ n ≀ 100000) β€” the size of the array. The second line contains n integers a_1, a_2... a_{n} (1 ≀ a_{i} ≀ 10^9) β€” the elements of the array. -----Output----- Print YES if Vasya can divide the array after moving one element. Otherwise print NO. -----Examples----- Input 3 1 3 2 Output YES Input 5 1 2 3 4 5 Output NO Input 5 2 2 3 4 5 Output YES -----Note----- In the first example Vasya can move the second element to the end of the array. In the second example no move can make the division possible. In the third example Vasya can move the fourth element by one position to the left.
{"inputs": ["1\n1\n", "1\n2\n", "1\n1\n", "1\n2\n", "1\n8\n", "1\n4\n", "1\n10\n", "1\n10\n"], "outputs": ["NO\n", "NO\n", "NO", "NO", "NO\n", "NO\n", "NO\n", "NO"]}
336
85
coding
Solve the programming task below in a Python markdown code block. #Unflatten a list (Easy) There are several katas like "Flatten a list". These katas are done by so many warriors, that the count of available list to flattin goes down! So you have to build a method, that creates new arrays, that can be flattened! #Shorter: You have to unflatten a list/an array. You get an array of integers and have to unflatten it by these rules: ``` - You start at the first number. - If this number x is smaller than 3, take this number x direct for the new array and continue with the next number. - If this number x is greater than 2, take the next x numbers (inclusive this number) as a sub-array in the new array. Continue with the next number AFTER this taken numbers. - If there are too few numbers to take by number, take the last available numbers. ``` The given array will always contain numbers. There will only be numbers > 0. Example: ``` [1,4,5,2,1,2,4,5,2,6,2,3,3] -> [1,[4,5,2,1],2,[4,5,2,6],2,[3,3]] Steps: 1. The 1 is added directly to the new array. 2. The next number is 4. So the next 4 numbers (4,5,2,1) are added as sub-array in the new array. 3. The 2 is added directly to the new array. 4. The next number is 4. So the next 4 numbers (4,5,2,6) are added as sub-array in the new array. 5. The 2 is added directly to the new array. 6. The next number is 3. So the next 3 numbers would be taken. There are only 2, so take these (3,3) as sub-array in the new array. ``` There is a harder version of this kata! Unflatten a list (Harder than easy) Have fun coding it and please don't forget to vote and rank this kata! :-) I have created other katas. Have a look if you like coding and challenges. Also feel free to reuse/extend the following starter code: ```python def unflatten(flat_array): ```
{"functional": "_inputs = [[[3, 5, 2, 1]], [[1, 4, 5, 2, 1, 2, 4, 5, 2, 6, 2, 3, 3]], [[1, 1, 1, 1]], [[1]], [[99, 1, 1, 1]], [[3, 1, 1, 3, 1, 1]]]\n_outputs = [[[[3, 5, 2], 1]], [[1, [4, 5, 2, 1], 2, [4, 5, 2, 6], 2, [3, 3]]], [[1, 1, 1, 1]], [[1]], [[[99, 1, 1, 1]]], [[[3, 1, 1], [3, 1, 1]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(unflatten(*i), o[0])"}
512
346
coding
Solve the programming task below in a Python markdown code block. We define the diameter of a strongly-connected oriented graph, $G=(V,E)$, as the minimum integer $\boldsymbol{d}$ such that for each $u,v\in G$ there is a path from $\mbox{u}$ to $v$ of length $\leq d$ (recall that a path's length is its number of edges). Given two integers, $n$ and $m$, build a strongly-connected oriented graph with $n$ vertices where each vertex has outdegree $m$ and the graph's diameter is as small as possible (see the Scoring section below for more detail). Then print the graph according to the Output Format specified below. Here's a sample strongly-connected oriented graph with $3$ nodes, whose outdegree is $2$ and diameter is $1$. Note: Cycles and multiple edges between vertices are allowed. Input Format Two space-separated integers describing the respective values of $n$ (the number of vertices) and $m$ (the outdegree of each vertex). Constraints $2\leq n\leq1000$ $2\leq m\leq\text{min}(n,5)$ Scoring We denote the diameter of your graph as $\boldsymbol{d}$ and the diameter of the graph in the author's solution as $\boldsymbol{\mathrm{~S~}}$. Your score for each test case (as a real number from $0$ to $\mbox{I}$) is: $1$ if $d\leq s+1$ $\frac{\mbox{s}}{d}$ if $s+1<d\leq5\times s$ $0$ if $5\times s<d$ Output Format First, print an integer denoting the diameter of your graph on a new line. Next, print $n$ lines where each line $\boldsymbol{i}$ ($0\leq i<n$) contains $m$ space-separated integers in the inclusive range from $0$ to $n-1$ describing the endpoints for each of vertex $\boldsymbol{i}$'s outbound edges. Sample Input 0 5 2 Sample Output 0 2 1 4 2 0 3 1 4 2 0 3 Explanation 0 The diagram below depicts a strongly-connected oriented graph with $n=5$ nodes where each node has an outdegree of $m=2$: The diameter of this graph is $\boldsymbol{d}=2$, which is minimal as the outdegree of each node must be $m$. We cannot construct a graph with a smaller diameter of $\boldsymbol{d}=1$ because it requires an outbound edge from each vertex to each other vertex in the graph (so the outdegree of that graph would be $n-1$).
{"inputs": ["5 2\n"], "outputs": ["2\n1 4\n2 0\n3 1\n4 2\n0 3\n"]}
606
36
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef has a simple undirected graph with $N$ vertices (numbered $1$ through $N$) and $M$ edges. He wants to divide it into $K$ parts (subgraphs) for some integer $K$. First, Chef divides the vertices in the graph into $K$ sets such that each vertex belongs to exactly one set; the subgraphs and sets are numbered $1$ through $K$ such that for each valid $i$, vertices from the $i$-th set belong to the $i$-th subgraph. Then, Chef checks all the edges in the graph. For an edge connecting vertices $u$ and $v$, if $u$ and $v$ are both in the $i$-th set, then this edge belongs to the $i$-th subgraph. Otherwise, this edge does not belong to any of these $K$ subgraphs. At the end, Chef checks these $K$ subgraphs. If each subgraph contains an even number of edges, then Chef thinks that this way of dividing the graph is *delicious*. Chef wants to divide the graph in a delicious way such that $K$ is the smallest possible. Find the minimum $K$ and one such way to divide the graph. ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first line of each test case contains two space-separated integers $N$ and $M$. Each of the next $M$ lines contains two space-separated integers $u$ and $v$ denoting that vertices $u$ and $v$ are connected by an edge. ------ Output ------ For each test case, print two lines. The first of these lines should contain a single integer ― the minimum $K$. The second line should contain $N$ space-separated integers, where for each valid $i$, the $i$-th integer denotes the subgraph that vertex $i$ belongs to. If there are multiple solutions, you may output any one. ------ Constraints ------ $1 ≀ T ≀ 3,000$ $1 ≀ M ≀ 100,000$ $2 ≀ N ≀ 100,000$ $1 ≀ u \neq v ≀ N$ the graph contains no duplicate edges or self-loops the sum of $N$ over all test cases does not exceed $10^{6}$ the sum of $M$ over all test cases does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (30 pts): $2 ≀ N ≀ 10$ Subtask #2 (70 pts): original constraints ----- Sample Input 1 ------ 1 5 5 1 2 1 3 2 3 2 4 3 4 ----- Sample Output 1 ------ 2 1 2 1 1 2 ----- explanation 1 ------ Example case 1: Subgraph $1$ contains vertices $1$, $3$, $4$ and edges $(1,3)$ and $(3,4)$. Subgraph $2$ contains vertices $2$ and $5$, but no edges.
{"inputs": ["1\n5 5\n1 2\n1 3\n2 3\n2 4\n3 4"], "outputs": ["2\n1 2 1 1 2"]}
735
46
coding
Solve the programming task below in a Python markdown code block. One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him? -----Input----- The single line of the input contains two positive integers a and b (1 ≀ a, b ≀ 100) β€” the number of red and blue socks that Vasya's got. -----Output----- Print two space-separated integers β€” the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. -----Examples----- Input 3 1 Output 1 1 Input 2 3 Output 2 0 Input 7 3 Output 3 2 -----Note----- In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
{"inputs": ["3 1\n", "2 3\n", "7 3\n", "1 1\n", "1 1\n", "2 1\n", "2 0\n", "7 5\n"], "outputs": ["1 1\n", "2 0\n", "3 2\n", "1 0\n", "1 0\n", "1 0\n", "0 1\n", "5 1\n"]}
364
102
coding
Solve the programming task below in a Python markdown code block. The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular phone) and every phone connects to the BTS with the strongest signal (in a little simplified view). Of course, BTSes need some attention and technicians need to check their function periodically. The technicians faced a very interesting problem recently. Given a set of BTSes to visit, they needed to find the shortest path to visit all of the given points and return back to the central company building. Programmers have spent several months studying this problem but with no results. They were unable to find the solution fast enough. After a long time, one of the programmers found this problem in a conference article. Unfortunately, he found that the problem is so called "Traveling Salesman Problem" and it is very hard to solve. If we have $N$ BTSes to be visited, we can visit them in any order, giving us $N!$ possibilities to examine. The function expressing that number is called factorial and can be computed as a product: $1.2.3.4....N$. The number is very high even for a relatively small $N$. The programmers understood they had no chance to solve the problem. But because they have already received the research grant from the government, they needed to continue with their studies and produce at least some results. So they started to study behaviour of the factorial function. For example, they defined the function $Z$. For any positive integer $N$, $Z$($N$) is the number of zeros at the end of the decimal form of number $N!$. They noticed that this function never decreases. If we have two numbers $N_{1} < N_{2}$ then $Z(N_{1}) ≀ Z(N_{2})$. It is because we can never "lose" any trailing zero by multiplying by any positive number. We can only get new and new zeros. The function $Z$ is very interesting, so we need a computer program that can determine its value efficiently. ------ Input: ------ There is a single positive integer $T$ on the first line of input (equal to about $100000$). It stands for the number of numbers to follow. Then there are $T$ lines, each containing exactly one positive integer number $N$, $1 ≀ N ≀ 10^{9}$. ------ Output: ------ For every number $N$, output a single line containing the single non-negative integer $Z(N)$. ----- Sample Input 1 ------ 6 3 60 100 1024 23456 8735373 ----- Sample Output 1 ------ 0 14 24 253 5861 2183837
{"inputs": ["6\n2\n188\n100\n415\n571\n92075", "6\n2\n188\n100\n415\n571\n216675", "6\n1\n37\n110\n671\n28\n11057064", "6\n1\n37\n110\n671\n36\n11057064", "6\n2\n37\n100\n671\n36\n11057064", "6\n3\n71\n100\n287\n4581\n8735373", "6\n8\n2\n100\n637\n31879\n8735373", "6\n3\n100\n100\n287\n351\n8735373"], "outputs": ["0\n45\n24\n102\n140\n23016\n", "0\n45\n24\n102\n140\n54165\n", "0\n8\n26\n166\n6\n2764261\n", "0\n8\n26\n166\n8\n2764261\n", "0\n8\n24\n166\n8\n2764261\n", "0\n16\n24\n70\n1143\n2183837\n", "1\n0\n24\n158\n7968\n2183837\n", "0\n24\n24\n70\n86\n2183837\n"]}
619
425
coding
Solve the programming task below in a Python markdown code block. Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high. At the beginning of the first experiment there is a single bacterium in the test tube. Every second each bacterium in the test tube divides itself into k bacteria. After that some abnormal effects create b more bacteria in the test tube. Thus, if at the beginning of some second the test tube had x bacteria, then at the end of the second it will have kx + b bacteria. The experiment showed that after n seconds there were exactly z bacteria and the experiment ended at this point. For the second experiment Qwerty is going to sterilize the test tube and put there t bacteria. He hasn't started the experiment yet but he already wonders, how many seconds he will need to grow at least z bacteria. The ranger thinks that the bacteria will divide by the same rule as in the first experiment. Help Qwerty and find the minimum number of seconds needed to get a tube with at least z bacteria in the second experiment. Input The first line contains four space-separated integers k, b, n and t (1 ≀ k, b, n, t ≀ 106) β€” the parameters of bacterial growth, the time Qwerty needed to grow z bacteria in the first experiment and the initial number of bacteria in the second experiment, correspondingly. Output Print a single number β€” the minimum number of seconds Qwerty needs to grow at least z bacteria in the tube. Examples Input 3 1 3 5 Output 2 Input 1 4 4 7 Output 3 Input 2 2 4 100 Output 0
{"inputs": ["5 5 2 1\n", "1 1 2 2\n", "1 1 1 1\n", "3 1 3 4\n", "1 4 1 5\n", "5 4 1 4\n", "2 3 4 5\n", "2 2 5 4\n"], "outputs": ["2\n", "1\n", "1\n", "2\n", "0\n", "1\n", "3\n", "4\n"]}
390
118
coding
Solve the programming task below in a Python markdown code block. There are $n$ participants in a competition, participant $i$ having a strength of $s_i$. Every participant wonders how much of an advantage they have over the other best participant. In other words, each participant $i$ wants to know the difference between $s_i$ and $s_j$, where $j$ is the strongest participant in the competition, not counting $i$ (a difference can be negative). So, they ask you for your help! For each $i$ ($1 \leq i \leq n$) output the difference between $s_i$ and the maximum strength of any participant other than participant $i$. -----Input----- The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β€” the number of test cases. The descriptions of the test cases follow. The first line of each test case contains an integer $n$ ($2 \leq n \leq 2\cdot10^5$) β€” the length of the array. The following line contains $n$ space-separated positive integers $s_1$, $s_2$, ..., $s_n$ ($1 \leq s_i \leq 10^9$) β€” the strengths of the participants. It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- For each test case, output $n$ space-separated integers. For each $i$ ($1 \leq i \leq n$) output the difference between $s_i$ and the maximum strength of any other participant. -----Examples----- Input 5 4 4 7 3 5 2 1 2 5 1 2 3 4 5 3 4 9 4 4 4 4 4 4 Output -3 2 -4 -2 -1 1 -4 -3 -2 -1 1 -5 5 -5 0 0 0 0 -----Note----- For the first test case: The first participant has a strength of $4$ and the largest strength of a participant different from the first one is $7$, so the answer for the first participant is $4 - 7 = -3$. The second participant has a strength of $7$ and the largest strength of a participant different from the second one is $5$, so the answer for the second participant is $7 - 5 = 2$. The third participant has a strength of $3$ and the largest strength of a participant different from the third one is $7$, so the answer for the third participant is $3 - 7 = -4$. The fourth participant has a strength of $5$ and the largest strength of a participant different from the fourth one is $7$, so the answer for the fourth participant is $5 - 7 = -2$.
{"inputs": ["5\n4\n4 7 3 5\n2\n1 2\n5\n1 2 3 4 5\n3\n4 9 4\n4\n4 4 4 4\n", "1\n23\n1 2 3 4 5 6 7 8 9 10 11 12 13 1 1 1 1 1 1 1 1 1 1\n"], "outputs": ["-3 2 -4 -2 \n-1 1 \n-4 -3 -2 -1 1 \n-5 5 -5 \n0 0 0 0 \n", "-12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 1 -12 -12 -12 -12 -12 -12 -12 -12 -12 -12 \n"]}
644
222
coding
Solve the programming task below in a Python markdown code block. In this challenge, the user enters a string and a substring. You have to print the number of times that the substring occurs in the given string. String traversal will take place from left to right, not from right to left. NOTE: String letters are case-sensitive. Input Format The first line of input contains the original string. The next line contains the substring. Constraints $1\leq len(string)\leq200$ Each character in the string is an ascii character. Output Format Output the integer number indicating the total number of occurrences of the substring in the original string. Sample Input ABCDCDC CDC Sample Output 2 Concept Some string processing examples, such as these, might be useful. There are a couple of new concepts: In Python, the length of a string is found by the function len(s), where $\boldsymbol{\mathrm{~S~}}$ is the string. To traverse through the length of a string, use a for loop: for i in range(0, len(s)): print (s[i]) A range function is used to loop over some length: range (0, 5) Here, the range loops over $\mbox{o}$ to $\begin{array}{c}A\end{array}$. $5$ is excluded.
{"inputs": ["ABCDCDC\nCDC\n"], "outputs": ["2\n"]}
292
18
coding
Solve the programming task below in a Python markdown code block. Given a number, write a function to output its reverse digits. (e.g. given 123 the answer is 321) Numbers should preserve their sign; i.e. a negative number should still be negative when reversed. ### Examples ``` 123 -> 321 -456 -> -654 1000 -> 1 ``` Also feel free to reuse/extend the following starter code: ```python def reverse_number(n): ```
{"functional": "_inputs = [[123], [-123], [1000], [4321234], [5], [0], [98989898]]\n_outputs = [[321], [-321], [1], [4321234], [5], [0], [89898989]]\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(reverse_number(*i), o[0])"}
121
227
coding
Solve the programming task below in a Python markdown code block. Johnny was asked by his math teacher to compute nn (n to the power of n, where n is an integer), and has to read his answer out loud. This is a bit of a tiring task, since the result is probably an extremely large number, and would certainly keep Johnny occupied for a while if he were to do it honestly. But Johnny knows that the teacher will certainly get bored when listening to his answer, and will sleep through most of it! So, Johnny feels he will get away with reading only the first k digits of the result before the teacher falls asleep, and then the last k digits when the teacher wakes up. Write a program to help Johnny to compute the digits he will need to read out. -----Input----- The first line contains t, the number of test cases (about 30000). Then t test cases follow. Each test case consists of one line containing two numbers n and k (1 ≀ n ≀ 109, 1 ≀ k ≀ 9). It is guaranteed that k is not more than the number of digits of nn. -----Output----- For each test case, print out one line containing two numbers, separated by a space, which are the first and the last k digits of nn. -----Example----- Input 2 4 2 9 3 Output 25 56 387 489
{"inputs": ["2\n4 2\n9 3"], "outputs": ["25 56\n387 489"]}
299
32
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that: 0 <= a, b, c, dΒ < n a, b, c, and d are distinct. nums[a] + nums[b] + nums[c] + nums[d] == target You may return the answer in any order. Β  Please complete the following python code precisely: ```python class Solution: def fourSum(self, nums: List[int], target: int) -> List[List[int]]: ```
{"functional": "def check(candidate):\n assert candidate(nums = [1,0,-1,0,-2,2], target = 0) == [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]\n assert candidate(nums = [2,2,2,2,2], target = 8) == [[2,2,2,2]]\n\n\ncheck(Solution().fourSum)"}
139
104
coding
Solve the programming task below in a Python markdown code block. Consider a list (list = []). You can perform the following commands: insert i e: Insert integer $\boldsymbol{\mathrm{~e~}}$ at position $\boldsymbol{i}$. print: Print the list. remove e: Delete the first occurrence of integer $\boldsymbol{\mathrm{~e~}}$. append e: Insert integer $\boldsymbol{\mathrm{~e~}}$ at the end of the list. sort: Sort the list. pop: Pop the last element from the list. reverse: Reverse the list. Initialize your list and read in the value of $n$ followed by $n$ lines of commands where each command will be of the $7$ types listed above. Iterate through each command in order and perform the corresponding operation on your list. Example $N=4$ $append 1$ $append 2$ $insert 3 1$ $print$ $append 1$: Append $\mbox{I}$ to the list, $arr=[1]$. $append 2$: Append $2$ to the list, $arr=[1,2]$. $insert 3 1$: Insert $3$ at index $\mbox{I}$, $arr=[1,3,2]$. $print$: Print the array. Output: [1, 3, 2] Input Format The first line contains an integer, $n$, denoting the number of commands. Each line $\boldsymbol{i}$ of the $n$ subsequent lines contains one of the commands described above. Constraints The elements added to the list must be integers. Output Format For each command of type print, print the list on a new line. Sample Input 0 12 insert 0 5 insert 1 10 insert 0 6 print remove 6 append 9 append 1 sort print pop reverse print Sample Output 0 [6, 5, 10] [1, 5, 9, 10] [9, 5, 1]
{"inputs": ["12\ninsert 0 5\ninsert 1 10\ninsert 0 6\nprint\nremove 6\nappend 9\nappend 1\nsort\nprint\npop\nreverse\nprint\n"], "outputs": ["[6, 5, 10]\n[1, 5, 9, 10]\n[9, 5, 1]\n"]}
462
91
coding
Solve the programming task below in a Python markdown code block. AquaMoon has n friends. They stand in a row from left to right, and the i-th friend from the left wears a T-shirt with a number a_i written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of n friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≀ t ≀ 50) β€” the number of test cases. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of Aquamoon's friends. The second line contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^5) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of n for all test cases does not exceed 10^5. Output For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). Example Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO Note The possible list of operations in the first test case: 1. Swap a_1 and a_2. The resulting sequence is 3, 4, 2, 5. The directions are: left, left, right, right. 2. Swap a_2 and a_3. The resulting sequence is 3, 2, 4, 5. The directions are: left, left, right, right. 3. Swap a_1 and a_2. The resulting sequence is 2, 3, 4, 5. The directions are: right, right, right, right.
{"inputs": ["1\n2\n4 3\n", "1\n2\n9 8\n", "1\n2\n6 5\n", "1\n2\n4 8\n", "1\n2\n7 8\n", "1\n2\n10 8\n", "1\n3\n6 5 4\n", "1\n3\n3 2 2\n"], "outputs": ["NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n"]}
537
123
coding
Solve the programming task below in a Python markdown code block. Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems. Determine the index of day when Polycarp will celebrate the equator. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 200\,000$) β€” the number of days to prepare for the programming contests. The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. -----Output----- Print the index of the day when Polycarp will celebrate the equator. -----Examples----- Input 4 1 3 2 1 Output 2 Input 6 2 2 2 2 2 2 Output 3 -----Note----- In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $6$ out of $12$ scheduled problems on six days of the training.
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "2\n1 3\n", "2\n1 2\n", "2\n3 4\n", "2\n2 3\n", "2\n6 7\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
405
96
coding
Solve the programming task below in a Python markdown code block. Given an array of ints, return the index such that the sum of the elements to the right of that index equals the sum of the elements to the left of that index. If there is no such index, return `-1`. If there is more than one such index, return the left-most index. For example: ``` peak([1,2,3,5,3,2,1]) = 3, because the sum of the elements at indexes 0,1,2 == sum of elements at indexes 4,5,6. We don't sum index 3. peak([1,12,3,3,6,3,1]) = 2 peak([10,20,30,40]) = -1 ``` The special case of an array of zeros (for instance `[0,0,0,0]`) will not be tested. More examples in the test cases. Good luck! Please also try [Simple time difference](https://www.codewars.com/kata/5b76a34ff71e5de9db0000f2) Also feel free to reuse/extend the following starter code: ```python def peak(arr): ```
{"functional": "_inputs = [[[1, 2, 3, 5, 3, 2, 1]], [[1, 12, 3, 3, 6, 3, 1]], [[10, 20, 30, 40]]]\n_outputs = [[3], [2], [-1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(peak(*i), o[0])"}
274
216
coding
Solve the programming task below in a Python markdown code block. ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≀ c, just the new word is appended to other words on the screen. If b - a > c, then everything on the screen disappears and after that the word you have typed appears on the screen. For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen. You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything. -----Input----- The first line contains two integers n and c (1 ≀ n ≀ 100 000, 1 ≀ c ≀ 10^9)Β β€” the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t_1, t_2, ..., t_{n} (1 ≀ t_1 < t_2 < ... < t_{n} ≀ 10^9), where t_{i} denotes the second when ZS the Coder typed the i-th word. -----Output----- Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second t_{n}. -----Examples----- Input 6 5 1 3 8 14 19 20 Output 3 Input 6 1 1 3 5 7 9 10 Output 2 -----Note----- The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≀ 1.
{"inputs": ["2 1\n1 2\n", "2 1\n1 2\n", "2 0\n1 2\n", "2 0\n1 3\n", "2 1\n1 100\n", "2 1\n1 100\n", "2 1\n2 100\n", "2 0\n1 100\n"], "outputs": ["2", "2\n", "1\n", "1\n", "1", "1\n", "1\n", "1\n"]}
566
124
coding
Solve the programming task below in a Python markdown code block. Chef is playing Ludo. According to the rules of Ludo, a player can enter a new token into the play only when he rolls a 6 on the die. In the current turn, Chef rolled the number X on the die. Determine if Chef can enter a new token into the play in the current turn or not. ------ 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 one integer X β€” the number rolled by the Chef on the die. ------ Output Format ------ For each test case, output YES if the Chef can enter a new token in the game. Otherwise, output NO. You may print each character of YES and NO in uppercase or lowercase (for example, yes, yEs, Yes will be considered identical). ------ Constraints ------ $1 ≀T ≀6$ $1 ≀X ≀6$ ----- Sample Input 1 ------ 3 1 6 3 ----- Sample Output 1 ------ NO YES NO ----- explanation 1 ------ Test Case 1: Since Chef did not roll a $6$, he can not enter a new token in the play. Test Case 2: Since Chef rolled a $6$, he can enter a new token in the play.
{"inputs": ["3\n1\n6\n3\n"], "outputs": ["NO\nYES\nNO\n"]}
288
24
coding
Solve the programming task below in a Python markdown code block. You are looking for a place to park your car on a wall street. You can park at any position that meets the following requirements: 1. It is not directly in front of a private driveway. 2. It is not directly in front of a bus stop. 3. It is not 5 meters before a bus stop. 4. It is not 10 meters before a bus stop. 5. It is not directly in front of a side-street. 6. It is not 5 meters before a side-street. 7. It is not 5 meters after a side-street. The street will be represented as a string, where each character describes a section of the street 5 meters in length. So the first character describes the first 5 meters of the street, the second character describes the next 5 meters and so on. street will use 'D' for driveway, 'B' for bus stop, 'S' for side-street and '-' for all other sections of the street. A position is directly in front of an object if it has the same index as the object in street. A position is before an object if its index is lower than the index of the object in street. Finally, a position is after an object if its index is higher than the index of the object in street. Given the street print the total number of possible parking spaces on that street. Input: First line contains no. of testcases and each testcase contains a string street. Output: Print the total number of possible parking spaces on that street. SAMPLE INPUT 3 ---B--S-D--S-- DDBDDBDDBDD --S--S--S--S-- SAMPLE OUTPUT 4 0 2 Explanation Testcase 1: The street looks like this: ---B--S-D--S-- You are allowed to park on position 0,4,9,13 on this street. Thus the output should be 4. Testcase 2: This street is full of private driveways and bus stops. You cannot park anywhere on this street. The output should be 0. Testcase 3: You can only park at the first and last positions on this street. The output should be 2.
{"inputs": ["46\n---B--S-D--S--\nDDBDDBDDBDD\n--S--S--S--S--\nSSD-B---BD-DDSB-----S-S--------S-B----BSB-S--B-S-D\n-SB---S----DD-D-DS---B--BD-S-SD---D----D-B---B-SDD\n------BB-----D--------S--D-BSSS-----B---S-S-SSS---\n----------S--S----D---------SD---DD--D---DSB-B----\n-S---------DDDB---BB----SSD---D-B---S-B-----DD---S\n-D--B---BD-D--------S---DS-SS-S-B-SBB---B--D--BS--\n------DD--S--D--S-S-DSS---B--D--S---B----S----DD-\n-D--B---DS-----B-----S-B--------------B-B-S----DB-\n---D--D---SDB-S-B--SSD-S---D-------SB------D------\n----B---D-S------S-S------DD---SS-B----DD-D-------\nDDDDDDDDDDDDDDDDDD\nD\nB\nS\n-\n--------------------\nSSSSSSSSSSSSSSSSSSSSSSS\nBBBBBBBBBBBBBBBBBB\n-DD-BDDD---B-DSBD---S-B--S--DDS-D-DBSBBDDD-S------\n---D-DDS---SDS---------B-B-D-D-B-DB--S--BD-SDDSB-D\nD--------DBBSBDSBB-------------DBS-DB-S-B--B----S-\n-D--BB-SD-D-B-DDD--B--DBB-S-BB-D-SDBD-------S--B-B\nSD-D-DS-DDD---------BS-SS-D-DD----S--DB---DDBDD---\nB--D-B--D---S-BDDD-D-----D---D---SB--D-B---DBB----\n--S-DDDSDSB--B-DSS----DD----BBBSD---BSD-B-BB-B-SB-\nB-S-D---D-S----DSDBDBD-BDBDD---D-S---DS-DSSS-BDS-\nBDS-D-B-DSB-DSB-BSBD--DS--SB-S-D-SB--BS--B-DB-BD-B\n-SDBS-DBB----SBSSDD--BB---B-DB-DS-DS--DD---DB--D-D\nB--\n--B\nS--\n--S\nD--\n--D\n-S-\n--------------------------------------------------\n-BBBBBBBBB\n-BDDDDDD\nSSD-B---BD----DD--D--SSDB-\n--B--B--B--B--B\n-B\n-\nS-B"], "outputs": ["4\n0\n2\n14\n15\n23\n32\n24\n16\n19\n25\n28\n28\n0\n0\n0\n0\n1\n20\n0\n0\n12\n15\n22\n11\n19\n25\n9\n11\n4\n11\n2\n0\n1\n1\n2\n2\n0\n50\n0\n0\n9\n0\n0\n1\n0"]}
485
734
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the root of a binary tree with n nodes where each node in the tree has node.val coins. There are n coins in total throughout the whole tree. In one move, we may choose two adjacent nodes and move one coin from one node to another. A move may be from parent to child, or from child to parent. Return the minimum number of moves required to make every node have exactly one coin. Β  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 distributeCoins(self, root: Optional[TreeNode]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(root = tree_node([3,0,0])) == 2\n assert candidate(root = tree_node([0,3,0])) == 3\n\n\ncheck(Solution().distributeCoins)"}
185
56
coding
Solve the programming task below in a Python markdown code block. You are given two non-empty strings $s$ and $t$, consisting of Latin letters. In one move, you can choose an occurrence of the string $t$ in the string $s$ and replace it with dots. Your task is to remove all occurrences of the string $t$ in the string $s$ in the minimum number of moves, and also calculate how many different sequences of moves of the minimum length exist. Two sequences of moves are considered different if the sets of indices at which the removed occurrences of the string $t$ in $s$ begin differ. For example, the sets $\{1, 2, 3\}$ and $\{1, 2, 4\}$ are considered different, the sets $\{2, 4, 6\}$ and $\{2, 6\}$ β€” too, but sets $\{3, 5\}$ and $\{5, 3\}$ β€” not. For example, let the string $s =$ "abababacababa" and the string $t =$ "aba". We can remove all occurrences of the string $t$ in $2$ moves by cutting out the occurrences of the string $t$ at the $3$th and $9$th positions. In this case, the string $s$ is an example of the form "ab...bac...ba". It is also possible to cut occurrences of the string $t$ at the $3$th and $11$th positions. There are two different sequences of minimum length moves. Since the answer can be large, output it modulo $10^9 + 7$. -----Input----- The first line of the input contains a single integer $q$ ($1 \le q \le 50$) β€” the number of test cases. The descriptions of the sets follow. The first line of each set contains a non-empty string $s$ ($1 \le |s| \le 500$) consisting of lowercase Latin letters. The second line of each set contains a non-empty string $t$ ($1 \le |t| \le 500$) consisting of lowercase Latin letters. It is guaranteed that the sum of string lengths $s$ over all test cases does not exceed $500$. Similarly, it is guaranteed that the sum of string lengths $t$ over all test cases does not exceed $500$. -----Output----- For each test case print two integers β€” the minimum number of moves and the number of different optimal sequences, modulo $10^9 + 7$. -----Examples----- Input 8 abababacababa aba ddddddd dddd xyzxyz xyz abc abcd abacaba abaca abc def aaaaaaaa a aaaaaaaa aa Output 2 2 1 4 2 1 0 1 1 1 0 1 8 1 3 6 -----Note----- The first test case is explained in the statement. In the second case, it is enough to cut any of the four occurrences. In the third case, string $s$ is the concatenation of two strings $t =$ "xyz", so there is a unique optimal sequence of $2$ moves. In the fourth and sixth cases, the string $s$ initially contains no occurrences of the string $t$. In the fifth case, the string $s$ contains exactly one occurrence of the string $t$.
{"inputs": ["8\nabababacababa\naba\nddddddd\ndddd\nxyzxyz\nxyz\nabc\nabcd\nabacaba\nabaca\nabc\ndef\naaaaaaaa\na\naaaaaaaa\naa\n", "3\nabacabadabacabaeabacabadabacabafabacabadabacabac\naba\nabacabadabacabaabacabadabaabaabacabaa\naba\nabacabadaababaaabacaaab\naba\n", "6\ncgleetgjqctvoln\ntttt\nqcmivmmvgifpnm\nmmmm\nxxxrgxxgwexlxxxxlxxxrxxxxo\nxx\nkkgkkkxkak\nkk\nviovvvrhdouvqvpvyvolvfvvlvqv\nvvvv\nyeygaaeheeexeeu\neeee\n", "5\nunkhbabenvqqryktmlttqlktznxnegp\neeee\nsrrlvubrrfrvrerrszrcrltxw\nrr\nepyaltnttjgtnilythtgfwn\nttt\npxjffvfffrf\nffff\nqqqbbrvuaqloxdcxacyqabqmq\nqqqq\n", "1\nmzjstbmimopmmowegmjmuuxxmrchmkcmmhoaeknashkwygomrqmmfyoaordzmmvsqjqhmhmwhqcmgynmmsmqsmvuthtnfmkznqrmeggxhamllaiotjyjkmuccyagbsjvoamnummmum\nmmm\n", "9\nnvnbxttannjawdqjldkq\njjj\nttzwzrogluitptpcttq\ntttt\ntxuegtute\ntt\nwspzmybak\nvvv\npmeq\npppp\njqyaviyyhwccyy\nyy\nwxodkxsvdrdhedxd\nddd\nbgkggzd\nggg\nxxxix\nxx\n", "8\nabaaabacaba\naba\nabacabadaba\naba\nabacabadabacabaabaa\naba\naabacaabaabac\naba\nabacabadabaa\naba\nabacabadabacabaea\naba\nabacabadabacab\naba\nabacabacaaba\naba\n", "3\nyivntiiiiktgujc\niii\niqbnegcccccomwvfzczcyqpcyckccitchulhudccccyfcnrccccccccyrc\nccc\nyzzrzzzxzxyxzdhsitudxmcizfzxzhktznzzsboznhznnhazjzsunzwzzazxxzzaylqzas\nzzzz\n"], "outputs": ["2 2\n1 4\n2 1\n0 1\n1 1\n0 1\n8 1\n3 6\n", "12 1\n10 1\n4 2\n", "0 1\n0 1\n5 4\n2 2\n0 1\n0 1\n", "0 1\n3 1\n0 1\n0 1\n0 1\n", "1 1\n", "0 1\n0 1\n0 1\n0 1\n0 1\n2 1\n0 1\n0 1\n1 2\n", "3 1\n3 1\n5 1\n3 1\n3 1\n4 1\n3 1\n3 1\n", "1 2\n4 36\n0 1\n"]}
742
815
coding
Solve the programming task below in a Python markdown code block. You have N items that you want to put them into a knapsack. Item i has value vi and weight wi. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most W, that is capacity of the knapsack. Find the maximum total value of items in the knapsack. Constraints * 1 ≀ N ≀ 100 * 1 ≀ vi ≀ 100 * 1 ≀ wi ≀ 10,000,000 * 1 ≀ W ≀ 1,000,000,000 Input N W v1 w1 v2 w2 : vN wN The first line consists of the integers N and W. In the following N lines, the value and weight of the i-th item are given. Output Print the maximum total values of the items in a line. Examples Input 4 5 4 2 5 2 2 1 8 3 Output 13 Input 2 20 5 9 4 10 Output 9
{"inputs": ["0 9\n4 5\n0 4", "2 2\n5 8\n2 7", "0 9\n4 5\n0 6", "2 20\n5 9\n1 8", "2 20\n4 5\n0 4", "0 20\n4 5\n1 2", "1 34\n3 9\n1 8", "1 5\n27 4\n0 1"], "outputs": ["0\n", "0\n", "0\n", "6\n", "4\n", "0\n", "3\n", "27\n"]}
271
148