task_type
stringclasses
1 value
problem
stringlengths
209
3.39k
answer
stringlengths
35
6.15k
problem_tokens
int64
60
774
answer_tokens
int64
12
2.04k
coding
Solve the programming task below in a Python markdown code block. Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0, 1, 0, 1}, {1, 0, 1}, and {1, 0, 1, 0} are alternating sequences, while {1, 0, 0} and {0, 1, 0, 1, 1} are not. Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have. Input The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000). The following line contains a binary string of length n representing Kevin's results on the USAICO. Output Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring. Examples Input 8 10000011 Output 5 Input 2 01 Output 2 Note In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'. In the second sample, Kevin can flip the entire string and still have the same score.
{"inputs": ["1\n0\n", "1\n1\n", "2\n00\n", "2\n10\n", "2\n11\n", "2\n01\n", "3\n101\n", "3\n001\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "3\n", "3\n"]}
506
94
coding
Solve the programming task below in a Python markdown code block. A few years ago, Aaron left his old school and registered at another due to security reasons. Now he wishes to find Jane, one of his schoolmates and good friends. There are `n` schools numbered from 1 to `n`. One can travel between each pair of schools by buying a ticket. The ticket between schools `i` and `j` costs `(i + j) modulo (n + 1)` and can be used multiple times. Help Aaron find the minimum total cost to visit all schools. He can start and finish at any school. Range : 1 ≤ n ≤ 10^(6) Also feel free to reuse/extend the following starter code: ```python def find_jane(n): ```
{"functional": "_inputs = [[2], [10]]\n_outputs = [[0], [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(find_jane(*i), o[0])"}
169
162
coding
Solve the programming task below in a Python markdown code block. Chef Ada is preparing $N$ dishes (numbered $1$ through $N$). For each valid $i$, it takes $C_i$ minutes to prepare the $i$-th dish. The dishes can be prepared in any order. Ada has a kitchen with two identical burners. For each valid $i$, to prepare the $i$-th dish, she puts it on one of the burners and after $C_i$ minutes, removes it from this burner; the dish may not be removed from the burner before those $C_i$ minutes pass, because otherwise it cools down and gets spoiled. Any two dishes may be prepared simultaneously, however, no two dishes may be on the same burner at the same time. Ada may remove a dish from a burner and put another dish on the same burner at the same time. What is the minimum time needed to prepare all dishes, i.e. reach the state where all dishes are prepared? -----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 $C_1, C_2, \ldots, C_N$. -----Output----- For each test case, print a single line containing one integer ― the minimum number of minutes needed to prepare all dishes. -----Constraints----- - $1 \le T \le 1,000$ - $1 \le N \le 4$ - $1 \le C_i \le 5$ for each valid $i$ -----Subtasks----- Subtask #1 (1 points): $C_1 = C_2 = \ldots = C_N$ Subtask #2 (99 points): original constraints -----Example Input----- 3 3 2 2 2 3 1 2 3 4 2 3 4 5 -----Example Output----- 4 3 7 -----Explanation----- Example case 1: Place the first two dishes on the burners, wait for two minutes, remove both dishes and prepare the last one on one burner. Example case 2: Place the first and third dish on the burners. When the first dish is prepared, remove it and put the second dish on the same burner. Example case 3: Place the third and fourth dish on the burners. When the third dish is prepared, remove it and put the second dish on the same burner. Similarly, replace the fourth dish (when it is prepared) by the first dish on the other burner.
{"inputs": ["3\n3\n2 2 2\n3\n1 2 3\n4\n2 3 4 5"], "outputs": ["4\n3\n7"]}
570
42
coding
Solve the programming task below in a Python markdown code block. Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states: XX XX .X X. X. .X XX XX Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't occupy the same square. Vasya has a board with $2\times n$ squares onto which he wants to put some bishwocks. To his dismay, several squares on this board are already occupied by pawns and Vasya can't put bishwocks there. However, pawns also don't attack bishwocks and they can occupy adjacent squares peacefully. Knowing the positions of pawns on the board, help Vasya to determine the maximum amount of bishwocks he can put onto the board so that they wouldn't occupy the same squares and wouldn't occupy squares with pawns. -----Input----- The input contains two nonempty strings that describe Vasya's board. Those strings contain only symbols "0" (zero) that denote the empty squares and symbols "X" (uppercase English letter) that denote the squares occupied by pawns. Strings are nonempty and are of the same length that does not exceed $100$. -----Output----- Output a single integer — the maximum amount of bishwocks that can be placed onto the given board. -----Examples----- Input 00 00 Output 1 Input 00X00X0XXX0 0XXX0X00X00 Output 4 Input 0X0X0 0X0X0 Output 0 Input 0XXX0 00000 Output 2
{"inputs": ["0\n0\n", "0\nX\n", "X\n0\n", "X\nX\n", "X\n0\n", "0\nX\n", "X\nX\n", "0\n0\n"], "outputs": ["0", "0", "0", "0", "0\n", "0\n", "0\n", "0\n"]}
405
82
coding
Solve the programming task below in a Python markdown code block. It’s still hot every day, but September has already come. It’s autumn according to the calendar. Looking around, I see two red dragonflies at rest on the wall in front of me. It’s autumn indeed. When two red dragonflies’ positional information as measured from the end of the wall is given, make a program to calculate the distance between their heads. Input The input is given in the following format. $x_1$ $x_2$ The input line provides dragonflies’ head positions $x_1$ and $x_2$ ($0 \leq x_1, x_2 \leq 100$) as integers. Output Output the distance between the two red dragonflies in a line. Examples Input 20 30 Output 10 Input 50 25 Output 25 Input 25 25 Output 0
{"inputs": ["0 0", "50 0", "58 0", "26 0", "50 6", "84 6", "6 -1", "84 0"], "outputs": ["0\n", "50\n", "58\n", "26\n", "44\n", "78\n", "7\n", "84\n"]}
207
90
coding
Solve the programming task below in a Python markdown code block. Spring has come, and the management of the AvtoBus bus fleet has given the order to replace winter tires with summer tires on all buses. You own a small bus service business and you have just received an order to replace $n$ tires. You know that the bus fleet owns two types of buses: with two axles (these buses have $4$ wheels) and with three axles (these buses have $6$ wheels). You don't know how many buses of which type the AvtoBus bus fleet owns, so you wonder how many buses the fleet might have. You have to determine the minimum and the maximum number of buses that can be in the fleet if you know that the total number of wheels for all buses is $n$. -----Input----- The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of test cases. The following lines contain description of test cases. The only line of each test case contains one integer $n$ ($1 \le n \le 10^{18}$) — the total number of wheels for all buses. -----Output----- For each test case print the answer in a single line using the following format. Print two integers $x$ and $y$ ($1 \le x \le y$) — the minimum and the maximum possible number of buses that can be in the bus fleet. If there is no suitable number of buses for the given $n$, print the number $-1$ as the answer. -----Examples----- Input 4 4 7 24 998244353998244352 Output 1 1 -1 4 6 166374058999707392 249561088499561088 -----Note----- In the first test case the total number of wheels is $4$. It means that there is the only one bus with two axles in the bus fleet. In the second test case it's easy to show that there is no suitable number of buses with $7$ wheels in total. In the third test case the total number of wheels is $24$. The following options are possible: Four buses with three axles. Three buses with two axles and two buses with three axles. Six buses with two axles. So the minimum number of buses is $4$ and the maximum number of buses is $6$.
{"inputs": ["1\n25000\n", "4\n4\n7\n24\n998244353998244352\n"], "outputs": ["4167 6250\n", "1 1\n-1\n4 6\n166374058999707392 249561088499561088\n"]}
542
109
coding
Solve the programming task below in a Python markdown code block. problem A mysterious $ X $ [cm] plant grows in one place. This plant has the following mysterious properties. * Say "nobiro" to this plant and it will grow $ A $ [cm]. * Say "tidime" to this plant and it will grow $ B $ [cm]. * If you say "karero" to this plant, it will be $ 0 $ [cm]. However, this plant does not have a negative length. Specifically, when it grows from the state of $ C $ [cm] to $ D $ [cm] $ (C + D \ lt 0) $, it is a plant. Stops growing when it reaches $ 0 $ [cm]. Say one of "nobiro", "tidime", "karero" to this plant only once a day for $ N $ days. Find the length [cm] of the plant after $ N $ days. output Print the length of the plant after $ N $ days. Also print a newline at the end. Example Input 10 30 10 3 nobiro nobiro tidime Output 80
{"inputs": ["8 48 5\n0\norioan\nnnciro\ndmifit", "7 48 5\n0\norioan\nnncior\ndmifit", "9 30 9\n0\nnoairo\noribon\nmidite", "4 30 5\n0\nnoairo\nnobiro\ntieimd", "3 30 5\n0\nnoairo\nnobiro\ntidime", "5 48 5\n0\norioan\nnncios\ndmifiu", "25 9 5\n0\norioan\nnobiro\nuifimd", "1 41 1\n0\norioan\nnncior\ndmifit"], "outputs": ["8\n", "7\n", "9\n", "4\n", "3\n", "5\n", "25\n", "1\n"]}
253
207
coding
Solve the programming task below in a Python markdown code block. An eviternity number is a number which: * contains only digits 8, 5 and 3, and * the count of the digit `8` >= count of digit `5` >= count of digit `3`. The first few eviternity numbers are as follows. ```Haskell [8, 58, 85, 88, 358, 385, 538, 583, 588, 835, 853, 858, 885, 888] ``` You will be given two integers, `a` and `b`, and your task is to return the number of eviternity numbers in the range `>= a and < b`. ```Haskell For example: solve(0,1000) = 14, because they are [8, 58, 85, 88, 358, 385, 538, 583, 588, 835, 853, 858, 885, 888] ``` The upper bound will not exceed `500,000`. More examples in test cases. Good luck! Also feel free to reuse/extend the following starter code: ```python def solve(a, b): ```
{"functional": "_inputs = [[0, 100], [0, 1000], [0, 10000], [0, 100000], [0, 500000], [90, 139701], [61, 56976]]\n_outputs = [[4], [14], [37], [103], [148], [99], [53]]\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])"}
319
249
coding
Solve the programming task below in a Python markdown code block. There is a square in the xy-plane. The coordinates of its four vertices are (x_1,y_1),(x_2,y_2),(x_3,y_3) and (x_4,y_4) in counter-clockwise order. (Assume that the positive x-axis points right, and the positive y-axis points up.) Takahashi remembers (x_1,y_1) and (x_2,y_2), but he has forgot (x_3,y_3) and (x_4,y_4). Given x_1,x_2,y_1,y_2, restore x_3,y_3,x_4,y_4. It can be shown that x_3,y_3,x_4 and y_4 uniquely exist and have integer values. -----Constraints----- - |x_1|,|y_1|,|x_2|,|y_2| \leq 100 - (x_1,y_1) ≠ (x_2,y_2) - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 -----Output----- Print x_3,y_3,x_4 and y_4 as integers, in this order. -----Sample Input----- 0 0 0 1 -----Sample Output----- -1 1 -1 0 (0,0),(0,1),(-1,1),(-1,0) is the four vertices of a square in counter-clockwise order. Note that (x_3,y_3)=(1,1),(x_4,y_4)=(1,0) is not accepted, as the vertices are in clockwise order.
{"inputs": ["2 1 6 6", "2 2 6 6", "2 2 6 2", "2 2 6 1", "3 2 6 2", "6 2 6 2", "6 2 6 3", "2 2 6 3"], "outputs": ["1 10 -3 5\n", "2 10 -2 6\n", "6 6 2 6\n", "7 5 3 6\n", "6 5 3 5\n", "6 2 6 2\n", "5 3 5 2\n", "5 7 1 6\n"]}
386
160
coding
Solve the programming task below in a Python markdown code block. For encrypting strings this region of chars is given (in this order!): * all letters (ascending, first all UpperCase, then all LowerCase) * all digits (ascending) * the following chars: `.,:;-?! '()$%&"` These are 77 chars! (This region is zero-based.) Write two methods: ```python def encrypt(text) def decrypt(encrypted_text) ``` Prechecks: 1. If the input-string has chars, that are not in the region, throw an Exception(C#, Python) or Error(JavaScript). 2. If the input-string is null or empty return exactly this value! For building the encrypted string: 1. For every second char do a switch of the case. 2. For every char take the index from the region. Take the difference from the region-index of the char before (from the input text! Not from the fresh encrypted char before!). (Char2 = Char1-Char2) Replace the original char by the char of the difference-value from the region. In this step the first letter of the text is unchanged. 3. Replace the first char by the mirror in the given region. (`'A' -> '"'`, `'B' -> '&'`, ...) Simple example: * Input: `"Business"` * Step 1: `"BUsInEsS"` * Step 2: `"B61kujla"` * `B -> U` * `B (1) - U (20) = -19` * `-19 + 77 = 58` * `Region[58] = "6"` * `U -> s` * `U (20) - s (44) = -24` * `-24 + 77 = 53` * `Region[53] = "1"` * Step 3: `"&61kujla"` This kata is part of the Simple Encryption Series: Simple Encryption #1 - Alternating Split Simple Encryption #2 - Index-Difference Simple Encryption #3 - Turn The Bits Around Simple Encryption #4 - Qwerty Have fun coding it and please don't forget to vote and rank this kata! :-) Also feel free to reuse/extend the following starter code: ```python def decrypt(encrypted_text): ```
{"functional": "_inputs = [[\"$-Wy,dM79H'i'o$n0C&I.ZTcMJw5vPlZc Hn!krhlaa:khV mkL;gvtP-S7Rt1Vp2RV:wV9VuhO Iz3dqb.U0w\"], ['5MyQa9p0riYplZc'], [\"5MyQa79H'ijQaw!Ns6jVtpmnlZ.V6p\"], [''], [None]]\n_outputs = [['Do the kata \"Kobayashi-Maru-Test!\" Endless fun and excitement when finding a solution!'], ['This is a test!'], ['This kata is very interesting!'], [''], [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(decrypt(*i), o[0])"}
508
307
coding
Solve the programming task below in a Python markdown code block. You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there? Here, a Shichi-Go-San number is a positive integer that satisfies the following condition: - When the number is written in base ten, each of the digits 7, 5 and 3 appears at least once, and the other digits never appear. -----Constraints----- - 1 \leq N < 10^9 - N is an integer. -----Input----- Input is given from Standard Input in the following format: N -----Output----- Print the number of the Shichi-Go-San numbers between 1 and N (inclusive). -----Sample Input----- 575 -----Sample Output----- 4 There are four Shichi-Go-San numbers not greater than 575: 357, 375, 537 and 573.
{"inputs": ["3", "2", "1", "0", "1\n", "60", "91", "79"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
222
66
coding
Solve the programming task below in a Python markdown code block. We have a string X, which has an even number of characters. Half the characters are `S`, and the other half are `T`. Takahashi, who hates the string `ST`, will perform the following operation 10^{10000} times: * Among the occurrences of `ST` in X as (contiguous) substrings, remove the leftmost one. If there is no occurrence, do nothing. Find the eventual length of X. Constraints * 2 ≦ |X| ≦ 200,000 * The length of X is even. * Half the characters in X are `S`, and the other half are `T`. Input The input is given from Standard Input in the following format: X Output Print the eventual length of X. Examples Input TSTTSS Output 4 Input SSTTST Output 0 Input TSSTTTSS Output 4
{"inputs": ["STTTSS", "SSSTTT", "TTTSSS", "TSTSST", "SSTTTS", "TSSTST", "STTSST", "TSSSTT"], "outputs": ["4\n", "0\n", "6\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
216
81
coding
Solve the programming task below in a Python markdown code block. We’ve all seen katas that ask for conversion from snake-case to camel-case, from camel-case to snake-case, or from camel-case to kebab-case — the possibilities are endless. But if we don’t know the case our inputs are in, these are not very helpful. ### Task: So the task here is to implement a function (called `id` in Ruby/Crystal/JavaScript/CoffeeScript and `case_id` in Python/C) that takes a string, `c_str`, and returns a string with the case the input is in. The possible case types are “kebab”, “camel”, and ”snake”. If none of the cases match with the input, or if there are no 'spaces' in the input (for example in snake case, spaces would be '_'s), return “none”. Inputs will only have letters (no numbers or special characters). ### Some definitions Kebab case: `lowercase-words-separated-by-hyphens` Camel case: `lowercaseFirstWordFollowedByCapitalizedWords` Snake case: `lowercase_words_separated_by_underscores` ### Examples: ```python case_id(“hello-world”) #=> “kebab” case_id(“hello-to-the-world”) #=> “kebab” case_id(“helloWorld”) #=> “camel” case_id(“helloToTheWorld”) #=> “camel” case_id(“hello_world”) #=> “snake” case_id(“hello_to_the_world”) #=> “snake” case_id(“hello__world”) #=> “none” case_id(“hello_World”) #=> “none” case_id(“helloworld”) #=> “none” case_id(“hello-World”) #=> “none” ``` Also check out my other creations — [Split Without Loss](https://www.codewars.com/kata/split-without-loss), [Adding Fractions](https://www.codewars.com/kata/adding-fractions), [Random Integers](https://www.codewars.com/kata/random-integers), [Implement String#transpose](https://www.codewars.com/kata/implement-string-number-transpose), [Implement Array#transpose!](https://www.codewars.com/kata/implement-array-number-transpose), [Arrays and Procs #1](https://www.codewars.com/kata/arrays-and-procs-number-1), and [Arrays and Procs #2](https://www.codewars.com/kata/arrays-and-procs-number-2) Also feel free to reuse/extend the following starter code: ```python def case_id(c_str): ```
{"functional": "_inputs = [['hello-world'], ['hello-to-the-world'], ['hello_world'], ['hello_to_the_world'], ['helloWorld'], ['helloToTheWorld'], ['hello-World'], ['hello-To-The-World'], ['good-Night'], ['he--llo'], ['good-night'], ['good_night'], ['goodNight'], ['hello_World'], ['hello_To_The_World'], ['he_lloWorld'], ['he_lo-lo'], ['he-llo--world'], ['he-llo--World'], ['hello_-World']]\n_outputs = [['kebab'], ['kebab'], ['snake'], ['snake'], ['camel'], ['camel'], ['none'], ['none'], ['none'], ['none'], ['kebab'], ['snake'], ['camel'], ['none'], ['none'], ['none'], ['none'], ['none'], ['none'], ['none']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(case_id(*i), o[0])"}
557
320
coding
Solve the programming task below in a Python markdown code block. There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai. The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is. The airport manager asked you to count for each of n walruses in the queue his displeasure. Input The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. Output Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. Examples Input 6 10 8 5 3 50 45 Output 2 1 0 -1 0 -1 Input 7 10 4 6 3 2 8 15 Output 4 2 1 0 -1 -1 -1 Input 5 10 3 1 10 11 Output 1 0 -1 -1 -1
{"inputs": ["5\n2 1 8 15 3\n", "5\n0 1 8 15 3\n", "5\n1 1 8 15 3\n", "5\n1 2 8 15 3\n", "5\n1 2 9 15 3\n", "5\n1 2 9 15 4\n", "5\n0 2 9 15 4\n", "5\n15 1 8 15 3\n"], "outputs": ["0 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "3 -1 1 0 -1 "]}
438
216
coding
Solve the programming task below in a Python markdown code block. Write a program to take two numbers as input and print their difference if the first number is greater than the second number otherwise$otherwise$ print their sum. -----Input:----- - First line will contain the first number (N1$N1$) - Second line will contain the second number (N2$N2$) -----Output:----- Output a single line containing the difference of 2 numbers (N1−N2)$(N1 - N2)$ if the first number is greater than the second number otherwise output their sum (N1+N2)$(N1 + N2)$. -----Constraints----- - −1000≤N1≤1000$-1000 \leq N1 \leq 1000$ - −1000≤N2≤1000$-1000 \leq N2 \leq 1000$ -----Sample Input:----- 82 28 -----Sample Output:----- 54
{"inputs": ["82\n28"], "outputs": ["54"]}
226
17
coding
Solve the programming task below in a Python markdown code block. Toby has found a game to entertain himself.The game is like this: You are in a coordinate system initially at (0,0) and you are given a sequence of steps which lead to your destination.The steps are given in the form of directions: ’U’ ,’D’ , ’L’ and ‘R’ for up, down, left and right respectively.If you are at position (x,y) then: - U:move to (x,y+1) - D:move to (x,y-1) - L:move to (x-1,y) - R:move to (x+1,y) The sequence is provided as a string ‘s’ of characters where $s_i$ $(1 \leq i \leq N)$ is one of the direction character as mentioned above.An example of a sequence of steps is: UULRUDR The destination according to this string is (1,2). You want to remove maximum number of characters from the string such that the resulting string leads to the same destination as before. For example in the example above we can remove characters at positions 1,3,4,6 and the resulting path will be UUR which will lead to the same destination i.e (1,2).so we reduced the number of steps by 4,and this is our score. You need to get maximum score. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - First line of each testcase contains a single integer $N$,size of string. - Second line of testcase contains a string $s$ of size $N$. -----Output:----- For each testcase, output a single line containing the maximum score possible. -----Constraints----- - $1 \leq T \leq 1000$ - $1 \leq N \leq 10^5$ -----Sample Input:----- 3 7 ULUDLLU 4 RUUR 4 LRLR -----Sample Output:----- 2 0 4 -----EXPLANATION:----- - test case 1: The final destination after moving according to the sequence is (-3,2). One way is to remove characters at positions 3,4 and the resulting string will be ULLLU and destination still remains (-3,2). - test case 2: No character can be removed in this case.
{"inputs": ["3\n7\nULUDLLU\n4\nRUUR\n4\nLRLR"], "outputs": ["2\n0\n4"]}
518
33
coding
Solve the programming task below in a Python markdown code block. # Task Given an array of 2^(k) integers (for some integer `k`), perform the following operations until the array contains only one element: ``` On the 1st, 3rd, 5th, etc. iterations (1-based) replace each pair of consecutive elements with their sum; On the 2nd, 4th, 6th, etc. iterations replace each pair of consecutive elements with their product. ``` After the algorithm has finished, there will be a single element left in the array. Return that element. # Example For inputArray = [1, 2, 3, 4, 5, 6, 7, 8], the output should be 186. We have `[1, 2, 3, 4, 5, 6, 7, 8] -> [3, 7, 11, 15] -> [21, 165] -> [186]`, so the answer is 186. # Input/Output - `[input]` integer array `arr` Constraints: 2^(1) ≤ arr.length ≤ 2^(5), -9 ≤ arr[i] ≤ 99. - `[output]` an integer Also feel free to reuse/extend the following starter code: ```python def array_conversion(arr): ```
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8]], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], [[3, 3, 5, 5]]]\n_outputs = [[186], [64], [60]]\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(array_conversion(*i), o[0])"}
310
245
coding
Solve the programming task below in a Python markdown code block. Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy. Input The only line contains three integers n, a and b (0 ≤ a, b < n ≤ 100). Output Print the single number — the number of the sought positions. Examples Input 3 1 1 Output 2 Input 5 2 3 Output 3 Note The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
{"inputs": ["9 4 3\n", "1 0 0\n", "6 5 5\n", "5 4 0\n", "9 4 4\n", "6 0 5\n", "3 0 1\n", "9 3 4\n"], "outputs": ["4", "1", "1", "1", "5\n", "6\n", "2\n", "5\n"]}
178
98
coding
Solve the programming task below in a Python markdown code block. There is a directed graph with N vertices numbered 1 to N and M edges. The i-th edge is directed from Vertex A_i to Vertex B_i, and there are C_i coins placed along that edge. Additionally, there is a button on Vertex N. We will play a game on this graph. You start the game on Vertex 1 with zero coins, and head for Vertex N by traversing the edges while collecting coins. It takes one minute to traverse an edge, and you can collect the coins placed along the edge each time you traverse it. As usual in games, even if you traverse an edge once and collect the coins, the same number of coins will reappear next time you traverse that edge, which you can collect again. When you reach Vertex N, you can end the game by pressing the button. (You can also choose to leave Vertex N without pressing the button and continue traveling.) However, when you end the game, you will be asked to pay T \times P coins, where T is the number of minutes elapsed since the start of the game. If you have less than T \times P coins, you will have to pay all of your coins instead. Your score will be the number of coins you have after this payment. Determine if there exists a maximum value of the score that can be obtained. If the answer is yes, find that maximum value. -----Constraints----- - 2 \leq N \leq 2500 - 1 \leq M \leq 5000 - 1 \leq A_i, B_i \leq N - 1 \leq C_i \leq 10^5 - 0 \leq P \leq 10^5 - All values in input are integers. - Vertex N can be reached from Vertex 1. -----Input----- Input is given from Standard Input in the following format: N M P A_1 B_1 C_1 : A_M B_M C_M -----Output----- If there exists a maximum value of the score that can be obtained, print that maximum value; otherwise, print -1. -----Sample Input----- 3 3 10 1 2 20 2 3 30 1 3 45 -----Sample Output----- 35 There are two ways to travel from Vertex 1 to Vertex 3: - Vertex 1 \rightarrow 2 \rightarrow 3: You collect 20 + 30 = 50 coins on the way. After two minutes from the start of the game, you press the button, pay 2 \times 10 = 20 coins, and you have 50 - 20 = 30 coins left. - Vertex 1 \rightarrow 2: You collect 45 coins on the way. After one minute from the start of the game, you press the button, pay 1 \times 10 = 10 coins, and you have 45 - 10 = 35 coins left. Thus, the maximum score that can be obtained is 35.
{"inputs": ["2 1 0\n1 2 1\n", "2 2 0\n1 2 1\n1 1 1\n", "2 2 1\n1 2 1\n2 2 1\n", "2 2 0\n1 2 1\n1 2 2\n", "2 2 1\n2 1 2\n1 2 1\n", "2 1 10\n1 2 100\n2 2 100", "2 1 13\n1 2 100\n4 2 100", "2 1 13\n1 2 101\n4 2 100"], "outputs": ["1\n", "-1\n", "0\n", "2\n", "-1\n", "90\n", "87\n", "88\n"]}
672
207
coding
Solve the programming task below in a Python markdown code block. You are given a book with $n$ chapters. Each chapter has a specified list of other chapters that need to be understood in order to understand this chapter. To understand a chapter, you must read it after you understand every chapter on its required list. Currently you don't understand any of the chapters. You are going to read the book from the beginning till the end repeatedly until you understand the whole book. Note that if you read a chapter at a moment when you don't understand some of the required chapters, you don't understand this chapter. Determine how many times you will read the book to understand every chapter, or determine that you will never understand every chapter no matter how many times you read the book. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2\cdot10^4$). The first line of each test case contains a single integer $n$ ($1 \le n \le 2\cdot10^5$) — number of chapters. Then $n$ lines follow. The $i$-th line begins with an integer $k_i$ ($0 \le k_i \le n-1$) — number of chapters required to understand the $i$-th chapter. Then $k_i$ integers $a_{i,1}, a_{i,2}, \dots, a_{i, k_i}$ ($1 \le a_{i, j} \le n, a_{i, j} \ne i, a_{i, j} \ne a_{i, l}$ for $j \ne l$) follow — the chapters required to understand the $i$-th chapter. It is guaranteed that the sum of $n$ and sum of $k_i$ over all testcases do not exceed $2\cdot10^5$. -----Output----- For each test case, if the entire book can be understood, print how many times you will read it, otherwise print $-1$. -----Examples----- Input 5 4 1 2 0 2 1 4 1 2 5 1 5 1 1 1 2 1 3 1 4 5 0 0 2 1 2 1 2 2 2 1 4 2 2 3 0 0 2 3 2 5 1 2 1 3 1 4 1 5 0 Output 2 -1 1 2 5 -----Note----- In the first example, we will understand chapters $\{2, 4\}$ in the first reading and chapters $\{1, 3\}$ in the second reading of the book. In the second example, every chapter requires the understanding of some other chapter, so it is impossible to understand the book. In the third example, every chapter requires only chapters that appear earlier in the book, so we can understand everything in one go. In the fourth example, we will understand chapters $\{2, 3, 4\}$ in the first reading and chapter $1$ in the second reading of the book. In the fifth example, we will understand one chapter in every reading from $5$ to $1$.
{"inputs": ["5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 2\n1 3\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 5\n0\n"], "outputs": ["2\n-1\n1\n2\n5\n"]}
708
123
coding
Solve the programming task below in a Python markdown code block. The new £5 notes have been recently released in the UK and they've certainly became a sensation! Even those of us who haven't been carrying any cash around for a while, having given in to the convenience of cards, suddenly like to have some of these in their purses and pockets. But how many of them could you get with what's left from your salary after paying all bills? The programme that you're about to write will count this for you! Given a salary and the array of bills, calculate your disposable income for a month and return it as a number of new £5 notes you can get with that amount. If the money you've got (or do not!) doesn't allow you to get any £5 notes return 0. £££ GOOD LUCK! £££ Also feel free to reuse/extend the following starter code: ```python def get_new_notes(salary,bills): ```
{"functional": "_inputs = [[2000, [500, 160, 400]], [1260, [500, 50, 100]], [3600, [1800, 350, 460, 500, 15]], [1995, [1500, 19, 44]], [10000, [1800, 500, 1200, 655, 150]], [2300, [590, 1500, 45, 655, 150]], [5300, [1190, 1010, 1045, 55, 10, 19, 55]], [2000, [500, 495, 100, 900]], [2000, [500, 496, 100, 900]], [2000, [500, 494, 100, 900]]]\n_outputs = [[188], [122], [95], [86], [1139], [0], [383], [1], [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(get_new_notes(*i), o[0])"}
201
465
coding
Solve the programming task below in a Python markdown code block. One of Arkady's friends works at a huge radio telescope. A few decades ago the telescope has sent a signal $s$ towards a faraway galaxy. Recently they've received a response $t$ which they believe to be a response from aliens! The scientists now want to check if the signal $t$ is similar to $s$. The original signal $s$ was a sequence of zeros and ones (everyone knows that binary code is the universe-wide language). The returned signal $t$, however, does not look as easy as $s$, but the scientists don't give up! They represented $t$ as a sequence of English letters and say that $t$ is similar to $s$ if you can replace all zeros in $s$ with some string $r_0$ and all ones in $s$ with some other string $r_1$ and obtain $t$. The strings $r_0$ and $r_1$ must be different and non-empty. Please help Arkady's friend and find the number of possible replacements for zeros and ones (the number of pairs of strings $r_0$ and $r_1$) that transform $s$ to $t$. -----Input----- The first line contains a string $s$ ($2 \le |s| \le 10^5$) consisting of zeros and ones — the original signal. The second line contains a string $t$ ($1 \le |t| \le 10^6$) consisting of lowercase English letters only — the received signal. It is guaranteed, that the string $s$ contains at least one '0' and at least one '1'. -----Output----- Print a single integer — the number of pairs of strings $r_0$ and $r_1$ that transform $s$ to $t$. In case there are no such pairs, print $0$. -----Examples----- Input 01 aaaaaa Output 4 Input 001 kokokokotlin Output 2 -----Note----- In the first example, the possible pairs $(r_0, r_1)$ are as follows: "a", "aaaaa" "aa", "aaaa" "aaaa", "aa" "aaaaa", "a" The pair "aaa", "aaa" is not allowed, since $r_0$ and $r_1$ must be different. In the second example, the following pairs are possible: "ko", "kokotlin" "koko", "tlin"
{"inputs": ["01\naaaaaa\n", "01\naabaaa\n", "01\naabbaa\n", "01\nbabbaa\n", "01\ncabbaa\n", "01\nbacbaa\n", "01\naacbaa\n", "01\naacaaa\n"], "outputs": ["4\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n"]}
552
108
coding
Solve the programming task below in a Python markdown code block. Everyone Knows AdFly and their Sister Sites. If we see the Page Source of an ad.fly site we can see this perticular line: Believe it or not This is actually the Encoded url which you would skip to. The Algorithm is as Follows: ``` 1) The ysmm value is broken like this ysmm = 0 1 2 3 4 5 6 7 8 9 = "0123456789" code1 = 0 2 4 6 8 = "02468" code2 = 9 7 5 3 1 = "97531" 2) code1+code2 is base64 Decoded 3) The result will be of this form : https://adf.ly/go.php?u= 4) has to be further decoded and the result is to be returned ``` Your Task: ``` Make a function to Encode text to ysmm value. and a function to Decode ysmm value. ``` Note: Take random values for The first 2 int values. I personally hate trivial error checking like giving integer input in place of string. ``` Input For Decoder & Encoder: Strings Return "Invalid" for invalid Strings ``` Also feel free to reuse/extend the following starter code: ```python def adFly_decoder(sc): ```
{"functional": "_inputs = [['O=T0ZToPdRHJRmwdcOz1oGvTL22lFzkRZhih5GsbezSw9kndbvyR50wYawHIAF/SdhT1'], ['N=z0dDoMdyHIRmwac1zMolvWLz2RFmkMZiiZ5HsZeySw9kndbvyR50wYawHIAF/SdhT1'], ['lololol']]\n_outputs = [['http://yahoo.com'], ['http://google.com'], ['Invalid']]\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(adFly_decoder(*i), o[0])"}
326
266
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array prices where prices[i] is the price of a given stock on the ith day. Find the maximum profit you can achieve. You may complete at most two transactions. Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).   Please complete the following python code precisely: ```python class Solution: def maxProfit(self, prices: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(prices = [3,3,5,0,0,3,1,4]) == 6\n assert candidate(prices = [1,2,3,4,5]) == 4\n assert candidate(prices = [7,6,4,3,1] ) == 0 \n assert candidate(prices = [1]) == 0\n\n\ncheck(Solution().maxProfit)"}
110
103
coding
Solve the programming task below in a Python markdown code block. We call a string good, if after merging all the consecutive equal characters, the resulting string is palindrome. For example, "aabba" is good, because after the merging step it will become "aba". Given a string, you have to find two values: the number of good substrings of even length; the number of good substrings of odd length. -----Input----- The first line of the input contains a single string of length n (1 ≤ n ≤ 10^5). Each character of the string will be either 'a' or 'b'. -----Output----- Print two space-separated integers: the number of good substrings of even length and the number of good substrings of odd length. -----Examples----- Input bb Output 1 2 Input baab Output 2 4 Input babb Output 2 5 Input babaa Output 2 7 -----Note----- In example 1, there are three good substrings ("b", "b", and "bb"). One of them has even length and two of them have odd length. In example 2, there are six good substrings (i.e. "b", "a", "a", "b", "aa", "baab"). Two of them have even length and four of them have odd length. In example 3, there are seven good substrings (i.e. "b", "a", "b", "b", "bb", "bab", "babb"). Two of them have even length and five of them have odd length. Definitions A substring s[l, r] (1 ≤ l ≤ r ≤ n) of string s = s_1s_2... s_{n} is string s_{l}s_{l} + 1... s_{r}. A string s = s_1s_2... s_{n} is a palindrome if it is equal to string s_{n}s_{n} - 1... s_1.
{"inputs": ["a\n", "a\n", "b\n", "bb\n", "aa\n", "bb\n", "ab\n", "ba\n"], "outputs": ["0 1\n", "0 1\n", "0 1\n", "1 2\n", "1 2\n", "1 2\n", "0 2\n", "0 2\n"]}
434
86
coding
Solve the programming task below in a Python markdown code block. # Task Below we will define what and n-interesting polygon is and your task is to find its area for a given n. A 1-interesting polygon is just a square with a side of length 1. An n-interesting polygon is obtained by taking the n - 1-interesting polygon and appending 1-interesting polygons to its rim side by side. You can see the 1-, 2- and 3-interesting polygons in the picture below. ![](https://files.gitter.im/myjinxin2015/Gwsw/blob) # Example For `n = 1`, the output should be `1`; For `n = 2`, the output should be `5`; For `n = 3`, the output should be `13`. # Input/Output - `[input]` integer `n` Constraints: `1 ≤ n < 10000.` - `[output]` an integer The area of the n-interesting polygon. Also feel free to reuse/extend the following starter code: ```python def shape_area(n): ```
{"functional": "_inputs = [[2], [3], [1], [5]]\n_outputs = [[5], [13], [1], [41]]\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(shape_area(*i), o[0])"}
249
174
coding
Solve the programming task below in a Python markdown code block. There is an integer array $\boldsymbol{d}$ which does not contain more than two elements of the same value. How many distinct ascending triples ($d[i]<d[j]<d[k],i<j<k$) are present?  Input format The first line contains an integer, $N$, denoting the number of elements in the array. This is followed by a single line, containing $N$ space-separated integers. Please note that there are no leading spaces before the first number, and there are no trailing spaces after the last number. Output format: A single integer that denotes the number of distinct ascending triplets present in the array. Constraints: $N\leq10^5$ Every element of the array is present at most twice. Every element of the array is a 32-bit non-negative integer. Sample input: 6 1 1 2 2 3 4 Sample output: 4 Explanation The distinct triplets are (1,2,3) (1,2,4) (1,3,4) (2,3,4) The elements of the array might not be sorted. Make no assumptions of the same.
{"inputs": ["6\n1 1 2 2 3 4\n"], "outputs": ["4\n"]}
267
26
coding
Solve the programming task below in a Python markdown code block. There are b blocks of digits. Each one consisting of the same n digits, which are given to you in the input. Wet Shark must choose exactly one digit from each block and concatenate all of those digits together to form one large integer. For example, if he chooses digit 1 from the first block and digit 2 from the second block, he gets the integer 12. Wet Shark then takes this number modulo x. Please, tell him how many ways he can choose one digit from each block so that he gets exactly k as the final result. As this number may be too large, print it modulo 10^9 + 7. Note, that the number of ways to choose some digit in the block is equal to the number of it's occurrences. For example, there are 3 ways to choose digit 5 from block 3 5 6 7 8 9 5 1 1 1 1 5. -----Input----- The first line of the input contains four space-separated integers, n, b, k and x (2 ≤ n ≤ 50 000, 1 ≤ b ≤ 10^9, 0 ≤ k < x ≤ 100, x ≥ 2) — the number of digits in one block, the number of blocks, interesting remainder modulo x and modulo x itself. The next line contains n space separated integers a_{i} (1 ≤ a_{i} ≤ 9), that give the digits contained in each block. -----Output----- Print the number of ways to pick exactly one digit from each blocks, such that the resulting integer equals k modulo x. -----Examples----- Input 12 1 5 10 3 5 6 7 8 9 5 1 1 1 1 5 Output 3 Input 3 2 1 2 6 2 2 Output 0 Input 3 2 1 2 3 1 2 Output 6 -----Note----- In the second sample possible integers are 22, 26, 62 and 66. None of them gives the remainder 1 modulo 2. In the third sample integers 11, 13, 21, 23, 31 and 33 have remainder 1 modulo 2. There is exactly one way to obtain each of these integers, so the total answer is 6.
{"inputs": ["3 2 1 2\n6 2 2\n", "3 2 1 2\n3 1 2\n", "3 2 1 2\n6 3 2\n", "3 2 1 2\n3 6 3\n", "3 2 0 2\n3 3 9\n", "3 2 0 2\n4 5 1\n", "3 2 0 2\n1 3 2\n", "3 2 1 2\n5 9 3\n"], "outputs": ["0\n", "6\n", "3\n", "6\n", "0\n", "3\n", "3\n", "9\n"]}
535
166
coding
Solve the programming task below in a Python markdown code block. *This kata is inspired by [Project Euler Problem #387](https://projecteuler.net/problem=387)* --- A [Harshad number](https://en.wikipedia.org/wiki/Harshad_number) (or Niven number) is a number that is divisible by the sum of its digits. A *right truncatable Harshad number* is any Harshad number that, when recursively right-truncated, results in a Harshad number at each truncation. By definition, 1-digit numbers are **not** right truncatable Harshad numbers. For example `201` (which is a Harshad number) yields `20`, then `2` when right-truncated, which are all Harshad numbers. Thus `201` is a *right truncatable Harshad number*. ## Your task Given a range of numbers (`(a, b)`, both included), return the list of right truncatable Harshad numbers in this range. ```if-not:javascript Note: there are `500` random tests, with 0 <= `a` <= `b` <= 10^(16) ``` ```if:javascript Note: there are `500` random tests, with `0 <= a <= b <= Number.MAX_SAFE_INTEGER` ``` ## Examples ``` 0, 20 --> [10, 12, 18, 20] 30, 100 --> [30, 36, 40, 42, 45, 48, 50, 54, 60, 63, 70, 72, 80, 81, 84, 90, 100] 90, 200 --> [90, 100, 102, 108, 120, 126, 180, 200] 200, 210 --> [200, 201, 204, 207, 209, 210] 1000, 2000 --> [1000, 1002, 1008, 1020, 1026, 1080, 1088, 1200, 1204, 1206, 1260, 1800, 2000] 2200, 2300 --> [] 9000002182976, 9000195371842 --> [9000004000000, 9000004000008] ``` --- ## My other katas If you enjoyed this kata then please try [my other katas](https://www.codewars.com/collections/katas-created-by-anter69)! :-) #### *Translations are welcome!* Also feel free to reuse/extend the following starter code: ```python def rthn_between(a, b): ```
{"functional": "_inputs = [[0, 20], [30, 100], [90, 200], [200, 210], [1000, 2000], [2200, 2300], [9000002182976, 9000195371842]]\n_outputs = [[[10, 12, 18, 20]], [[30, 36, 40, 42, 45, 48, 50, 54, 60, 63, 70, 72, 80, 81, 84, 90, 100]], [[90, 100, 102, 108, 120, 126, 180, 200]], [[200, 201, 204, 207, 209, 210]], [[1000, 1002, 1008, 1020, 1026, 1080, 1088, 1200, 1204, 1206, 1260, 1800, 2000]], [[]], [[9000004000000, 9000004000008]]]\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(rthn_between(*i), o[0])"}
735
503
coding
Solve the programming task below in a Python markdown code block. It's been a while since I played with A, B, and C. Mr. A and Mr. B became players, and Mr. C became a referee and played a badminton singles game. The rules decided by the three people are as follows. * 3 Play the game. * The person who gets 11 points first wins the game. * The first serve of the first game starts with Mr. A, but the next serve is done by the person who got the previous point. * In the 2nd and 3rd games, the person who took the previous game makes the first serve. * After 10-10, the winner will be the one who has a difference of 2 points. After all the games were over, I tried to see the score, but referee C forgot to record the score. However, he did record the person who hit the serve. Create a program that calculates the score from the records in the order of serve. However, the total number of serves hit by two people is 100 or less, and the record of the serve order is represented by the character string "A" or "B" representing the person who hit the serve. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: record1 record2 record3 The i-line is given a string that represents the serve order of the i-game. The number of datasets does not exceed 20. Output For each dataset, output the score of Mr. A and the score of Mr. B of the i-game on the i-line, separated by blanks. Example Input ABAABBBAABABAAABBAA AABBBABBABBAAABABABAAB BABAABAABABABBAAAB AABABAAABBAABBBABAA AAAAAAAAAAA ABBBBBBBBBB 0 Output 11 8 10 12 11 7 11 8 11 0 0 11
{"inputs": ["AABBAAABABAABBBAABA\nAABBBABBABBAAABABABAAB\nBABAABAABABABBAAAB\nAABABAAABBAABBBABAA\nAAAAAAAAAAA\nABBBBBBBBBB\n0", "ABAABBBAABABAAABBAA\nAABBBABBABBAAABABABAAB\nBABAABAABABABBAAAB\nAABABAAABBAABBBABAA\nAAAAAAAAAAA\nABBBBBABBBB\n0", "ABAABBBAABABAAABBAA\nAABBBABBABBAAABABABAAB\nBABAABAABABABBAAAB\nAABAABBAABBAAABABAA\nAAAAAAAAAAA\nABBBBBABBBB\n0", "ABAABABAABABAAABBAA\nAABBBABBABBAAABABABAAB\nBABAABAABABABBAAAB\nAABABAAABBAABBBABAA\nAAAAAAAAAAA\nABBBBBABBBB\n0", "AABBAAABABAABBBAABA\nAABBBABBABBAAABABABAAB\nBABAABAABABABBAAAB\nAABAABBAABBAAABABAA\nAAAAAAAAAAA\nABBBABABBBB\n0", "ABBABBAAABABAAABBAA\nAABBBABBABBAAABABABAAB\nBABAABAABABABBBAAB\nAABBBBBAABAAAABABAA\nAAAAAAAAAAA\nABBBBBABBBB\n0", "AABBAAABABAABBBAABA\nAABBBABBABBAAABABABAAB\nBABAABAABAABBBAAAB\nAABAABBAABBAAABABAB\nAAAAAAAAAAA\nABBBABABBBB\n0", "ABAABBBAABABAAABBAA\nAABBBABBABBAAABABABAAB\nBABAABAABABABBAAAA\nAABAABBAABBAAABABAA\nAAAAAAAAAAA\nABBBBBABBBB\n0"], "outputs": ["11 8\n10 12\n11 7\n11 8\n11 0\n0 11\n", "11 8\n10 12\n11 7\n11 8\n11 0\n1 10\n", "11 8\n10 12\n11 7\n12 7\n11 0\n1 10\n", "12 7\n10 12\n11 7\n11 8\n11 0\n1 10\n", "11 8\n10 12\n11 7\n12 7\n11 0\n2 9\n", "11 8\n10 12\n10 8\n11 8\n11 0\n1 10\n", "11 8\n10 12\n11 7\n11 8\n11 0\n2 9\n", "11 8\n10 12\n12 6\n12 7\n11 0\n1 10\n"]}
453
680
coding
Solve the programming task below in a Python markdown code block. Make a program that filters a list of strings and returns a list with only your friends name in it. If a name has exactly 4 letters in it, you can be sure that it has to be a friend of yours! Otherwise, you can be sure he's not... Ex: Input = ["Ryan", "Kieran", "Jason", "Yous"], Output = ["Ryan", "Yous"] i.e. Note: keep the original order of the names in the output. Also feel free to reuse/extend the following starter code: ```python def friend(x): ```
{"functional": "_inputs = [[['Ryan', 'Kieran', 'Mark']], [['Ryan', 'Jimmy', '123', '4', 'Cool Man']], [['Jimm', 'Cari', 'aret', 'truehdnviegkwgvke', 'sixtyiscooooool']], [['Love', 'Your', 'Face', '1']], [['Hell', 'Is', 'a', 'badd', 'word']], [['Issa', 'Issac', 'Issacs', 'ISISS']], [['Robot', 'Your', 'MOMOMOMO']], [['Your', 'BUTT']], [['Hello', 'I', 'AM', 'Sanjay', 'Gupt']], [['This', 'IS', 'enough', 'TEst', 'CaSe']], [[]]]\n_outputs = [[['Ryan', 'Mark']], [['Ryan']], [['Jimm', 'Cari', 'aret']], [['Love', 'Your', 'Face']], [['Hell', 'badd', 'word']], [['Issa']], [['Your']], [['Your', 'BUTT']], [['Gupt']], [['This', 'TEst', 'CaSe']], [[]]]\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(friend(*i), o[0])"}
132
378
coding
Solve the programming task below in a Python markdown code block. There are 2N squares arranged from left to right. You are given a string of length 2N representing the color of each of the squares. The color of the i-th square from the left is black if the i-th character of S is `B`, and white if that character is `W`. You will perform the following operation exactly N times: choose two distinct squares, then invert the colors of these squares and the squares between them. Here, to invert the color of a square is to make it white if it is black, and vice versa. Throughout this process, you cannot choose the same square twice or more. That is, each square has to be chosen exactly once. Find the number of ways to make all the squares white at the end of the process, modulo 10^9+7. Two ways to make the squares white are considered different if and only if there exists i (1 \leq i \leq N) such that the pair of the squares chosen in the i-th operation is different. Constraints * 1 \leq N \leq 10^5 * |S| = 2N * Each character of S is `B` or `W`. Input Input is given from Standard Input in the following format: N S Output Print the number of ways to make all the squares white at the end of the process, modulo 10^9+7. If there are no such ways, print 0. Examples Input 2 BWWB Output 4 Input 4 BWBBWWWB Output 288 Input 5 WWWWWWWWWW Output 0
{"inputs": ["2\nBWWB", "4\nBWWWBBWB", "4\nBWBBWBWW", "4\nBWBBWBWX", "4\nBWBBWCWW", "4\nBWABWCWW", "4\nBWABVCWW", "4\nBBAWVCWW"], "outputs": ["4", "288\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
363
103
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Chefland has 2 different types of coconut, type A and type B. Type A contains only x_{a} milliliters of coconut water and type B contains only x_{b} grams of coconut pulp. Chef's nutritionist has advised him to consume X_{a} milliliters of coconut water and X_{b} grams of coconut pulp every week in the summer. Find the total number of coconuts (type A + type B) that Chef should buy each week to keep himself active in the hot weather. ------ Input Format ------ - The first line contains an integer T, the number of test cases. Then the test cases follow. - Each test case contains a single line of input, four integers x_{a}, x_{b}, X_{a}, X_{b}. ------ Output Format ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≤ T ≤ 15000$ $100 ≤ x_{a} ≤ 200$ $400 ≤ x_{b} ≤ 500$ $1000 ≤ X_{a} ≤ 1200$ $1000 ≤ X_{b} ≤ 1500$ $x_{a}$ divides $X_{a}$. $x_{b}$ divides $X_{b}$. ------ subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 100 400 1000 1200 100 450 1000 1350 150 400 1200 1200 ----- Sample Output 1 ------ 13 13 11 ----- explanation 1 ------ TestCase $1$: Number of coconuts of Type $A$ required = $\frac{1000}{100} = 10$ and number of coconuts of Type $B$ required = $\frac{1200}{400} = 3$. So the total number of coconuts required is $10 + 3 = 13$. TestCase $2$: Number of coconuts of Type $A$ required = $\frac{1000}{100} = 10$ and number of coconuts of Type $B$ required = $\frac{1350}{450} = 3$. So the total number of coconuts required is $10 + 3 = 13$. TestCase $3$: Number of coconuts of Type $A$ required = $\frac{1200}{150} = 8$ and number of coconuts of Type $B$ required = $\frac{1200}{400} = 3$. So the total number of coconuts required is $8 + 3 = 11$.
{"inputs": ["3\n100 400 1000 1200\n100 450 1000 1350\n150 400 1200 1200"], "outputs": ["13\n13\n11"]}
686
73
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integers m and n. Consider an m x n grid where each cell is initially white. You can paint each cell red, green, or blue. All cells must be painted. Return the number of ways to color the grid with no two adjacent cells having the same color. Since the answer can be very large, return it modulo 109 + 7.   Please complete the following python code precisely: ```python class Solution: def colorTheGrid(self, m: int, n: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(m = 1, n = 1) == 3\n assert candidate(m = 1, n = 2) == 6\n assert candidate(m = 5, n = 5) == 580986\n\n\ncheck(Solution().colorTheGrid)"}
130
76
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "".   Please complete the following python code precisely: ```python class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: ```
{"functional": "def check(candidate):\n assert candidate(strs = [\"flower\",\"flow\",\"flight\"]) == \"fl\"\n assert candidate(strs = [\"dog\",\"racecar\",\"car\"]) == \"\"\n\n\ncheck(Solution().longestCommonPrefix)"}
78
61
coding
Solve the programming task below in a Python markdown code block. Chef loves to play with arrays by himself. Today, he has an array A consisting of N distinct integers. He wants to perform the following operation on his array A. - Select a pair of adjacent integers and remove the larger one of these two. This decreases the array size by 1. Cost of this operation will be equal to the smaller of them. Find out minimum sum of costs of operations needed to convert the array into a single element. -----Input----- First line of input contains a single integer T denoting the number of test cases. First line of each test case starts with an integer N denoting the size of the array A. Next line of input contains N space separated integers, where the ith integer denotes the value Ai. -----Output----- For each test case, print the minimum cost required for the transformation. -----Constraints----- - 1 ≤ T ≤ 10 - 2 ≤ N ≤ 50000 - 1 ≤ Ai ≤ 105 -----Subtasks----- - Subtask 1 : 2 ≤ N ≤ 15 : 35 pts - Subtask 2 : 2 ≤ N ≤ 100 : 25 pts - Subtask 3 : 2 ≤ N ≤ 50000 : 40 pts -----Example----- Input 2 2 3 4 3 4 2 5 Output 3 4 -----Explanation-----Test 1 : Chef will make only 1 move: pick up both the elements (that is, 3 and 4), remove the larger one (4), incurring a cost equal to the smaller one (3).
{"inputs": ["2\n2\n3 4\n3\n4 2 5", "2\n2\n3 4\n3\n4 2 9", "2\n2\n3 4\n3\n0 2 5", "2\n2\n0 4\n3\n4 0 9", "2\n2\n0 4\n3\n7 2 9", "2\n2\n0 4\n3\n4 1 9", "2\n2\n1 4\n3\n4 2 9", "2\n2\n1 4\n3\n3 0 4"], "outputs": ["3\n4", "3\n4\n", "3\n0\n", "0\n0\n", "0\n4\n", "0\n2\n", "1\n4\n", "1\n0\n"]}
361
189
coding
Solve the programming task below in a Python markdown code block. Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? Constraints * 1 \leq N \leq 50 * 1 \leq A \leq 50 * 1 \leq x_i \leq 50 * N,\,A,\,x_i are integers. Input The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N Output Print the number of ways to select cards such that the average of the written integers is exactly A. Examples Input 4 8 7 9 8 9 Output 5 Input 3 8 6 6 9 Output 0 Input 8 5 3 6 2 8 7 6 5 9 Output 19 Input 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Output 8589934591
{"inputs": ["3 8\n9 6 9", "3 8\n6 6 6", "3 8\n9 9 9", "3 8\n6 6 9", "3 8\n15 6 9", "3 8\n15 3 9", "3 8\n15 2 9", "1 11\n2 0 7"], "outputs": ["1\n", "0\n", "0\n", "0", "0\n", "0\n", "0\n", "0\n"]}
334
129
coding
Solve the programming task below in a Python markdown code block. We will define Ginkgo numbers and multiplication on Ginkgo numbers. A Ginkgo number is a pair <m, n> where m and n are integers. For example, <1, 1>, <-2, 1> and <-3,-1> are Ginkgo numbers. The multiplication on Ginkgo numbers is defined by <m, n> * <x, y> = <mx − ny, my + nx>. For example, <1, 1> * <-2, 1> = <-3,-1>. A Ginkgo number <m, n> is called a divisor of a Ginkgo number <p, q> if there exists a Ginkgo number <x, y> such that <m, n> * <x, y> = <p, q>. For any Ginkgo number <m, n>, Ginkgo numbers <1, 0>, <0, 1>, <-1, 0>, <0,-1>, <m, n>, <-n,m>, <-m,-n> and <n,-m> are divisors of <m, n>. If m2+n2 > 1, these Ginkgo numbers are distinct. In other words, any Ginkgo number such that m2 + n2 > 1 has at least eight divisors. A Ginkgo number <m, n> is called a prime if m2+n2 > 1 and it has exactly eight divisors. Your mission is to check whether a given Ginkgo number is a prime or not. The following two facts might be useful to check whether a Ginkgo number is a divisor of another Ginkgo number. * Suppose m2 + n2 > 0. Then, <m, n> is a divisor of <p, q> if and only if the integer m2 + n2 is a common divisor of mp + nq and mq − np. * If <m, n> * <x, y> = <p, q>, then (m2 + n2)(x2 + y2) = p2 + q2. Input The first line of the input contains a single integer, which is the number of datasets. The rest of the input is a sequence of datasets. Each dataset is a line containing two integers m and n, separated by a space. They designate the Ginkgo number <m, n>. You can assume 1 < m2 + n2 < 20000. Output For each dataset, output a character 'P' in a line if the Ginkgo number is a prime. Output a character 'C' in a line otherwise. Example Input 8 10 0 0 2 -3 0 4 2 0 -13 -4 1 -2 -1 3 -1 Output C C P C C P P C
{"inputs": ["8\n2 0\n1 2\n-3 1\n4 2\n0 -13\n-4 1\n-2 0\n2 0", "8\n10 -1\n0 2\n0 3\n4 0\n2 -25\n-4 0\n-2 0\n2 0", "8\n10 -1\n0 2\n0 3\n8 0\n2 -23\n-4 0\n-2 1\n2 0", "8\n2 0\n1 2\n-3 1\n4 2\n0 -13\n-4 1\n-2 0\n2 -1", "8\n10 -1\n0 2\n0 3\n4 1\n2 -23\n-4 0\n-2 0\n2 0", "8\n4 0\n0 2\n-3 1\n4 2\n0 -32\n-4 0\n-3 0\n2 -1", "8\n2 0\n1 4\n-3 1\n4 2\n0 -13\n-8 2\n-5 -1\n2 0", "8\n2 0\n1 4\n-3 1\n4 2\n0 -23\n-8 2\n-5 -1\n2 0"], "outputs": ["C\nP\nC\nC\nC\nP\nC\nC\n", "P\nC\nP\nC\nC\nC\nC\nC\n", "P\nC\nP\nC\nC\nC\nP\nC\n", "C\nP\nC\nC\nC\nP\nC\nP\n", "P\nC\nP\nP\nC\nC\nC\nC\n", "C\nC\nC\nC\nC\nC\nP\nP\n", "C\nP\nC\nC\nC\nC\nC\nC\n", "C\nP\nC\nC\nP\nC\nC\nC\n"]}
635
462
coding
Solve the programming task below in a Python markdown code block. Complete the `greatestProduct` method so that it'll find the greatest product of five consecutive digits in the given string of digits. For example: The input string always has more than five digits. Adapted from Project Euler. Also feel free to reuse/extend the following starter code: ```python def greatest_product(n): ```
{"functional": "_inputs = [['123834539327238239583'], ['395831238345393272382'], ['92494737828244222221111111532909999'], ['02494037820244202221011110532909999']]\n_outputs = [[3240], [3240], [5292], [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(greatest_product(*i), o[0])"}
81
290
coding
Solve the programming task below in a Python markdown code block. Given two integers `a` and `b`, which can be positive or negative, find the sum of all the numbers between including them too and return it. If the two numbers are equal return `a` or `b`. **Note:** `a` and `b` are not ordered! ## Examples ```python get_sum(1, 0) == 1 // 1 + 0 = 1 get_sum(1, 2) == 3 // 1 + 2 = 3 get_sum(0, 1) == 1 // 0 + 1 = 1 get_sum(1, 1) == 1 // 1 Since both are same get_sum(-1, 0) == -1 // -1 + 0 = -1 get_sum(-1, 2) == 2 // -1 + 0 + 1 + 2 = 2 ``` ```C get_sum(1, 0) == 1 // 1 + 0 = 1 get_sum(1, 2) == 3 // 1 + 2 = 3 get_sum(0, 1) == 1 // 0 + 1 = 1 get_sum(1, 1) == 1 // 1 Since both are same get_sum(-1, 0) == -1 // -1 + 0 = -1 get_sum(-1, 2) == 2 // -1 + 0 + 1 + 2 = 2 ``` Also feel free to reuse/extend the following starter code: ```python def get_sum(a,b): ```
{"functional": "_inputs = [[0, 1], [1, 2], [5, -1], [505, 4], [321, 123], [0, -1], [-50, 0], [-1, -5], [-5, -5], [-505, 4], [-321, 123], [0, 0], [-5, -1], [5, 1], [-17, -17], [17, 17]]\n_outputs = [[1], [3], [14], [127759], [44178], [-1], [-1275], [-15], [-5], [-127755], [-44055], [0], [-15], [15], [-17], [17]]\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(get_sum(*i), o[0])"}
378
336
coding
Solve the programming task below in a Python markdown code block. You are given an $array$ of size $N$ and an integer $K$ ( $N > 1 , K > 0$ ). Each element in the array can be incremented by $K$ or decremented by $K$ $at$ $most$ $once$. So there will be $3^n$ possible combinations of final array. (As there are 3 options for every element). Out of these combinations, you have to select a combination, in which the $absolute$ difference between the largest and the smallest element is $maximum$. You have to print the $maximum$ $absolute$ $difference$. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains of a two lines of input - First line contains two integers $N, K$. - Second line contains $N$ space separated integers. -----Output:----- For each testcase, output the maximum absolute difference that can be achieved on a new line. -----Constraints----- - $1 \leq T \leq 10$ - $2 \leq N \leq 1000$ - $1 \leq K , arr[i] \leq 10000$ $NOTE$: Large input files, Use of fastio is recommended. -----Sample Input:----- 2 4 3 4 2 5 1 3 5 2 5 3 -----Sample Output:----- 10 13
{"inputs": ["2\n4 3\n4 2 5 1\n3 5\n2 5 3"], "outputs": ["10\n13"]}
335
38
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A password is said to be strong if it satisfies all the following criteria: It has at least 8 characters. It contains at least one lowercase letter. It contains at least one uppercase letter. It contains at least one digit. It contains at least one special character. The special characters are the characters in the following string: "!@#$%^&*()-+". It does not contain 2 of the same character in adjacent positions (i.e., "aab" violates this condition, but "aba" does not). Given a string password, return true if it is a strong password. Otherwise, return false.   Please complete the following python code precisely: ```python class Solution: def strongPasswordCheckerII(self, password: str) -> bool: ```
{"functional": "def check(candidate):\n assert candidate(password = \"IloveLe3tcode!\") == True\n assert candidate(password = \"Me+You--IsMyDream\") == False\n assert candidate(password = \"1aB!\") == False\n\n\ncheck(Solution().strongPasswordCheckerII)"}
173
69
coding
Solve the programming task below in a Python markdown code block. Chef is multi-talented. He has developed a cure for coronavirus called COVAC-19. Now that everyone in the world is infected, it is time to distribute it throughout the world efficiently to wipe out coronavirus from the Earth. Chef just cooks the cure, you are his distribution manager. In the world, there are $N$ countries (numbered $1$ through $N$) with populations $a_1, a_2, \ldots, a_N$. Each cure can be used to cure one infected person once. Due to lockdown rules, you may only deliver cures to one country per day, but you may choose that country arbitrarily and independently on each day. Days are numbered by positive integers. On day $1$, Chef has $x$ cures ready. On each subsequent day, Chef can supply twice the number of cures that were delivered (i.e. people that were cured) on the previous day. Chef cannot supply leftovers from the previous or any earlier day, as the cures expire in a day. The number of cures delivered to some country on some day cannot exceed the number of infected people it currently has, either. However, coronavirus is not giving up so easily. It can infect a cured person that comes in contact with an infected person again ― formally, it means that the number of infected people in a country doubles at the end of each day, i.e. after the cures for this day are used (obviously up to the population of that country). Find the minimum number of days needed to make the world corona-free. -----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 $x$. - The second line contains $N$ space-separated integers $a_1, a_2, \ldots, a_N$. -----Output----- For each test case, print a single line containing one integer ― the minimum number of days. -----Constraints----- - $1 \le T \le 10^3$ - $1 \le N \le 10^5$ - $1 \le a_i \le 10^9$ for each valid $i$ - $1 \le x \le 10^9$ - the sum of $N$ over all test cases does not exceed $10^6$ -----Subtasks----- Subtask #1 (20 points): $a_1 = a_2 = \ldots = a_N$ Subtask #2 (80 points): original constraints -----Example Input----- 3 5 5 1 2 3 4 5 5 1 40 30 20 10 50 3 10 20 1 110 -----Example Output----- 5 9 6
{"inputs": ["3\n5 5\n1 2 3 4 5\n5 1\n40 30 20 10 50\n3 10\n20 1 110"], "outputs": ["5\n9\n6"]}
633
63
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed arrays of strings startWords and targetWords. Each string consists of lowercase English letters only. For each string in targetWords, check if it is possible to choose a string from startWords and perform a conversion operation on it to be equal to that from targetWords. The conversion operation is described in the following two steps: Append any lowercase letter that is not present in the string to its end. For example, if the string is "abc", the letters 'd', 'e', or 'y' can be added to it, but not 'a'. If 'd' is added, the resulting string will be "abcd". Rearrange the letters of the new string in any arbitrary order. For example, "abcd" can be rearranged to "acbd", "bacd", "cbda", and so on. Note that it can also be rearranged to "abcd" itself. Return the number of strings in targetWords that can be obtained by performing the operations on any string of startWords. Note that you will only be verifying if the string in targetWords can be obtained from a string in startWords by performing the operations. The strings in startWords do not actually change during this process.   Please complete the following python code precisely: ```python class Solution: def wordCount(self, startWords: List[str], targetWords: List[str]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(startWords = [\"ant\",\"act\",\"tack\"], targetWords = [\"tack\",\"act\",\"acti\"]) == 2\n assert candidate(startWords = [\"ab\",\"a\"], targetWords = [\"abc\",\"abcd\"]) == 1\n\n\ncheck(Solution().wordCount)"}
311
80
coding
Solve the programming task below in a Python markdown code block. We define the score of permutations of combinations, of an integer number (the function to obtain this value:```sc_perm_comb```) as the total sum of all the numbers obtained from the permutations of all the possible combinations of its digits. For example we have the number 348. ```python sc_perm_comb(348) = 3 + 4 + 8 + 34 + 38 + 48 + 43 + 83 + 84 + 348 + 384 + 834 + 843 + 438 + 483 = 3675 ``` If the number has a digit 0, the numbers formed by a leading 0 should be discarded: ```python sc_perm_comb(340) = 3 + 4 + 34 + 30 + 40 + 43 + 340 + 304 + 430 + 403 = 1631 ``` If the number has digits that occur more than once, the score the adden will not be taken than twice or more: ```python sc_perm_comb(333) = 3 + 33 + 333 = 369 ``` If the number has only one digit its score is the same number: ```python sc_perm_comb(6) = 6 sc_perm_comb(0) = 0 ``` Enjoy it!! Also feel free to reuse/extend the following starter code: ```python def sc_perm_comb(num): ```
{"functional": "_inputs = [[348], [340], [333], [6], [0]]\n_outputs = [[3675], [1631], [369], [6], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(sc_perm_comb(*i), o[0])"}
359
193
coding
Solve the programming task below in a Python markdown code block. # Task A robot is standing at the `(0, 0)` point of the Cartesian plane and is oriented towards the vertical (y) axis in the direction of increasing y values (in other words, he's facing up, or north). The robot executes several commands each of which is a single positive integer. When the robot is given a positive integer K it moves K squares forward and then turns 90 degrees clockwise. The commands are such that both of the robot's coordinates stay non-negative. Your task is to determine if there is a square that the robot visits at least twice after executing all the commands. # Example For `a = [4, 4, 3, 2, 2, 3]`, the output should be `true`. The path of the robot looks like this: ![](https://codefightsuserpics.s3.amazonaws.com/tasks/robotWalk/img/path.png?_tm=1486563151922) The point `(4, 3)` is visited twice, so the answer is `true`. # Input/Output - `[input]` integer array a An array of positive integers, each number representing a command. Constraints: `3 ≤ a.length ≤ 100` `1 ≤ a[i] ≤ 10000` - `[output]` a boolean value `true` if there is a square that the robot visits at least twice, `false` otherwise. Also feel free to reuse/extend the following starter code: ```python def robot_walk(a): ```
{"functional": "_inputs = [[[4, 4, 3, 2, 2, 3]], [[7, 5, 4, 5, 2, 3]], [[10, 3, 10, 2, 5, 1, 2]], [[11, 8, 6, 6, 4, 3, 7, 2, 1]], [[5, 5, 5, 5]], [[34241, 23434, 2341]], [[9348, 2188, 9348]]]\n_outputs = [[True], [True], [False], [True], [True], [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(robot_walk(*i), o[0])"}
349
306
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are n villages in a line in an area. There are two kinds of tribes A and B that reside there. A village can be either empty or occupied by one of the tribes. An empty village is said to be controlled by a tribe of village A if it is surrounded by villages of tribes A from the left and from the right. Same goes for the tribe B. Find out the number of villages that are either occupied by or controlled by tribes A and B, respectively. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of the input contains a string s denoting the configuration of the villages, each character of which can be 'A', 'B' or '.'. ------ Output ------ For each test case, output two space-separated integers denoting the number of villages either occupied by or controlled by tribe A and B, respectively. ------ Constraints ------ $1 ≤ T ≤ 20$ $1 ≤ |s| ≤ 10^{5}$ ------ Subtasks ------ $Subtask #1 (40 points): 1 ≤ |s| ≤ 10^{3}$ $Subtask #2 (60 points): Original constraints$ ----- Sample Input 1 ------ 4 A..A..B...B ..A.. A....A ..B..B..B.. ----- Sample Output 1 ------ 4 5 1 0 6 0 0 7
{"inputs": ["4\nA..A..B...B\n..A..\nA....A\n..B..B..B.."], "outputs": ["4 5\n1 0\n6 0\n0 7"]}
334
50
coding
Solve the programming task below in a Python markdown code block. =====Problem Statement===== We have seen that lists are mutable (they can be changed), and tuples are immutable (they cannot be changed). Let's try to understand this with an example. You are given an immutable string, and you want to make changes to it. Task Read a given string, change the character at a given index and then print the modified string. =====Example===== Example >>> string = "abracadabra" You can access an index by: >>> print string[5] a What if you would like to assign a value? >>> string[5] = 'k' Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'str' object does not support item assignment How would you approach this? One solution is to convert the string to a list and then change the value. Example >>> string = "abracadabra" >>> l = list(string) >>> l[5] = 'k' >>> string = ''.join(l) >>> print string abrackdabra Another approach is to slice the string and join it back. Example >>> string = string[:5] + "k" + string[6:] >>> print string abrackdabra =====Input Format===== The first line contains a string, S. The next line contains an integer i, denoting the index location and a character c separated by a space. =====Output Format===== Using any of the methods explained above, replace the character at index i with character c. Also feel free to reuse/extend the following starter code: ```python def mutate_string(string, position, character): return if __name__ == '__main__': s = input() i, c = input().split() s_new = mutate_string(s, int(i), c) print(s_new) ```
{"functional": "_inputs = [['abracadabra', 5, 'k']]\n_outputs = ['abrackdabra']\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(mutate_string(*i), o)"}
400
165
coding
Solve the programming task below in a Python markdown code block. You start with a value in dollar form, e.g. $5.00. You must convert this value to a string in which the value is said, like '5 dollars' for example. This should account for ones, cents, zeroes, and negative values. Here are some examples: ```python dollar_to_speech('$0.00') == '0 dollars.' dollar_to_speech('$1.00') == '1 dollar.' dollar_to_speech('$0.01') == '1 cent.' dollar_to_speech('$5.00') == '5 dollars.' dollar_to_speech('$20.18') == '20 dollars and 18 cents.' dollar_to_speech('$-1.00') == 'No negative numbers are allowed!' ``` These examples account for pretty much everything. This kata has many specific outputs, so good luck! Also feel free to reuse/extend the following starter code: ```python def dollar_to_speech(value): ```
{"functional": "_inputs = [['$20.18'], ['$5.62'], ['$83.47'], ['$16.93'], ['$0.00'], ['$0.01'], ['$0.63'], ['$0.28'], ['$1.00'], ['$2.00'], ['$31.00'], ['$45.00'], ['$-5843.21'], ['$-45.32'], ['$-2.63'], ['$-234.48']]\n_outputs = [['20 dollars and 18 cents.'], ['5 dollars and 62 cents.'], ['83 dollars and 47 cents.'], ['16 dollars and 93 cents.'], ['0 dollars.'], ['1 cent.'], ['63 cents.'], ['28 cents.'], ['1 dollar.'], ['2 dollars.'], ['31 dollars.'], ['45 dollars.'], ['No negative numbers are allowed!'], ['No negative numbers are allowed!'], ['No negative numbers are allowed!'], ['No negative numbers are allowed!']]\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(dollar_to_speech(*i), o[0])"}
227
382
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. We distribute some number of candies, to a row of n = num_people people in the following way: We then give 1 candy to the first person, 2 candies to the second person, and so on until we give n candies to the last person. Then, we go back to the start of the row, giving n + 1 candies to the first person, n + 2 candies to the second person, and so on until we give 2 * n candies to the last person. This process repeats (with us giving one more candy each time, and moving to the start of the row after we reach the end) until we run out of candies.  The last person will receive all of our remaining candies (not necessarily one more than the previous gift). Return an array (of length num_people and sum candies) that represents the final distribution of candies.   Please complete the following python code precisely: ```python class Solution: def distributeCandies(self, candies: int, num_people: int) -> List[int]: ```
{"functional": "def check(candidate):\n assert candidate(candies = 7, num_people = 4) == [1,2,3,1]\n assert candidate(candies = 10, num_people = 3) == [5,2,3]\n\n\ncheck(Solution().distributeCandies)"}
244
75
coding
Solve the programming task below in a Python markdown code block. You are given a string $t$ consisting of $n$ lowercase Latin letters and an integer number $k$. Let's define a substring of some string $s$ with indices from $l$ to $r$ as $s[l \dots r]$. Your task is to construct such string $s$ of minimum possible length that there are exactly $k$ positions $i$ such that $s[i \dots i + n - 1] = t$. In other words, your task is to construct such string $s$ of minimum possible length that there are exactly $k$ substrings of $s$ equal to $t$. It is guaranteed that the answer is always unique. -----Input----- The first line of the input contains two integers $n$ and $k$ ($1 \le n, k \le 50$) — the length of the string $t$ and the number of substrings. The second line of the input contains the string $t$ consisting of exactly $n$ lowercase Latin letters. -----Output----- Print such string $s$ of minimum possible length that there are exactly $k$ substrings of $s$ equal to $t$. It is guaranteed that the answer is always unique. -----Examples----- Input 3 4 aba Output ababababa Input 3 2 cat Output catcat
{"inputs": ["1 1\na\n", "1 1\na\n", "1 50\nq\n", "2 4\naa\n", "2 2\noo\n", "2 2\naa\n", "2 1\naa\n", "2 2\nab\n"], "outputs": ["a\n", "a\n", "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\n", "aaaaa\n", "ooo\n", "aaa\n", "aa\n", "abab\n"]}
299
129
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a bookstore owner that has a store open for n minutes. You are given an integer array customers of length n where customers[i] is the number of the customers that enter the store at the start of the ith minute and all those customers leave after the end of that minute. During certain minutes, the bookstore owner is grumpy. You are given a binary array grumpy where grumpy[i] is 1 if the bookstore owner is grumpy during the ith minute, and is 0 otherwise. When the bookstore owner is grumpy, the customers entering during that minute are not satisfied. Otherwise, they are satisfied. The bookstore owner knows a secret technique to remain not grumpy for minutes consecutive minutes, but this technique can only be used once. Return the maximum number of customers that can be satisfied throughout the day.   Please complete the following python code precisely: ```python class Solution: def maxSatisfied(self, customers: List[int], grumpy: List[int], minutes: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], minutes = 3) == 16\n assert candidate(customers = [1], grumpy = [0], minutes = 1) == 1\n\n\ncheck(Solution().maxSatisfied)"}
225
97
coding
Solve the programming task below in a Python markdown code block. Chef published a blog post, and is now receiving many queries about it. On day $i$, he receives $Q_i$ queries. But Chef can answer at most $k$ queries in a single day. Chef always answers the maximum number of questions that he can on any given day (note however that this cannot be more than $k$). The remaining questions (if any) will be carried over to the next day. Fortunately, after $n$ days, the queries have stopped. Chef would like to know the first day during which he has some free time, i.e. the first day when he answered less than $k$ questions. -----Input:----- - First line will contain $T$, the number of testcases. Then the testcases follow. - The first line of each testcase contains two space separated integers $n$ and $k$. - The second line of each testcase contains $n$ space separated integers, namely $Q_1, Q_2, ... Q_n$. -----Output:----- For each testcase, output in a single line the first day during which chef answers less than $k$ questions. -----Constraints----- - $1 \leq T \leq 10^5$ - $1 \leq $ sum of $n$ over all testcases $ \leq 10^5$ - $1 \leq k \leq 10^8$ - $0 \leq Q_i \leq 10^8$ -----Subtasks----- - Subtask 1 - 20% points - Sum of $Q_i$ over all testcases and days $\leq 3 . 10^6$ - Subtask 2 - 80% points - Original constraints -----Sample Input:----- 2 6 5 10 5 5 3 2 1 1 1 100 -----Sample Output:----- 6 101 -----Explanation:----- Test Case 1 On the first day, chef answers 5 questions and leaves the remaining 5 (out of the 10) for the future days. On the second day, chef has 10 questions waiting to be answered (5 received on the second day and 5 unanswered questions from day 1). Chef answers 5 of these questions and leaves the remaining 5 for the future. On the third day, chef has 10 questions waiting to be answered (5 received on the third day and 5 unanswered questions from earlier). Chef answers 5 of these questions and leaves the remaining 5 for later. On the fourth day, chef has 8 questions waiting to be answered (3 received on the fourth day and 5 unanswered questions from earlier). Chef answers 5 of these questions and leaves the remaining 3 for later. On the fifth day, chef has 5 questions waiting to be answered (2 received on the fifth day and 3 unanswered questions from earlier). Chef answers all 5 of these questions. On the sixth day, chef has 1 question, which he answers. This is the first day he answers less than 5 questions, and so the answer is 6. Test Case 2 Chef answers 1 question a day for the first 100 days. On day 101, he is free.
{"inputs": ["2\n6 5\n10 5 5 3 2 1\n1 1\n100"], "outputs": ["6\n101"]}
709
41
coding
Solve the programming task below in a Python markdown code block. You have two arrays of integers, $V=\{V_1,V_2,\ldots,V_N\}$ and $P=\{P_1,P_2,\ldots,P_N\}$, where both have $N$ number of elements. Consider the following function: score = 0 int Go(step, energy) { if (step == N) { score += V[step]; return (score); } else { int way = random(1, 2); if (way == 1) { score += V[step]; } else { energy = P[step]; } if (energy > 0) { Go(step + 1, energy - 1); } else { KillTheWorld(); } } } What is the maximum possible value of score that we can get in the end, if we call $Go(1,0)$?. Note that the function should never invoke KillTheWorld function. And $\textit{random(1,2)}$ generates a random integer from set [1, 2]. It is guaranteed there will be a solution that wont kill the world. Input Format The first line contains an integer N. Each of the following N lines contains a pair of integers. The i-th line contains a pair of numbers, $V_i,P_i$, separated by space. Constraints $1\leq N\leq5\times10^5$ $0\leq V_i\leq10^9$ $0\leq P_i\leq10^5$ Output Format Derive the maximum score given by return (score);. Sample Input 4 4 2 0 2 4 0 3 4 Sample Output 7 Explanation In the best case, the first and second function call in Go variable $\textbf{way}$ will take value 2, while in the other calls it will be equal to 1 then the final score will be equal to the value of 7.
{"inputs": ["4\n4 2\n0 2\n4 0\n3 4\n"], "outputs": ["7\n"]}
456
30
coding
Solve the programming task below in a Python markdown code block. There is a tree with N vertices numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Initially, each vertex is uncolored. Takahashi and Aoki is playing a game by painting the vertices. In this game, they alternately perform the following operation, starting from Takahashi: * Select a vertex that is not painted yet. * If it is Takahashi who is performing this operation, paint the vertex white; paint it black if it is Aoki. Then, after all the vertices are colored, the following procedure takes place: * Repaint every white vertex that is adjacent to a black vertex, in black. Note that all such white vertices are repainted simultaneously, not one at a time. If there are still one or more white vertices remaining, Takahashi wins; if all the vertices are now black, Aoki wins. Determine the winner of the game, assuming that both persons play optimally. Constraints * 2 ≤ N ≤ 10^5 * 1 ≤ a_i,b_i ≤ N * a_i ≠ b_i * The input graph is a tree. Input Input is given from Standard Input in the following format: N a_1 b_1 : a_{N-1} b_{N-1} Output Print `First` if Takahashi wins; print `Second` if Aoki wins. Examples Input 3 1 2 2 3 Output First Input 4 1 2 2 3 2 4 Output First Input 6 1 2 2 3 3 4 2 5 5 6 Output Second
{"inputs": ["3\n1 2\n1 3", "3\n0 2\n2 3", "3\n1 1\n2 3", "3\n1 1\n2 2", "3\n1 2\n2 3", "4\n1 2\n2 3\n2 3", "4\n1 2\n1 3\n2 4", "4\n1 2\n2 3\n2 2"], "outputs": ["First\n", "First\n", "First\n", "First\n", "First", "First\n", "Second\n", "First\n"]}
375
137
coding
Solve the programming task below in a Python markdown code block. This is a very simply formulated task. Let's call an integer number `N` 'green' if `N²` ends with all of the digits of `N`. Some examples: `5` is green, because `5² = 25` and `25` ends with `5`. `11` is not green, because `11² = 121` and `121` does not end with `11`. `376` is green, because `376² = 141376` and `141376` ends with `376`. Your task is to write a function `green` that returns `n`th green number, starting with `1` - `green (1) == 1` --- ## Data range ```if:haskell `n <= 4000` for Haskell ``` ```if:java `n <= 5000` for Java ``` ```if:python `n <= 5000` for Python ``` ```if:javascript `n <= 3000` for JavaScript Return values should be `String`s, and should be exact. A BigNum library is recommended. ``` Also feel free to reuse/extend the following starter code: ```python def green(n): ```
{"functional": "_inputs = [[1], [2], [3], [4], [12], [13], [100], [110]]\n_outputs = [[1], [5], [6], [25], [2890625], [7109376], [6188999442576576769103890995893380022607743740081787109376], [9580863811000557423423230896109004106619977392256259918212890625]]\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(green(*i), o[0])"}
303
335
coding
Solve the programming task below in a Python markdown code block. There is a grid with $n$ rows and $m$ columns. Some cells are colored black, and the rest of the cells are colored white. In one operation, you can select some black cell and do exactly one of the following: color all cells in its row black, or color all cells in its column black. You are given two integers $r$ and $c$. Find the minimum number of operations required to make the cell in row $r$ and column $c$ black, or determine that it is impossible. -----Input----- The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 100$) — the number of test cases. The description of the test cases follows. The first line of each test case contains four integers $n$, $m$, $r$, and $c$ ($1 \leq n, m \leq 50$; $1 \leq r \leq n$; $1 \leq c \leq m$) — the number of rows and the number of columns in the grid, and the row and column of the cell you need to turn black, respectively. Then $n$ lines follow, each containing $m$ characters. Each of these characters is either 'B' or 'W' — a black and a white cell, respectively. -----Output----- For each test case, if it is impossible to make the cell in row $r$ and column $c$ black, output $-1$. Otherwise, output a single integer — the minimum number of operations required to make the cell in row $r$ and column $c$ black. -----Examples----- Input 9 3 5 1 4 WBWWW BBBWB WWBBB 4 3 2 1 BWW BBW WBB WWB 2 3 2 2 WWW WWW 2 2 1 1 WW WB 5 9 5 9 WWWWWWWWW WBWBWBBBW WBBBWWBWW WBWBWBBBW WWWWWWWWW 1 1 1 1 B 1 1 1 1 W 1 2 1 1 WB 2 1 1 1 W B Output 1 0 -1 2 2 0 -1 1 1 -----Note----- The first test case is pictured below. We can take the black cell in row $1$ and column $2$, and make all cells in its row black. Therefore, the cell in row $1$ and column $4$ will become black. In the second test case, the cell in row $2$ and column $1$ is already black. In the third test case, it is impossible to make the cell in row $2$ and column $2$ black. The fourth test case is pictured below. We can take the black cell in row $2$ and column $2$ and make its column black. Then, we can take the black cell in row $1$ and column $2$ and make its row black. Therefore, the cell in row $1$ and column $1$ will become black.
{"inputs": ["1\n3 3 1 1\nWWW\nWWW\nWWB\n", "1\n4 4 1 4\nWWWW\nWWWW\nWBWW\nWWWW\n", "9\n3 5 1 4\nWBWWW\nBBBWB\nWWBBB\n4 3 2 1\nBWW\nBBW\nWBB\nWWB\n2 3 2 2\nWWW\nWWW\n2 2 1 1\nWW\nWB\n5 9 5 9\nWWWWWWWWW\nWBWBWBBBW\nWBBBWWBWW\nWBWBWBBBW\nWWWWWWWWW\n1 1 1 1\nB\n1 1 1 1\nW\n1 2 1 1\nWB\n2 1 1 1\nW\nB\n"], "outputs": ["2\n", "2\n", "1\n0\n-1\n2\n2\n0\n-1\n1\n1\n"]}
709
225
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A newly designed keypad was tested, where a tester pressed a sequence of n keys, one at a time. You are given a string keysPressed of length n, where keysPressed[i] was the ith key pressed in the testing sequence, and a sorted list releaseTimes, where releaseTimes[i] was the time the ith key was released. Both arrays are 0-indexed. The 0th key was pressed at the time 0, and every subsequent key was pressed at the exact time the previous key was released. The tester wants to know the key of the keypress that had the longest duration. The ith keypress had a duration of releaseTimes[i] - releaseTimes[i - 1], and the 0th keypress had a duration of releaseTimes[0]. Note that the same key could have been pressed multiple times during the test, and these multiple presses of the same key may not have had the same duration. Return the key of the keypress that had the longest duration. If there are multiple such keypresses, return the lexicographically largest key of the keypresses.   Please complete the following python code precisely: ```python class Solution: def slowestKey(self, releaseTimes: List[int], keysPressed: str) -> str: ```
{"functional": "def check(candidate):\n assert candidate(releaseTimes = [9,29,49,50], keysPressed = \"cbcd\") == \"c\"\n assert candidate(releaseTimes = [12,23,36,46,62], keysPressed = \"spuda\") == \"a\"\n\n\ncheck(Solution().slowestKey)"}
281
86
coding
Solve the programming task below in a Python markdown code block. ## Emotional Sort ( ︶︿︶) You'll have a function called "**sortEmotions**" that will return an array of **emotions** sorted. It has two parameters, the first parameter called "**arr**" will expect an array of **emotions** where an **emotion** will be one of the following: - **:D** -> Super Happy - **:)** -> Happy - **:|** -> Normal - **:(** -> Sad - **T\_T** -> Super Sad Example of the array:``[ 'T_T', ':D', ':|', ':)', ':(' ]`` And the second parameter is called "**order**", if this parameter is **true** then the order of the emotions will be descending (from **Super Happy** to **Super Sad**) if it's **false** then it will be ascending (from **Super Sad** to **Super Happy**) Example if **order** is true with the above array: ``[ ':D', ':)', ':|', ':(', 'T_T' ]`` - Super Happy -> Happy -> Normal -> Sad -> Super Sad If **order** is false: ``[ 'T_T', ':(', ':|', ':)', ':D' ]`` - Super Sad -> Sad -> Normal -> Happy -> Super Happy Example: ``` arr = [':D', ':|', ':)', ':(', ':D'] sortEmotions(arr, true) // [ ':D', ':D', ':)', ':|', ':(' ] sortEmotions(arr, false) // [ ':(', ':|', ':)', ':D', ':D' ] ``` **More in test cases!** Notes: - The array could be empty, in that case return the same empty array ¯\\\_( ツ )\_/¯ - All **emotions** will be valid ## Enjoy! (づ。◕‿‿◕。)づ Also feel free to reuse/extend the following starter code: ```python def sort_emotions(arr, order): ```
{"functional": "_inputs = [[[':D', 'T_T', ':D', ':('], True], [['T_T', ':D', ':(', ':('], True], [[':)', 'T_T', ':)', ':D', ':D'], True], [[':D', 'T_T', ':D', ':('], False], [['T_T', ':D', ':(', ':('], False], [[':)', 'T_T', ':)', ':D', ':D'], False], [[], False], [[], True]]\n_outputs = [[[':D', ':D', ':(', 'T_T']], [[':D', ':(', ':(', 'T_T']], [[':D', ':D', ':)', ':)', 'T_T']], [['T_T', ':(', ':D', ':D']], [['T_T', ':(', ':(', ':D']], [['T_T', ':)', ':)', ':D', ':D']], [[]], [[]]]\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(sort_emotions(*i), o[0])"}
439
334
coding
Solve the programming task below in a Python markdown code block. You have a multiset containing several integers. Initially, it contains $a_1$ elements equal to $1$, $a_2$ elements equal to $2$, ..., $a_n$ elements equal to $n$. You may apply two types of operations: choose two integers $l$ and $r$ ($l \le r$), then remove one occurrence of $l$, one occurrence of $l + 1$, ..., one occurrence of $r$ from the multiset. This operation can be applied only if each number from $l$ to $r$ occurs at least once in the multiset; choose two integers $i$ and $x$ ($x \ge 1$), then remove $x$ occurrences of $i$ from the multiset. This operation can be applied only if the multiset contains at least $x$ occurrences of $i$. What is the minimum number of operations required to delete all elements from the multiset? -----Input----- The first line contains one integer $n$ ($1 \le n \le 5000$). The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_i \le 10^9$). -----Output----- Print one integer — the minimum number of operations required to delete all elements from the multiset. -----Examples----- Input 4 1 4 1 1 Output 2 Input 5 1 0 1 0 1 Output 3
{"inputs": ["1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n6\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
336
86
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 and two integers limit and goal. The array nums has an interesting property that abs(nums[i]) <= limit. Return the minimum number of elements you need to add to make the sum of the array equal to goal. The array must maintain its property that abs(nums[i]) <= limit. Note that abs(x) equals x if x >= 0, and -x otherwise.   Please complete the following python code precisely: ```python class Solution: def minElements(self, nums: List[int], limit: int, goal: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(nums = [1,-1,1], limit = 3, goal = -4) == 2\n assert candidate(nums = [1,-10,9,1], limit = 100, goal = 0) == 1\n\n\ncheck(Solution().minElements)"}
138
76
coding
Solve the programming task below in a Python markdown code block. This is the performance version of [this kata](https://www.codewars.com/kata/59afff65f1c8274f270020f5). --- Imagine two rings with numbers on them. The inner ring spins clockwise and the outer ring spins anti-clockwise. We start with both rings aligned on 0 at the top, and on each move we spin each ring by 1. How many moves will it take before both rings show the same number at the top again? The inner ring has integers from 0 to innerMax and the outer ring has integers from 0 to outerMax, where innerMax and outerMax are integers >= 1. ``` e.g. if innerMax is 2 and outerMax is 3 then after 1 move: inner = 2, outer = 1 2 moves: inner = 1, outer = 2 3 moves: inner = 0, outer = 3 4 moves: inner = 2, outer = 0 5 moves: inner = 1, outer = 1 Therefore it takes 5 moves for the two rings to reach the same number Therefore spinningRings(2, 3) = 5 ``` ``` e.g. if innerMax is 3 and outerMax is 2 then after 1 move: inner = 3, outer = 1 2 moves: inner = 2, outer = 2 Therefore it takes 2 moves for the two rings to reach the same number spinningRings(3, 2) = 2 ``` --- Test input range: - `100` tests with `1 <= innerMax, outerMax <= 10000` - `400` tests with `1 <= innerMax, outerMax <= 2^48` Also feel free to reuse/extend the following starter code: ```python def spinning_rings(inner_max, outer_max): ```
{"functional": "_inputs = [[5, 5], [2, 10], [10, 2], [7, 9], [1, 1], [16777216, 14348907]]\n_outputs = [[3], [13], [10], [4], [1], [23951671]]\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(spinning_rings(*i), o[0])"}
431
230
coding
Solve the programming task below in a Python markdown code block. Chef's current score is X. Each second, Chef will find the smallest [prime factor] of his score and add it to his score. Determine the minimum time in seconds, after which his score becomes ≥ Y. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of a single line containing two integers X and Y, the initial and required score of Chef. ------ Output Format ------ For each test case, output the minimum time in seconds, after which Chef's score becomes ≥ Y. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ X ≤ 10$ $20 ≤ Y ≤ 10^{9}$ ----- Sample Input 1 ------ 4 2 23 9 20 5 100 6 89 ----- Sample Output 1 ------ 11 5 46 42 ----- explanation 1 ------ Test case $1$: The initial score is $2$. Chef needs the score to be at least $23$. - The smallest prime factor of $2$ is $2$. Thus, the score increase to $2+2 = 4$. - The smallest prime factor of $4$ is $2$. Thus, the score increase to $4+2 = 6$. - Similarly, each time the score would be increased by $2$. Thus, after $11$ seconds, the score becomes $24$, which is $≥ 23$. Test case $2$: The initial score is $9$. Chef needs the score to be at least $20$. - The smallest prime factor of $9$ is $3$. Thus, the score increase to $9+3 = 12$. - The smallest prime factor of $12$ is $2$. Thus, the score increase to $12+2 = 14$. - The smallest prime factor of $14$ is $2$. Thus, the score increase to $14+2 = 16$. - The smallest prime factor of $16$ is $2$. Thus, the score increase to $16+2 = 18$. - The smallest prime factor of $18$ is $2$. Thus, the score increase to $18+2 = 20$. Thus, after $5$ seconds, the score becomes $20$, which is $≥ 20$.
{"inputs": ["4\n2 23\n9 20\n5 100\n6 89\n"], "outputs": ["11\n5\n46\n42\n"]}
546
44
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Sereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in long straight corridor in which people sit in a way such that they won't leave any empty space in between two consecutive persons at any given time. When a person number i arrives at the corridor, he must go and stand to the immediate right of the person numbered A[i] (if A[i] = 0, then this person just stands at the leftmost end of the line). But there is a problem, as there is no space between two consecutive persons at any given time, so for this person to sit, space must be created by moving either all the persons to left of the place to the left one step each, or all the persons to right of the place to the right one step each. Now, Sereja is wondering about what could be the minimum number of steps people will take so as to sit in the dinner party. Please find it fast, so that Sereja can peacefully entertain his guests. ------ Input ------ First line of input contain an integer T — the number of test cases. T tests follow. First line of each test case contain the integer N, and the next line contains N integers — A[1], A[2], ... , A[N]. ------ Output ------ For each test case, output a single line with the answer — the minimal number of steps required. ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ N ≤ 100$ $0 ≤ A[i] < i$ ----- Sample Input 1 ------ 3 1 0 3 0 0 0 5 0 1 2 1 4 ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ Example case 3. First three persons don't need any steps to sit. The line after the arrangement of these persons will look like [1, 2, 3]. When person #4 comes in, he wants to sit to the right of person 1, so we need to either move the first person to the left, or the second and third persons to the right. The first case is clearly better. Now the line will look like [1, 4, 2, 3]. When person #5 arrives, he will need to move 2 persons in either case. The final arrangement will be [1, 4, 5, 2, 3]. So total number of steps people moved during the entire process is 1 + 2 = 3. So the answer is 3.
{"inputs": ["3\n1\n0\n3\n0 0 0\n5\n0 1 2 1 4"], "outputs": ["0\n0\n3"]}
594
40
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given positive integers n and target. An array nums is beautiful if it meets the following conditions: nums.length == n. nums consists of pairwise distinct positive integers. There doesn't exist two distinct indices, i and j, in the range [0, n - 1], such that nums[i] + nums[j] == target. Return the minimum possible sum that a beautiful array could have modulo 109 + 7.   Please complete the following python code precisely: ```python class Solution: def minimumPossibleSum(self, n: int, target: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(n = 2, target = 3) == 4\n assert candidate(n = 3, target = 3) == 8\n assert candidate(n = 1, target = 1) == 1\n\n\ncheck(Solution().minimumPossibleSum)"}
141
71
coding
Solve the programming task below in a Python markdown code block. In this kata you will be given an **integer n**, which is the number of times that is thown a coin. You will have to return an array of string for all the possibilities (heads[H] and tails[T]). Examples: ```coin(1) should return {"H", "T"}``` ```coin(2) should return {"HH", "HT", "TH", "TT"}``` ```coin(3) should return {"HHH", "HHT", "HTH", "HTT", "THH", "THT", "TTH", "TTT"}``` When finished sort them alphabetically. In C and C++ just return a ```char*``` with all elements separated by```,``` (without space): ```coin(2) should return "HH,HT,TH,TT"``` INPUT: ```0 < n < 18``` Careful with performance!! You'll have to pass 3 basic test (n = 1, n = 2, n = 3), many medium tests (3 < n <= 10) and many large tests (10 < n < 18) Also feel free to reuse/extend the following starter code: ```python def coin(n): ```
{"functional": "_inputs = [[1], [2], [3]]\n_outputs = [[['H', 'T']], [['HH', 'HT', 'TH', 'TT']], [['HHH', 'HHT', 'HTH', 'HTT', 'THH', 'THT', 'TTH', 'TTT']]]\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(coin(*i), o[0])"}
275
209
coding
Solve the programming task below in a Python markdown code block. Maya writes weekly articles to a well known magazine, but she is missing one word each time she is about to send the article to the editor. The article is not complete without this word. Maya has a friend, Dan, and he is very good with words, but he doesn't like to just give them away. He texts Maya a number and she needs to find out the hidden word. The words can contain only the letter: "a", "b", "d", "e", "i", "l", "m", "n", "o", and "t". Luckily, Maya has the key: "a" - 6 "b" - 1 "d" - 7 "e" - 4 "i" - 3 "l" - 2 "m" - 9 "n" - 8 "o" - 0 "t" - 5 You can help Maya by writing a function that will take a number between 100 and 999999 and return a string with the word. The input is always a number, contains only the numbers in the key. The output should be always a string with one word, all lowercase. Maya won't forget to thank you at the end of her article :) Also feel free to reuse/extend the following starter code: ```python def hidden(num): ```
{"functional": "_inputs = [[637], [7468], [49632], [1425], [6250], [12674], [4735], [7345], [3850], [2394], [2068], [137], [1065], [6509], [3549], [5394], [56124], [968], [103247], [67935], [7415], [2687], [261], [8054], [942547]]\n_outputs = [['aid'], ['dean'], ['email'], ['belt'], ['alto'], ['blade'], ['edit'], ['diet'], ['into'], ['lime'], ['loan'], ['bid'], ['boat'], ['atom'], ['item'], ['time'], ['table'], ['man'], ['boiled'], ['admit'], ['debt'], ['land'], ['lab'], ['note'], ['melted']]\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(hidden(*i), o[0])"}
308
382
coding
Solve the programming task below in a Python markdown code block. You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game. The boss battle consists of $n$ turns. During each turn, you will get several cards. Each card has two parameters: its cost $c_i$ and damage $d_i$. You may play some of your cards during each turn in some sequence (you choose the cards and the exact order they are played), as long as the total cost of the cards you play during the turn does not exceed $3$. After playing some (possibly zero) cards, you end your turn, and all cards you didn't play are discarded. Note that you can use each card at most once. Your character has also found an artifact that boosts the damage of some of your actions: every $10$-th card you play deals double damage. What is the maximum possible damage you can deal during $n$ turns? -----Input----- The first line contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of turns. Then $n$ blocks of input follow, the $i$-th block representing the cards you get during the $i$-th turn. Each block begins with a line containing one integer $k_i$ ($1 \le k_i \le 2 \cdot 10^5$) — the number of cards you get during $i$-th turn. Then $k_i$ lines follow, each containing two integers $c_j$ and $d_j$ ($1 \le c_j \le 3$, $1 \le d_j \le 10^9$) — the parameters of the corresponding card. It is guaranteed that $\sum \limits_{i = 1}^{n} k_i \le 2 \cdot 10^5$. -----Output----- Print one integer — the maximum damage you may deal. -----Example----- Input 5 3 1 6 1 7 1 5 2 1 4 1 3 3 1 10 3 5 2 3 3 1 15 2 4 1 10 1 1 100 Output 263 -----Note----- In the example test the best course of action is as follows: During the first turn, play all three cards in any order and deal $18$ damage. During the second turn, play both cards and deal $7$ damage. During the third turn, play the first and the third card and deal $13$ damage. During the fourth turn, play the first and the third card and deal $25$ damage. During the fifth turn, play the only card, which will deal double damage ($200$).
{"inputs": ["1\n4\n1 1\n1 1\n2 2\n3 4\n", "1\n4\n1 1\n1 1\n2 2\n3 4\n", "1\n4\n2 1\n1 1\n2 2\n3 4\n", "1\n4\n1 0\n1 2\n2 3\n3 4\n", "1\n4\n2 2\n1 1\n1 2\n3 8\n", "1\n4\n1 0\n2 2\n2 3\n3 0\n", "1\n4\n1 0\n1 1\n2 2\n3 6\n", "1\n4\n1 0\n1 4\n2 3\n3 4\n"], "outputs": ["4\n", "4\n", "4\n", "5\n", "8\n", "3\n", "6\n", "7\n"]}
607
214
coding
Solve the programming task below in a Python markdown code block. There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: - Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform. -----Constraints----- - 1 \leq N \leq 200 - 1 \leq A_i \leq 10^9 -----Input----- Input is given from Standard Input in the following format: N A_1 A_2 ... A_N -----Output----- Print the maximum possible number of operations that Snuke can perform. -----Sample Input----- 3 8 12 40 -----Sample Output----- 2 Initially, [8, 12, 40] are written on the blackboard. Since all those integers are even, Snuke can perform the operation. After the operation is performed once, [4, 6, 20] are written on the blackboard. Since all those integers are again even, he can perform the operation. After the operation is performed twice, [2, 3, 10] are written on the blackboard. Now, there is an odd number 3 on the blackboard, so he cannot perform the operation any more. Thus, Snuke can perform the operation at most twice.
{"inputs": ["3\n4 7 31", "3\n4 7 52", "3\n7 7 52", "3\n7 7 25", "3\n7 13 5", "3\n7 13 8", "3\n6 12 31", "3\n4 12 31"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
311
120
coding
Solve the programming task below in a Python markdown code block. Takahashi and Aoki are going to together construct a sequence of integers. First, Takahashi will provide a sequence of integers a, satisfying all of the following conditions: - The length of a is N. - Each element in a is an integer between 1 and K, inclusive. - a is a palindrome, that is, reversing the order of elements in a will result in the same sequence as the original. Then, Aoki will perform the following operation an arbitrary number of times: - Move the first element in a to the end of a. How many sequences a can be obtained after this procedure, modulo 10^9+7? -----Constraints----- - 1≤N≤10^9 - 1≤K≤10^9 -----Input----- The input is given from Standard Input in the following format: N K -----Output----- Print the number of the sequences a that can be obtained after the procedure, modulo 10^9+7. -----Sample Input----- 4 2 -----Sample Output----- 6 The following six sequences can be obtained: - (1, 1, 1, 1) - (1, 1, 2, 2) - (1, 2, 2, 1) - (2, 2, 1, 1) - (2, 1, 1, 2) - (2, 2, 2, 2)
{"inputs": ["1 5", "2 2", "2 4", "2 0", "4 4", "6 4", "2 3", "2 6"], "outputs": ["5\n", "2\n", "4\n", "0\n", "28\n", "184\n", "3\n", "6\n"]}
317
81
coding
Solve the programming task below in a Python markdown code block. "I'm a fan of anything that tries to replace actual human contact." - Sheldon. After years of hard work, Sheldon was finally able to develop a formula which would diminish the real human contact. He found k$k$ integers n1,n2...nk$n_1,n_2...n_k$ . Also he found that if he could minimize the value of m$m$ such that ∑ki=1$\sum_{i=1}^k$n$n$i$i$C$C$m$m$i$i$ is even, where m$m$ = ∑ki=1$\sum_{i=1}^k$mi$m_i$, he would finish the real human contact. Since Sheldon is busy choosing between PS-4 and XBOX-ONE, he want you to help him to calculate the minimum value of m$m$. -----Input:----- - The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows. - The first line of each test case contains a single integer k$k$. - Next line contains k space separated integers n1,n2...nk$n_1,n_2...n_k$ . -----Output:----- For each test case output the minimum value of m for which ∑ki=1$\sum_{i=1}^k$n$n$i$i$C$C$m$m$i$i$ is even, where m$m$=m1$m_1$+m2$m_2$+. . . mk$m_k$ and 0$0$ <= mi$m_i$<= ni$n_i$ . If no such answer exists print -1. -----Constraints----- - 1≤T≤1000$1 \leq T \leq 1000$ - 1≤k≤1000$1 \leq k \leq 1000$ - 1≤ni≤10$1 \leq n_i \leq 10$18$18$ -----Sample Input:----- 1 1 5 -----Sample Output:----- 2 -----EXPLANATION:----- 5$5$C$C$2$2$ = 10 which is even and m is minimum.
{"inputs": ["1\n1\n5"], "outputs": ["2"]}
497
16
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef’s girlfriend's birthday is near, so he wants to surprise her by making a special cake for her. Chef knows that his girlfriend likes cherries on the cake, so he puts cherries on the top of the cake, but he was not satisfied. Therefore, he decided to replace some of the cherries to make a beautiful pattern. However, Chef has a lot of other work to do so he decided to ask for your help. The cherries are of two colors red and green. Now Chef wants the cherries to be placed in such a way that each cherry of one color must be adjacent to only cherries of the other color, two cherries are adjacent if they share a side. Now Chef has asked for your help in making that pattern on the cake. You can replace any cherry of given color with the other color. But there is a cost for each replacement: if you replace a red cherry with a green one, the cost is 5 units and if you replace a green cherry with a red one, the cost is 3 units. Help your friend Chef by making the cake special with minimum cost. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains two space-separated integers N and M, where N × M are the dimensions of the cake. Each of the next N lines contains a string of length M. ------ Output ------ For each test case, output the minimum cost required to make the cake special. ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ N, M ≤ 100$ $each string consists only of letters 'R' and 'G' denoting red and green cherries respectively ----- Sample Input 1 ------ 2 4 5 RGRGR GRGRG RGRGR GRGRG 2 3 RRG GGR ----- Sample Output 1 ------ 0 8
{"inputs": ["2\n4 5\nRGRGR\nGRGRG\nRGRGR\nGRGRG\n2 3\nRRG\nGGR"], "outputs": ["0\n8"]}
444
44
coding
Solve the programming task below in a Python markdown code block. We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i). Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there? We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}. -----Constraints----- - 1 \leq N \leq 2\times 10^5 - 0 \leq D \leq 2\times 10^5 - |X_i|,|Y_i| \leq 2\times 10^5 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: N D X_1 Y_1 \vdots X_N Y_N -----Output----- Print an integer representing the number of points such that the distance from the origin is at most D. -----Sample Input----- 4 5 0 5 -2 4 3 4 4 -4 -----Sample Output----- 3 The distance between the origin and each of the given points is as follows: - \sqrt{0^2+5^2}=5 - \sqrt{(-2)^2+4^2}=4.472\ldots - \sqrt{3^2+4^2}=5 - \sqrt{4^2+(-4)^2}=5.656\ldots Thus, we have three points such that the distance from the origin is at most 5.
{"inputs": ["4 5\n0 5\n-2 4\n3 4\n4 -4\n", "12 3\n1 1\n1 1\n1 1\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n", "20 100000\n14309 -32939\n-56855 100340\n151364 25430\n103789 -113141\n147404 -136977\n-37006 -30929\n188810 -49557\n13419 70401\n-88280 165170\n-196399 137941\n-176527 -61904\n46659 115261\n-153551 114185\n98784 -6820\n94111 -86268\n-30401 61477\n-55056 7872\n5901 -163796\n138819 -185986\n-69848 -96669\n"], "outputs": ["3\n", "7\n", "6\n"]}
365
371
coding
Solve the programming task below in a Python markdown code block. Now that you have won Code Monk and been hired by HackerEarth as a software engineer, you have been assigned to work on their wildly popular programming contest website. HackerEarth is expecting a lot of participants (P) in Code Monk next year, and they want to make sure that the site can support that many people at the same time. During Code Monk 2014 you learned that the site could support at least L people at a time without any errors, but you also know that the site can't yet support P people. To determine how many more machines you'll need, you want to know within a factor of C how many people the site can support. This means that there is an integer a such that you know the site can support a people, but you know the site can't support a * C people. You can run a test series of Think a Thon, each of which will determine whether the site can support at least X people for some integer value of X that you choose. If you pick an optimal strategy, choosing what tests to run based on the results of previous tests, how many Think a Thon do you need in the worst case? Input The first line of the input gives the number of test cases, T. T lines follow, each of which contains space-separated integers L, P and C in that order. Output For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of load tests you need to run in the worst case before knowing within a factor of C how many people the site can support. CONSTRAINTS 1 ≤ T ≤ 1000. 2 ≤ C ≤ 10. L, P and C are all integers. 1 ≤ L < P ≤ 109. SAMPLE INPUT 2 19 57 3 24 97 2 SAMPLE OUTPUT Case #1: 0 Case #2: 2 Explanation In Case #1, we already know that the site can support between 19 and 57 people. Since those are a factor of 3 apart, we don't need to do any testing. In Case #2, we can test 48; but if the site can support 48 people, we need more testing, because 48*2 < 97. We could test 49; but if the site can't support 49 people, we need more testing, because 24 * 2 < 49. So we need two tests.
{"inputs": ["2\n19 57 3\n24 97 2", "4\n50 700 2\n19 57 3\n1 1000 2\n24 97 2"], "outputs": ["Case #1: 0\nCase #2: 2", "Case #1: 2\nCase #2: 0\nCase #3: 4\nCase #4: 2"]}
559
106
coding
Solve the programming task below in a Python markdown code block. There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations. Constraints * 1 \leq N,M \leq 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of cards that face down after all the operations. Examples Input 2 2 Output 0 Input 1 7 Output 5 Input 314 1592 Output 496080
{"inputs": ["1 2", "0 0", "8 0", "1 7", "2 2", "0 -1", "54 8", "60 4"], "outputs": ["0\n", "4\n", "-12\n", "5", "0", "6\n", "312\n", "116\n"]}
263
83
coding
Solve the programming task below in a Python markdown code block. In the previous challenge, you wrote code to perform an Insertion Sort on an unsorted array. But how would you prove that the code is correct? I.e. how do you show that for any input your code will provide the right output? Loop Invariant In computer science, you could prove it formally with a loop invariant, where you state that a desired property is maintained in your loop. Such a proof is broken down into the following parts: Initialization: It is true (in a limited sense) before the loop runs. Maintenance: If it's true before an iteration of a loop, it remains true before the next iteration. Termination: It will terminate in a useful way once it is finished. Insertion Sort's Invariant Say, you have some InsertionSort code, where the outer loop goes through the whole array $\mbox{A}$: for(int i = 1; i < A.length; i++){ //insertion sort code You could then state the following loop invariant: At the start of every iteration of the outer loop (indexed with $\boldsymbol{i}$), the subarray until $ar[i]$ consists of the original elements that were there, but in sorted order. To prove Insertion Sort is correct, you will then demonstrate it for the three stages: Initialization - The subarray starts with the first element of the array, and it is (obviously) sorted to begin with. Maintenance - Each iteration of the loop expands the subarray, but keeps the sorted property. An element $\mbox{V}$ gets inserted into the array only when it is greater than the element to its left. Since the elements to its left have already been sorted, it means $\mbox{V}$ is greater than all the elements to its left, so the array remains sorted. (In Insertion Sort 2 we saw this by printing the array each time an element was properly inserted.) Termination - The code will terminate after $\boldsymbol{i}$ has reached the last element in the array, which means the sorted subarray has expanded to encompass the entire array. The array is now fully sorted. You can often use a similar process to demonstrate the correctness of many algorithms. You can see these notes for more information. Challenge In the InsertionSort code below, there is an error. Can you fix it? Print the array only once, when it is fully sorted. Input Format There will be two lines of input: $\boldsymbol{\mathrm{~S~}}$ - the size of the array $\textbf{arr}$ - the list of numbers that makes up the array Constraints $1\leq s\leq1000$ $-1500\le V\le1500,V\in\textit{arr}$ Output Format Output the numbers in order, space-separated on one line. Sample Input 6 7 4 3 5 6 2 Sample Output 2 3 4 5 6 7 Explanation The corrected code returns the sorted array.
{"inputs": ["6\n7 4 3 5 6 2\n"], "outputs": ["2 3 4 5 6 7\n"]}
653
36
coding
Solve the programming task below in a Python markdown code block. You are given two strings $s$ and $t$ consisting of lowercase Latin letters. Also you have a string $z$ which is initially empty. You want string $z$ to be equal to string $t$. You can perform the following operation to achieve this: append any subsequence of $s$ at the end of string $z$. A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. For example, if $z = ac$, $s = abcde$, you may turn $z$ into following strings in one operation: $z = acace$ (if we choose subsequence $ace$); $z = acbcd$ (if we choose subsequence $bcd$); $z = acbce$ (if we choose subsequence $bce$). Note that after this operation string $s$ doesn't change. Calculate the minimum number of such operations to turn string $z$ into string $t$. -----Input----- The first line contains the integer $T$ ($1 \le T \le 100$) — the number of test cases. The first line of each testcase contains one string $s$ ($1 \le |s| \le 10^5$) consisting of lowercase Latin letters. The second line of each testcase contains one string $t$ ($1 \le |t| \le 10^5$) consisting of lowercase Latin letters. It is guaranteed that the total length of all strings $s$ and $t$ in the input does not exceed $2 \cdot 10^5$. -----Output----- For each testcase, print one integer — the minimum number of operations to turn string $z$ into string $t$. If it's impossible print $-1$. -----Example----- Input 3 aabce ace abacaba aax ty yyt Output 1 -1 3
{"inputs": ["3\naabce\nace\nabacaba\naax\nty\nyyt\n", "3\naabce\nace\nabbcaaa\naax\nty\nyyt\n", "3\naabcf\nace\nabbcaaa\naax\nty\nyyt\n", "3\necbaa\nace\nabbcaaa\naax\nty\nyyt\n", "3\nbaacf\nace\nabbcaaa\naax\nty\nyyt\n", "3\naabce\nace\nabacaba\naax\nty\nyyt\n", "11\na\naaaaaaaaaaa\ncba\nabcabcabcabcabcabcabc\nbvdhsdvlbelrivbhxbhie\nx\nabacabadabacaba\nabacabadabacaba\nabacabadabacaba\nbaabaabcaa\naabab\naaababbbaaaabbab\nt\ny\nu\nu\nabcdefghijk\nkjihgfedcba\nabcdefghijk\nkjihgfdecba\nabb\nababbbbb\n", "11\na\naaaaaaaaaaa\ncba\nabcabcabcabcabcabcabc\nbvdhsdvlbelrivbhxbhie\nx\nabacabadabacaba\nabacabadabacaba\nabacabadabacaba\nbaabaabcaa\naabab\naaababbbaaaabbab\nt\ny\nu\nu\nabcdefghijk\nkjihgfedcba\nabcdefghijk\nkjihgfdecba\nabb\nababbbbb\n"], "outputs": ["1\n-1\n3\n", "1\n-1\n3\n", "-1\n-1\n3\n", "3\n-1\n3\n", "-1\n-1\n3\n", "1\n-1\n3\n", "11\n15\n1\n1\n1\n5\n-1\n1\n11\n10\n4\n", "11\n15\n1\n1\n1\n5\n-1\n1\n11\n10\n4\n"]}
430
453
coding
Solve the programming task below in a Python markdown code block. Daenerys Targaryen has been suggested by her counselors to leave the Meereen and start conquering other parts of the world. But she knows giving up on the people of Meereen means victory of slavery. Her plan is to start conquering rest of the world while she remains in Meereen. She can only trust her bravest and most beloved Daario Naharis to undertake this risk. She asks him to conquer a few nations and promises him a help from her dragons. She also promises to marry him if he successfully conquers all the nations and not if he is defeated. Daario has to conquer 'N' number of nations each nation with army size A[i]. He attacks the nations serially. As promised, he gets help from Daenerys's Dragons. His first 'M' attacks are made with the help of Dragons. For first 'M' attacks, he gains A[i] soldiers. For the rest, he looses ceiling of A[i]/2 soldiers. He is defeated if he is left with no army before he conquers all the 'N' nations. He has no army initially and only has Dragons. -----Input----- First line has 'T' which is the number of test cases. For each test cases there are two space separated integers 'N' and 'M' denoting the number of nations and the number of nations he has Dragon's help for respectively. Follows N space separated integers denoting the size of army of each nation. -----Output----- Print 'VICTORY' if Daario conquers all nations and 'DEFEAT' if he doesn't. -----Constraints----- - 1 ≤ T ≤ 500 - 1 ≤ M ≤N ≤ 100000 - 1 ≤ A[i] ≤ 100000 -----Example----- Input: 3 5 3 1 2 3 4 5 6 2 4 4 4 4 4 4 7 4 10 10 10 10 50 60 70 Output: VICTORY VICTORY DEFEAT -----Explanation----- Example case 1. First 3 attacks add 1,2,3 to his army making it 6. (1+2+3 = 6) Then he looses 2 and 3 making it 1. (6-2-3 = 1) He conquers all so VICTORY. Example case 2. First 2 attacks add 4,4 to his army making it 8. (4+4 = 8) Then he looses 2,2,2,2 making it 0. (8-2-2-2-2 = 0) He conquers all so VICTORY. Example case 3. First 4 attacks add 10,10,10,10 to his army making it 40. (10+10+10+10 = 40) Then he looses 25 and then all 15 out of possible 30 making it 0. (40-25-15 = 0) He is defeated on 6th attack so DEFEAT.
{"inputs": ["3\n5 3\n1 2 3 4 5\n6 2\n4 4 4 4 4 4\n7 4\n10 10 10 10 50 60 70"], "outputs": ["VICTORY\nVICTORY\nDEFEAT"]}
705
77
coding
Solve the programming task below in a Python markdown code block. # Task Given a square `matrix`, your task is to reverse the order of elements on both of its longest diagonals. The longest diagonals of a square matrix are defined as follows: * the first longest diagonal goes from the top left corner to the bottom right one; * the second longest diagonal goes from the top right corner to the bottom left one. # Example For the matrix ``` 1, 2, 3 4, 5, 6 7, 8, 9 ``` the output should be: ``` 9, 2, 7 4, 5, 6 3, 8, 1 ``` # Input/Output - `[input]` 2D integer array `matrix` Constraints: `1 ≤ matrix.length ≤ 10, matrix.length = matrix[i].length, 1 ≤ matrix[i][j] ≤ 1000` - `[output]` 2D integer array Matrix with the order of elements on its longest diagonals reversed. Also feel free to reuse/extend the following starter code: ```python def reverse_on_diagonals(matrix): ```
{"functional": "_inputs = [[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]], [[[239]]], [[[1, 10], [100, 1000]]], [[[43, 455, 32, 103], [102, 988, 298, 981], [309, 21, 53, 64], [2, 22, 35, 291]]]]\n_outputs = [[[[9, 2, 7], [4, 5, 6], [3, 8, 1]]], [[[239]]], [[[1000, 100], [10, 1]]], [[[291, 455, 32, 2], [102, 53, 21, 981], [309, 298, 988, 64], [103, 22, 35, 43]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(reverse_on_diagonals(*i), o[0])"}
258
403
coding
Solve the programming task below in a Python markdown code block. Given an array of numbers, return a string made up of four parts: a) a four character 'word', made up of the characters derived from the first two and last two numbers in the array. order should be as read left to right (first, second, second last, last), b) the same as above, post sorting the array into ascending order, c) the same as above, post sorting the array into descending order, d) the same as above, post converting the array into ASCII characters and sorting alphabetically. The four parts should form a single string, each part separated by a hyphen: '-' example format of solution: 'asdf-tyui-ujng-wedg' Also feel free to reuse/extend the following starter code: ```python def sort_transform(arr): ```
{"functional": "_inputs = [[[111, 112, 113, 114, 115, 113, 114, 110]], [[51, 62, 73, 84, 95, 100, 99, 126]], [[66, 101, 55, 111, 113]], [[78, 117, 110, 99, 104, 117, 107, 115, 120, 121, 125]], [[101, 48, 75, 105, 99, 107, 121, 122, 124]], [[80, 117, 115, 104, 65, 85, 112, 115, 66, 76, 62]], [[91, 100, 111, 121, 51, 62, 81, 92, 63]], [[78, 93, 92, 98, 108, 119, 116, 100, 85, 80]], [[111, 121, 122, 124, 125, 126, 117, 118, 119, 121, 122, 73]], [[82, 98, 72, 71, 71, 72, 62, 67, 68, 115, 117, 112, 122, 121, 93]], [[99, 98, 97, 96, 81, 82, 82]], [[66, 99, 88, 122, 123, 110]], [[66, 87, 98, 59, 57, 50, 51, 52]]]\n_outputs = [['oprn-nors-sron-nors'], ['3>c~-3>d~-~d>3-3>d~'], ['Beoq-7Boq-qoB7-7Boq'], ['Nuy}-Ncy}-}ycN-Ncy}'], ['e0z|-0Kz|-|zK0-0Kz|'], ['PuL>->Asu-usA>->Asu'], ['[d\\\\?-3>oy-yo>3-3>oy'], ['N]UP-NPtw-wtPN-NPtw'], ['oyzI-Io}~-~}oI-Io}~'], ['Rby]->Cyz-zyC>->Cyz'], ['cbRR-QRbc-cbRQ-QRbc'], ['Bc{n-BXz{-{zXB-BXz{'], ['BW34-23Wb-bW32-23Wb']]\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(sort_transform(*i), o[0])"}
178
884
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return the number of AND triples. An AND triple is a triple of indices (i, j, k) such that: 0 <= i < nums.length 0 <= j < nums.length 0 <= k < nums.length nums[i] & nums[j] & nums[k] == 0, where & represents the bitwise-AND operator.   Please complete the following python code precisely: ```python class Solution: def countTriplets(self, nums: List[int]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(nums = [2,1,3]) == 12\n assert candidate(nums = [0,0,0]) == 27\n\n\ncheck(Solution().countTriplets)"}
125
54
coding
Solve the programming task below in a Python markdown code block. We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel? -----Constraints----- - 1 \leq N \leq 100 - 1 \leq A_{i, j} \leq 100 (1 \leq i \leq 2, 1 \leq j \leq N) -----Input----- Input is given from Standard Input in the following format: N A_{1, 1} A_{1, 2} ... A_{1, N} A_{2, 1} A_{2, 2} ... A_{2, N} -----Output----- Print the maximum number of candies that can be collected. -----Sample Input----- 5 3 2 2 4 1 1 2 2 2 1 -----Sample Output----- 14 The number of collected candies will be maximized when you: - move right three times, then move down once, then move right once.
{"inputs": ["1\n2\n6", "1\n2\n7", "1\n2\n1", "1\n1\n1", "1\n8\n2", "1\n1\n0", "1\n0\n0", "1\n2\n3"], "outputs": ["8\n", "9\n", "3\n", "2\n", "10\n", "1\n", "0\n", "5"]}
358
94
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A valid parentheses string is either empty "", "(" + A + ")", or A + B, where A and B are valid parentheses strings, and + represents string concatenation. For example, "", "()", "(())()", and "(()(()))" are all valid parentheses strings. A valid parentheses string s is primitive if it is nonempty, and there does not exist a way to split it into s = A + B, with A and B nonempty valid parentheses strings. Given a valid parentheses string s, consider its primitive decomposition: s = P1 + P2 + ... + Pk, where Pi are primitive valid parentheses strings. Return s after removing the outermost parentheses of every primitive string in the primitive decomposition of s.   Please complete the following python code precisely: ```python class Solution: def removeOuterParentheses(self, s: str) -> str: ```
{"functional": "def check(candidate):\n assert candidate(s = \"(()())(())\") == \"()()()\"\n assert candidate(s = \"(()())(())(()(()))\") == \"()()()()(())\"\n assert candidate(s = \"()()\") == \"\"\n\n\ncheck(Solution().removeOuterParentheses)"}
197
75
coding
Solve the programming task below in a Python markdown code block. You are currently studying the language $A j o b$ ( which means strange in English ) from a renowned professor. The language has infinite number of letters in its alphabet ( now you know, why it is called ajob ). The professor taught you $N$ words, one by one. The number of letters in a word is equal to it's place in the teaching order. Thus, the $1^{st}$ word taught by the professor has $\mbox{1}$ letter, $2^{nd}$ word has $2$ letters, $3^{rd}$ word has $3$ letters, $\ldots$, the $N^{th}$ word has $N$ letters. All the letters within a word are distinct to each other. Now, you are handed an assignment. You have to choose any one of the $N$ words and form a subsequence from it. The length of the subsequence should be exactly $\mbox{K}$ less than the length of original word. For example, if the length of the chosen word is $\mbox{L}$, then the length of the subsequence should be $L-K$. If for any word, $\mbox{L}$ is smaller than $\mbox{K}$ $\left(L<K\right)$, then you must not choose that word. Two subsequences are different to each other if, the lengths of them are different or they contain different characters in the same position. Find the number of ways you can complete the assignment ${modulo}\:p$ ( ${p}$ will always be a $\textit{prime}$ ). 1. The first line contains ${T}$, the number of testcases. The next ${T}$ lines contain three space separated integers $N$, ${K}$ and ${p}$. Output Format For each testcase, print one integer in a single line, the number possible ways you can complete the assignment, ${modulo}\:p$. Constraints $1\leq T\leq100$ $2\leq N\leq10^{18}$ $0<K<N$ $2\leq p\leq10^5$ $p\:\text{is a Prime}$ Sample Input #00 3 2 1 2 2 1 5 5 3 13 Sample Output #00 1 3 2 Sample Input #01 5 5 2 3 6 5 11 7 6 3 6 5 7 6 5 5 Sample Output #01 2 7 2 0 2
{"inputs": ["3\n2 1 2\n2 1 5\n5 3 13\n", "5\n5 2 3\n6 5 11\n7 6 3\n6 5 7\n6 5 5\n"], "outputs": ["1\n3\n2\n", "2\n7\n2\n0\n2\n"]}
571
84
coding
Solve the programming task below in a Python markdown code block. Yaroslav has an array, consisting of (2·n - 1) integers. In a single operation Yaroslav can change the sign of exactly n elements in the array. In other words, in one operation Yaroslav can select exactly n array elements, and multiply each of them by -1. Yaroslav is now wondering: what maximum sum of array elements can be obtained if it is allowed to perform any number of described operations? Help Yaroslav. Input The first line contains an integer n (2 ≤ n ≤ 100). The second line contains (2·n - 1) integers — the array elements. The array elements do not exceed 1000 in their absolute value. Output In a single line print the answer to the problem — the maximum sum that Yaroslav can get. Examples Input 2 50 50 50 Output 150 Input 2 -1 -100 -1 Output 100 Note In the first sample you do not need to change anything. The sum of elements equals 150. In the second sample you need to change the sign of the first two elements. Then we get the sum of the elements equal to 100.
{"inputs": ["2\n-1 0 1\n", "2\n-1 -1 1\n", "2\n50 54 50\n", "2\n50 50 50\n", "3\n-1 1 1 1 1\n", "3\n-2 3 4 5 6\n", "3\n-2 3 0 5 6\n", "2\n-1 -112 -1\n"], "outputs": ["2\n", "3\n", "154\n", "150\n", "5\n", "20\n", "16\n", "112\n"]}
287
152
coding
Solve the programming task below in a Python markdown code block. This year in Equestria was a year of plenty, so Applejack has decided to build some new apple storages. According to the advice of the farm designers, she chose to build two storages with non-zero area: one in the shape of a square and another one in the shape of a rectangle (which possibly can be a square as well). Applejack will build the storages using planks, she is going to spend exactly one plank on each side of the storage. She can get planks from her friend's company. Initially, the company storehouse has $n$ planks, Applejack knows their lengths. The company keeps working so it receives orders and orders the planks itself. Applejack's friend can provide her with information about each operation. For convenience, he will give her information according to the following format: $+$ $x$: the storehouse received a plank with length $x$ $-$ $x$: one plank with length $x$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $x$). Applejack is still unsure about when she is going to order the planks so she wants to know if she can order the planks to build rectangular and square storages out of them after every event at the storehouse. Applejack is busy collecting apples and she has completely no time to do the calculations so she asked you for help! We remind you that all four sides of a square are equal, and a rectangle has two pairs of equal sides. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 10^5$): the initial amount of planks at the company's storehouse, the second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^5$): the lengths of the planks. The third line contains a single integer $q$ ($1 \le q \le 10^5$): the number of events in the company. Each of the next $q$ lines contains a description of the events in a given format: the type of the event (a symbol $+$ or $-$) is given first, then goes the integer $x$ ($1 \le x \le 10^5$). -----Output----- After every event in the company, print "YES" if two storages of the required shape can be built from the planks of that company's set, and print "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 1 1 2 1 1 6 + 2 + 1 - 1 + 2 - 1 + 2 Output NO YES NO NO NO YES -----Note----- After the second event Applejack can build a rectangular storage using planks with lengths $1$, $2$, $1$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$. After the sixth event Applejack can build a rectangular storage using planks with lengths $2$, $2$, $2$, $2$ and a square storage using planks with lengths $1$, $1$, $1$, $1$.
{"inputs": ["5\n1 1 1 1 1\n1\n+ 1\n", "5\n1 1 1 2 1\n1\n+ 1\n", "5\n1 1 1 4 1\n1\n+ 1\n", "5\n1 1 1 8 1\n1\n+ 1\n", "10\n1 1 1 1 1 1 1 1 1 1\n1\n+ 1\n", "10\n1 1 1 1 1 1 1 1 1 1\n1\n+ 1\n", "10\n1 1 1 1 0 1 1 1 1 1\n1\n+ 1\n", "10\n1 2 1 1 0 1 1 1 1 1\n1\n+ 1\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
721
242
coding
Solve the programming task below in a Python markdown code block. A person is getting ready to leave and needs a pair of matching socks. If there are $n$ colors of socks in the drawer, how many socks need to be removed to be certain of having a matching pair? Example $n=2$ There are $2$ colors of socks in the drawer. If they remove $2$ socks, they may not match. The minimum number to insure success is $3$. Function Description Complete the maximumDraws function in the editor below. maximumDraws has the following parameter: int n: the number of colors of socks Returns int: the minimum number of socks to remove to guarantee a matching pair. Input Format The first line contains the number of test cases, $\boldsymbol{\boldsymbol{t}}$. Each of the following $\boldsymbol{\boldsymbol{t}}$ lines contains an integer $n$. Constraints $1\leq t\leq1000$ $0<n<10^6$ Sample Input 2 1 2 Sample Output 2 3 Explanation Case 1 : Only 1 color of sock is in the drawer. Any $2$ will match. Case 2 : 2 colors of socks are in the drawer. The first two removed may not match. At least $3$ socks need to be removed to guarantee success.
{"inputs": ["2\n1\n2\n"], "outputs": ["2\n3\n"]}
308
20
coding
Solve the programming task below in a Python markdown code block. Victor and Peter are playing hide-and-seek. Peter has hidden, and Victor is to find him. In the room where they are playing, there is only one non-transparent wall and one double-sided mirror. Victor and Peter are points with coordinates (xv, yv) and (xp, yp) respectively. The wall is a segment joining points with coordinates (xw, 1, yw, 1) and (xw, 2, yw, 2), the mirror — a segment joining points (xm, 1, ym, 1) and (xm, 2, ym, 2). If an obstacle has a common point with a line of vision, it's considered, that the boys can't see each other with this line of vision. If the mirror has a common point with the line of vision, it's considered, that the boys can see each other in the mirror, i.e. reflection takes place. The reflection process is governed by laws of physics — the angle of incidence is equal to the angle of reflection. The incident ray is in the same half-plane as the reflected ray, relative to the mirror. I.e. to see each other Victor and Peter should be to the same side of the line, containing the mirror (see example 1). If the line of vision is parallel to the mirror, reflection doesn't take place, and the mirror isn't regarded as an obstacle (see example 4). Victor got interested if he can see Peter, while standing at the same spot. Help him solve this problem. Input The first line contains two numbers xv and yv — coordinates of Victor. The second line contains two numbers xp and yp — coordinates of Peter. The third line contains 4 numbers xw, 1, yw, 1, xw, 2, yw, 2 — coordinates of the wall. The forth line contains 4 numbers xm, 1, ym, 1, xm, 2, ym, 2 — coordinates of the mirror. All the coordinates are integer numbers, and don't exceed 104 in absolute value. It's guaranteed, that the segments don't have common points, Victor and Peter are not on any of the segments, coordinates of Victor and Peter aren't the same, the segments don't degenerate into points. Output Output YES, if Victor can see Peter without leaving the initial spot. Otherwise output NO. Examples Input -1 3 1 3 0 2 0 4 0 0 0 1 Output NO Input 0 0 1 1 0 1 1 0 -100 -100 -101 -101 Output NO Input 0 0 1 1 0 1 1 0 -1 1 1 3 Output YES Input 0 0 10 0 100 100 101 101 1 0 3 0 Output YES
{"inputs": ["0 0\n5 0\n1 0 2 0\n3 0 4 0\n", "0 0\n2 0\n0 2 2 2\n1 1 1 0\n", "0 0\n3 0\n0 2 2 2\n1 0 2 0\n", "0 0\n3 0\n1 0 2 0\n0 2 2 2\n", "0 1\n5 0\n1 0 2 0\n3 0 4 0\n", "0 0\n3 0\n0 2 2 2\n1 1 1 0\n", "0 0\n4 0\n0 2 2 2\n1 0 2 0\n", "0 0\n2 0\n1 1 1 -1\n0 2 2 2\n"], "outputs": ["NO", "NO", "YES", "YES", "YES\n", "NO\n", "YES\n", "YES"]}
661
241
coding
Solve the programming task below in a Python markdown code block. Chef wants to buy a new phone, but he is not willing to spend a lot of money. Instead, he checks the price of his chosen model everyday and waits for the price to drop to an acceptable value. So far, he has observed the price for $N$ days (numbere $1$ through $N$); for each valid $i$, the price on the $i$-th day was $P_i$ dollars. On each day, Chef considers the price of the phone to be good if it is strictly smaller than all the prices he has observed during the previous five days. If there is no record of the price on some of the previous five days (because Chef has not started checking the price on that day yet), then Chef simply ignores that previous day ― we could say that he considers the price on that day to be infinite. Now, Chef is wondering ― on how many days has he considered the price to be good? Find the number of these days. -----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 $P_1, P_2, \dots, P_N$. -----Output----- For each test case, print a single line containing one integer ― the number of days with a good price. -----Constraints----- - $1 \le T \le 100$ - $7 \le N \le 100$ - $350 \le P_i \le 750$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $N = 7$ Subtask #2 (70 points): original constraints -----Example Input----- 1 7 375 750 723 662 647 656 619 -----Example Output----- 2 -----Explanation----- Example case 1: Chef considers the price to be good on day $1$, because he has not observed any prices on the previous days. The prices on days $2, 3, 4, 5, 6$ are not considered good because they are greater than the price on day $1$. Finally, the price on day $7$ is considered good because it is smaller than all of the prices on days $2, 3, 4, 5, 6$.
{"inputs": ["1\n7\n375 750 723 662 647 656 619"], "outputs": ["2"]}
545
42
coding
Solve the programming task below in a Python markdown code block. In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest. Vova and Lesha are friends. They often meet at Vova's place and compete against each other in a computer game named The Ancient Papyri: Swordsink. Vova always chooses a warrior as his fighter and Leshac chooses an archer. After that they should choose initial positions for their characters and start the fight. A warrior is good at melee combat, so Vova will try to make the distance between fighters as small as possible. An archer prefers to keep the enemy at a distance, so Lesha will try to make the initial distance as large as possible. There are n (n is always even) possible starting positions for characters marked along the Ox axis. The positions are given by their distinct coordinates x_1, x_2, ..., x_{n}, two characters cannot end up at the same position. Vova and Lesha take turns banning available positions, Vova moves first. During each turn one of the guys bans exactly one of the remaining positions. Banned positions cannot be used by both Vova and Lesha. They continue to make moves until there are only two possible positions remaining (thus, the total number of moves will be n - 2). After that Vova's character takes the position with the lesser coordinate and Lesha's character takes the position with the bigger coordinate and the guys start fighting. Vova and Lesha are already tired by the game of choosing positions, as they need to play it before every fight, so they asked you (the developer of the The Ancient Papyri: Swordsink) to write a module that would automatically determine the distance at which the warrior and the archer will start fighting if both Vova and Lesha play optimally. -----Input----- The first line on the input contains a single integer n (2 ≤ n ≤ 200 000, n is even) — the number of positions available initially. The second line contains n distinct integers x_1, x_2, ..., x_{n} (0 ≤ x_{i} ≤ 10^9), giving the coordinates of the corresponding positions. -----Output----- Print the distance between the warrior and the archer at the beginning of the fight, provided that both Vova and Lesha play optimally. -----Examples----- Input 6 0 1 3 7 15 31 Output 7 Input 2 73 37 Output 36 -----Note----- In the first sample one of the optimum behavior of the players looks like that: Vova bans the position at coordinate 15; Lesha bans the position at coordinate 3; Vova bans the position at coordinate 31; Lesha bans the position at coordinate 1. After these actions only positions 0 and 7 will remain, and the distance between them is equal to 7. In the second sample there are only two possible positions, so there will be no bans.
{"inputs": ["2\n0 1\n", "2\n0 1\n", "2\n0 2\n", "2\n73 37\n", "2\n73 37\n", "2\n129 37\n", "2\n129 16\n", "2\n129 20\n"], "outputs": ["1\n", "1\n", "2\n", "36\n", "36\n", "92\n", "113\n", "109\n"]}
682
122
coding
Solve the programming task below in a Python markdown code block. You are given an array A of length N. Find the number of pairs of indices (i,j) such that 1 ≤ i < j ≤ N A_{i} \cdot A_{j} > 0 ------ Input Format ------ - The first line contains a single integer T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the number of pairs which satisfy the above conditions. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $-10^{4} ≤ A_{i} ≤ 10^{4}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$ ----- Sample Input 1 ------ 3 5 1 -3 0 2 -1 4 -1 -1 -1 -1 4 0 1 2 3 ----- Sample Output 1 ------ 2 6 3 ----- explanation 1 ------ Test case 1: The pairs which satisfy the conditions are $(1,4)$ and $(2,5)$. Test case 2: The pairs which satisfy the conditions are $(1,2)$, $(1,3)$, $(1,4)$, $(2,3)$, $(2,4)$ and $(3,4)$. Test case 3: The pairs which satisfy the conditions are $(2,3)$, $(2,4)$ and $(3,4)$.
{"inputs": ["3\n5\n1 -3 0 2 -1\n4\n-1 -1 -1 -1\n4\n0 1 2 3\n"], "outputs": ["2\n6\n3\n"]}
395
51
coding
Solve the programming task below in a Python markdown code block. Chefland has all the cities on a straight line. There are $N$ cities in Chefland numbered $1$ to $N$. City $i$ is located at coordinate $x_i$ on the x-axis. Guru wants to travel from city $A$ to city $B$. He starts at time t=0. He has following choices to travel. - He can walk $1$ metre in $P$ secs. - There is a train that travels from city $C$ to city $D$ which travels $1$ metre in $Q$ secs which starts at time t=$Y$ secs. Guru can take the train only at city $C$ and leave the train only at city $D$. Can you help Guru find the minimum time he will need to travel from city $A$ to $B$. Note that you cannot board the train after time t =$Y$. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - First line of each testcase contains eight space separated integers $N, A, B, C, D, P, Q, Y $. - Second line of each testcase contains $N$ space-separated integers with the $i$-th integer representing $x_i$. -----Output:----- For each testcase, output in a single line containing the minimum travel time. -----Constraints----- - $1 \leq T \leq 300$ - $2 \leq N \leq 300$ - $-1000 \leq x_i \leq 1000$ - $0 \leq Y \leq 100000$ - $1 \leq A,B,C,D \leq n $ - $A \neq B$ - $C \neq D$ - $1 \leq P, Q \leq 100$ - $x_i < x_j$ if $i < j$ -----Sample Input:----- 1 4 1 3 2 4 3 2 4 1 2 3 4 -----Sample Output:----- 6 -----EXPLANATION:----- Guru can walk directly in 6 secs. If Guru takes train, then he will need atleast 11 secs.
{"inputs": ["1\n4 1 3 2 4 3 2 4\n1 2 3 4"], "outputs": ["6"]}
503
36
coding
Solve the programming task below in a Python markdown code block. Ela likes Chess a lot. During breaks, she usually challenges her co-worker in DTL to some chess games. She's not an expert at classic chess, but she's very interested in Chess variants, where she has to adapt to new rules and test her tactical mindset to win the game. The problem, which involves a non-standard chess pieces type that is described below, reads: given $3$ white crickets on a $n \cdot n$ board, arranged in an "L" shape next to each other, there are no other pieces on the board. Ela wants to know with a finite number of moves, can she put any white cricket on the square on row $x$, column $y$? An "L"-shape piece arrangement can only be one of the below: For simplicity, we describe the rules for crickets on the board where only three white crickets are. It can move horizontally, vertically, or diagonally, but only to a square in some direction that is immediately after another cricket piece (so that it must jump over it). If the square immediately behind the piece is unoccupied, the cricket will occupy the square. Otherwise (when the square is occupied by another cricket, or does not exist), the cricket isn't allowed to make such a move. See an example of valid crickets' moves on the pictures in the Note section. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows. The first line of each test case contains $n$ ($4 \le n \le 10^5$) — denotes the size of the chessboard. The second line of each test case contains 6 numbers: $r_1$, $c_1$, $r_2$, $c_2$, $r_3$, $c_3$ ($1 \le r_1, c_1, r_2, c_2, r_3, c_3 \le n$) — coordinates of the crickets. The input ensures that the three crickets are arranged in an "L" shape that the legend stated. The third line of each test case contains 2 numbers: $x$, $y$ ($1 \le x, y \le n$) — coordinates of the target square. -----Output----- For each test case, print "YES" or "NO" to denotes whether Ela can put a cricket on the target square. -----Examples----- Input 6 8 7 2 8 2 7 1 5 1 8 2 2 1 2 2 1 5 5 8 2 2 1 2 2 1 6 6 8 1 1 1 2 2 1 5 5 8 2 2 1 2 2 1 8 8 8 8 8 8 7 7 8 4 8 Output YES NO YES NO YES YES -----Note----- Here's the solution for the first test case. The red square denotes where the crickets need to reach. Note that in chess horizontals are counted from bottom to top, as well as on this picture.
{"inputs": ["1\n4\n4 1 4 2 3 1\n1 3\n", "1\n100000\n1 1 2 1 1 2\n26298 33691\n", "6\n8\n7 2 8 2 7 1\n5 1\n8\n2 2 1 2 2 1\n5 5\n8\n2 2 1 2 2 1\n6 6\n8\n1 1 1 2 2 1\n5 5\n8\n2 2 1 2 2 1\n8 8\n8\n8 8 8 7 7 8\n4 8\n", "3\n100000\n100000 100000 99999 100000 100000 99999\n69 100000\n100000\n2 100000 1 99999 1 100000\n100000 9\n100000\n2 3 3 2 3 3\n6 7\n", "10\n4\n2 2 3 3 2 3\n2 3\n7\n1 1 1 2 2 1\n6 7\n9\n9 1 8 1 9 2\n5 9\n6\n2 4 3 4 2 3\n6 5\n7\n2 2 2 1 3 1\n3 5\n7\n6 1 7 2 7 1\n2 2\n7\n2 1 2 2 1 2\n7 6\n7\n3 6 3 7 4 7\n3 7\n10\n2 1 1 2 1 1\n6 3\n4\n2 3 1 3 2 4\n3 4\n"], "outputs": ["NO\n", "NO\n", "YES\nNO\nYES\nNO\nYES\nYES\n", "YES\nNO\nYES\n", "YES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nNO\nNO\n"]}
715
539
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Let the function f(s) be the frequency of the lexicographically smallest character in a non-empty string s. For example, if s = "dcce" then f(s) = 2 because the lexicographically smallest character is 'c', which has a frequency of 2. You are given an array of strings words and another array of query strings queries. For each query queries[i], count the number of words in words such that f(queries[i]) < f(W) for each W in words. Return an integer array answer, where each answer[i] is the answer to the ith query.   Please complete the following python code precisely: ```python class Solution: def numSmallerByFrequency(self, queries: List[str], words: List[str]) -> List[int]: ```
{"functional": "def check(candidate):\n assert candidate(queries = [\"cbd\"], words = [\"zaaaz\"]) == [1]\n assert candidate(queries = [\"bbb\",\"cc\"], words = [\"a\",\"aa\",\"aaa\",\"aaaa\"]) == [1,2]\n\n\ncheck(Solution().numSmallerByFrequency)"}
181
80
coding
Solve the programming task below in a Python markdown code block. Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: An 'L' indicates he should move one unit left. An 'R' indicates he should move one unit right. A 'U' indicates he should move one unit up. A 'D' indicates he should move one unit down. But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in s with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string. -----Input----- The first and only line contains the string s (1 ≤ |s| ≤ 100 000) — the instructions Memory is given. -----Output----- If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1. -----Examples----- Input RRU Output -1 Input UDUR Output 1 Input RUUR Output 2 -----Note----- In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk. In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change s to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin.
{"inputs": ["R\n", "R\n", "LR\n", "UL\n", "UD\n", "LU\n", "RR\n", "LR\n"], "outputs": ["-1\n", "-1\n", "0\n", "1\n", "0\n", "1\n", "1\n", "0\n"]}
415
71
coding
Solve the programming task below in a Python markdown code block. Using his tip-top physique, Kim has now climbed up the mountain where the base is located. Kim has found the door to the (supposedly) super secret base. Well, it is super secret, but obviously no match for Kim's talents. The door is guarded by a row of $N$ buttons. Every button has a single number $A_i$ written on it. Surprisingly, more than one button can have the same number on it. Kim recognises this as Soum's VerySafe door, for which you need to press two buttons to enter the password. More importantly, the sum of the two numbers on the buttons you press must be odd. Kim can obviously break through this door easily, but he also wants to know how many different pairs of buttons he can pick in order to break through the door. Can you help Kim find the number of different pairs of buttons he can press to break through the door? Note: Two pairs are considered different if any of the buttons pressed in the pair is different (by position of the button pressed). Two pairs are not considered different if they're the same position of buttons, pressed in a different order. Please refer to the samples for more details. -----Input:----- - The first line contains a single integer $T$, representing the number of testcases. $2T$ lines follow, 2 for each testcase. - For each testcase, the first line contains a single integer $N$, the number of buttons. - The second line of each testcase contains $N$ space-separated integers, $A_1, A_2, \ldots, A_N$, representing the numbers written on each button. -----Output:----- Print a single number, $K$, representing the number of pairs of buttons in $A$ which have an odd sum. -----Subtasks----- For all subtasks, $1 \leq T \leq 10$, $1 \leq N \leq 100000$, and $1 \leq A_i \leq 100000$ for all $A_i$. Subtask 1 [15 points] : $N \leq 2$, There are at most 2 buttons Subtask 2 [45 points] : $N \leq 1000$, There are at most 1000 buttons Subtask 3 [40 points] : No additional constraints. -----Sample Input:----- 3 4 3 5 3 4 2 5 7 1 4 -----Sample Output:----- 3 0 0 -----EXPLANATION:----- This section uses 1-indexing. In the first sample, the buttons are: $[3, 5, 3, 4]$ $A[1] + A[4] = 3 + 4 = 7$ which is odd. $A[2] + A[4] = 5 + 4 = 9$ which is odd. $A[3] + A[4] = 3 + 4 = 7$ which is odd. In total, there are 3 pairs with an odd sum, so the answer is 3. In the second sample, the buttons are: $[5, 7]$. There are no odd pairs, so the answer is $0$. In the third sample, the buttons are: $[4]$. There are no pairs at all, so the answer is $0$.
{"inputs": ["3\n4\n3 5 3 4\n2\n5 7\n1\n4"], "outputs": ["3\n0\n0"]}
751
36
coding
Solve the programming task below in a Python markdown code block. This challenge is only forPython 2. input() In Python 2, the expression input() is equivalent to eval(raw _input(prompt)). Code >>> input() 1+2 3 >>> company = 'HackerRank' >>> website = 'www.hackerrank.com' >>> input() 'The company name: '+company+' and website: '+website 'The company name: HackerRank and website: www.hackerrank.com' Task You are given a polynomial $\mbox{P}$ of a single indeterminate (or variable), $\boldsymbol{x}$. You are also given the values of $\boldsymbol{x}$ and $\boldsymbol{\mbox{k}}$. Your task is to verify if $P(x)=k$. Constraints All coefficients of polynomial $\mbox{P}$ are integers. $\boldsymbol{x}$ and $y$ are also integers. Input Format The first line contains the space separated values of $\boldsymbol{x}$ and $\boldsymbol{\mbox{k}}$. The second line contains the polynomial $\mbox{P}$. Output Format Print True if $P(x)=k$. Otherwise, print False. Sample Input 1 4 x**3 + x**2 + x + 1 Sample Output True Explanation $P(1)=1^3+1^2+1+1=4=k$ Hence, the output is True.
{"inputs": ["1 4\nx**3 + x**2 + x + 1\n"], "outputs": ["True\n"]}
317
29
coding
Solve the programming task below in a Python markdown code block. Alice and Bob play the following game.They choose a number N to play with.The runs are as follows : 1.Bob plays first and the two players alternate. 2.In his/her turn ,a player can subtract from N any prime number(including 1) less than N.The number thus obtained is the new N. 3.The person who cannot make a move in his/her turn loses the game. Assuming both play optimally,who wins the game ? ------ Input format: ------ The first line contains the number of test cases T.Each of the next lines contains an integer N. ------ Output format: ------ Output T lines one for each test case,containing "ALICE" if Alice wins the game ,or "BOB" if Bob wins the game. Constraints: 1 ≤ T ≤ 1000000 1 ≤ N ≤ 1000000000 Note : For the first test case, Bob cannot make any move and hence Alice wins the game. For the second test case, Bob subtracts 1 from N. Now, Alice cannot make a move and loses the game. ----- Sample Input 1 ------ 2 1 2 ----- Sample Output 1 ------ ALICE BOB
{"inputs": ["2\n1\n2"], "outputs": ["ALICE\nBOB"]}
273
20
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 points (0-indexed). Starting with 0 points, you want to maximize the number of points you can get from the matrix. To gain points, you must pick one cell in each row. Picking the cell at coordinates (r, c) will add points[r][c] to your score. However, you will lose points if you pick a cell too far from the cell that you picked in the previous row. For every two adjacent rows r and r + 1 (where 0 <= r < m - 1), picking cells at coordinates (r, c1) and (r + 1, c2) will subtract abs(c1 - c2) from your score. Return the maximum number of points you can achieve. abs(x) is defined as: x for x >= 0. -x for x < 0.   Please complete the following python code precisely: ```python class Solution: def maxPoints(self, points: List[List[int]]) -> int: ```
{"functional": "def check(candidate):\n assert candidate(points = [[1,2,3],[1,5,1],[3,1,1]]) == 9\n assert candidate(points = [[1,5],[2,3],[4,2]]) == 11\n\n\ncheck(Solution().maxPoints)"}
231
70
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string array words, where words[i] consists of lowercase English letters. In one operation, select any index i such that 0 < i < words.length and words[i - 1] and words[i] are anagrams, and delete words[i] from words. Keep performing this operation as long as you can select an index that satisfies the conditions. Return words after performing all operations. It can be shown that selecting the indices for each operation in any arbitrary order will lead to the same result. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase using all the original letters exactly once. For example, "dacb" is an anagram of "abdc".   Please complete the following python code precisely: ```python class Solution: def removeAnagrams(self, words: List[str]) -> List[str]: ```
{"functional": "def check(candidate):\n assert candidate(words = [\"abba\",\"baba\",\"bbaa\",\"cd\",\"cd\"]) == [\"abba\",\"cd\"]\n assert candidate(words = [\"a\",\"b\",\"c\",\"d\",\"e\"]) == [\"a\",\"b\",\"c\",\"d\",\"e\"]\n\n\ncheck(Solution().removeAnagrams)"}
202
85