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
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n binary matrix mat, return the number of submatrices that have all ones.   Please complete the following python code precisely: ```python class Solution: def numSubmat(self, mat: List[List[int]]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(mat = [[1,0,1],[1,1,0],[1,1,0]]) == 13\n assert candidate(mat = [[0,1,1,0],[0,1,1,1],[1,1,1,0]]) == 24\n\n\ncheck(Solution().numSubmat)"}
71
84
coding
Solve the programming task below in a Python markdown code block. Rahul is assigned a task by his fellow mates.He has to take a string from somewhere and first of all he has to calculate the weight of that string.The weight of string is calculated by adding the ASCII values of each characters in that string and then dividing it with the total no of characters in that string.Then the weight of string is rounded off to previous integer. Now this weight of string is used to perform some tasks if the weight is odd then he has to print the character that is repeated maximum number of times in original string else he has to print the reverse of the whole string. INPUT First line inputs the string. OUTPUT According to the task the output is generated. CONSRAINTS length of string should be less than 100. SAMPLE INPUT Hello World SAMPLE OUTPUT l Explanation The entered string is Hello World the sum of ascii values of its character is 1052,there are 11 characters so weight equals to 95. Now as weight is odd so maximum times repeated character is l so it is given as the output
{"inputs": ["Hello", "Worldd", "Hello World"], "outputs": ["olleH", "d", "l"]}
237
27
coding
Solve the programming task below in a Python markdown code block. Two words rhyme if their last 3 letters are a match. Given N words, print the test case number (of the format Case : num) followed by the rhyming words in separate line adjacent to each other. The output can be in anyorder. -----Input----- First line contains the number of test case T The next line contains the number of words N Next N words follow . They’ll contain only alphabets from ‘a’-‘z’. -----Output----- Print case number (for each test case) of the format Case : num followed by the words that rhyme in a new line. -----Constraints----- 1 <= T <= 5 1 <= N <= 1000 3 <= length of each word <= 1000 -----Example----- Input: 3 3 nope qwerty hope 5 brain drain request grain nest 4 these words dont rhyme Output: Case : 1 hope nope qwerty Case : 2 brain drain grain nest request Case : 3 these dont words rhyme -----Explanation----- Case : 2 brain drain grain nest request Case : 3 these dont words rhyme Explanation for case 1: since hope and nope rhyme (suffix “ope” matches), we print them in the same line and qwerty In a new line. Note that qwerty nope hope is also correct (the output can be in any order )
{"inputs": ["3\n3\nnope qwerty hope\n5\nbrain drain request grain nest\n4\nthese words dont rhyme"], "outputs": ["Case : 1\nhope nope\nqwerty\nCase : 2\nbrain drain grain\nnest request\nCase : 3\nthese\ndont\nwords\nrhyme"]}
326
72
coding
Solve the programming task below in a Python markdown code block. Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if: * the Euclidean distance between A and B is one unit and neither A nor B is blocked; * or there is some integral point C, such that A is 4-connected with C, and C is 4-connected with B. Let's assume that the plane doesn't contain blocked points. Consider all the integral points of the plane whose Euclidean distance from the origin is no more than n, we'll name these points special. Chubby Yang wants to get the following property: no special point is 4-connected to some non-special point. To get the property she can pick some integral points of the plane and make them blocked. What is the minimum number of points she needs to pick? Input The first line contains an integer n (0 ≤ n ≤ 4·107). Output Print a single integer — the minimum number of points that should be blocked. Examples Input 1 Output 4 Input 2 Output 8 Input 3 Output 16
{"inputs": ["0\n", "9\n", "8\n", "4\n", "7\n", "6\n", "5\n", "2\n"], "outputs": ["1\n", "48\n", "44\n", "20\n", "36\n", "32\n", "28\n", "8\n"]}
267
76
coding
Solve the programming task below in a Python markdown code block. LiLand is a country, consisting of n cities. The cities are numbered from 1 to n. The country is well known because it has a very strange transportation system. There are many one-way flights that make it possible to travel between the cities, but the flights are arranged in a way that once you leave a city you will never be able to return to that city again. Previously each flight took exactly one hour, but recently Lily has become the new manager of transportation system and she wants to change the duration of some flights. Specifically, she wants to change the duration of some flights to exactly 2 hours in such a way that all trips from city 1 to city n take the same time regardless of their path. Your task is to help Lily to change the duration of flights. Input First line of the input contains two integer numbers n and m (2 ≤ n ≤ 1000; 1 ≤ m ≤ 5000) specifying the number of cities and the number of flights. Each of the next m lines contains two integers ai and bi (1 ≤ ai < bi ≤ n) specifying a one-directional flight from city ai to city bi. It is guaranteed that there exists a way to travel from city number 1 to city number n using the given flights. It is guaranteed that there is no sequence of flights that forms a cyclical path and no two flights are between the same pair of cities. Output If it is impossible for Lily to do her task, print "No" (without quotes) on the only line of the output. Otherwise print "Yes" (without quotes) on the first line of output, then print an integer ansi (1 ≤ ansi ≤ 2) to each of the next m lines being the duration of flights in new transportation system. You should print these numbers in the order that flights are given in the input. If there are multiple solutions for the input, output any of them. Examples Input 3 3 1 2 2 3 1 3 Output Yes 1 1 2 Input 4 4 1 2 2 3 3 4 1 4 Output No Input 5 6 1 2 2 3 3 5 1 4 4 5 1 3 Output Yes 1 1 1 2 1 2
{"inputs": ["3 3\n1 2\n2 3\n1 3\n", "4 3\n1 2\n2 3\n3 4\n1 4\n", "4 4\n1 2\n2 3\n3 4\n1 3\n", "4 2\n1 2\n2 4\n3 4\n1 4\n", "4 3\n1 2\n2 3\n3 4\n1 3\n", "4 3\n1 2\n2 3\n3 4\n2 3\n", "4 3\n1 2\n2 3\n3 4\n1 5\n", "4 3\n1 2\n2 3\n3 4\n0 3\n"], "outputs": ["Yes\n1\n1\n2\n", "Yes\n2\n2\n2\n", "Yes\n1\n1\n2\n2\n", "Yes\n2\n2\n", "Yes\n2\n2\n2\n", "Yes\n2\n2\n2\n", "Yes\n2\n2\n2\n", "Yes\n2\n2\n2\n"]}
514
258
coding
Solve the programming task below in a Python markdown code block. When naming identifiers (variables and functions) in programming, compound words that concatenate words are used. However, if you concatenate them as they are, you will not be able to understand the word breaks, so in general, select and apply the one that is unified from the following naming conventions: * Set to Upper CamelCase Connect words directly to form a compound word, and capitalize only the first letter of each word. Example: GetUserName * Set to Lower CamelCase Connect words directly to form a compound word, and capitalize only the first letter of each word. However, the first letter of the compound word should be lowercase. Example: getUserName * Connect with underscore Words are concatenated with underscores to form a compound word. Make all letters of the word lowercase. Example: get_user_name Create a program that outputs the given identifier by applying the specified naming convention. It is assumed that any of the above naming conventions has already been applied to the identifier given. Input Multiple datasets are given as input. Each dataset is given in the following format: name type (identifier, naming convention: space-separated strings and characters) type is a character indicating the naming convention and is as shown in the table below: type | Naming convention --- | --- U | Upper CamelCase L | Lower CamelCase D | Connect with underscore The number of characters in the given identifier is 1 or more and 100 or less. End of input when type is'X'. Do not output to this input. Output For each dataset, print the identifier with the naming convention on one line. Example Input get_user_name L getUserName U GetUserName D EndOfInput X Output getUserName GetUserName get_user_name
{"inputs": ["get_user_name L\ngetUserOame U\nGetUserName D\nEndOfInput X", "get_user_name L\ngetUserName U\nGrtUseeName D\nEndOfInput X", "get_user_nbme L\ngetUserOame U\nGetUserName D\nEndOfInput X", "embn_resu_teg L\ngetUserOame U\nGetUserName D\nEndOfInput X", "get_user_name L\ngetUserNamd U\nGetUserName D\nEndOfInput X", "get_user_name L\ngatUserNeme U\nGrtUseeName D\nEndOfInput X", "get_user_name L\ngetUsdrNamd U\nGetUserName D\nEndOfInput X", "get_user_name L\ngetUsfrName U\nGetUserName D\nEndOfInput X"], "outputs": ["getUserName\nGetUserOame\nget_user_name\n", "getUserName\nGetUserName\ngrt_usee_name\n", "getUserNbme\nGetUserOame\nget_user_name\n", "embnResuTeg\nGetUserOame\nget_user_name\n", "getUserName\nGetUserNamd\nget_user_name\n", "getUserName\nGatUserNeme\ngrt_usee_name\n", "getUserName\nGetUsdrNamd\nget_user_name\n", "getUserName\nGetUsfrName\nget_user_name\n"]}
372
301
coding
Solve the programming task below in a Python markdown code block. Consider the string `"1 2 36 4 8"`. Lets take pairs of these numbers, concatenate each pair and determine how many of them of divisible by `k`. ```Pearl If k = 3, we get following numbers ['12', '18', '21', '24', '42', '48', '81', '84'], all divisible by 3. Note: -- 21 and 12 are different pairs. -- Elements must be from different indices, so '3636` is not a valid. ``` Given a string of numbers and an integer `k`, return the number of pairs that when concatenated, are divisible by `k`. ``` solve("1 2 36 4 8", 3) = 8, because they are ['12', '18', '21', '24', '42', '48', '81', '84'] solve("1 3 6 3", 3) = 6. They are ['36', '33', '63', '63', '33', '36'] ``` More examples in test cases. Good luck! Please also try [Simple remove duplicates](https://www.codewars.com/kata/5ba38ba180824a86850000f7) Also feel free to reuse/extend the following starter code: ```python def solve(s,k): ```
{"functional": "_inputs = [['1 2 36 4 8', 2], ['1 2 36 4 8', 3], ['1 2 36 4 8', 4], ['1 2 36 4 8', 8]]\n_outputs = [[16], [8], [11], [4]]\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])"}
342
222
coding
Solve the programming task below in a Python markdown code block. Chef is good at making pancakes. Generally he gets requests to serve N pancakes at once. He serves them in the form of a stack. A pancake can be treated as a circular disk with some radius. Chef needs to take care that when he places a pancake on the top of the stack the radius of the pancake should not exceed the radius of the largest pancake in the stack by more than 1. Additionally all radii should be positive integers, and the bottom most pancake should have its radius as 1. Chef wants you to find out in how many ways can he create a stack containing N pancakes. ------ Input Format ------ First line of the input contains T (T ≤ 1000) denoting the number of test cases. T lines follow each containing a single integer N (1 ≤ N ≤ 1000) denoting the size of the required stack. ------ Output Format ------ For each case the output should be a single integer representing the number of ways a stack of size N can be created. As the answer can be large print it modulo 1000000007. ----- Sample Input 1 ------ 2 1 2 ----- Sample Output 1 ------ 1 2
{"inputs": ["2\n1\n2", "2\n0\n2", "2\n0\n4", "2\n0\n5", "2\n0\n6", "2\n0\n8", "2\n1\n8", "2\n2\n8"], "outputs": ["1\n2", "0\n2\n", "0\n15\n", "0\n52\n", "0\n203\n", "0\n4140\n", "1\n4140\n", "2\n4140\n"]}
272
122
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums of length n. Assume arrk to be an array obtained by rotating nums by k positions clock-wise. We define the rotation function F on nums as follow: F(k) = 0 * arrk[0] + 1 * arrk[1] + ... + (n - 1) * arrk[n - 1]. Return the maximum value of F(0), F(1), ..., F(n-1). The test cases are generated so that the answer fits in a 32-bit integer.   Please complete the following python code precisely: ```python class Solution: def maxRotateFunction(self, nums: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(nums = [4,3,2,6]) == 26\n assert candidate(nums = [100]) == 0\n\n\ncheck(Solution().maxRotateFunction)"}
164
53
coding
Solve the programming task below in a Python markdown code block. William has array of $n$ numbers $a_1, a_2, \dots, a_n$. He can perform the following sequence of operations any number of times: Pick any two items from array $a_i$ and $a_j$, where $a_i$ must be a multiple of $2$ $a_i = \frac{a_i}{2}$ $a_j = a_j \cdot 2$ Help William find the maximal sum of array elements, which he can get by performing the sequence of operations described above. -----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 an integer $n$ $(1 \le n \le 15)$, the number of elements in William's array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i < 16)$, the contents of William's array. -----Output----- For each test case output the maximal sum of array elements after performing an optimal sequence of operations. -----Examples----- Input 5 3 6 4 2 5 1 2 3 4 5 1 10 3 2 3 4 15 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 Output 50 46 10 26 35184372088846 -----Note----- In the first example test case the optimal sequence would be: Pick $i = 2$ and $j = 1$. After performing a sequence of operations $a_2 = \frac{4}{2} = 2$ and $a_1 = 6 \cdot 2 = 12$, making the array look as: [12, 2, 2]. Pick $i = 2$ and $j = 1$. After performing a sequence of operations $a_2 = \frac{2}{2} = 1$ and $a_1 = 12 \cdot 2 = 24$, making the array look as: [24, 1, 2]. Pick $i = 3$ and $j = 1$. After performing a sequence of operations $a_3 = \frac{2}{2} = 1$ and $a_1 = 24 \cdot 2 = 48$, making the array look as: [48, 1, 1]. The final answer $48 + 1 + 1 = 50$. In the third example test case there is no way to change the sum of elements, so the answer is $10$.
{"inputs": ["5\n3\n6 4 2\n5\n1 2 3 4 5\n1\n10\n3\n2 3 4\n15\n8 8 8 8 8 8 8 8 8 8 8 8 8 8 8\n"], "outputs": ["50\n46\n10\n26\n35184372088846\n"]}
632
105
coding
Solve the programming task below in a Python markdown code block. This kata is part of the collection [Mary's Puzzle Books](https://www.codewars.com/collections/marys-puzzle-books). Mary brought home a "spot the differences" book. The book is full of a bunch of problems, and each problem consists of two strings that are similar. However, in each string there are a few characters that are different. An example puzzle from her book is: ``` String 1: "abcdefg" String 2: "abcqetg" ``` Notice how the "d" from String 1 has become a "q" in String 2, and "f" from String 1 has become a "t" in String 2. It's your job to help Mary solve the puzzles. Write a program `spot_diff`/`Spot` that will compare the two strings and return a list with the positions where the two strings differ. In the example above, your program should return `[3, 5]` because String 1 is different from String 2 at positions 3 and 5. NOTES: ```if-not:csharp • If both strings are the same, return `[]` ``` ```if:csharp • If both strings are the same, return `new List()` ``` • Both strings will always be the same length • Capitalization and punctuation matter Also feel free to reuse/extend the following starter code: ```python def spot_diff(s1, s2): ```
{"functional": "_inputs = [['abcdefg', 'abcqetg'], ['Hello World!', 'hello world.'], ['FixedGrey', 'FixedGrey'], ['HACKER', 'H4CK3R'], ['This is a really long sentence.', 'That is a_really long sentence,'], ['', ''], ['abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba'], ['YOLO lol', 'ROLO mom'], ['www.youtube.com/zedaphplays', 'www.twitter.com/zedaphplays'], ['Congratulations! You did it!', 'Conglaturations! U did this!']]\n_outputs = [[[3, 5]], [[0, 6, 11]], [[]], [[1, 4]], [[2, 3, 9, 30]], [[]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]], [[0, 5, 7]], [[4, 5, 6, 8, 9, 10]], [[4, 8, 17, 18, 19, 20, 22, 23, 24, 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(spot_diff(*i), o[0])"}
319
472
coding
Solve the programming task below in a Python markdown code block. A boy PCK is playing with N electric metronomes. The i-th metronome is set to tick every t_i seconds. He started all of them simultaneously. He noticed that, even though each metronome has its own ticking interval, all of them tick simultaneously from time to time in certain intervals. To explore this interesting phenomenon more fully, he is now trying to shorten the interval of ticking in unison by adjusting some of the metronomes’ interval settings. Note, however, that the metronomes do not allow any shortening of the intervals. Given the number of metronomes and their preset intervals t_i (sec), write a program to make the tick-in-unison interval shortest by adding a non-negative integer d_i to the current interval setting of the i-th metronome, and report the minimum value of the sum of all d_i. Input The input is given in the following format. N t_1 t_2 : t_N The first line provides the number of metronomes N (1 ≤ N ≤ 105). Each of the subsequent N lines provides the preset ticking interval t_i (1 ≤ t_i ≤ 104) of the i-th metronome. Output Output the minimum value. Examples Input 3 3 6 8 Output 3 Input 2 10 10 Output 0
{"inputs": ["2\n8\n2", "2\n8\n4", "2\n4\n4", "2\n8\n6", "2\n4\n1", "2\n4\n0", "2\n10\n4", "2\n10\n6"], "outputs": ["0\n", "0\n", "0\n", "2\n", "0\n", "1\n", "1\n", "4\n"]}
305
96
coding
Solve the programming task below in a Python markdown code block. Stephanie just learned about a game called Nim in which there are two players and $n$ piles of stones. During each turn, a player must choose any non-empty pile and take as many stones as they want. The first player who cannot complete their turn (i.e., because all piles are empty) loses. Stephanie knows that, for each start position in this game, it's possible to know which player will win (i.e., the first or second player) if both players play optimally. Now she wants to know the number of different games that exist that satisfy all of the following conditions: The game starts with $n$ non-empty piles and each pile contains less than $2^{m}$ stones. All the piles contain pairwise different numbers of stones. The first player wins if that player moves optimally. Help Stephanie by finding and printing the number of such games satisfying all the above criteria, modulo $10^9+7$. Input Format The first line contains two space-separated integers describing the respective values of $n$ and $m$. Constraints $1\leq n,m\leq10^7$ Output Format Print the number of such games, modulo $10^9+7$. Sample Input 0 2 2 Sample Output 0 6 Explanation 0 We want to know the number of games with $n=2$ piles where each pile contains $<2^m=2^2=4$ stones. There are six such possible games with the following distributions of stones: $(1,2),(1,3),(2,1),(2,3),(3,1),(3,2)$. Thus, we print the result of $6\ \text{mod}\ (10^9+7)=6$ as our answer.
{"inputs": ["2 2\n"], "outputs": ["6\n"]}
393
16
coding
Solve the programming task below in a Python markdown code block. The internet is a very confounding place for some adults. Tom has just joined an online forum and is trying to fit in with all the teens and tweens. It seems like they're speaking in another language! Help Tom fit in by translating his well-formatted English into n00b language. The following rules should be observed: - "to" and "too" should be replaced by the number 2, even if they are only part of a word (E.g. today = 2day) - Likewise, "for" and "fore" should be replaced by the number 4 - Any remaining double o's should be replaced with zeros (E.g. noob = n00b) - "be", "are", "you", "please", "people", "really", "have", and "know" should be changed to "b", "r", "u", "plz", "ppl", "rly", "haz", and "no" respectively (even if they are only part of the word) - When replacing words, always maintain case of the first letter unless another rule forces the word to all caps. - The letter "s" should always be replaced by a "z", maintaining case - "LOL" must be added to the beginning of any input string starting with a "w" or "W" - "OMG" must be added to the beginning (after LOL, if applicable,) of a string 32 characters^(1) or longer - All evenly numbered words^(2) must be in ALL CAPS (Example: ```Cake is very delicious.``` becomes ```Cake IZ very DELICIOUZ```) - If the input string starts with "h" or "H", the entire output string should be in ALL CAPS - Periods ( . ), commas ( , ), and apostrophes ( ' ) are to be removed - ^(3)A question mark ( ? ) should have more question marks added to it, equal to the number of words^(2) in the sentence (Example: ```Are you a foo?``` has 4 words, so it would be converted to ```r U a F00????```) - ^(3)Similarly, exclamation points ( ! ) should be replaced by a series of alternating exclamation points and the number 1, equal to the number of words^(2) in the sentence (Example: ```You are a foo!``` becomes ```u R a F00!1!1```) ^(1) Characters should be counted After: any word conversions, adding additional words, and removing punctuation. Excluding: All punctuation and any 1's added after exclamation marks ( ! ). Character count includes spaces. ^(2) For the sake of this kata, "words" are simply a space-delimited substring, regardless of its characters. Since the output may have a different number of words than the input, words should be counted based on the output string. Example: ```whoa, you are my 123 <3``` becomes ```LOL WHOA u R my 123 <3``` = 7 words ^(3)The incoming string will be punctuated properly, so punctuation does not need to be validated. Also feel free to reuse/extend the following starter code: ```python def n00bify(text): ```
{"functional": "_inputs = [['Hi, how are you today?'], ['I think it would be nice if we could all get along.'], [\"Let's eat, Grandma!\"], ['Woot woot woot woot woot woot!'], ['Hi, I can have cheeseburger?'], ['Sometimes I use ? in the middle of a sentence; is that ok?!'], ['Unto us a child is born.'], ['What happened at the zoo?'], ['Oodles is a really fun word to say (in my opinion).'], ['Would you please stop, pause, and take a deep breath?'], ['Too, to, and 2 are all two!'], ['Before I knew it, 4 people were looking for you!'], ['Before you know it... wait, what does this have to do with UNO!?'], ['After conversions, this should be!'], ['Well, 32 chars without OMG on!'], ['Never try cheating a Kata, friend.']]\n_outputs = [['HI HOW R U 2DAY?????'], ['OMG I think IT would B nice IF we COULD all GET along'], ['Letz EAT Grandma!1!'], ['LOL OMG W00t W00T w00t W00T w00t W00T!1!1!1!1'], ['HI I CAN HAZ CHEEZEBURGER?????'], ['OMG ZOMETIMEZ I UZE ?????????????? IN the MIDDLE of A zentence; IZ that OK??????????????!1!1!1!1!1!1!1'], ['Un2 UZ a CHILD iz BORN'], ['LOL WHAT happened AT the Z00??????'], ['OMG 00DLEZ iz A rly FUN word 2 zay (IN my OPINION)'], ['LOL OMG Would U plz Z2P pauze AND take A deep BREATH????????????'], ['2 2 and 2 r ALL two!1!1!1!'], ['OMG B4 I KNEW it 4 ppl WERE l00king 4 u!1!1!1!1!1!'], ['OMG B4 u NO it WAIT what DOEZ thiz HAZ 2 DO with UNO!1!1!1!1!1!1!1??????????????'], ['After CONVERZIONZ thiz ZHOULD b!1!1!'], ['LOL OMG Well 32 charz WITHOUT OMG ON!1!1!1!1'], ['OMG NEVER try CHEATING a KATA friend']]\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(n00bify(*i), o[0])"}
713
708
coding
Solve the programming task below in a Python markdown code block. Given $n$ two-dimensional points in space, determine whether they lie on some vertical or horizontal line. If yes, print YES; otherwise, print NO. Input Format The first line contains a single positive integer, $n$, denoting the number of points. Each line $\boldsymbol{i}$ of $n$ subsequent lines contain two space-separated integers detailing the respective values of $x_i$ and $y_i$ (i.e., the coordinates of the $i^{\mbox{th}}$ point). Constraints $2\leq n\leq10$ $-10\leq x_i,y_i\leq10$ Output Format Print YES if all points lie on some horizontal or vertical line; otherwise, print NO. Sample Input 0 5 0 1 0 2 0 3 0 4 0 5 Sample Output 0 YES Explanation 0 All points lie on a vertical line. Sample Input 1 5 0 1 0 2 1 3 0 4 0 5 Sample Output 1 NO Explanation 1 The points do not all form a horizontal or vertical line.
{"inputs": ["5\n0 1\n0 2\n0 3\n0 4\n0 5\n", "5\n0 1\n0 2\n1 3\n0 4\n0 5\n"], "outputs": ["YES\n", "NO\n"]}
268
62
coding
Solve the programming task below in a Python markdown code block. You are given positive integers A and B. Find the K-th largest positive integer that divides both A and B. The input guarantees that there exists such a number. -----Constraints----- - All values in input are integers. - 1 \leq A, B \leq 100 - The K-th largest positive integer that divides both A and B exists. - K \geq 1 -----Input----- Input is given from Standard Input in the following format: A B K -----Output----- Print the K-th largest positive integer that divides both A and B. -----Sample Input----- 8 12 2 -----Sample Output----- 2 Three positive integers divides both 8 and 12: 1, 2 and 4. Among them, the second largest is 2.
{"inputs": ["2 1 1", "4 8 1", "1 1 1", "1 1 1\n", "12 3 2", "8 12 3", "6 12 2", "16 1 1"], "outputs": ["1\n", "4\n", "1", "1\n", "1\n", "1\n", "3\n", "1\n"]}
180
98
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. On a 2D plane, we place n stones at some integer coordinate points. Each coordinate point may have at most one stone. A stone can be removed if it shares either the same row or the same column as another stone that has not been removed. Given an array stones of length n where stones[i] = [xi, yi] represents the location of the ith stone, return the largest possible number of stones that can be removed.   Please complete the following python code precisely: ```python class Solution: def removeStones(self, stones: List[List[int]]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]) == 5\n assert candidate(stones = [[0,0],[0,2],[1,1],[2,0],[2,2]]) == 3\n assert candidate(stones = [[0,0]]) == 0\n\n\ncheck(Solution().removeStones)"}
139
101
coding
Solve the programming task below in a Python markdown code block. There is a game called "I Wanna Be the Guy", consisting of n levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only p levels of the game. And Little Y can pass only q levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other? -----Input----- The first line contains a single integer n (1 ≤ n ≤ 100). The next line contains an integer p (0 ≤ p ≤ n) at first, then follows p distinct integers a_1, a_2, ..., a_{p} (1 ≤ a_{i} ≤ n). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to n. -----Output----- If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). -----Examples----- Input 4 3 1 2 3 2 2 4 Output I become the guy. Input 4 3 1 2 3 2 2 3 Output Oh, my keyboard! -----Note----- In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both. In the second sample, no one can pass level 4.
{"inputs": ["1\n0\n0\n", "1\n0\n0\n", "1\n0\n1 1\n", "1\n1 1\n0\n", "100\n0\n0\n", "1\n0\n1 1\n", "1\n1 1\n0\n", "100\n0\n0\n"], "outputs": ["Oh, my keyboard!\n", "Oh, my keyboard!\n", "I become the guy.\n", "I become the guy.\n", "Oh, my keyboard!\n", "I become the guy.\n", "I become the guy.\n", "Oh, my keyboard!\n"]}
363
146
coding
Solve the programming task below in a Python markdown code block. Your task is to define a function that understands basic mathematical expressions and solves them. For example: ```python calculate("1 + 1") # => 2 calculate("18 + 4*6") # => 42 calculate("245 - 826") # => -581 calculate("09 + 000482") # => 491 calculate("8 / 4 + 6") # => 8 calculate("5 + 1 / 5") # => 5.2 calculate("1+2+3") # => 6 calculate("9 /3 + 12/ 6") # => 5 ``` Notes: - Input string will contain numbers (may be integers and floats) and arithmetic operations. - Input string may contain spaces, and all space characters should be ignored. - Operations that will be used: addition (+), subtraction (-), multiplication (*), and division (/) - Operations must be done in the order of operations: First multiplication and division, then addition and subtraction. - In this kata, input expression will not have negative numbers. (ex: "-4 + 5") - If output is an integer, return as integer. Else return as float. - If input string is empty, contains letters, has a wrong syntax, contains division by zero or is not a string, return False. Also feel free to reuse/extend the following starter code: ```python def calculate(input): ```
{"functional": "_inputs = [['1 + 1'], ['9 - 4'], ['1 - 4'], ['3 * 4'], ['9 / 3'], ['26 + 73'], ['524 + 277'], ['1 / 2'], ['2 / 5'], ['1 + 2 + 3 + 4 + 5 + 6'], ['123 - 3 - 20 - 100'], ['123 * 987 * 135 * 246'], ['200 / 2 / 10 / 5'], ['1+2-3+4-5+6-7+8-9+10'], ['5*2/3*9/10*123/8'], ['1*2*3/1/2/3+1+2+3-1-2-3'], ['1+2 * 4'], ['1+2 / 4'], ['1-2 * 4'], ['1-2 / 4'], ['1+2-3*4/6'], [''], ['7 - A'], ['3 + 2 * '], [' / 7 + 3'], [5], ['1 / 0']]\n_outputs = [[2], [5], [-3], [12], [3], [99], [801], [0.5], [0.4], [21], [0], [4031727210], [2], [7], [46.125], [1], [9], [1.5], [-7], [0.5], [1], [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(calculate(*i), o[0])"}
334
528
coding
Solve the programming task below in a Python markdown code block. Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages. Recent actions shows a list of n different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time. Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the i-th place in the list there is a thread that was at the a_{i}-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages. Help Emuskald find out the number of threads that surely have new messages. A thread x surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold: thread x is not updated (it has no new messages); the list order 1, 2, ..., n changes to a_1, a_2, ..., a_{n}. -----Input----- The first line of input contains an integer n, the number of threads (1 ≤ n ≤ 10^5). The next line contains a list of n space-separated integers a_1, a_2, ..., a_{n} where a_{i} (1 ≤ a_{i} ≤ n) is the old position of the i-th thread in the new list. It is guaranteed that all of the a_{i} are distinct. -----Output----- Output a single integer — the number of threads that surely contain a new message. -----Examples----- Input 5 5 2 1 3 4 Output 2 Input 3 1 2 3 Output 0 Input 4 4 3 2 1 Output 3 -----Note----- In the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages. In the second test case, there may be no new messages at all, since the thread order hasn't changed. In the third test case, only thread 1 can contain no new messages.
{"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "3\n1 2 3\n", "3\n2 1 3\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n"]}
540
102
coding
Solve the programming task below in a Python markdown code block. This is the hard version of this problem. The only difference between the easy and hard versions is the constraints on $k$ and $m$. In this version of the problem, you need to output the answer by modulo $10^9+7$. You are given a sequence $a$ of length $n$ consisting of integers from $1$ to $n$. The sequence may contain duplicates (i.e. some elements can be equal). Find the number of tuples of $m$ elements such that the maximum number in the tuple differs from the minimum by no more than $k$. Formally, you need to find the number of tuples of $m$ indices $i_1 < i_2 < \ldots < i_m$, such that $$\max(a_{i_1}, a_{i_2}, \ldots, a_{i_m}) - \min(a_{i_1}, a_{i_2}, \ldots, a_{i_m}) \le k.$$ For example, if $n=4$, $m=3$, $k=2$, $a=[1,2,4,3]$, then there are two such triples ($i=1, j=2, z=4$ and $i=2, j=3, z=4$). If $n=4$, $m=2$, $k=1$, $a=[1,1,1,1]$, then all six possible pairs are suitable. As the result can be very large, you should print the value modulo $10^9 + 7$ (the remainder when divided by $10^9 + 7$). -----Input----- The first line contains a single integer $t$ ($1 \le t \le 2 \cdot 10^5$) — the number of test cases. Then $t$ test cases follow. The first line of each test case contains three integers $n$, $m$, $k$ ($1 \le n \le 2 \cdot 10^5$, $1 \le m \le 100$, $1 \le k \le n$) — the length of the sequence $a$, number of elements in the tuples and the maximum difference of elements in the tuple. The next line contains $n$ integers $a_1, a_2,\ldots, a_n$ ($1 \le a_i \le n$) — the sequence $a$. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- Output $t$ answers to the given test cases. Each answer is the required number of tuples of $m$ elements modulo $10^9 + 7$, such that the maximum value in the tuple differs from the minimum by no more than $k$. -----Examples----- Input 4 4 3 2 1 2 4 3 4 2 1 1 1 1 1 1 1 1 1 10 4 3 5 6 1 3 2 9 8 1 2 4 Output 2 6 1 20 -----Note----- None
{"inputs": ["3\n1 1 1\n1\n1 1 1\n1\n1 1 1\n1\n", "4\n4 3 2\n1 2 4 3\n4 2 1\n1 1 1 1\n1 1 1\n1\n10 4 3\n5 6 1 3 2 9 8 1 2 4\n", "4\n4 3 2\n1 2 4 3\n4 3 2\n1 1 1 1\n1 3 1\n1\n10 3 2\n5 6 1 3 2 9 8 1 2 4\n"], "outputs": ["1\n1\n1\n", "2\n6\n1\n20\n", "2\n4\n0\n15\n"]}
702
198
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.   Please complete the following python code precisely: ```python class Solution: def sortedSquares(self, nums: List[int]) -> List[int]: ```
{"functional": "def check(candidate):\n assert candidate(nums = [-4,-1,0,3,10]) == [0,1,9,16,100]\n assert candidate(nums = [-7,-3,2,3,11]) == [4,9,9,49,121]\n\n\ncheck(Solution().sortedSquares)"}
78
86
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n integer matrix mat and an integer target. Choose one integer from each row in the matrix such that the absolute difference between target and the sum of the chosen elements is minimized. Return the minimum absolute difference. The absolute difference between two numbers a and b is the absolute value of a - b.   Please complete the following python code precisely: ```python class Solution: def minimizeTheDifference(self, mat: List[List[int]], target: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(mat = [[1,2,3],[4,5,6],[7,8,9]], target = 13) == 0\n assert candidate(mat = [[1],[2],[3]], target = 100) == 94\n assert candidate(mat = [[1,2,9,8,7]], target = 6) == 1\n\n\ncheck(Solution().minimizeTheDifference)"}
119
104
coding
Solve the programming task below in a Python markdown code block. "You must lift the dam. With a lever. I will give it to you. You must block the canal. With a rock. I will not give the rock to you." Danik urgently needs rock and lever! Obviously, the easiest way to get these things is to ask Hermit Lizard for them. Hermit Lizard agreed to give Danik the lever. But to get a stone, Danik needs to solve the following task. You are given a positive integer $n$, and an array $a$ of positive integers. The task is to calculate the number of such pairs $(i,j)$ that $i<j$ and $a_i$ $\&$ $a_j \ge a_i \oplus a_j$, where $\&$ denotes the bitwise AND operation, and $\oplus$ denotes the bitwise XOR operation. Danik has solved this task. But can you solve it? -----Input----- Each test contains multiple test cases. The first line contains one positive integer $t$ ($1 \le t \le 10$) denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $n$ ($1 \le n \le 10^5$) — length of the array. The second line contains $n$ positive integers $a_i$ ($1 \le a_i \le 10^9$) — elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For every test case print one non-negative integer — the answer to the problem. -----Example----- Input 5 5 1 4 3 7 10 3 1 1 1 4 6 2 5 3 2 2 4 1 1 Output 1 3 2 0 0 -----Note----- In the first test case there is only one pair: $(4,7)$: for it $4$ $\&$ $7 = 4$, and $4 \oplus 7 = 3$. In the second test case all pairs are good. In the third test case there are two pairs: $(6,5)$ and $(2,3)$. In the fourth test case there are no good pairs.
{"inputs": ["1\n1\n1000000000\n", "1\n1\n1000000000\n", "1\n1\n1000000001\n", "1\n1\n1000001001\n", "1\n1\n1000011001\n", "1\n1\n1000111001\n", "1\n1\n1000101001\n", "1\n1\n1000101101\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
508
174
coding
Solve the programming task below in a Python markdown code block. An ordered sequence of numbers from 1 to N is given. One number might have deleted from it, then the remaining numbers were mixed. Find the number that was deleted. Example: - The starting array sequence is `[1,2,3,4,5,6,7,8,9]` - The mixed array with one deleted number is `[3,2,4,6,7,8,1,9]` - Your function should return the int `5`. If no number was deleted from the array and no difference with it, your function should return the int `0`. Note that N may be 1 or less (in the latter case, the first array will be `[]`). Also feel free to reuse/extend the following starter code: ```python def find_deleted_number(arr, mixed_arr): ```
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8, 9], [5, 7, 9, 4, 8, 1, 2, 3]], [[1, 2, 3, 4, 5, 6, 7], [2, 3, 6, 1, 5, 4, 7]], [[1, 2, 3, 4, 5, 6, 7, 8, 9], [5, 7, 6, 9, 4, 8, 1, 2, 3]], [[1], []], [[], []]]\n_outputs = [[6], [0], [0], [1], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(find_deleted_number(*i), o[0])"}
186
320
coding
Solve the programming task below in a Python markdown code block. You have an n × m rectangle table, its cells are not initially painted. Your task is to paint all cells of the table. The resulting picture should be a tiling of the table with squares. More formally: each cell must be painted some color (the colors are marked by uppercase Latin letters); we will assume that two cells of the table are connected if they are of the same color and share a side; each connected region of the table must form a square. Given n and m, find lexicographically minimum coloring of the table that meets the described properties. -----Input----- The first line contains two integers, n and m (1 ≤ n, m ≤ 100). -----Output----- Print lexicographically minimum coloring of the table that meets the described conditions. One coloring (let's call it X) is considered lexicographically less than the other one (let's call it Y), if: consider all the table cells from left to right and from top to bottom (first, the first cell in the first row, then the second cell in the first row and so on); let's find in this order the first cell that has distinct colors in two colorings; the letter that marks the color of the cell in X, goes alphabetically before the letter that marks the color of the cell in Y. -----Examples----- Input 1 3 Output ABA Input 2 2 Output AA AA Input 3 4 Output AAAB AAAC AAAB
{"inputs": ["1 3\n", "2 2\n", "3 4\n", "4 3\n", "1 1\n", "2 3\n", "3 2\n", "1 2\n"], "outputs": ["ABA\n", "AA\nAA\n", "AAAB\nAAAC\nAAAB\n", "AAA\nAAA\nAAA\nBCB\n", "A\n", "AAB\nAAC\n", "AA\nAA\nBC\n", "AB\n"]}
331
109
coding
Solve the programming task below in a Python markdown code block. Minion Chef likes to eat bananas a lot. There are N piles of bananas in front of Chef; for each i (1 ≤ i ≤ N), the i-th pile contains Ai bananas. Chef's mother wants her to eat the bananas and be healthy. She has gone to the office right now and will come back in H hours. Chef would like to make sure that she can finish eating all bananas by that time. Suppose Chef has an eating speed of K bananas per hour. Each hour, she will choose some pile of bananas. If this pile contains at least K bananas, then she will eat K bananas from it. Otherwise, she will simply eat the whole pile (and won't eat any more bananas during this hour). Chef likes to eat slowly, but still wants to finish eating all the bananas on time. Therefore, she would like to choose the minimum K such that she is able to eat all the bananas in H hours. Help Chef find that value of K. -----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 H denoting the number of piles and the number of hours after which Chef's mom will come home. - The second line contains N space-separated integers A1, A2, ..., AN. -----Output----- For each test case, print a single line containing one integer — the minimum possible value of K. -----Constraints----- - 1 ≤ T ≤ 10 - 1 ≤ N ≤ 105 - N ≤ H ≤ 109 - 1 ≤ Ai ≤ 109 for each valid i -----Subtasks----- Subtask #1 (30 points): - 1 ≤ N ≤ 100 - Ai ≤ 103 for each valid i Subtask #2 (70 points): original constraints -----Example----- Input: 3 3 3 1 2 3 3 4 1 2 3 4 5 4 3 2 7 Output: 3 2 4 -----Explanation----- Example case 1: With a speed of K = 3 bananas per hour, Chef can finish eating all the bananas in 3 hours. It's the minimum possible speed with which she can eat all the bananas in 3 hours. With a speed of 2 bananas per hour, she would take at least 4 hours and with a speed of 1 banana per hour, she would take at least 6 hours.
{"inputs": ["3\n3 3\n1 2 3\n3 4\n1 2 3\n4 5\n4 3 2 7"], "outputs": ["3\n2\n4"]}
552
48
coding
Solve the programming task below in a Python markdown code block. Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes. Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels. Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), and if k = 2, they do not rhyme (ommit ≠ ermit). Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines): * Clerihew (aabb); * Alternating (abab); * Enclosed (abba). If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented by aaaa). If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem is aaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme. Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task. Input The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104. If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1, 2, 3, 4; the second one contains lines number 5, 6, 7, 8; and so on. Output Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes. Examples Input 1 1 day may sun fun Output aabb Input 1 1 day may gray way Output aaaa Input 2 1 a a a a a a e e Output aabb Input 2 1 day may sun fun test hill fest thrill Output NO Note In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".
{"inputs": ["1 1\ne\ne\ne\ne\n", "1 1\na\na\na\na\n", "1 1\ne\na\na\na\n", "1 1\ne\na\ne\na\n", "1 1\na\na\na\ne\n", "1 1\ne\na\ne\ne\n", "1 1\ne\na\na\ne\n", "1 1\na\ne\na\ni\n"], "outputs": ["aaaa\n", "aaaa\n", "NO\n", "abab\n", "NO\n", "NO\n", "abba\n", "NO\n"]}
688
152
coding
Solve the programming task below in a Python markdown code block. In this Kata, we define an arithmetic progression as a series of integers in which the differences between adjacent numbers are the same. You will be given an array of ints of `length > 2` and your task will be to convert it into an arithmetic progression by the following rule: ```Haskell For each element there are exactly three options: an element can be decreased by 1, an element can be increased by 1 or it can be left unchanged. ``` Return the minimum number of changes needed to convert the array to an arithmetic progression. If not possible, return `-1`. ```Haskell For example: solve([1,1,3,5,6,5]) == 4 because [1,1,3,5,6,5] can be changed to [1,2,3,4,5,6] by making 4 changes. solve([2,1,2]) == 1 because it can be changed to [2,2,2] solve([1,2,3]) == 0 because it is already a progression, and no changes are needed. solve([1,1,10) == -1 because it's impossible. solve([5,6,5,3,1,1]) == 4. It becomes [6,5,4,3,2,1] ``` More examples in the test cases. Good luck! Also feel free to reuse/extend the following starter code: ```python def solve(arr): ```
{"functional": "_inputs = [[[1, 1, 3, 5, 6, 5]], [[2, 1, 2]], [[1, 2, 3]], [[1, 1, 10]], [[24, 21, 14, 10]], [[3, 2, 1, 1, 1]], [[1, 3, 6, 9, 12]], [[0, 0, 0, 0, 0]], [[5, 4, 3, 2, 1, 1]], [[1, 2, 1]], [[1, 2, 3, 1, 1]], [[1, 3, 6, 8, 10]], [[5, 6, 5, 3, 1, 1]]]\n_outputs = [[4], [1], [0], [-1], [3], [4], [1], [0], [1], [1], [4], [2], [4]]\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])"}
327
371
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a special typewriter with lowercase English letters 'a' to 'z' arranged in a circle with a pointer. A character can only be typed if the pointer is pointing to that character. The pointer is initially pointing to the character 'a'. Each second, you may perform one of the following operations: Move the pointer one character counterclockwise or clockwise. Type the character the pointer is currently on. Given a string word, return the minimum number of seconds to type out the characters in word.   Please complete the following python code precisely: ```python class Solution: def minTimeToType(self, word: str) -> int: ```
{"functional": "def check(candidate):\n assert candidate(word = \"abc\") == 5\n assert candidate(word = \"bza\") == 7\n assert candidate(word = \"zjpc\") == 34\n\n\ncheck(Solution().minTimeToType)"}
152
61
coding
Solve the programming task below in a Python markdown code block. You are given an integer K. Print the string obtained by repeating the string `ACL` K times and concatenating them. For example, if K = 3, print `ACLACLACL`. Constraints * 1 \leq K \leq 5 * All values in input are integers. Input Input is given from Standard Input in the following format: K Output Print the string obtained by repeating the string `ACL` K times and concatenating them. Example Input 3 Output ACLACLACL
{"inputs": ["4", "6", "5", "8", "7", "9", "2", "1"], "outputs": ["ACLACLACLACL\n", "ACLACLACLACLACLACL\n", "ACLACLACLACLACL\n", "ACLACLACLACLACLACLACLACL\n", "ACLACLACLACLACLACLACL\n", "ACLACLACLACLACLACLACLACLACL\n", "ACLACL\n", "ACL\n"]}
122
96
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n matrix M initialized with all 0's and an array of operations ops, where ops[i] = [ai, bi] means M[x][y] should be incremented by one for all 0 <= x < ai and 0 <= y < bi. Count and return the number of maximum integers in the matrix after performing all the operations.   Please complete the following python code precisely: ```python class Solution: def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(m = 3, n = 3, ops = [[2,2],[3,3]]) == 4\n assert candidate(m = 3, n = 3, ops = [[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3]]) == 4\n assert candidate(m = 3, n = 3, ops = []) == 9\n\n\ncheck(Solution().maxCount)"}
133
135
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 an integer $N$ and he wants to generate a matrix $M$ with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$). He thinks that $M$ would be *delicious* if: Each element of this matrix is an integer between $1$ and $N^{2}$ inclusive. All the elements of the matrix are pairwise distinct. For each square submatrix containing cells in rows $r$ through $r+a$ and in columns $c$ through $c+a$ (inclusive) for some valid integers $r$, $c$ and $a ≥ 0$: - $M_{r,c} + M_{r+a,c+a}$ is even - $M_{r,c+a} + M_{r+a,c}$ is even Can you help Chef generate a delicious matrix? It can be proved that a solution always exists. If there are multiple solutions, you may find any one. ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each test case contains a single integer $N$. ------ Output ------ For each test case, print $N$ lines describing a delicious matrix $M$. For each valid $i$, the $i$-th of these lines should contain $N$ space-separated integers $M_{i,1}, M_{i,2}, \ldots, M_{i,N}$. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{3}$ the sum of $N$ over all test cases does not exceed $10^{3}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 1 2 ----- Sample Output 1 ------ 1 2 4 3 ----- explanation 1 ------ Example case 1: The matrix $M$ has five square submatrices. Four of them ($[1]$, $[2]$, $[4]$, $[3]$) have $a=0$, so they obviously satisfy all conditions. The last square submatrix is the whole matrix $M$, with $r=c=a=1$, and we can see that $M_{1,1} + M_{2,2} = 1 + 3 = 4$ and $M_{1,2} + M_{2,1} = 2 + 4 = 6$ are both even.
{"inputs": ["1\n2"], "outputs": ["1 2\n4 3"]}
601
20
coding
Solve the programming task below in a Python markdown code block. We have a permutation p = {p_1,\ p_2,\ ...,\ p_n} of {1,\ 2,\ ...,\ n}. Print the number of elements p_i (1 < i < n) that satisfy the following condition: - p_i is the second smallest number among the three numbers p_{i - 1}, p_i, and p_{i + 1}. -----Constraints----- - All values in input are integers. - 3 \leq n \leq 20 - p is a permutation of {1,\ 2,\ ...,\ n}. -----Input----- Input is given from Standard Input in the following format: n p_1 p_2 ... p_n -----Output----- Print the number of elements p_i (1 < i < n) that satisfy the condition. -----Sample Input----- 5 1 3 5 4 2 -----Sample Output----- 2 p_2 = 3 is the second smallest number among p_1 = 1, p_2 = 3, and p_3 = 5. Also, p_4 = 4 is the second smallest number among p_3 = 5, p_4 = 4, and p_5 = 2. These two elements satisfy the condition.
{"inputs": ["3\n1 2 3\n", "3\n1 3 2\n", "3\n2 1 3\n", "5\n2 3 5 4 2", "5\n2 1 5 4 2", "5\n2 6 4 8 3", "5\n2 1 5 4 3", "5\n2 1 2 4 3"], "outputs": ["1\n", "0\n", "0\n", "2\n", "1\n", "0\n", "1\n", "1\n"]}
284
133
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store. Notice that you may not slant the container.   Please complete the following python code precisely: ```python class Solution: def maxArea(self, height: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate([1,8,6,2,5,4,8,3,7]) == 49 \n assert candidate(height = [1,1]) == 1\n\n\ncheck(Solution().maxArea)"}
131
61
coding
Solve the programming task below in a Python markdown code block. You are given a matrix of size n × n filled with lowercase English letters. You can change no more than k letters in this matrix. Consider all paths from the upper left corner to the lower right corner that move from a cell to its neighboring cell to the right or down. Each path is associated with the string that is formed by all the letters in the cells the path visits. Thus, the length of each string is 2n - 1. Find the lexicographically smallest string that can be associated with a path after changing letters in at most k cells of the matrix. A string a is lexicographically smaller than a string b, if the first different letter in a and b is smaller in a. Input The first line contains two integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ n^2) — the size of the matrix and the number of letters you can change. Each of the next n lines contains a string of n lowercase English letters denoting one row of the matrix. Output Output the lexicographically smallest string that can be associated with some valid path after changing no more than k letters in the matrix. Examples Input 4 2 abcd bcde bcad bcde Output aaabcde Input 5 3 bwwwz hrhdh sepsp sqfaf ajbvw Output aaaepfafw Input 7 6 ypnxnnp pnxonpm nxanpou xnnpmud nhtdudu npmuduh pmutsnz Output aaaaaaadudsnz Note In the first sample test case it is possible to change letters 'b' in cells (2, 1) and (3, 1) to 'a', then the minimum path contains cells (1, 1), (2, 1), (3, 1), (4, 1), (4, 2), (4, 3), (4, 4). The first coordinate corresponds to the row and the second coordinate corresponds to the column.
{"inputs": ["1 0\nz\n", "1 1\ng\n", "1 0\na\n", "1 1\nz\n", "1 0\ng\n", "1 0\ny\n", "1 1\nf\n", "1 2\nf\n"], "outputs": ["z\n", "a\n", "a\n", "a\n", "g\n", "y", "a", "a"]}
458
99
coding
Solve the programming task below in a Python markdown code block. There are N points in a D-dimensional space. The coordinates of the i-th point are (X_{i1}, X_{i2}, ..., X_{iD}). The distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... + (y_D - z_D)^2}. How many pairs (i, j) (i < j) are there such that the distance between the i-th point and the j-th point is an integer? -----Constraints----- - All values in input are integers. - 2 \leq N \leq 10 - 1 \leq D \leq 10 - -20 \leq X_{ij} \leq 20 - No two given points have the same coordinates. That is, if i \neq j, there exists k such that X_{ik} \neq X_{jk}. -----Input----- Input is given from Standard Input in the following format: N D X_{11} X_{12} ... X_{1D} X_{21} X_{22} ... X_{2D} \vdots X_{N1} X_{N2} ... X_{ND} -----Output----- Print the number of pairs (i, j) (i < j) such that the distance between the i-th point and the j-th point is an integer. -----Sample Input----- 3 2 1 2 5 5 -2 8 -----Sample Output----- 1 The number of pairs with an integer distance is one, as follows: - The distance between the first point and the second point is \sqrt{|1-5|^2 + |2-5|^2} = 5, which is an integer. - The distance between the second point and the third point is \sqrt{|5-(-2)|^2 + |5-8|^2} = \sqrt{58}, which is not an integer. - The distance between the third point and the first point is \sqrt{|-2-1|^2+|8-2|^2} = 3\sqrt{5}, which is not an integer.
{"inputs": ["1 1\n1\n2\n3\n4\n5", "5 1\n0\n2\n3\n4\n5", "0 1\n1\n2\n3\n4\n5", "1 0\n1\n2\n3\n4\n5", "1 0\n1\n2\n3\n4\n4", "1 0\n1\n2\n3\n7\n4", "1 0\n1\n3\n3\n7\n4", "0 0\n1\n3\n3\n7\n4"], "outputs": ["0\n", "10\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
514
159
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0). The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x1 - x2)2 + (y1 - y2)2). You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in).   Please complete the following python code precisely: ```python class Solution: def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]: ```
{"functional": "def check(candidate):\n assert candidate(points = [[1,3],[-2,2]], k = 1) == [[-2,2]]\n assert candidate(points = [[3,3],[5,-1],[-2,4]], k = 2) == [[3,3],[-2,4]]\n\n\ncheck(Solution().kClosest)"}
163
83
coding
Solve the programming task below in a Python markdown code block. You work as a system administrator in a dormitory, which has $n$ rooms one after another along a straight hallway. Rooms are numbered from $1$ to $n$. You have to connect all $n$ rooms to the Internet. You can connect each room to the Internet directly, the cost of such connection for the $i$-th room is $i$ coins. Some rooms also have a spot for a router. The cost of placing a router in the $i$-th room is also $i$ coins. You cannot place a router in a room which does not have a spot for it. When you place a router in the room $i$, you connect all rooms with the numbers from $max(1,~i - k)$ to $min(n,~i + k)$ inclusive to the Internet, where $k$ is the range of router. The value of $k$ is the same for all routers. Calculate the minimum total cost of connecting all $n$ rooms to the Internet. You can assume that the number of rooms which have a spot for a router is not greater than the number of routers you have. -----Input----- The first line of the input contains two integers $n$ and $k$ ($1 \le n, k \le 2 \cdot 10^5$) — the number of rooms and the range of each router. The second line of the input contains one string $s$ of length $n$, consisting only of zeros and ones. If the $i$-th character of the string equals to '1' then there is a spot for a router in the $i$-th room. If the $i$-th character of the string equals to '0' then you cannot place a router in the $i$-th room. -----Output----- Print one integer — the minimum total cost of connecting all $n$ rooms to the Internet. -----Examples----- Input 5 2 00100 Output 3 Input 6 1 000000 Output 21 Input 4 1 0011 Output 4 Input 12 6 000010000100 Output 15 -----Note----- In the first example it is enough to place the router in the room $3$, then all rooms will be connected to the Internet. The total cost of connection is $3$. In the second example you can place routers nowhere, so you need to connect all rooms directly. Thus, the total cost of connection of all rooms is $1 + 2 + 3 + 4 + 5 + 6 = 21$. In the third example you need to connect the room $1$ directly and place the router in the room $3$. Thus, the total cost of connection of all rooms is $1 + 3 = 4$. In the fourth example you need to place routers in rooms $5$ and $10$. Then all rooms will be connected to the Internet. The total cost of connection is $5 + 10 = 15$.
{"inputs": ["1 1\n0\n", "1 1\n1\n", "1 1\n0\n", "1 1\n1\n", "1 0\n1\n", "1 0\n0\n", "4 1\n0011\n", "4 2\n0011\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "4\n", "3\n"]}
673
108
coding
Solve the programming task below in a Python markdown code block. A tatami mat, a Japanese traditional floor cover, has a rectangular form with aspect ratio 1:2. When spreading tatami mats on a floor, it is prohibited to make a cross with the border of the tatami mats, because it is believed to bring bad luck. Your task is to write a program that reports how many possible ways to spread tatami mats of the same size on a floor of given height and width. Input The input consists of multiple datasets. Each dataset cosists of a line which contains two integers H and W in this order, separated with a single space. H and W are the height and the width of the floor respectively. The length of the shorter edge of a tatami mat is regarded as a unit length. You may assume 0 < H, W ≤ 20. The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed. Output For each dataset, print the number of possible ways to spread tatami mats in one line. Example Input 3 4 4 4 0 0 Output 4 2
{"inputs": ["3 1\n4 4\n0 0", "3 1\n6 4\n0 0", "3 4\n4 1\n0 0", "3 1\n4 2\n0 0", "3 2\n6 4\n0 0", "3 7\n4 1\n0 0", "4 4\n4 1\n0 0", "4 1\n4 2\n0 0"], "outputs": ["0\n2\n", "0\n3\n", "4\n1\n", "0\n4\n", "3\n3\n", "0\n1\n", "2\n1\n", "1\n4\n"]}
249
158
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, return a list of all simplified fractions between 0 and 1 (exclusive) such that the denominator is less-than-or-equal-to n. You can return the answer in any order.   Please complete the following python code precisely: ```python class Solution: def simplifiedFractions(self, n: int) -> List[str]: ```
{"functional": "def check(candidate):\n assert candidate(n = 2) == [\"1/2\"]\n assert candidate(n = 3) == [\"1/2\",\"1/3\",\"2/3\"]\n assert candidate(n = 4) == [\"1/2\",\"1/3\",\"1/4\",\"2/3\",\"3/4\"]\n assert candidate(n = 1) == []\n\n\ncheck(Solution().simplifiedFractions)"}
92
108
coding
Solve the programming task below in a Python markdown code block. Given is a lowercase English letter C that is not z. Print the letter that follows C in alphabetical order. -----Constraints----- - C is a lowercase English letter that is not z. -----Input----- Input is given from Standard Input in the following format: C -----Output----- Print the letter that follows C in alphabetical order. -----Sample Input----- a -----Sample Output----- b a is followed by b.
{"inputs": ["z", "b", "x", "`", "w", "_", "{", "^"], "outputs": ["{\n", "c\n", "y\n", "a\n", "x\n", "`\n", "|\n", "_\n"]}
97
58
coding
Solve the programming task below in a Python markdown code block. Polycarp doesn't like integers that are divisible by $3$ or end with the digit $3$ in their decimal representation. Integers that meet both conditions are disliked by Polycarp, too. Polycarp starts to write out the positive (greater than $0$) integers which he likes: $1, 2, 4, 5, 7, 8, 10, 11, 14, 16, \dots$. Output the $k$-th element of this sequence (the elements are numbered from $1$). -----Input----- The first line contains one integer $t$ ($1 \le t \le 100$) — the number of test cases. Then $t$ test cases follow. Each test case consists of one line containing one integer $k$ ($1 \le k \le 1000$). -----Output----- For each test case, output in a separate line one integer $x$ — the $k$-th element of the sequence that was written out by Polycarp. -----Examples----- Input 10 1 2 3 4 5 6 7 8 9 1000 Output 1 2 4 5 7 8 10 11 14 1666 -----Note----- None
{"inputs": ["1\n5\n", "1\n5\n", "1\n2\n", "1\n3\n", "1\n6\n", "1\n1\n", "1\n4\n", "1\n8\n"], "outputs": ["7\n", "7\n", "2\n", "4\n", "8\n", "1\n", "5\n", "11\n"]}
302
87
coding
Solve the programming task below in a Python markdown code block. Read problems statements in mandarin chinese, russian and vietnamese as well. You are given a multi-set S of N integers, and an integer K. You want to find the maximum value of minimal excluded non-negative integer (MEX) of the multi-set given that you are allowed to add at most any K integers to the multi-set. Find the maximum value of MEX that you can obtain. Few examples of finding MEX of a multi-set are as follows. MEX of multi-set {0} is 1, {1} is 0, {0, 1, 3} is 2, {0, 1, 2, 3, 5, 6} is 4. ------ Input ------ The first line of the input contains an integer T denoting the number of testcases. The first line of each test case contains two space seperated integers N and K denoting the size of the multi-set and the maximum number of extra integers that you can add in the multi-set respectively. The second line contains N space separated integers denoting the multi-set S: S_{1}, S_{2} ,.... S_{N}. ------ Output ------ For each testcase, output the answer in a single line. ------ Constraints ------ 1 ≤ T ≤ 10 1 ≤ N ≤ 10^{5} 0 ≤ K ≤ 10^{5} 0 ≤ S_{i} ≤ 2 * 10^{5} ------ Subtasks ------ Subtask #1 (15 points): K=0. Subtask #2 (85 points): Original Constraints. ----- Sample Input 1 ------ 4 3 0 1 0 2 3 1 1 0 2 4 3 2 5 4 9 2 0 3 4 ----- Sample Output 1 ------ 3 4 6 0 ----- explanation 1 ------ Example case 1. As K = 0, so we can't add any element to the multi-set. Elements of the set are {1, 0, 2}. The MEX value of this set is 3. Example case 2. As K = 1, you are allowed to add at most 1 element to the multi-set. The multi-set are {1, 0, 2}. You can add element 3 to the multi-set, and it becomes {1, 0, 2, 3}. The MEX value of this multi-set is 4. There is no other way to have higher value of MEX of the set by adding at most one element to the multi-set.
{"inputs": ["4\n3 0\n1 0 2\n3 1\n1 0 2\n4 3\n2 5 4 9\n2 0\n3 4"], "outputs": ["3\n4\n6\n0"]}
573
58
coding
Solve the programming task below in a Python markdown code block. Goal Given a list of elements [a1, a2, ..., an], with each ai being a string, write a function **majority** that returns the value that appears the most in the list. If there's no winner, the function should return None, NULL, nil, etc, based on the programming language. Example majority(["A", "B", "A"]) returns "A" majority(["A", "B", "B", "A"]) returns None Also feel free to reuse/extend the following starter code: ```python def majority(arr): ```
{"functional": "_inputs = [[['A', 'B', 'A']], [['A', 'B', 'C']], [['A', 'B', 'B', 'A']], [['A', 'A', 'A', 'A']], [['A']], [['A', 'A', 'A', 'BBBBBBBB']], [['A', 'B', 'C', 'C']], [[]], [['B', 'C', '', '']]]\n_outputs = [['A'], [None], [None], ['A'], ['A'], ['A'], ['C'], [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(majority(*i), o[0])"}
135
258
coding
Solve the programming task below in a Python markdown code block. Everything got unclear to us in a far away constellation Tau Ceti. Specifically, the Taucetians choose names to their children in a very peculiar manner. Two young parents abac and bbad think what name to give to their first-born child. They decided that the name will be the permutation of letters of string s. To keep up with the neighbours, they decided to call the baby so that the name was lexicographically strictly larger than the neighbour's son's name t. On the other hand, they suspect that a name tax will be introduced shortly. According to it, the Taucetians with lexicographically larger names will pay larger taxes. That's the reason abac and bbad want to call the newborn so that the name was lexicographically strictly larger than name t and lexicographically minimum at that. The lexicographical order of strings is the order we are all used to, the "dictionary" order. Such comparison is used in all modern programming languages to compare strings. Formally, a string p of length n is lexicographically less than string q of length m, if one of the two statements is correct: * n < m, and p is the beginning (prefix) of string q (for example, "aba" is less than string "abaa"), * p1 = q1, p2 = q2, ..., pk - 1 = qk - 1, pk < qk for some k (1 ≤ k ≤ min(n, m)), here characters in strings are numbered starting from 1. Write a program that, given string s and the heighbours' child's name t determines the string that is the result of permutation of letters in s. The string should be lexicographically strictly more than t and also, lexicographically minimum. Input The first line contains a non-empty string s (1 ≤ |s| ≤ 5000), where |s| is its length. The second line contains a non-empty string t (1 ≤ |t| ≤ 5000), where |t| is its length. Both strings consist of lowercase Latin letters. Output Print the sought name or -1 if it doesn't exist. Examples Input aad aac Output aad Input abad bob Output daab Input abc defg Output -1 Input czaaab abcdef Output abczaa Note In the first sample the given string s is the sought one, consequently, we do not need to change the letter order there.
{"inputs": ["z\na\n", "a\nb\n", "a\na\n", "b\nb\n", "b\na\n", "ac\na\n", "z\nww\n", "ab\nb\n"], "outputs": ["z\n", "-1\n", "-1\n", "-1", "b", "ac\n", "z\n", "ba\n"]}
547
84
coding
Solve the programming task below in a Python markdown code block. Chef loves squares! You are given N points with integers coordinates, Chef asks you to find out how many points he should add to these set of N points, so that one could create at least one square having its vertices from the points of the resulting set. Note that the square created need not to be parallel to the axis. -----Input----- The first line contains singe integer N. Each of next N lines contains two integers Xi and Yi denotine the coordinates of i-th point. -----Output----- In a single line print single integer - the minimal number of points Chef need to paint to receive at least one square. -----Constraints----- - 0 ≤ N ≤ 2000 - -10^6 ≤ Xi, Yi ≤ 10^6 - There are NO coincided points -----Example----- Input: 3 0 0 2 2 3 3 Output: 2 Input: 5 0 0 100 100 200 200 100 0 0 100 Output: 0 -----Explanation----- For the first example Chef can add points (2, 0), (0, 2) or (2, 3), (3, 2) For the second example Chef already has square (0, 0), (100, 0), (0, 100), (100, 100).
{"inputs": ["3\n0 0\n2 2\n3 3", "3\n0 0\n2 2\n3 3", "5\n0 0\n100 100\n200 200\n100 0\n0 100", "5\n0 0\n100 100\n200 200\n100 0\n0 100"], "outputs": ["2", "2", "0", "0"]}
320
118
coding
Solve the programming task below in a Python markdown code block. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions x_{i}, y_{i} (x_{i} < y_{i}) in the permuted array a. Let's define the value d_{i} = y_{i} - x_{i} — the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum $s = \sum_{i = 1}^{n}(n - i) \cdot|d_{i} + i - n$. -----Input----- The only line contains integer n (1 ≤ n ≤ 5·10^5). -----Output----- Print 2n integers — the permuted array a that minimizes the value of the sum s. -----Examples----- Input 2 Output 1 1 2 2 Input 1 Output 1 1
{"inputs": ["2\n", "1\n", "3\n", "4\n", "4\n", "3\n", "8\n", "6\n"], "outputs": ["1 1 2 2\n", "1 1\n", "1 3 1 2 2 3\n", "1 3 3 1 2 4 2 4\n", "1 3 3 1 2 4 2 4 ", "1 3 1 2 2 3 ", "1 3 5 7 7 5 3 1 2 4 6 8 6 4 2 8 \n", "1 3 5 5 3 1 2 4 6 4 2 6 \n"]}
216
178
coding
Solve the programming task below in a Python markdown code block. Given is an integer sequence of length N: A_1, A_2, \cdots, A_N. An integer sequence X, which is also of length N, will be chosen randomly by independently choosing X_i from a uniform distribution on the integers 1, 2, \ldots, A_i for each i (1 \leq i \leq N). Compute the expected value of the length of the longest increasing subsequence of this sequence X, modulo 1000000007. More formally, under the constraints of the problem, we can prove that the expected value can be represented as a rational number, that is, an irreducible fraction \frac{P}{Q}, and there uniquely exists an integer R such that R \times Q \equiv P \pmod {1000000007} and 0 \leq R < 1000000007, so print this integer R. -----Notes----- A subsequence of a sequence X is a sequence obtained by extracting some of the elements of X and arrange them without changing the order. The longest increasing subsequence of a sequence X is the sequence of the greatest length among the strictly increasing subsequences of X. -----Constraints----- - 1 \leq N \leq 6 - 1 \leq A_i \leq 10^9 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N -----Output----- Print the expected value modulo 1000000007. -----Sample Input----- 3 1 2 3 -----Sample Output----- 2 X becomes one of the following, with probability 1/6 for each: - X = (1,1,1), for which the length of the longest increasing subsequence is 1; - X = (1,1,2), for which the length of the longest increasing subsequence is 2; - X = (1,1,3), for which the length of the longest increasing subsequence is 2; - X = (1,2,1), for which the length of the longest increasing subsequence is 2; - X = (1,2,2), for which the length of the longest increasing subsequence is 2; - X = (1,2,3), for which the length of the longest increasing subsequence is 3. Thus, the expected value of the length of the longest increasing subsequence is (1 + 2 + 2 + 2 + 2 + 3) / 6 \equiv 2 \pmod {1000000007}.
{"inputs": ["3\n1 2 3\n", "3\n2 1 2\n", "1\n78261382\n", "5\n9 7 4 4 1\n", "5\n4 5 7 10 9\n", "6\n7 4 4 2 6 1\n", "6\n6 3 4 5 5 5\n", "6\n1 1 1 1 1 1\n"], "outputs": ["2\n", "500000005\n", "1\n", "825396833\n", "966269851\n", "420386910\n", "880111120\n", "1\n"]}
595
188
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef lives in a huge apartment building with $N$ floors, numbered $0$ (ground floor) through $N$ (terrace). Unfortunately, it has only one lift. We say that when the lift travels from a floor $a$ to a floor $b$, it travels $|b-a|$ floors. Initially, the lift is on the ground floor. Then, it receives $Q$ requests (numbered $1$ through $Q$). For each valid $i$, the $i$-th request is for the lift to move from its current floor to a source floor $f_{i}$, where some people enter the lift, and then move to a destination floor $d_{i}$, where they exit the lift. The lift should not stop anywhere in between moving to the floor $f_{i}$ or from the floor $f_{i}$ to the floor $d_{i}$. The lift must serve the requests sequentially, i.e. completely fulfill request $1$, then request $2$ and so on. The lift does not move anywhere after serving the final request. Find the total number of floors the lift needs to travel to fulfill all the requests. ------ 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 $Q$. The following $Q$ lines describe requests. For each valid $i$, the $i$-th of these lines contains two space-separated integers $f_{i}$ and $d_{i}$. ------ Output ------ For each test case, print a single line containing one integer ― the total number of floors travelled by the lift. ------ Constraints ------ $1 ≤ T ≤ 250$ $1 ≤ N ≤ 10^{6}$ $1 ≤ Q ≤ 10^{5}$ $0 ≤ f_{i}, d_{i} ≤ N$ for each valid $i$ $f_{i} \neq d_{i}$ for each valid $i$ the sum of $Q$ over all test cases does not exceed $10^{5}$ ----- Sample Input 1 ------ 1 2 3 1 2 0 1 1 0 ----- Sample Output 1 ------ 6 ----- explanation 1 ------ Example case 1: The lift travels $2$ floors up to serve the first request, $3$ floors ($2$ down, then $1$ up) to serve the second request and $1$ floor down to serve the third request. Note that in this case, the lift returned to the ground floor, but it may end up at any floor.
{"inputs": ["1\n2 3\n1 2\n0 1\n1 0"], "outputs": ["6"]}
621
28
coding
Solve the programming task below in a Python markdown code block. You are given a binary string S of length N (i.e. every character of S is either 0 or 1). You can perform the following operation on S: select any two indices i, j of the same parity, i.e. either both i, j are odd or both i, j are even swap S_{i} and S_{j} For example, in the string 1110, we can swap the second and the fourth characters to get 1011. However, we can never obtain 1101 from 1110 by performing such swaps. Find the maximum possible number of occurrences of the string 01 as a [substring] of S after performing the above operation any number of times (it is also allowed to not perform any operation). For example, the string 1110 has no occurrence of the string 01 as a substring, whereas we can swap the second and fourth characters to obtain 1{\color{red}{01}}1 which has exactly one occurrence of 01 (colored red). ------ Input Format ------ - The first line of input contains an integer T, denoting the number of testcases. The description of the T testcases follow. - Each testcase consists of two lines. - The first line contains a single integer N, the length of the string S. - The second line contains a binary string of length N. ------ Output Format ------ - For each testcase, print in a single line, an integer — the answer as per the problem statement. ------ Constraints ------ $1 ≤ T ≤ 4000$ $1 ≤ |S| ≤ 10^{5}$ - The sum of $|S|$ over all testcases doesn't exceed $10^{5}$ ------ subtasks ------ Subtask #1 (100 points): Original constraints ----- Sample Input 1 ------ 3 5 00100 5 01010 5 10001 ----- Sample Output 1 ------ 1 2 2 ----- explanation 1 ------ Test case $1$: The only strings that can be obtained by performing the given operations are $\{10000, 00100, 00001\}$. Of these the two strings $0{\color{red}{01}}00$ and $000{\color{red}{01}}$ contain exactly one occurrence of $01$. Test case $2$: The given string $S$ cannot be changed by performing the given operation and contains $2$ occurrences of the string $01$, i.e. ${\color{red}01}{\color{blue}01}0$. Test case $3$: The only strings that can be obtained by performing the given operations are $\{00101, 10001, 10100\}$. The string $0{\color{red}{01}}{\color{blue}{01}}$ contains two occurrences of $01$.
{"inputs": ["3\n5\n00100\n5\n01010\n5\n10001"], "outputs": ["1\n2\n2"]}
666
40
coding
Solve the programming task below in a Python markdown code block. The educational program (AHK Education) of the Aiz Broadcasting Association broadcasts a handicraft program for children, "Play with Tsukuro". This time I will make a box with sticks, but I would like to see if I can make a rectangular parallelepiped using the 12 sticks I prepared. However, the stick must not be cut or broken. Given the lengths of the twelve bars, write a program to determine if you can create a rectangular parallelepiped with all of them as sides. Input The input is given in the following format. e1 e2 ... e12 The input consists of one line and is given the integer ei (1 ≤ ei ≤ 100) representing the length of each bar. Output If a rectangular parallelepiped can be created, "yes" is output, and if it cannot be created, "no" is output. However, since a cube is a kind of rectangular parallelepiped, "yes" is output even if it is a cube. Examples Input 1 1 3 4 8 9 7 3 4 5 5 5 Output no Input 1 1 2 2 3 1 2 3 3 3 1 2 Output yes
{"inputs": ["1 1 2 2 3 1 1 3 3 3 1 2", "1 1 3 4 8 9 7 3 3 5 5 5", "1 0 2 2 3 1 1 3 3 3 1 2", "1 1 3 7 8 9 7 3 3 5 5 5", "0 0 2 2 3 1 1 3 3 3 1 2", "1 1 2 2 5 1 2 3 3 3 1 2", "1 1 3 4 8 9 3 3 4 5 5 5", "1 1 2 2 3 1 2 3 2 3 1 2"], "outputs": ["no\n", "no\n", "no\n", "no\n", "no\n", "no\n", "no\n", "no\n"]}
283
238
coding
Solve the programming task below in a Python markdown code block. You are given a string $s$ of length $n$ consisting of lowercase Latin letters. You may apply some operations to this string: in one operation you can delete some contiguous substring of this string, if all letters in the substring you delete are equal. For example, after deleting substring bbbb from string abbbbaccdd we get the string aaccdd. Calculate the minimum number of operations to delete the whole string $s$. -----Input----- The first line contains one integer $n$ ($1 \le n \le 500$) — the length of string $s$. The second line contains the string $s$ ($|s| = n$) consisting of lowercase Latin letters. -----Output----- Output a single integer — the minimal number of operation to delete string $s$. -----Examples----- Input 5 abaca Output 3 Input 8 abcddcba Output 4
{"inputs": ["1\nx\n", "1\nx\n", "1\nx\n", "5\nabaca\n", "5\nabaca\n", "8\nabcddcba\n", "8\nabcddcba\n", "500\nbbababaabaabaabbbbbbaabbabbabbaabababababbbbabaaabbbbaaabbbbbbbabababaaaaabbbbabaababbababbaaaaaabbaaabbaabaaababbbbbabbaabaabaabbbaaabaabbaaabbaabababbaaabaaabaaaaabbbababaabbbbabbbbbababbbaabaabbabaabbabbababbbbbaababbaabbbbbbbbaabbabbbabababaaaaaaaaaabababaaabbaabbbabbabbbbabbbaabaaabbbaabbabbbbbbbaaabbbabaaaaaabaabbbabbbbaaaabbbbbbabaaaaaaabbbbbbabababbaabbbaabaabbbabbbbaaaabbbbbabaaababbababbbabaaabbbbaababaababaaaaabbbaabbababaabaaabaaabbbbbabbbabbaaabbbbbbbaaaaabaaabbabaabbabbbbbbbbabbbab\n"], "outputs": ["1\n", "1\n", "1\n", "3\n", "3\n", "4\n", "4\n", "121\n"]}
204
301
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums. You have to find the maximum sum of a pair of numbers from nums such that the largest digit in both numbers is equal. For example, 2373 is made up of three distinct digits: 2, 3, and 7, where 7 is the largest among them. Return the maximum sum or -1 if no such pair exists.   Please complete the following python code precisely: ```python class Solution: def maxSum(self, nums: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(nums = [51,71,17,24,42]) == 88\n assert candidate(nums = [1,2,3,4]) == -1\n\n\ncheck(Solution().maxSum)"}
129
63
coding
Solve the programming task below in a Python markdown code block. Problem statement There is an unsigned $ 2 $ decimal integer $ X $ with $ N $ in digits including Leading-zeros. Output the largest non-negative integer that can be expressed in $ 2 $ base in $ N $ digits where the Hamming distance from $ X $ is $ D $. The Hamming distance between integers expressed in $ 2 $ is the number of digits with different values ​​in a number of $ 2 $. For example, the Hamming distance between $ 000 $ and $ 110 $ is $ 2 $. Constraint $ 1 \ leq N \ leq 1000 $ $ 0 \ leq D \ leq N $ All inputs are non-negative integers sample Sample input 1 Five 00001 3 Sample output 1 11101 Sample input 2 7 0110100 Four Sample output 2 1111111 Sample input 3 18 110001001110100100 6 Sample output 3 111111111111100100 Sample input 4 3 000 0 Sample output 4 000 input $ N $ $ X $ $ D $ output Output the integer of the answer on the $ 1 $ line in unsigned $ 2 $ decimal notation. Example Input 5 00001 3 Output 11101
{"inputs": ["5\n00001\n4", "5\n00000\n3", "5\n00001\n1", "5\n10001\n1", "5\n10001\n2", "5\n10001\n4", "5\n10000\n1", "5\n00010\n1"], "outputs": ["11111\n", "11100\n", "10001\n", "11001\n", "11101\n", "11110\n", "11000\n", "10010\n"]}
357
158
coding
Solve the programming task below in a Python markdown code block. A football league of N teams is taking place, where each team plays other teams once in [single round robin] fashion. A team gets 3 points for winning a game and 0 for losing (assume that no games end in a draw/tie). What is the maximum possible difference of points between the winning team and the second-placed team? ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. Then the test cases follow. - Each test case consists of a single line of input, containing a single integer N. ------ Output Format ------ For each test case, output in a single line the maximum difference of points between first and second place. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{9}$ ----- Sample Input 1 ------ 4 2 3 4 9 ----- Sample Output 1 ------ 3 3 6 12 ----- explanation 1 ------ Test case $1$: There will only be one match played between the two teams, therefore one team wins by $3$ points. Test case $2$: Let the three teams be A, B, C. If team A wins both the games against team B and team C, then team A will win by $3$ points since one of team B and team C will win the game between them. Test case $3$: Let the four teams be A, B, C, D. One possibility is for A to win all its games, and then B beats C, C beats D, D beats B. This way, the winner has $9$ points and second place has $3$ points, making a difference of $6$. Test case $4$: It can be shown that it's not possible to achieve a difference higher than $12$ when $9$ teams play. One way of achieving this is for the winner to score $24$ points and second place to score $12$.
{"inputs": ["4\n2\n3\n4\n9"], "outputs": ["3\n3\n6\n12"]}
435
27
coding
Solve the programming task below in a Python markdown code block. Read problems statements in mandarin chinese, russian and vietnamese as well. Given a board of N rows and M columns, place the minimum number of knights such that every cell either contains a knight or is attacked by at least one knight. Like in standard chess, a knight attacks every cell that is two squares away horizontally and one square vertically, or two squares vertically and one square horizontally. ------ Input ------ The first line of input contains one number T, the number of test cases. Each test case contains two integers N and M, the dimensions of the board. ------ Output ------ For each test case print the minimum number of knights required to cover every cell of the board. ------ Constraints ------ 1 ≤ T ≤ 150 1 ≤ N ≤ 3 1 ≤ M ≤ 50 ----- Sample Input 1 ------ 1 2 4 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ One optimal configuration is: Cells (1, 1), (1, 2), (4, 1) and (4, 2) contain knights. Cell (2, 1) is attacked by the knight in cell (4, 2). Cell (2, 2) is attacked by the knight in cell (4, 1). Cell (3, 1) is attacked by the knight in cell (1, 2). And cell (3, 2) is attacked by the knight in cell (1, 1). So every cell either contains a knight or is attacked by at least one knight, hence this is a valid configuration. There is no valid configuration with fewer knights, and so the answer is 4.
{"inputs": ["1\n2 4"], "outputs": ["4"]}
362
16
coding
Solve the programming task below in a Python markdown code block. Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows: If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s. -----Input----- The first line contains a non-empty string s. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 10^6 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. -----Output----- In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s. -----Examples----- Input x Output x Input yxyxy Output y Input xxxxxy Output xxxx -----Note----- In the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change. In the second test the transformation will be like this: string "yxyxy" transforms into string "xyyxy"; string "xyyxy" transforms into string "xyxyy"; string "xyxyy" transforms into string "xxyyy"; string "xxyyy" transforms into string "xyy"; string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".
{"inputs": ["x\n", "y\n", "x\n", "xxx\n", "xxx\n", "yxx\n", "yxyxy\n", "xxyxx\n"], "outputs": ["x\n", "y\n", "x", "xxx\n", "xxx", "x\n", "y\n", "xxx\n"]}
587
73
coding
Solve the programming task below in a Python markdown code block. Write a function named `first_non_repeating_letter` that takes a string input, and returns the first character that is not repeated anywhere in the string. For example, if given the input `'stress'`, the function should return `'t'`, since the letter *t* only occurs once in the string, and occurs first in the string. As an added challenge, upper- and lowercase letters are considered the **same character**, but the function should return the correct case for the initial letter. For example, the input `'sTreSS'` should return `'T'`. If a string contains *all repeating characters*, it should return an empty string (`""`) or `None` -- see sample tests. Also feel free to reuse/extend the following starter code: ```python def first_non_repeating_letter(string): ```
{"functional": "_inputs = [['a'], ['stress'], ['moonmen'], [''], ['abba'], ['aa'], ['~><#~><'], ['hello world, eh?'], ['sTreSS'], [\"Go hang a salami, I'm a lasagna hog!\"]]\n_outputs = [['a'], ['t'], ['e'], [''], [''], [''], ['#'], ['w'], ['T'], [',']]\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(first_non_repeating_letter(*i), o[0])"}
182
231
coding
Solve the programming task below in a Python markdown code block. Today Chef wants to evaluate the dishes of his $N$ students. He asks each one to cook a dish and present it to him. Chef loves his secret ingredient, and only likes dishes with at least $X$ grams of it. Given $N$, $X$ and the amount of secret ingredient used by each student $A_i$, find out whether Chef will like at least one dish. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - The first line of each testcase contains two integers $N$ (number of students) and $X$ (minimum amount of secret ingredient that a dish must contain for Chef to like it). - The next line contains $N$ space separated integers, $A_i$ denoting the amount of secret ingredient used by the students in their dishes. -----Output:----- For each testcase, print a single string "YES" if Chef likes at least one dish. Otherwise, print "NO". (Without quotes). -----Constraints:----- - $1 \leq T \leq 100$ - $1 \leq N \leq 1000$ - $1 \leq X \leq 1000000$ - $1 \leq A_i \leq 1000000$ -----Sample Input:----- 3 5 100 11 22 33 44 55 5 50 10 20 30 40 50 5 45 12 24 36 48 60 -----Sample Output:----- NO YES YES
{"inputs": ["3\n5 100\n11 22 33 44 55\n5 50\n10 20 30 40 50\n5 45\n12 24 36 48 60"], "outputs": ["NO\nYES\nYES"]}
373
77
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a machine which he uses to rotate sequences. If he puts a sequence $S_{1}, S_{2}, \ldots, S_{N}$ into the machine, it produces the sequence $S_{2}, S_{3}, \ldots, S_{N}, S_{1}$, i.e. the first element of the sequence is moved to the end. Chef is definitely not a newbie ― he knows about trivial things like finding the maximum sum of a contiguous subsequence. Therefore, he now made a difficult problem to challenge himself: You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$. For each $k$ ($0 ≤ k ≤ N-1$), consider the sequence produced by inserting it into the machine repeatedly $k$ times (i.e. inserting $A$ into the machine and replacing $A$ by the sequence it produces, $k$ times); find the maximum sum of a non empty contiguous subsequence of this sequence. However, to solve this problem, Chef needs the help of a pro. Solve it for him. ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first line of each test case contains a single integer $N$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing $N$ space-separated integers. For each valid $i$, the $i$-th of these integers should denote the largest sum of a non empty contiguous subsequence of the sequence produced by the machine after $i-1$ repeated insertions. ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ N ≤ 5 \cdot 10^{5}$ $|A_{i}| ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$ ----- Sample Input 1 ------ 1 4 -5 4 1 2 ----- Sample Output 1 ------ 7 7 4 5 ----- explanation 1 ------ Example case 1: - After zero insertions, $A = [-5, 4, 1, 2]$. The contiguous subsequence with the maximum sum is $A = [4, 1, 2]$. - After one insertion, $A = [4, 1, 2, -5]$. The contiguous subsequence with the maximum sum is $A = [4, 1, 2]$. - After two insertions, $A = [1, 2, -5, 4]$. The contiguous subsequence with the maximum sum is $A = [4]$. - After three insertions, $A = [2, -5, 4, 1]$. The contiguous subsequence with the maximum sum is $A = [4, 1]$.
{"inputs": ["1\n4\n-5 4 1 2"], "outputs": ["7 7 4 5"]}
703
29
coding
Solve the programming task below in a Python markdown code block. In this kata, you'll be given an integer of range `0 <= x <= 99` and have to return that number spelt out in English. A few examples: ```python name_that_number(4) # returns "four" name_that_number(19) # returns "nineteen" name_that_number(99) # returns "ninety nine" ``` Words should be separated by only spaces and not hyphens. No need to validate parameters, they will always be in the range [0, 99]. Make sure that the returned String has no leading of trailing spaces. Good luck! Also feel free to reuse/extend the following starter code: ```python def name_that_number(x): ```
{"functional": "_inputs = [[1], [52], [21], [99], [0], [53], [23], [76]]\n_outputs = [['one'], ['fifty two'], ['twenty one'], ['ninety nine'], ['zero'], ['fifty three'], ['twenty three'], ['seventy six']]\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(name_that_number(*i), o[0])"}
168
214
coding
Solve the programming task below in a Python markdown code block. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix $M$ of size $n \times n$ contains only 'X' and '.' (without quotes). The element in the $i$-th row and the $j$-th column $(i, j)$ is defined as $M(i, j)$, where $1 \leq i, j \leq n$. We define a cross appearing in the $i$-th row and the $j$-th column ($1 < i, j < n$) if and only if $M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = $ 'X'. The following figure illustrates a cross appearing at position $(2, 2)$ in a $3 \times 3$ matrix. X.X .X. X.X Your task is to find out the number of crosses in the given matrix $M$. Two crosses are different if and only if they appear in different rows or columns. -----Input----- The first line contains only one positive integer $n$ ($1 \leq n \leq 500$), denoting the size of the matrix $M$. The following $n$ lines illustrate the matrix $M$. Each line contains exactly $n$ characters, each of them is 'X' or '.'. The $j$-th element in the $i$-th line represents $M(i, j)$, where $1 \leq i, j \leq n$. -----Output----- Output a single line containing only one integer number $k$ — the number of crosses in the given matrix $M$. -----Examples----- Input 5 ..... .XXX. .XXX. .XXX. ..... Output 1 Input 2 XX XX Output 0 Input 6 ...... X.X.X. .X.X.X X.X.X. .X.X.X ...... Output 4 -----Note----- In the first sample, a cross appears at $(3, 3)$, so the answer is $1$. In the second sample, no crosses appear since $n < 3$, so the answer is $0$. In the third sample, crosses appear at $(3, 2)$, $(3, 4)$, $(4, 3)$, $(4, 5)$, so the answer is $4$.
{"inputs": ["1\nX\n", "1\n.\n", "1\n.\n", "1\nX\n", "1\n/\n", "1\nY\n", "1\n0\n", "1\nZ\n"], "outputs": ["0\n", "0\n", "0", "0", "0\n", "0\n", "0\n", "0\n"]}
558
84
coding
Solve the programming task below in a Python markdown code block. The medians of a triangle are the segments that unit the vertices with the midpoint of their opposite sides. The three medians of a triangle intersect at the same point, called the barycenter or the centroid. Given a triangle, defined by the cartesian coordinates of its vertices we need to localize its barycenter or centroid. The function ```bar_triang() or barTriang or bar-triang```, receives the coordinates of the three vertices ```A, B and C ``` as three different arguments and outputs the coordinates of the barycenter ```O``` in an array ```[xO, yO]``` This is how our asked function should work: the result of the coordinates should be expressed up to four decimals, (rounded result). You know that the coordinates of the barycenter are given by the following formulas. For additional information about this important point of a triangle see at: (https://en.wikipedia.org/wiki/Centroid) Let's see some cases: ```python bar_triang([4, 6], [12, 4], [10, 10]) ------> [8.6667, 6.6667] bar_triang([4, 2], [12, 2], [6, 10] ------> [7.3333, 4.6667] ``` The given points form a real or a degenerate triangle but in each case the above formulas can be used. Enjoy it and happy coding!! Also feel free to reuse/extend the following starter code: ```python def bar_triang(pointA, pointB, pointC): ```
{"functional": "_inputs = [[[4, 6], [12, 4], [10, 10]], [[4, 2], [12, 2], [6, 10]], [[4, 8], [8, 2], [16, 6]]]\n_outputs = [[[8.6667, 6.6667]], [[7.3333, 4.6667]], [[9.3333, 5.3333]]]\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(bar_triang(*i), o[0])"}
355
257
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Find all valid combinations of k numbers that sum up to n such that the following conditions are true: Only numbers 1 through 9 are used. Each number is used at most once. Return a list of all possible valid combinations. The list must not contain the same combination twice, and the combinations may be returned in any order.   Please complete the following python code precisely: ```python class Solution: def combinationSum3(self, k: int, n: int) -> List[List[int]]: ```
{"functional": "def check(candidate):\n assert candidate(k = 3, n = 7) == [[1,2,4]]\n assert candidate(k = 3, n = 9) == [[1,2,6],[1,3,5],[2,3,4]]\n assert candidate(k = 4, n = 1) == []\n\n\ncheck(Solution().combinationSum3)"}
121
95
coding
Solve the programming task below in a Python markdown code block. Alice, Bob, and Charlie are contributing to buy a Netflix subscription. However, Netfix allows only two users to share a subscription. Given that Alice, Bob, and Charlie have A, B, and C rupees respectively and a Netflix subscription costs X rupees, find whether any two of them can contribute to buy a subscription. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case contains four space-separated integers A, B, C, and X — the amount that Alice, Bob, and Charlie have, and the cost of a Netflix subscription respectively. ------ Output Format ------ For each test case, output YES, if any two of Alice, Bob, and Charlie can contribute to buy a Netflix subscription or NO otherwise. You may print each character in uppercase or lowercase. For example, NO, no, No, and nO are all considered identical. ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤ A, B, C, X ≤ 100$ ------ subtasks ------ Subtask 1 (10 points): $1 ≤ M ≤ 10$ Subtask 2 (20 points): The sum of $N$ across all test cases won't exceed $20$. Subtask 3 (70 points): No further constraints. ----- Sample Input 1 ------ 4 1 1 1 3 2 3 1 5 4 2 3 4 2 1 4 7 ----- Sample Output 1 ------ NO YES YES NO ----- explanation 1 ------ Test case $1$: No two people can contribute to collect enough money to buy a Netflix subscription. Test case $2$: Alice and Bob can contribute and collect a total of $5$ rupees which is enough to buy a Netflix subscription of $5$ rupees. Test case $3$: One possible way is, Bob and Charlie can contribute and collect a total of $5$ rupees which is enough to buy a Netflix subscription of $4$ rupees. Note that there are other possible ways as well. Test case $4$: No two people can contribute to collect enough money to buy a Netflix subscription.
{"inputs": ["4\n1 1 1 3\n2 3 1 5\n4 2 3 4\n2 1 4 7\n"], "outputs": ["NO\nYES\nYES\nNO\n"]}
487
52
coding
Solve the programming task below in a Python markdown code block. In this Kata you need to write the method SharedBits that returns true if 2 integers share at least two '1' bits. For simplicity assume that all numbers are positive For example int seven = 7; //0111 int ten = 10; //1010 int fifteen = 15; //1111 SharedBits(seven, ten); //false SharedBits(seven, fifteen); //true SharedBits(ten, fifteen); //true - seven and ten share only a single '1' (at index 3) - seven and fifteen share 3 bits (at indexes 1, 2, and 3) - ten and fifteen share 2 bits (at indexes 0 and 2) Hint: you can do this with just string manipulation, but binary operators will make your life much easier. Also feel free to reuse/extend the following starter code: ```python def shared_bits(a, b): ```
{"functional": "_inputs = [[1, 2], [16, 8], [1, 1], [2, 3], [7, 10], [43, 77], [7, 15], [23, 7]]\n_outputs = [[False], [False], [False], [False], [False], [True], [True], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(shared_bits(*i), o[0])"}
224
226
coding
Solve the programming task below in a Python markdown code block. Chef's phone shows a Battery Low notification if the battery level is 15 \% or less. Given that the battery level of Chef's phone is X \%, determine whether it would show a Battery low notification. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains a single line of input, an integer X, denoting the battery level of the phone. ------ Output Format ------ For each test case, output in a single line \texttt{Yes}, if the battery level is 15 \% or below. Otherwise, print \text{No}. You may print each character of \texttt{Yes} and \text{No} in uppercase or lowercase (for example, \texttt{YeS}, \texttt{YES}, \texttt{yes} will be considered identical). ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ X ≤ 100$ ------ subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 15 3 65 ----- Sample Output 1 ------ Yes Yes No ----- explanation 1 ------ Test Case 1: The battery level is $15$. Thus, it would show a battery low notification. Test Case 2: The battery level is $3$, which is less than $15$. Thus, it would show a battery low notification. Test Case 3: The battery level is $65$, which is greater than $15$. Thus, it would not show a battery low notification.
{"inputs": ["3\n15\n3\n65"], "outputs": ["Yes\nYes\nNo"]}
359
24
coding
Solve the programming task below in a Python markdown code block. Jimmy loves playing with strings. He thinks string $\mbox{A}$ is similar to string $\mbox{B}$ if the following conditions are satisfied: Both strings have the same length (i.e., $A=a_{0}a_{1}\ldots a_{n-1}$ and $B=b_0b_1\ldots b_{n-1}$). For each valid pair of indices, $(i,j)$, in the strings, $[a_i=a_j$ and $b_i=b_j]$ or $[a_i\neq a_j$ and $b_i\neq b_j]$. For example, string $a="adba"$ and $b="bcgb''$ are similar as for $i=0,j=3$, $a[0]==a[3]$ and $b[0]==b[3]$ and for all other $i,j$ pairs $a[i]\neq a[j]$ as well as $b[i]\neq b[j]$. He has a string, $\mbox{S}$, of size $n$ and gives you $\textit{q}$ queries to answer where each query is in the form of a pair of integers $(l_i,r_i)$. For each substring $S[l_i,r_i]$, find the number of substrings $S[x,y]$ where substring $S[l_i,r_i]$ is similar to substring $S[x,y]$ and print this number on a new line. Note: Substring $S[x,y]$ is the contiguous sequence of characters from index $\boldsymbol{x}$ to index $y$. For example, if $S=$ abcdefgh, then $S[3,6]=$ cdef. Input Format The first line contains two space-separated integers describing the respective values of $n$ and $\textit{q}$. The second line contains string $\mbox{S}$. Each line $\boldsymbol{i}$ of the $\textit{q}$ subsequent lines contains two space-separated integers describing the respective values of $l_i$ and $r_i$ for query $\boldsymbol{i}$. Constraints $1\leq n,q\leq5\times10^4$ $1\leq L_i\leq R_i\leq n$ $s_i\in\{a,b,c,d,e,f,g,h,i,j\}$ Output Format For each query, print the number of similar substrings on a new line. Sample Input 8 4 giggabaj 1 1 1 2 1 3 2 4 Sample Output 8 6 2 1 Explanation We perform the following sequence of queries: Strings with length $1$ are all similar, so our answer is $8$. gi, ig, ga, ab, ba, and aj are similar, so our answer is $6$. gig and aba are similar, so our answer is $2$. igg has no similar string, so our answer is $1$.
{"inputs": ["8 4\ngiggabaj\n1 1\n1 2\n1 3\n2 4\n"], "outputs": ["8\n6\n2\n1\n"]}
651
42
coding
Solve the programming task below in a Python markdown code block. Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the information the berlanders needed so much. The captured enemy had an array of positive integers. Berland intelligence have long been aware of the flatland code: to convey the message, which contained a number m, the enemies use an array of integers a. The number of its subarrays, in which there are at least k equal numbers, equals m. The number k has long been known in the Berland army so General Touristov has once again asked Corporal Vasya to perform a simple task: to decipher the flatlanders' message. Help Vasya, given an array of integers a and number k, find the number of subarrays of the array of numbers a, which has at least k equal numbers. Subarray a[i... j] (1 ≤ i ≤ j ≤ n) of array a = (a1, a2, ..., an) is an array, made from its consecutive elements, starting from the i-th one and ending with the j-th one: a[i... j] = (ai, ai + 1, ..., aj). Input The first line contains two space-separated integers n, k (1 ≤ k ≤ n ≤ 4·105), showing how many numbers an array has and how many equal numbers the subarrays are required to have, correspondingly. The second line contains n space-separated integers ai (1 ≤ ai ≤ 109) — elements of the array. Output Print the single number — the number of such subarrays of array a, that they have at least k equal integers. Please do not use the %lld specifier to read or write 64-bit integers in С++. In is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 4 2 1 2 1 2 Output 3 Input 5 3 1 2 1 1 3 Output 2 Input 3 1 1 1 1 Output 6 Note In the first sample are three subarrays, containing at least two equal numbers: (1,2,1), (2,1,2) and (1,2,1,2). In the second sample are two subarrays, containing three equal numbers: (1,2,1,1,3) and (1,2,1,1). In the third sample any subarray contains at least one 1 number. Overall they are 6: (1), (1), (1), (1,1), (1,1) and (1,1,1).
{"inputs": ["1 1\n5\n", "3 1\n1 1 1\n", "2 2\n97 197\n", "2 1\n97 197\n", "2 2\n193 193\n", "4 2\n0 2 1 2\n", "4 2\n0 2 2 2\n", "4 2\n1 2 1 2\n"], "outputs": [" 1\n", " 6\n", " 0\n", "3\n", " 1\n", "2\n", "5\n", " 3\n"]}
616
150
coding
Solve the programming task below in a Python markdown code block. You are given an array A consisting of N positive integers and a positive integer K. Find whether there exists a *subset* S of the elements of A such that the product of all elements of S is divisible by K. Note that a *subset* is obtained by deleting some or no elements without changing the order of the remaining elements. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains two space-separated integers N and K — the number of elements of A and the above mentioned integer K. - The second line of each test case contains N space-separated integers A_{1},A_{2},\ldots,A_{N} representing the array A. ------ Output Format ------ For each test case, print on a new line the answer: YES if there exists a subset S and NO otherwise. Each character of the output may be printed in either uppercase or lowercase, i.e, the strings Yes, YES, yes, yEs will all be treated as identical. ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ N ≤ 100$ $1 ≤ A_{i}, K ≤ 10^{9}$ ----- Sample Input 1 ------ 3 2 2 7 8 5 3 1 1 2 1 1 3 6 7 2 3 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case $1$: Consider the subset $S = [8]$. The product of all the elements is $8$ which is divisible by $K = 2$. Test case $2$: There exists no subset of $A$ such that the product of all elements of the subset is divisible by $K$. Test case $3$: Consider the subset $S = [2, 3]$. The product of all the elements is $6$ which is divisible by $K = 6$.
{"inputs": ["3\n2 2\n7 8\n5 3\n1 1 2 1 1\n3 6\n7 2 3\n"], "outputs": ["YES\nNO\nYES"]}
449
49
coding
Solve the programming task below in a Python markdown code block. Akash loves going to school, but not on weekends. A week consists of 7 days (Monday to Sunday). Akash takes a leave every Saturday. If a month consists of N days and the first-day of the month is Monday, find the number of days Akash would take a leave in the whole month. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - Each test case contains a single line of input, one integer N - the number of days in the month. ------ Output Format ------ For each test case, output in a single line, the number of days Akash would take a leave in the whole month. ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ N ≤ 10^{9}$ ------ subtasks ------ Subtask 1 (30 points) : $1 ≤ N ≤ 100$ Subtask 2 (70 points) : Original Constraints ----- Sample Input 1 ------ 4 5 6 8 22 ----- Sample Output 1 ------ 0 1 1 3 ----- explanation 1 ------ Test case $1$: The month consists of $5$ days (Monday, Tuesday, Wednesday, Thursday, and Friday). Since there are no Saturdays, Akash would go to school every day. Thus, he takes a leave for $0$ days. Test case $2$: The month consists of $6$ days (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday). Akash takes a leave only on Saturday. Thus, he takes a leave for $1$ day. Test case $3$: The month consists of $8$ days (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday, Monday). Akash takes a leave only on Saturday. Thus, he takes a leave for $1$ day.
{"inputs": ["4\n5\n6\n8\n22"], "outputs": ["0\n1\n1\n3"]}
410
27
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers arr and two integers k and threshold, return the number of sub-arrays of size k and average greater than or equal to threshold.   Please complete the following python code precisely: ```python class Solution: def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4) == 3\n assert candidate(arr = [11,13,17,23,29,31,7,5,2,3], k = 3, threshold = 5) == 6\n\n\ncheck(Solution().numOfSubarrays)"}
89
103
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array nums of length n, consisting of non-negative integers. For each index i from 0 to n - 1, you must determine the size of the minimum sized non-empty subarray of nums starting at i (inclusive) that has the maximum possible bitwise OR. In other words, let Bij be the bitwise OR of the subarray nums[i...j]. You need to find the smallest subarray starting at i, such that bitwise OR of this subarray is equal to max(Bik) where i <= k <= n - 1. The bitwise OR of an array is the bitwise OR of all the numbers in it. Return an integer array answer of size n where answer[i] is the length of the minimum sized subarray starting at i with maximum bitwise OR. A subarray is a contiguous non-empty sequence of elements within an array.   Please complete the following python code precisely: ```python class Solution: def smallestSubarrays(self, nums: List[int]) -> List[int]: ```
{"functional": "def check(candidate):\n assert candidate(nums = [1,0,2,1,3]) == [3,3,2,2,1]\n assert candidate(nums = [1,2]) == [2,1]\n\n\ncheck(Solution().smallestSubarrays)"}
229
67
coding
Solve the programming task below in a Python markdown code block. Chef has a binary string S of size N. Chef can perform the following operation on the string: Select any substring of size 3 and reverse it. Find the minimum *distance* between any two 1s Chef can achieve, by applying the above operation any (possibly zero) number of times. Note: The *distance* between two characters S_{i} and S_{j} is defined as abs(i-j). It is guaranteed that the string contains at least two occurrences of 1. A substring is obtained by deleting some (possibly zero) elements from the beginning and some (possibly zero) elements from the end of the string. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains an integer N — the number of characters in the string. - The next line contains a binary string of length N. ------ Output Format ------ For each test case, output on a new line, the minimum distance between any two 1s Chef can achieve, by applying the above operation any (possibly zero) number of times. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $S_{i}$ contains $0$ and $1$ only. - It is guaranteed that $S$ contains at least two occurrences of $1$. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 11 3 101 7 0100101 ----- Sample Output 1 ------ 1 2 1 ----- explanation 1 ------ Test case $1$: There are only two $1$s in the string. The distance between the $1$s is $2-1 = 1$. Test case $2$: The distance between the given $1$s is $3-1 = 2$. It can be shown that we cannot achieve a distance smaller than $2$ by applying any number of operations. Test case $3$: Chef can perform the following operation: - Select the substring $S[2,4] = 100$ and reverse it. Thus, the string becomes $S = 0001101$. The minimum distance between the $1$s in the string is $5-4 = 1$. It can be shown that we cannot achieve a distance smaller than $1$ by applying any number of operations.
{"inputs": ["3\n2\n11\n3\n101\n7\n0100101\n"], "outputs": ["1\n2\n1"]}
560
38
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array points where points[i] = [xstart, xend] denotes a balloon whose horizontal diameter stretches between xstart and xend. You do not know the exact y-coordinates of the balloons. Arrows can be shot up directly vertically (in the positive y-direction) from different points along the x-axis. A balloon with xstart and xend is burst by an arrow shot at x if xstart <= x <= xend. There is no limit to the number of arrows that can be shot. A shot arrow keeps traveling up infinitely, bursting any balloons in its path. Given the array points, return the minimum number of arrows that must be shot to burst all balloons.   Please complete the following python code precisely: ```python class Solution: def findMinArrowShots(self, points: List[List[int]]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(points = [[10,16],[2,8],[1,6],[7,12]]) == 2\n assert candidate(points = [[1,2],[3,4],[5,6],[7,8]]) == 4\n assert candidate(points = [[1,2],[2,3],[3,4],[4,5]]) == 2\n\n\ncheck(Solution().findMinArrowShots)"}
216
103
coding
Solve the programming task below in a Python markdown code block. Nauuo is a girl who loves writing comments. One day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes. It's known that there were $x$ persons who would upvote, $y$ persons who would downvote, and there were also another $z$ persons who would vote, but you don't know whether they would upvote or downvote. Note that each of the $x+y+z$ people would vote exactly one time. There are three different results: if there are more people upvote than downvote, the result will be "+"; if there are more people downvote than upvote, the result will be "-"; otherwise the result will be "0". Because of the $z$ unknown persons, the result may be uncertain (i.e. there are more than one possible results). More formally, the result is uncertain if and only if there exist two different situations of how the $z$ persons vote, that the results are different in the two situations. Tell Nauuo the result or report that the result is uncertain. -----Input----- The only line contains three integers $x$, $y$, $z$ ($0\le x,y,z\le100$), corresponding to the number of persons who would upvote, downvote or unknown. -----Output----- If there is only one possible result, print the result : "+", "-" or "0". Otherwise, print "?" to report that the result is uncertain. -----Examples----- Input 3 7 0 Output - Input 2 0 1 Output + Input 1 1 0 Output 0 Input 0 0 1 Output ? -----Note----- In the first example, Nauuo would definitely get three upvotes and seven downvotes, so the only possible result is "-". In the second example, no matter the person unknown downvotes or upvotes, Nauuo would get more upvotes than downvotes. So the only possible result is "+". In the third example, Nauuo would definitely get one upvote and one downvote, so the only possible result is "0". In the fourth example, if the only one person upvoted, the result would be "+", otherwise, the result would be "-". There are two possible results, so the result is uncertain.
{"inputs": ["3 7 0\n", "2 0 1\n", "1 1 0\n", "0 0 1\n", "1 0 1\n", "5 7 1\n", "1 1 1\n", "0 0 0\n"], "outputs": ["-", "+", "0", "?", "?", "-", "?", "0"]}
501
87
coding
Solve the programming task below in a Python markdown code block. You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer. -----Constraints----- - a and b are integers. - 1 \leq a, b \leq 100 -----Input----- Input is given from Standard Input in the following format: a b -----Output----- Print x rounded up to the nearest integer. -----Sample Input----- 1 3 -----Sample Output----- 2 The average of 1 and 3 is 2.0, and it will be rounded up to the nearest integer, 2.
{"inputs": ["1 3\n", "7 4\n", "5 5\n"], "outputs": ["2\n", "6\n", "5\n"]}
140
36
coding
Solve the programming task below in a Python markdown code block. The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be? In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: * on each holiday day the Hedgehog will necessarily receive a present, * he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). Input The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. Output Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. Examples Input 5 2 1 3 Output 3 Input 10 1 3 6 7 8 Output 10
{"inputs": ["5 1\n0\n", "1 1\n0\n", "5 2\n0\n", "2 1\n0\n", "3 1\n0\n", "2 2\n0\n", "15 5\n0\n", "20 1\n0\n"], "outputs": ["5\n", "1\n", "2\n", "2\n", "3\n", "1\n", "3\n", "20\n"]}
400
105
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5. Given an integer n, return the nth ugly number.   Please complete the following python code precisely: ```python class Solution: def nthUglyNumber(self, n: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(n = 10) == 12\n assert candidate(n = 1) == 1\n\n\ncheck(Solution().nthUglyNumber)"}
83
47
coding
Solve the programming task below in a Python markdown code block. Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 = 100. Input Given multiple datasets. Each dataset is given the integer n (n ≤ 10000). When n is 0, it is the last input. The number of datasets does not exceed 50. Output For n in each dataset, print s on one line. Example Input 2 9 0 Output 5 100
{"inputs": ["2\n2\n0", "2\n7\n0", "2\n0\n0", "2\n5\n0", "2\n1\n0", "2\n3\n0", "2\n8\n0", "2\n6\n0"], "outputs": ["5\n5\n", "5\n58\n", "5\n", "5\n28\n", "5\n2\n", "5\n10\n", "5\n77\n", "5\n41\n"]}
231
113
coding
Solve the programming task below in a Python markdown code block. $n$ students attended the first meeting of the Berland SU programming course ($n$ is even). All students will be divided into two groups. Each group will be attending exactly one lesson each week during one of the five working days (Monday, Tuesday, Wednesday, Thursday and Friday), and the days chosen for the groups must be different. Furthermore, both groups should contain the same number of students. Each student has filled a survey in which they told which days of the week are convenient for them to attend a lesson, and which are not. Your task is to determine if it is possible to choose two different week days to schedule the lessons for the group (the first group will attend the lesson on the first chosen day, the second group will attend the lesson on the second chosen day), and divide the students into two groups, so the groups have equal sizes, and for each student, the chosen lesson day for their group is convenient. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. Then the descriptions of $t$ testcases follow. The first line of each testcase contains one integer $n$ ($2 \le n \le 1000$) — the number of students. The $i$-th of the next $n$ lines contains $5$ integers, each of them is $0$ or $1$. If the $j$-th integer is $1$, then the $i$-th student can attend the lessons on the $j$-th day of the week. If the $j$-th integer is $0$, then the $i$-th student cannot attend the lessons on the $j$-th day of the week. Additional constraints on the input: for each student, at least one of the days of the week is convenient, the total number of students over all testcases doesn't exceed $10^5$. -----Output----- For each testcase print an answer. If it's possible to divide the students into two groups of equal sizes and choose different days for the groups so each student can attend the lesson in the chosen day of their group, print "YES" (without quotes). Otherwise, print "NO" (without quotes). -----Examples----- Input 2 4 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 1 0 2 0 0 0 1 0 0 0 0 1 0 Output YES NO -----Note----- In the first testcase, there is a way to meet all the constraints. For example, the first group can consist of the first and the third students, they will attend the lessons on Thursday (the fourth day); the second group can consist of the second and the fourth students, and they will attend the lessons on Tuesday (the second day). In the second testcase, it is impossible to divide the students into groups so they attend the lessons on different days.
{"inputs": ["2\n4\n1 0 0 1 0\n0 1 0 0 1\n0 0 0 1 0\n0 1 0 1 0\n2\n0 0 0 1 0\n0 0 0 1 0\n", "2\n4\n1 0 0 1 0\n0 1 0 0 1\n0 0 0 1 0\n0 1 0 1 0\n2\n0 0 0 0 0\n0 0 0 1 0\n", "2\n4\n1 0 0 1 0\n1 1 0 0 1\n0 0 0 0 0\n0 1 0 1 0\n2\n0 0 0 0 0\n0 0 0 1 1\n", "2\n4\n1 0 0 1 0\n0 1 0 0 1\n0 0 0 1 0\n0 1 0 1 0\n2\n0 0 0 1 1\n0 0 0 1 0\n", "2\n4\n1 0 0 1 0\n1 1 0 0 1\n0 0 0 0 0\n0 1 0 1 0\n2\n0 0 1 0 0\n0 0 0 1 1\n", "2\n4\n1 0 0 1 0\n0 1 1 0 1\n0 0 0 1 0\n0 1 0 1 0\n2\n0 0 0 0 0\n0 0 0 1 0\n", "2\n4\n1 0 0 1 0\n1 1 0 0 1\n0 0 0 1 0\n0 1 0 1 0\n2\n0 0 0 0 0\n0 0 0 1 0\n", "2\n4\n1 0 0 1 0\n1 1 0 0 1\n0 0 0 1 0\n0 1 0 1 0\n2\n0 0 0 0 0\n0 0 0 1 1\n"], "outputs": ["YES\nNO\n", "YES\nNO\n", "NO\nNO\n", "YES\nYES\n", "NO\nYES\n", "YES\nNO\n", "YES\nNO\n", "YES\nNO\n"]}
657
598
coding
Solve the programming task below in a Python markdown code block. Write a function `take_umbrella()` that takes two arguments: a string representing the current weather and a float representing the chance of rain today. Your function should return `True` or `False` based on the following criteria. * You should take an umbrella if it's currently raining or if it's cloudy and the chance of rain is over `0.20`. * You shouldn't take an umbrella if it's sunny unless it's more likely to rain than not. The options for the current weather are `sunny`, `cloudy`, and `rainy`. For example, `take_umbrella('sunny', 0.40)` should return `False`. As an additional challenge, consider solving this kata using only logical operaters and not using any `if` statements. Also feel free to reuse/extend the following starter code: ```python def take_umbrella(weather, rain_chance): ```
{"functional": "_inputs = [['sunny', 0.4], ['rainy', 0.0], ['cloudy', 0.2]]\n_outputs = [[False], [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(take_umbrella(*i), o[0])"}
202
187
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Limak is a little polar bear, who loves eating cookies and drinking milk. For this reason he often visits Chef's kitchen. Limak is going to spend N minutes in the kitchen. Each minute he either eats a cookie or drinks milk. Cookies are very sweet and thus Limak's parents have instructed him, that after eating a cookie, he has to drink milk in the next minute. You are given whether he ate a cookie or drank milk in each of the N minutes. Your task is to check if Limak followed his parents' instructions. That is, you need to verify whether after each eaten cookie he drinks milk in the next minute. Print "YES" or "NO" for each test case accordingly. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains an integer N denoting the number of minutes. The second line of a test case contains N space-separated strings S_{1}, S_{2}, ..., S_{N}. The string S_{i} is either "cookie" (if Limak eats a cookie in the i-th minute) or "milk" (otherwise). ------ Output ------ For each test case, output a single line containing the answer — "YES" if Limak followed his parents' instructions, and "NO" otherwise, both without the quotes. ------ Constraints ------ $1 ≤ T ≤ 50$ $1 ≤ N ≤ 50$ $ Each S_{i} is either "cookie" or "milk" (without the quotes). ------ Subtasks ------ $Subtask #1 (40 points) N = 2$ $Subtask #2 (60 points) Original constraints$ ----- Sample Input 1 ------ 4 7 cookie milk milk cookie milk cookie milk 5 cookie cookie milk milk milk 4 milk milk milk milk 1 cookie ----- Sample Output 1 ------ YES NO YES NO ----- explanation 1 ------ Test case 1. Limak is in the kitchen for 7 minutes. He eats three cookies and after each of them he indeed drinks milk in the next minute. The answer is "YES". Test case 2. Limak is in the kitchen for 5 minutes. In the first minute he eats a cookie and in the second minute he eats a cookie again, instead of drinking milk. The answer is "NO". Test case 3. Here Limak doesn't eat any cookies. The answer is "YES" because the condition is satisfied (there is no situation when Limak eats a cookie but doesn't drink milk in the next minute). Test case 4. Limak eats a cookie and doesn't drink milk in the next minute so the answer is "NO".
{"inputs": ["4\n7\ncookie milk milk cookie milk cookie milk\n5\ncookie cookie milk milk milk\n4\nmilk milk milk milk\n1\ncookie"], "outputs": ["YES\nNO\nYES\nNO"]}
611
48
coding
Solve the programming task below in a Python markdown code block. # Definition **_Extra perfect number_** *is the number that* **_first_** and **_last_** *bits* are **_set bits_**. ____ # Task **_Given_** *a positive integer* `N` , **_Return_** the **_extra perfect numbers_** *in range from* `1` to `N` . ____ # Warm-up (Highly recommended) # [Playing With Numbers Series](https://www.codewars.com/collections/playing-with-numbers) ___ # Notes * **_Number_** *passed is always* **_Positive_** . * **_Returned array/list_** should *contain the extra perfect numbers in ascending order* **from lowest to highest** ___ # Input >> Output Examples ``` extraPerfect(3) ==> return {1,3} ``` ## **_Explanation_**: # (1)10 =(1)2 **First** and **last** bits as **_set bits_**. # (3)10 = (11)2 **First** and **last** bits as **_set bits_**. ___ ``` extraPerfect(7) ==> return {1,3,5,7} ``` ## **_Explanation_**: # (5)10 = (101)2 **First** and **last** bits as **_set bits_**. # (7)10 = (111)2 **First** and **last** bits as **_set bits_**. ___ ___ ___ # [Playing with Numbers Series](https://www.codewars.com/collections/playing-with-numbers) # [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays) # [For More Enjoyable Katas](http://www.codewars.com/users/MrZizoScream/authored) ___ ## ALL translations are welcomed ## Enjoy Learning !! # Zizou Also feel free to reuse/extend the following starter code: ```python def extra_perfect(n): ```
{"functional": "_inputs = [[3], [5], [7], [28], [39]]\n_outputs = [[[1, 3]], [[1, 3, 5]], [[1, 3, 5, 7]], [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27]], [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]]]\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(extra_perfect(*i), o[0])"}
480
319
coding
Solve the programming task below in a Python markdown code block. You will be given an array of non-negative integers and positive integer bin width. Your task is to create the Histogram method that will return histogram data corresponding to the input array. The histogram data is an array that stores under index i the count of numbers that belong to bin i. The first bin always starts with zero. On empty input you should return empty output. Examples: For input data [1, 1, 0, 1, 3, 2, 6] and binWidth=1 the result will be [1, 3, 1, 1, 0, 0, 1] as the data contains single element "0", 3 elements "1" etc. For the same data and binWidth=2 the result will be [4, 2, 0, 1] For input data [7] and binWidth=1 the result will be [0, 0, 0, 0, 0, 0, 0, 1] Also feel free to reuse/extend the following starter code: ```python def histogram(values, bin_width): ```
{"functional": "_inputs = [[[1, 1, 0, 1, 3, 2, 6], 1], [[1, 1, 0, 1, 3, 2, 6], 2], [[], 1], [[8], 1]]\n_outputs = [[[1, 3, 1, 1, 0, 0, 1]], [[4, 2, 0, 1]], [[]], [[0, 0, 0, 0, 0, 0, 0, 0, 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(histogram(*i), o[0])"}
248
269
coding
Solve the programming task below in a Python markdown code block. You are given a sequence whose $n^{\text{th}}$ term is $T_{n}=n^{K}$ You have to evaluate the series $S_n=T_1+T_2+T_3+\cdots+T_n$ Find $S_n\:\text{mod}\:(10^9+7)$. Input Format The first line of input contains $\mathbf{T}$, the number of test cases. Each test case consists of one line containing two space-separated integers $n$ and $\mbox{K}$. Output Format For each test case, print the required answer in a line. Constraints $1\leq T\leq10$ $0\leq K\leq10^3$ $1\leq n\leq10^{16}$ Sample Input 3 5 3 4 2 4 1 Sample Output 225 30 10 Explanation Case 1: We have $225=1^3+2^3+3^3+4^3+5^3$ Case 2: We have $30=1^2+2^2+3^2+4^2$ Case 3: We have $10=1^1+2^1+3^1+4^1$
{"inputs": ["3\n5 3\n4 2\n4 1\n"], "outputs": ["225\n30\n10\n"]}
314
34
coding
Solve the programming task below in a Python markdown code block. Chef's son wants to go on a roller coaster ride. The height of Chef's son is X inches while the minimum height required to go on the ride is H inches. Determine whether he can go on the ride 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 two integers X and H - the height of Chef's son and the minimum height required for the ride respectively. ------ Output Format ------ For each test case, output in a single line, YES if Chef's son can go on the ride. Otherwise, output NO. You may print each character of YES and NO in uppercase or lowercase (for example, yes, yEs, Yes will be considered identical) ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤ X, H ≤ 100$ ----- Sample Input 1 ------ 4 15 20 50 48 32 32 38 39 ----- Sample Output 1 ------ NO YES YES NO ----- explanation 1 ------ Test case 1: Chef's son can not go on the ride as his height $<$ the minimum required height. Test case 2: Chef's son can go on the ride as his height $≥$ the minimum required height. Test case 3: Chef's son can go on the ride as his height $≥$ the minimum required height. Test case 4: Chef's son can not go on the ride as his height $<$ the minimum required height.
{"inputs": ["4\n15 20\n50 48\n32 32\n38 39\n"], "outputs": ["NO\nYES\nYES\nNO"]}
357
43
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a forest with an unknown number of rabbits. We asked n rabbits "How many rabbits have the same color as you?" and collected the answers in an integer array answers where answers[i] is the answer of the ith rabbit. Given the array answers, return the minimum number of rabbits that could be in the forest.   Please complete the following python code precisely: ```python class Solution: def numRabbits(self, answers: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(answers = [1,1,2]) == 5\n assert candidate(answers = [10,10,10]) == 11\n\n\ncheck(Solution().numRabbits)"}
115
59
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of unique integers preorder, return true if it is the correct preorder traversal sequence of a binary search tree.   Please complete the following python code precisely: ```python class Solution: def verifyPreorder(self, preorder: List[int]) -> bool: ```
{"functional": "def check(candidate):\n assert candidate(preorder = [5,2,1,3,6]) == True\n assert candidate(preorder = [5,2,6,1,3]) == False\n\n\ncheck(Solution().verifyPreorder)"}
73
60
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. For two strings s and t, we say "t divides s" if and only if s = t + t + t + ... + t + t (i.e., t is concatenated with itself one or more times). Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2.   Please complete the following python code precisely: ```python class Solution: def gcdOfStrings(self, str1: str, str2: str) -> str: ```
{"functional": "def check(candidate):\n assert candidate(str1 = \"ABCABC\", str2 = \"ABC\") == \"ABC\"\n assert candidate(str1 = \"ABABAB\", str2 = \"ABAB\") == \"AB\"\n assert candidate(str1 = \"LEET\", str2 = \"CODE\") == \"\"\n\n\ncheck(Solution().gcdOfStrings)"}
124
84
coding
Solve the programming task below in a Python markdown code block. Our lazy white falcon finally decided to learn heavy-light decomposition. Her teacher gave an assignment for her to practice this new technique. Please help her by solving this problem. You are given a tree with $N$ nodes and each node's value is initially $0$. The problem asks you to operate the following two types of queries: "1 u x" assign $\boldsymbol{x}$ to the value of the node $\mbox{u}$. "2 u v" print the maximum value of the nodes on the unique path between $\mbox{u}$ and $\boldsymbol{\nu}$. Input Format First line consists of two integers seperated by a space: $N$ and $Q$. Following $N-1$ lines consisting of two integers denotes the undirectional edges of the tree. Following $Q$ lines consist of the queries you are asked to operate. Constraints $1\leq N,Q,x\leq50000$ It is guaranteed that input denotes a connected tree with $N$ nodes. Nodes are enumerated with 0-based indexing. Output Format For each second type of query print single integer in a single line, denoting the asked maximum value. Sample Input 3 3 0 1 1 2 1 0 1 1 1 2 2 0 2 Sample Output 2 Explanation After the first two updates value of the $0$th node is $1$ and $1$st node is $2$. That is why maxiumum value on the path between $0$ and $2$ is $max(1,2)=2$.
{"inputs": ["3 3\n0 1\n1 2\n1 0 1\n1 1 2\n2 0 2\n"], "outputs": ["2\n"]}
358
42
coding
Solve the programming task below in a Python markdown code block. Today was a sad day. Having bought a new beard trimmer, I set it to the max setting and shaved away at my joyous beard. Stupidly, I hadnt checked just how long the max setting was, and now I look like Ive just started growing it! Your task, given a beard represented as an arrayof arrays, is to trim the beard as follows: ['|', 'J', '|', '|'], ['|', '|', '|', 'J'], ['...', '...', '...', '...']; To trim the beard use the following rules: trim any curled hair --> replace 'J' with '|' trim any hair from the chin (last array) --> replace '|' or 'J' with '...' All sub arrays will be same length. Return the corrected array of arrays Also feel free to reuse/extend the following starter code: ```python def trim(beard): ```
{"functional": "_inputs = [[[['J', '|'], ['J', '|'], ['...', '|']]], [[['J', '|', 'J'], ['J', '|', '|'], ['...', '|', 'J']]], [[['J', '|', 'J', 'J'], ['J', '|', '|', 'J'], ['...', '|', 'J', '|']]]]\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(trim(*i), o[0])"}
198
288
coding
Solve the programming task below in a Python markdown code block. Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer). There are t seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than t seconds. Note, that he can choose to not use all t seconds. Moreover, he can even choose to not round the grade at all. In this problem, classic rounding rules are used: while rounding number to the n-th digit one has to take a look at the digit n + 1. If it is less than 5 than the n-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the n + 1 digit is greater or equal to 5, the digit at the position n is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away. For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3. -----Input----- The first line of the input contains two integers n and t (1 ≤ n ≤ 200 000, 1 ≤ t ≤ 10^9) — the length of Efim's grade and the number of seconds till the end of the break respectively. The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0. -----Output----- Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes. -----Examples----- Input 6 1 10.245 Output 10.25 Input 6 2 10.245 Output 10.3 Input 3 100 9.2 Output 9.2 -----Note----- In the first two samples Efim initially has grade 10.245. During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect. In the third sample the optimal strategy is to not perform any rounding at all.
{"inputs": ["3 1\n0.1\n", "3 1\n9.9\n", "3 1\n0.9\n", "3 1\n9.5\n", "3 3\n9.9\n", "3 3\n9.9\n", "3 1\n0.1\n", "3 1\n9.9\n"], "outputs": ["0.1\n", "10\n", "1\n", "10\n", "10\n", "10\n", "0.1\n", "10\n"]}
628
127
coding
Solve the programming task below in a Python markdown code block. Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players. Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns. On his step player must add a single letter in the end of the word, the resulting word must be prefix of at least one string from the group. A player loses if he cannot move. Andrew and Alex decided to play this game k times. The player who is the loser of the i-th game makes the first move in the (i + 1)-th game. Guys decided that the winner of all games is the player who wins the last (k-th) game. Andrew and Alex already started the game. Fedor wants to know who wins the game if both players will play optimally. Help him. -----Input----- The first line contains two integers, n and k (1 ≤ n ≤ 10^5; 1 ≤ k ≤ 10^9). Each of the next n lines contains a single non-empty string from the given group. The total length of all strings from the group doesn't exceed 10^5. Each string of the group consists only of lowercase English letters. -----Output----- If the player who moves first wins, print "First", otherwise print "Second" (without the quotes). -----Examples----- Input 2 3 a b Output First Input 3 1 a b c Output First Input 1 2 ab Output Second
{"inputs": ["1 2\nab\n", "1 3\nab\n", "1 3\nab\n", "1 0\nab\n", "0 2\nab\n", "1 1\nab\n", "1 1\naa\n", "1 2\nab\n"], "outputs": ["Second\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n"]}
341
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at that point (i, j). The rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a square to another 4-directionally adjacent square if and only if the elevation of both squares individually are at most t. You can swim infinite distances in zero time. Of course, you must stay within the boundaries of the grid during your swim. Return the least time until you can reach the bottom right square (n - 1, n - 1) if you start at the top left square (0, 0).   Please complete the following python code precisely: ```python class Solution: def swimInWater(self, grid: List[List[int]]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(grid = [[0,2],[1,3]]) == 3\n assert candidate(grid = [[0,1,2,3,4],[24,23,22,21,5],[12,13,14,15,16],[11,17,18,19,20],[10,9,8,7,6]]) == 16\n\n\ncheck(Solution().swimInWater)"}
189
115
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A cell (r, c) of an excel sheet is represented as a string "<col><row>" where: <col> denotes the column number c of the cell. It is represented by alphabetical letters. For example, the 1st column is denoted by 'A', the 2nd by 'B', the 3rd by 'C', and so on. <row> is the row number r of the cell. The rth row is represented by the integer r. You are given a string s in the format "<col1><row1>:<col2><row2>", where <col1> represents the column c1, <row1> represents the row r1, <col2> represents the column c2, and <row2> represents the row r2, such that r1 <= r2 and c1 <= c2. Return the list of cells (x, y) such that r1 <= x <= r2 and c1 <= y <= c2. The cells should be represented as strings in the format mentioned above and be sorted in non-decreasing order first by columns and then by rows.   Please complete the following python code precisely: ```python class Solution: def cellsInRange(self, s: str) -> List[str]: ```
{"functional": "def check(candidate):\n assert candidate(s = \"K1:L2\") == [\"K1\",\"K2\",\"L1\",\"L2\"]\n assert candidate(s = \"A1:F1\") == [\"A1\",\"B1\",\"C1\",\"D1\",\"E1\",\"F1\"]\n\n\ncheck(Solution().cellsInRange)"}
287
81
coding
Solve the programming task below in a Python markdown code block. Little C loves number «3» very much. He loves all things about it. Now he is playing a game on a chessboard of size $n \times m$. The cell in the $x$-th row and in the $y$-th column is called $(x,y)$. Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly $3$. The Manhattan distance between two cells $(x_i,y_i)$ and $(x_j,y_j)$ is defined as $|x_i-x_j|+|y_i-y_j|$. He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place. -----Input----- A single line contains two integers $n$ and $m$ ($1 \leq n,m \leq 10^9$) — the number of rows and the number of columns of the chessboard. -----Output----- Print one integer — the maximum number of chessmen Little C can place. -----Examples----- Input 2 2 Output 0 Input 3 3 Output 8 -----Note----- In the first example, the Manhattan distance between any two cells is smaller than $3$, so the answer is $0$. In the second example, a possible solution is $(1,1)(3,2)$, $(1,2)(3,3)$, $(2,1)(1,3)$, $(3,1)(2,3)$.
{"inputs": ["2 2\n", "3 3\n", "1 4\n", "1 6\n", "7 1\n", "7 2\n", "2 3\n", "2 5\n"], "outputs": ["0", "8", "2", "6", "6", "12", "4", "10"]}
339
80
coding
Solve the programming task below in a Python markdown code block. Fennec is fighting with N monsters. The health of the i-th monster is H_i. Fennec can do the following two actions: - Attack: Fennec chooses one monster. That monster's health will decrease by 1. - Special Move: Fennec chooses one monster. That monster's health will become 0. There is no way other than Attack and Special Move to decrease the monsters' health. Fennec wins when all the monsters' healths become 0 or below. Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times. -----Constraints----- - 1 \leq N \leq 2 \times 10^5 - 0 \leq K \leq 2 \times 10^5 - 1 \leq H_i \leq 10^9 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: N K H_1 ... H_N -----Output----- Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning. -----Sample Input----- 3 1 4 1 5 -----Sample Output----- 5 By using Special Move on the third monster, and doing Attack four times on the first monster and once on the second monster, Fennec can win with five Attacks.
{"inputs": ["3 1\n0 1 5", "3 0\n0 1 5", "3 1\n4 1 6", "3 1\n4 1 5", "3 1\n4 1 5\n", "8 8\n7 9 3 2 3 8 4 6", "8 0\n4 9 5 2 3 6 5 6", "8 1\n4 9 5 2 3 6 5 6"], "outputs": ["1\n", "6\n", "5\n", "5", "5\n", "0\n", "40\n", "31\n"]}
320
158
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. Let's call a positive integer $M$ a *beautiful number* if the following conditions are satisfied: The decimal representation of $M$ (without leading zeros) does not contain any zeros. The sum of squares of all decimal digits of $M$ is a perfect square. For example, $1$, $4$ and $221$ are beautiful, but $10$ and $333$ are not. You are given a positive integer $N$. Find the smallest $N$-digit beautiful number or determine that all $N$-digit integers are not beautiful. ------ 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 a single line containing one integer ― the smallest $N$-digit beautiful number, or $-1$ if there is no such number. ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ N ≤ 10^{6}$ the sum of $N$ over all test cases does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (10 points): $1 ≤ N ≤ 100$ Subtask #2 (90 points): $1 ≤ T ≤ 10$ ----- Sample Input 1 ------ 2 1 2 ----- Sample Output 1 ------ 1 34 ----- explanation 1 ------ Example case 1: It is obvious that $1$ is the smallest beautiful number. Example case 2: $34$ is beautiful because $3^{2} + 4^{2} = 9 + 16 = 25 = 5^{2}$. On the other hand, we can prove that this is the smallest beautiful number.
{"inputs": ["2\n1\n2"], "outputs": ["1\n34"]}
453
19