task_type
stringclasses 1
value | problem
stringlengths 261
3.34k
| answer
stringlengths 35
6.15k
| problem_tokens
int64 62
774
| answer_tokens
int64 12
2.04k
|
|---|---|---|---|---|
coding
|
Solve the programming task below in a Python markdown code block.
There are N stores called Store 1, Store 2, \cdots, Store N. Takahashi, who is at his house at time 0, is planning to visit some of these stores.
It takes Takahashi one unit of time to travel from his house to one of the stores, or between any two stores.
If Takahashi reaches Store i at time t, he can do shopping there after standing in a queue for a_i \times t + b_i units of time. (We assume that it takes no time other than waiting.)
All the stores close at time T + 0.5. If Takahashi is standing in a queue for some store then, he cannot do shopping there.
Takahashi does not do shopping more than once in the same store.
Find the maximum number of times he can do shopping before time T + 0.5.
Constraints
* All values in input are integers.
* 1 \leq N \leq 2 \times 10^5
* 0 \leq a_i \leq 10^9
* 0 \leq b_i \leq 10^9
* 0 \leq T \leq 10^9
Input
Input is given from Standard Input in the following format:
N T
a_1 b_1
a_2 b_2
\vdots
a_N b_N
Output
Print the answer.
Examples
Input
3 7
2 0
3 2
0 3
Output
2
Input
1 3
0 3
Output
0
Input
5 21600
2 14
3 22
1 3
1 10
1 9
Output
5
Input
7 57
0 25
3 10
2 4
5 15
3 22
2 14
1 15
Output
3
|
{"inputs": ["1 3\n0 0", "1 0\n1 0", "1 0\n1 1", "0 0\n1 1", "0 1\n1 1", "0 1\n2 1", "0 1\n4 1", "0 1\n4 2"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
| 439
| 110
|
coding
|
Solve the programming task below in a Python markdown code block.
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.
For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen w_{i} seconds after midnight, all w_{i}'s are distinct. Each visit lasts exactly one second.
What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
-----Input-----
The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit.
The next line contains m space-separated numbers w_{i} (1 ≤ i ≤ m, 1 ≤ w_{i} ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All w_{i}'s are distinct, they follow in the strictly increasing order.
-----Output-----
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that.
If that is impossible, print - 1.
-----Examples-----
Input
1 8 3
10
Output
3
Input
2 10 1
5 8
Output
1
Input
1 1 3
10
Output
-1
-----Note-----
Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.
It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.
In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.
In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.
In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
|
{"inputs": ["1 1 1\n4\n", "1 1 1\n4\n", "1 6 5\n9\n", "1 1 2\n4\n", "1 8 3\n10\n", "1 1 3\n10\n", "1 8 5\n10\n", "1 8 6\n10\n"], "outputs": ["1\n", "1\n", "5\n", "-1\n", "3\n", "-1\n", "5\n", "6\n"]}
| 648
| 122
|
coding
|
Solve the programming task below in a Python markdown code block.
## Fixed xor
Write a function that takes two hex strings as input and XORs them against each other. If the strings are different lengths the output should be the length of the shortest string.
Hint: The strings would first need to be converted to binary to be XOR'd.
## Note:
If the two strings are of different lengths, the output string should be the same length as the smallest string. This means that the longer string will be cut down to the same size as the smaller string, then xor'd
### Further help
More information on the XOR operation can be found here https://www.khanacademy.org/computing/computer-science/cryptography/ciphers/a/xor-bitwise-operation
More information of the binary and hex bases can be found here https://www.khanacademy.org/math/algebra-home/alg-intro-to-algebra/algebra-alternate-number-bases/v/number-systems-introduction
Examples:
```python
fixed_xor("ab3f", "ac") == "07"
fixed_xor("aadf", "bce2") == "163d"
fixed_xor("1c0111001f010100061a024b53535009181c", "686974207468652062756c6c277320657965") == "746865206b696420646f6e277420706c6179"
```
Also feel free to reuse/extend the following starter code:
```python
def fixed_xor(a, b):
```
|
{"functional": "_inputs = [['1c0111001f010100061a024b53535009181c', '686974207468652062756c6c277320657965'], ['aadf', 'bce2'], ['ab3f', 'ac'], ['', ''], ['c611d9bdd9de38b9eb', '23a0745505d4d25494'], ['7d1e875da9d5e89b54c7eaf', '3541599be591709795cebd5'], ['785a6677b3e52f0e7', 'a8d97da7441'], ['6cbd75511e7f750c6827', '1753547c813bfcd']]\n_outputs = [['746865206b696420646f6e277420706c6179'], ['163d'], ['07'], [''], ['e5b1ade8dc0aeaed7f'], ['485fdec64c44980cc10957a'], ['d0831bd0f7f'], ['7bee212d9f4489d']]\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(fixed_xor(*i), o[0])"}
| 385
| 505
|
coding
|
Solve the programming task below in a Python markdown code block.
James found a love letter that his friend Harry has written to his girlfriend. James is a prankster, so he decides to meddle with the letter. He changes all the words in the letter into palindromes.
To do this, he follows two rules:
He can only reduce the value of a letter by $1$, i.e. he can change d to c, but he cannot change c to d or d to b.
The letter $a$ may not be reduced any further.
Each reduction in the value of any letter is counted as a single operation. Find the minimum number of operations required to convert a given string into a palindrome.
Example
$s=ade$
The following two operations are performed: cde → cdd → cdc. Return $2$.
Function Description
Complete the theLoveLetterMystery function in the editor below.
theLoveLetterMystery has the following parameter(s):
string s: the text of the letter
Returns
int: the minimum number of operations
Input Format
The first line contains an integer $q$, the number of queries.
The next $q$ lines will each contain a string $s$.
Constraints
$1\leq q\leq10$
$1\leq$ | s | $\leq10^{4}$
All strings are composed of lower case English letters, ascii[a-z], with no spaces.
Sample Input
STDIN Function
----- --------
4 q = 4
abc query 1 = 'abc'
abcba
abcd
cba
Sample Output
2
0
4
2
Explanation
For the first query, abc → abb → aba.
For the second query, abcba is already a palindromic string.
For the third query, abcd → abcc → abcb → abca → abba.
For the fourth query, cba → bba → aba.
|
{"inputs": ["4\nabc\nabcba\nabcd\ncba\n"], "outputs": ["2\n0\n4\n2\n"]}
| 418
| 30
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed 2D integer array items of length n and an integer k.
items[i] = [profiti, categoryi], where profiti and categoryi denote the profit and category of the ith item respectively.
Let's define the elegance of a subsequence of items as total_profit + distinct_categories2, where total_profit is the sum of all profits in the subsequence, and distinct_categories is the number of distinct categories from all the categories in the selected subsequence.
Your task is to find the maximum elegance from all subsequences of size k in items.
Return an integer denoting the maximum elegance of a subsequence of items with size exactly k.
Note: A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order.
Please complete the following python code precisely:
```python
class Solution:
def findMaximumElegance(self, items: List[List[int]], k: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(items = [[3,2],[5,1],[10,1]], k = 2) == 17\n assert candidate(items = [[3,1],[3,1],[2,2],[5,3]], k = 3) == 19\n assert candidate(items = [[1,1],[2,1],[3,1]], k = 3) == 7\n\n\ncheck(Solution().findMaximumElegance)"}
| 229
| 110
|
coding
|
Solve the programming task below in a Python markdown code block.
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and $Q$ integers $x_i$ as queries, for each query, print the number of combinations of two integers $(l, r)$ which satisfies the condition: $1 \leq l \leq r \leq N$ and $a_l + a_{l+1} + ... + a_{r-1} + a_r \leq x_i$.
Constraints
* $1 \leq N \leq 10^5$
* $1 \leq Q \leq 500$
* $1 \leq a_i \leq 10^9$
* $1 \leq x_i \leq 10^{14}$
Input
The input is given in the following format.
$N$ $Q$
$a_1$ $a_2$ ... $a_N$
$x_1$ $x_2$ ... $x_Q$
Output
For each query, print the number of combinations in a line.
Example
Input
6 5
1 2 3 4 5 6
6 9 12 21 15
Output
9
12
15
21
18
|
{"inputs": ["6 5\n1 2 3 2 6 6\n6 9 5 21 15", "6 5\n1 2 4 2 6 6\n6 9 5 21 15", "6 5\n1 2 4 2 6 7\n6 9 5 21 15", "6 5\n1 4 0 2 7 6\n6 1 3 21 15", "6 5\n0 2 4 2 6 6\n6 9 5 21 15", "6 5\n1 2 3 4 7 6\n6 9 12 21 15", "6 5\n1 2 3 2 7 6\n6 9 12 21 15", "6 5\n1 2 3 5 5 6\n6 9 12 21 15"], "outputs": ["10\n13\n7\n21\n18\n", "9\n13\n5\n21\n18\n", "8\n13\n5\n20\n18\n", "10\n2\n4\n21\n19\n", "10\n13\n5\n21\n18\n", "8\n11\n13\n19\n15\n", "9\n13\n14\n21\n18\n", "9\n10\n14\n20\n16\n"]}
| 296
| 366
|
coding
|
Solve the programming task below in a Python markdown code block.
Tenten runs a weapon shop for ninjas. Today she is willing to sell $n$ shurikens which cost $1$, $2$, ..., $n$ ryo (local currency). During a day, Tenten will place the shurikens onto the showcase, which is empty at the beginning of the day. Her job is fairly simple: sometimes Tenten places another shuriken (from the available shurikens) on the showcase, and sometimes a ninja comes in and buys a shuriken from the showcase. Since ninjas are thrifty, they always buy the cheapest shuriken from the showcase.
Tenten keeps a record for all events, and she ends up with a list of the following types of records:
+ means that she placed another shuriken on the showcase; - x means that the shuriken of price $x$ was bought.
Today was a lucky day, and all shurikens were bought. Now Tenten wonders if her list is consistent, and what could be a possible order of placing the shurikens on the showcase. Help her to find this out!
-----Input-----
The first line contains the only integer $n$ ($1\leq n\leq 10^5$) standing for the number of shurikens.
The following $2n$ lines describe the events in the format described above. It's guaranteed that there are exactly $n$ events of the first type, and each price from $1$ to $n$ occurs exactly once in the events of the second type.
-----Output-----
If the list is consistent, print "YES". Otherwise (that is, if the list is contradictory and there is no valid order of shurikens placement), print "NO".
In the first case the second line must contain $n$ space-separated integers denoting the prices of shurikens in order they were placed. If there are multiple answers, print any.
-----Examples-----
Input
4
+
+
- 2
+
- 3
+
- 1
- 4
Output
YES
4 2 3 1
Input
1
- 1
+
Output
NO
Input
3
+
+
+
- 2
- 1
- 3
Output
NO
-----Note-----
In the first example Tenten first placed shurikens with prices $4$ and $2$. After this a customer came in and bought the cheapest shuriken which costed $2$. Next, Tenten added a shuriken with price $3$ on the showcase to the already placed $4$-ryo. Then a new customer bought this $3$-ryo shuriken. After this she added a $1$-ryo shuriken. Finally, the last two customers bought shurikens $1$ and $4$, respectively. Note that the order $[2, 4, 3, 1]$ is also valid.
In the second example the first customer bought a shuriken before anything was placed, which is clearly impossible.
In the third example Tenten put all her shurikens onto the showcase, after which a customer came in and bought a shuriken with price $2$. This is impossible since the shuriken was not the cheapest, we know that the $1$-ryo shuriken was also there.
|
{"inputs": ["1\n- 1\n+\n", "1\n+\n- 1\n", "1\n+\n- 1\n", "1\n- 1\n+\n", "3\n+\n+\n+\n- 2\n- 1\n- 3\n", "3\n+\n+\n+\n- 2\n- 1\n- 2\n", "3\n+\n+\n+\n- 2\n- 1\n- 3\n", "4\n+\n+\n- 2\n+\n- 3\n+\n- 1\n- 4\n"], "outputs": ["NO\n", "YES\n1 \n", "YES\n1\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n4 2 3 1 \n"]}
| 723
| 186
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ positive integers.
You are allowed to perform this operation any number of times (possibly, zero):
choose an index $i$ ($2 \le i \le n$), and change $a_i$ to $a_i - a_{i-1}$.
Is it possible to make $a_i=0$ for all $2\le i\le n$?
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 100$) — the number of test cases. The description of the test cases follows.
The first line contains one integer $n$ ($2 \le n \le 100$) — the length of array $a$.
The second line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
For each test case, print "YES" (without quotes), if it is possible to change $a_i$ to $0$ for all $2 \le i \le n$, and "NO" (without quotes) otherwise.
You can print letters in any case (upper or lower).
-----Examples-----
Input
4
2
5 10
3
1 2 3
4
1 1 1 1
9
9 9 8 2 4 4 3 5 3
Output
YES
YES
YES
NO
-----Note-----
In the first test case, the initial array is $[5,10]$. You can perform $2$ operations to reach the goal:
Choose $i=2$, and the array becomes $[5,5]$.
Choose $i=2$, and the array becomes $[5,0]$.
In the second test case, the initial array is $[1,2,3]$. You can perform $4$ operations to reach the goal:
Choose $i=3$, and the array becomes $[1,2,1]$.
Choose $i=2$, and the array becomes $[1,1,1]$.
Choose $i=3$, and the array becomes $[1,1,0]$.
Choose $i=2$, and the array becomes $[1,0,0]$.
In the third test case, you can choose indices in the order $4$, $3$, $2$.
|
{"inputs": ["1\n3\n3 9 96\n", "1\n4\n1 8 6 7\n", "1\n4\n3 21 9 6\n", "1\n5\n2 8 4 8 4\n", "1\n4\n5 10 5 10\n", "1\n4\n5 10 20 5\n", "1\n5\n2 4 4 10 10\n", "1\n8\n5 10 15 20 40 5 5 5\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
| 540
| 172
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given the array of integer numbers a_0, a_1, ..., a_{n} - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 2·10^5) — length of the array a. The second line contains integer elements of the array separated by single spaces ( - 10^9 ≤ a_{i} ≤ 10^9).
-----Output-----
Print the sequence d_0, d_1, ..., d_{n} - 1, where d_{i} is the difference of indices between i and nearest j such that a_{j} = 0. It is possible that i = j.
-----Examples-----
Input
9
2 1 0 3 0 0 3 2 4
Output
2 1 0 1 0 0 1 2 3
Input
5
0 1 2 3 4
Output
0 1 2 3 4
Input
7
5 6 0 1 -2 3 4
Output
2 1 0 1 2 3 4
|
{"inputs": ["1\n0\n", "1\n0\n", "1\n0\n", "1\n0\n", "1\n0\n", "2\n0 0\n", "2\n0 1\n", "2\n1 0\n"], "outputs": ["0 ", "0 ", "0 ", "0 ", "0 ", "0 0 ", "0 1 ", "1 0 "]}
| 290
| 91
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a positive integer num, return the number of positive integers less than or equal to num whose digit sums are even.
The digit sum of a positive integer is the sum of all its digits.
Please complete the following python code precisely:
```python
class Solution:
def countEven(self, num: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(num = 4) == 2\n assert candidate(num = 30) == 14\n\n\ncheck(Solution().countEven)"}
| 86
| 45
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n bulbs that are initially off. You first turn on all the bulbs, then you turn off every second bulb.
On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the ith round, you toggle every i bulb. For the nth round, you only toggle the last bulb.
Return the number of bulbs that are on after n rounds.
Please complete the following python code precisely:
```python
class Solution:
def bulbSwitch(self, n: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 3) == 1 \n assert candidate(n = 0) == 0\n assert candidate(n = 1) == 1\n\n\ncheck(Solution().bulbSwitch)"}
| 134
| 57
|
coding
|
Solve the programming task below in a Python markdown code block.
Find out the maximum sub-array of non negative numbers from an array.
The sub-array should be continuous. That is, a sub-array created by choosing the second and fourth element and skipping the third element is invalid.
Maximum sub-array is defined in terms of the sum of the elements in the sub-array. Sub-array A is greater than sub-array B if sum(A) > sum(B).
NOTE 1 :If there is a tie, then compare with segment's length and return segment which has maximum length
NOTE 2: If there is still a tie, then return the segment with minimum starting index.
-----Input-----
The first line contains the number of test cases. Each test cases contains an integer N. next line consists of N integers, the elements of the array.
-----Output-----
Print out the maximum sub-array as stated above.
-----Constraints-----
- 1 ≤ T ≤ 100
- 1 ≤ N ≤ 105
- 1 ≤ Ai ≤ 105
-----Example-----
Input:
1
6
1 2 5 -7 2 3
Output:
1 2 5
|
{"inputs": ["1\n6\n1 2 5 -7 2 3"], "outputs": ["1 2 5"]}
| 262
| 30
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
The *MEX* (minimum excluded) of an array is the smallest non-negative integer that does not belong to the array. For instance:
The MEX of [2, 2, 1] is 0, because 0 does not belong to the array.
The MEX of [3, 1, 0, 1] is 2, because 0 and 1 belong to the array, but 2 does not.
The MEX of [0, 3, 1, 2] is 4 because 0, 1, 2 and 3 belong to the array, but 4 does not.
Find the maximum possible MEX of an array of non-negative integers such that the [bitwise OR] of the elements in the array does not exceed X.
------ Input Format ------
- The first line contains T denoting the number of test cases. Then the test cases follow.
- Each test case contains a single integer X on a single line.
------ Output Format ------
For each test case, output on a single line the maximum possible MEX of the array satisfying the given property.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ X ≤ 10^{9}$
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
4
0
1
2
5
----- Sample Output 1 ------
1
2
2
4
----- explanation 1 ------
Test case $1$: The array could be $[0]$.
Test case $2$: The array could be $[0, 1]$. Here the bitwise OR of $0$ and $1$ is $1$ and the MEX of the array is $2$ as both $0$ and $1$ belongs to the array.
Test case $4$: The array could be $[1, 0, 3, 2]$. Here the bitwise OR of all integers in the array is $3$ and the MEX of the array is $4$.
|
{"inputs": ["4\n0\n1\n2\n5\n"], "outputs": ["1\n2\n2\n4\n"]}
| 478
| 28
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a C++ program, remove comments from it. The program source is an array of strings source where source[i] is the ith line of the source code. This represents the result of splitting the original source code string by the newline character '\n'.
In C++, there are two types of comments, line comments, and block comments.
The string "//" denotes a line comment, which represents that it and the rest of the characters to the right of it in the same line should be ignored.
The string "/*" denotes a block comment, which represents that all characters until the next (non-overlapping) occurrence of "*/" should be ignored. (Here, occurrences happen in reading order: line by line from left to right.) To be clear, the string "/*/" does not yet end the block comment, as the ending would be overlapping the beginning.
The first effective comment takes precedence over others.
For example, if the string "//" occurs in a block comment, it is ignored.
Similarly, if the string "/*" occurs in a line or block comment, it is also ignored.
If a certain line of code is empty after removing comments, you must not output that line: each string in the answer list will be non-empty.
There will be no control characters, single quote, or double quote characters.
For example, source = "string s = "/* Not a comment. */";" will not be a test case.
Also, nothing else such as defines or macros will interfere with the comments.
It is guaranteed that every open block comment will eventually be closed, so "/*" outside of a line or block comment always starts a new comment.
Finally, implicit newline characters can be deleted by block comments. Please see the examples below for details.
After removing the comments from the source code, return the source code in the same format.
Please complete the following python code precisely:
```python
class Solution:
def removeComments(self, source: List[str]) -> List[str]:
```
|
{"functional": "def check(candidate):\n assert candidate(source = [\"/*Test program */\", \"int main()\", \"{ \", \" // variable declaration \", \"int a, b, c;\", \"/* This is a test\", \" multiline \", \" comment for \", \" testing */\", \"a = b + c;\", \"}\"]) == [\"int main()\",\"{ \",\" \",\"int a, b, c;\",\"a = b + c;\",\"}\"]\n assert candidate(source = [\"a/*comment\", \"line\", \"more_comment*/b\"]) == [\"ab\"]\n\n\ncheck(Solution().removeComments)"}
| 425
| 152
|
coding
|
Solve the programming task below in a Python markdown code block.
Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them.
He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2).
Find the minimum total cost to achieve his objective.
-----Constraints-----
- 1≦N≦100
- -100≦a_i≦100
-----Input-----
The input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
-----Output-----
Print the minimum total cost to achieve Evi's objective.
-----Sample Input-----
2
4 8
-----Sample Output-----
8
Transforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is the minimum.
|
{"inputs": ["2\n5 8", "2\n4 8", "2\n4 8\n", "2\n5 11", "2\n10 6", "2\n17 5", "2\n17 1", "2\n17 2"], "outputs": ["5\n", "8", "8\n", "18\n", "8\n", "72\n", "128\n", "113\n"]}
| 225
| 105
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Once upon a time chef decided to learn encodings. And, obviously, he started with the easiest one (well, actually the easiest after Caesar cypher) – substitution cypher.
But very soon Chef got bored with encoding/decoding, so he started thinking how to hack this cypher.
He already knows some algorithm, which is not always correct,
but it’s sufficient for now. Here is its description.
Imagine we know frequency sequence of English letters (this means, that letters are sorted by their frequency of appearing in English texts, in ascending order).
And let’s find frequency sequence of cyphered letters (if some of them appear equal number of times, then first in frequency sequence will be lower letter between them).
Now, using this two frequency sequences we can recover plain text. Just substitute cyphered letter with origin one, if they are at same positions in sequences.
Now, Chef has frequency sequence of English letters and cypher text. And he asks you to recover plain text. Please, help him.
------ Input ------
In first line number T is given - number of test cases. Then T test cases follow. Each test case consists of two lines - frequency sequence and encrypted text.
------ Output ------
For each test case you should output decrypted with the given frequency sequence text. Please note, that the case of letters should be preserved.
------ Constraints ------
$ 1 ≤ T ≤ 1000; $
$ Length of frequency sequence is always 26; $
$ 1 ≤ length of the text ≤ 150000; $
$ 1 ≤ sum lengths of all texts ≤ 150000. $
$ Frequency sequence consists of all lowercase English letters. Text consists of any characters. $
----- Sample Input 1 ------
3
qwrtyuipasdfgjkzxcvbnmheol
dummy!
bfgjklmopqrstuwxzhvnicdyea
abcd b efgd hbi!
qwrtyuipasdfgjkzxcvbnmheol
Dummy!
----- Sample Output 1 ------
hello!
have a nice day!
Hello!
|
{"inputs": ["3\nqwrtyuipasdfgjkzxcvbnmheol\ndummy!\nbfgjklmopqrstuwxzhvnicdyea\nabcd b efgd hbi!\nqwrtyuipasdfgjkzxcvbnmheol\nDummy!", "3\nqwrtyuipasdfgjkzxcvbnmheol\ndummy!\nbfgjklmopqrstuwxzhvnicdyea\nabcd b efgd hbi!\nqwrtyuipasdfgjkzxcvbnmheol\nDummy!"], "outputs": ["hello!\nhave a nice day!\nHello!", "hello!\nhave a nice day!\nHello!"]}
| 472
| 162
|
coding
|
Solve the programming task below in a Python markdown code block.
# Task
Your task is to find the sum for the range `0 ... m` for all powers from `0 ... n.
# Example
For `m = 2, n = 3`, the result should be `20`
`0^0+1^0+2^0 + 0^1+1^1+2^1 + 0^2+1^2+2^2 + 0^3+1^3+2^3 = 20`
Note, that no output ever exceeds 2e9.
# Input/Output
- `[input]` integer m
`0 <= m <= 50000`
- `[input]` integer `n`
`0 <= n <= 9`
- `[output]` an integer(double in C#)
The sum value.
Also feel free to reuse/extend the following starter code:
```python
def S2N(m, n):
```
|
{"functional": "_inputs = [[2, 3], [3, 5], [10, 9], [1, 1], [0, 0], [300, 2], [567, 2], [37, 4], [36, 4]]\n_outputs = [[20], [434], [1762344782], [3], [1], [9090501], [61083856], [15335280], [13409059]]\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(S2N(*i), o[0])"}
| 220
| 276
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given the array $a$ consisting of $n$ positive (greater than zero) integers.
In one move, you can choose two indices $i$ and $j$ ($i \ne j$) such that the absolute difference between $a_i$ and $a_j$ is no more than one ($|a_i - a_j| \le 1$) and remove the smallest of these two elements. If two elements are equal, you can remove any of them (but exactly one).
Your task is to find if it is possible to obtain the array consisting of only one element using several (possibly, zero) such moves or not.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then $t$ test cases follow.
The first line of the test case contains one integer $n$ ($1 \le n \le 50$) — the length of $a$. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the $i$-th element of $a$.
-----Output-----
For each test case, print the answer: "YES" if it is possible to obtain the array consisting of only one element using several (possibly, zero) moves described in the problem statement, or "NO" otherwise.
-----Example-----
Input
5
3
1 2 2
4
5 5 5 5
3
1 2 4
4
1 3 4 4
1
100
Output
YES
YES
NO
NO
YES
-----Note-----
In the first test case of the example, we can perform the following sequence of moves: choose $i=1$ and $j=3$ and remove $a_i$ (so $a$ becomes $[2; 2]$); choose $i=1$ and $j=2$ and remove $a_j$ (so $a$ becomes $[2]$).
In the second test case of the example, we can choose any possible $i$ and $j$ any move and it doesn't matter which element we remove.
In the third test case of the example, there is no way to get rid of $2$ and $4$.
|
{"inputs": ["1\n1\n23\n", "1\n1\n46\n", "1\n1\n114\n", "1\n1\n157\n", "1\n1\n305\n", "1\n1\n292\n", "1\n1\n430\n", "2\n3\n1 2 2\n4\n5 5 5 5\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\nYES\n"]}
| 544
| 130
|
coding
|
Solve the programming task below in a Python markdown code block.
Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n.
Input
The first line contains two integers n and k (2 ≤ n ≤ 100000, 1 ≤ k ≤ 20).
Output
If it's impossible to find the representation of n as a product of k numbers, print -1.
Otherwise, print k integers in any order. Their product must be equal to n. If there are multiple answers, print any of them.
Examples
Input
100000 2
Output
2 50000
Input
100000 20
Output
-1
Input
1024 5
Output
2 64 2 2 2
|
{"inputs": ["4 5\n", "9 6\n", "5 6\n", "5 4\n", "8 2\n", "6 2\n", "2 5\n", "5 3\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "2 4\n", "2 3\n", "-1\n", "-1\n"]}
| 192
| 91
|
coding
|
Solve the programming task below in a Python markdown code block.
A famous student of AESC MSU, as you know, comes from Kostomuksha. Kostomuksha has a popular game called Doka.
The essence of Doka is as follows:
You are given an array A and an integer X. You want to calculate how many subarrays of this array have a geometric mean of X.
Formally, calculate the number of pairs of integers (L, R) such that 1 ≤ L ≤ R ≤ N and
\sqrt[R-L+1]{A_{L} \cdot A_{L + 1} \cdot \ldots \cdot A_{R}} = X
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case consists of two lines of input.
- The first line of each test case contains two space-separated integers N, X — the size of the array A and the required geometric mean.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, on a new line print the number of subarrays that satisfy the condition.
------ Constraints ------
$1 ≤ T ≤ 10^{3}$
$1 ≤ N ≤ 2 \cdot 10^{5}$
$1 ≤ X, A_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
------ subtasks ------
Subtask #1 (100 points): Original constraints
----- Sample Input 1 ------
3
3 3
3 3 3
4 4
1 2 3 4
4 54
36 81 54 54
----- Sample Output 1 ------
6
1
6
----- explanation 1 ------
Test case $1$: Every subarray has a geometric mean of $3$, and there are $6$ subarrays in total so the answer is $6$.
Test case $2$: The only subarray with a geometric mean of $4$ is the singleton array $[4]$, obtained with $L = R = 4$.
Test case $3$: The $6$ pairs of $(L, R)$ which have a geometric mean of $54$ are:
- $(1, 2)$, giving the subarray $[36, 81]$
- $(1, 3)$, giving the subarray $[36, 81, 54]$
- $(1, 4)$, giving the subarray $[36, 81, 54, 54]$
- $(3, 3)$, giving the subarray $[54]$
- $(3, 4)$, giving the subarray $[54, 54]$
- $(4, 4)$, giving the subarray $[54]$
|
{"inputs": ["3\n3 3\n3 3 3\n4 4\n1 2 3 4\n4 54\n36 81 54 54"], "outputs": ["6\n1\n6"]}
| 666
| 55
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s that consists of lower case English letters and brackets.
Reverse the strings in each pair of matching parentheses, starting from the innermost one.
Your result should not contain any brackets.
Please complete the following python code precisely:
```python
class Solution:
def reverseParentheses(self, s: str) -> str:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"(abcd)\") == \"dcba\"\n assert candidate(s = \"(u(love)i)\") == \"iloveu\"\n assert candidate(s = \"(ed(et(oc))el)\") == \"leetcode\"\n assert candidate(s = \"a(bcdefghijkl(mno)p)q\") == \"apmnolkjihgfedcbq\"\n\n\ncheck(Solution().reverseParentheses)"}
| 89
| 106
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 2D array of characters grid of size m x n, you need to find if there exists any cycle consisting of the same value in grid.
A cycle is a path of length 4 or more in the grid that starts and ends at the same cell. From a given cell, you can move to one of the cells adjacent to it - in one of the four directions (up, down, left, or right), if it has the same value of the current cell.
Also, you cannot move to the cell that you visited in your last move. For example, the cycle (1, 1) -> (1, 2) -> (1, 1) is invalid because from (1, 2) we visited (1, 1) which was the last visited cell.
Return true if any cycle of the same value exists in grid, otherwise, return false.
Please complete the following python code precisely:
```python
class Solution:
def containsCycle(self, grid: List[List[str]]) -> bool:
```
|
{"functional": "def check(candidate):\n assert candidate(grid = [[\"a\",\"a\",\"a\",\"a\"],[\"a\",\"b\",\"b\",\"a\"],[\"a\",\"b\",\"b\",\"a\"],[\"a\",\"a\",\"a\",\"a\"]]) == True\n assert candidate(grid = [[\"c\",\"c\",\"c\",\"a\"],[\"c\",\"d\",\"c\",\"c\"],[\"c\",\"c\",\"e\",\"c\"],[\"f\",\"c\",\"c\",\"c\"]]) == True\n assert candidate(grid = [[\"a\",\"b\",\"b\"],[\"b\",\"z\",\"b\"],[\"b\",\"b\",\"a\"]]) == False\n\n\ncheck(Solution().containsCycle)"}
| 232
| 150
|
coding
|
Solve the programming task below in a Python markdown code block.
Watson likes to challenge Sherlock's math ability. He will provide a starting and ending value that describe a range of integers, inclusive of the endpoints. Sherlock must determine the number of square integers within that range.
Note: A square integer is an integer which is the square of an integer, e.g. $1,4,9,16,25$.
Example
$a=24$
$b=49$
There are three square integers in the range: $25,36$ and $49$. Return $3$.
Function Description
Complete the squares function in the editor below. It should return an integer representing the number of square integers in the inclusive range from $a$ to $b$.
squares has the following parameter(s):
int a: the lower range boundary
int b: the upper range boundary
Returns
int: the number of square integers in the range
Input Format
The first line contains $q$, the number of test cases.
Each of the next $q$ lines contains two space-separated integers, $a$ and $b$, the starting and ending integers in the ranges.
Constraints
$1\leq q\leq100$
$1\leq a\leq b\leq10^9$
Sample Input
2
3 9
17 24
Sample Output
2
0
Explanation
Test Case #00: In range $[3,9]$, $4$ and $9$ are the two square integers.
Test Case #01: In range $[17,24]$, there are no square integers.
|
{"inputs": ["2\n3 9\n17 24\n"], "outputs": ["2\n0\n"]}
| 365
| 26
|
coding
|
Solve the programming task below in a Python markdown code block.
We have 3N colored balls with IDs from 1 to 3N. A string S of length 3N represents the colors of the balls. The color of Ball i is red if S_i is `R`, green if S_i is `G`, and blue if S_i is `B`. There are N red balls, N green balls, and N blue balls.
Takahashi will distribute these 3N balls to N people so that each person gets one red ball, one blue ball, and one green ball. The people want balls with IDs close to each other, so he will additionally satisfy the following condition:
* Let a_j < b_j < c_j be the IDs of the balls received by the j-th person in ascending order.
* Then, \sum_j (c_j-a_j) should be as small as possible.
Find the number of ways in which Takahashi can distribute the balls. Since the answer can be enormous, compute it modulo 998244353. We consider two ways to distribute the balls different if and only if there is a person who receives different sets of balls.
Constraints
* 1 \leq N \leq 10^5
* |S|=3N
* S consists of `R`, `G`, and `B`, and each of these characters occurs N times in S.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the number of ways in which Takahashi can distribute the balls, modulo 998244353.
Examples
Input
3
RRRGGGBBB
Output
216
Input
5
BBRGRRGRGGRBBGB
Output
960
|
{"inputs": ["3\nBBBGGGRRR", "3\nRRRBGGBGB", "3\nBRRGGGRBB", "3\nBGRGGRRBB", "3\nRGRBGRBGB", "3\nBBBGGRRGR", "3\nBBGBGRRRG", "3\nBBGBGGRRR"], "outputs": ["216", "36", "12", "24", "6", "72", "48", "144"]}
| 379
| 113
|
coding
|
Solve the programming task below in a Python markdown code block.
Given two integer arrays where the second array is a shuffled duplicate of the first array with one element missing, find the missing element.
Please note, there may be duplicates in the arrays, so checking if a numerical value exists in one and not the other is not a valid solution.
```
find_missing([1, 2, 2, 3], [1, 2, 3]) => 2
```
```
find_missing([6, 1, 3, 6, 8, 2], [3, 6, 6, 1, 2]) => 8
```
The first array will always have at least one element.
Also feel free to reuse/extend the following starter code:
```python
def find_missing(arr1, arr2):
```
|
{"functional": "_inputs = [[[1, 2, 3], [1, 3]], [[6, 1, 3, 6, 8, 2], [3, 6, 6, 1, 2]], [[7], []], [[4, 3, 3, 61, 8, 8], [8, 61, 8, 3, 4]], [[0, 0, 0, 0, 0], [0, 0, 0, 0]]]\n_outputs = [[2], [8], [7], [3], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(find_missing(*i), o[0])"}
| 179
| 278
|
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 indexDiff and valueDiff.
Find a pair of indices (i, j) such that:
i != j,
abs(i - j) <= indexDiff.
abs(nums[i] - nums[j]) <= valueDiff, and
Return true if such pair exists or false otherwise.
Please complete the following python code precisely:
```python
class Solution:
def containsNearbyAlmostDuplicate(self, nums: List[int], indexDiff: int, valueDiff: int) -> bool:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,1], indexDiff = 3, valueDiff = 0) == True\n assert candidate(nums = [1,5,9,1,5,9], indexDiff = 2, valueDiff = 3) == False\n\n\ncheck(Solution().containsNearbyAlmostDuplicate)"}
| 127
| 84
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed binary matrix grid. In one operation, you can flip any 1 in grid to be 0.
A binary matrix is well-isolated if there is no 1 in the matrix that is 4-directionally connected (i.e., horizontal and vertical) to another 1.
Return the minimum number of operations to make grid well-isolated.
Please complete the following python code precisely:
```python
class Solution:
def minimumOperations(self, grid: List[List[int]]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(grid = [[1,1,0],[0,1,1],[1,1,1]]) == 3\n assert candidate(grid = [[0,0,0],[0,0,0],[0,0,0]]) == 0\n assert candidate(grid = [[0,1],[1,0]]) == 0\n\n\ncheck(Solution().minimumOperations)"}
| 127
| 93
|
coding
|
Solve the programming task below in a Python markdown code block.
This time around, Baby Ehab will play with permutations. He has $n$ cubes arranged in a row, with numbers from $1$ to $n$ written on them. He'll make exactly $j$ operations. In each operation, he'll pick up $2$ cubes and switch their positions.
He's wondering: how many different sequences of cubes can I have at the end? Since Baby Ehab is a turbulent person, he doesn't know how many operations he'll make, so he wants the answer for every possible $j$ between $1$ and $k$.
-----Input-----
The only line contains $2$ integers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 200$) — the number of cubes Baby Ehab has, and the parameter $k$ from the statement.
-----Output-----
Print $k$ space-separated integers. The $i$-th of them is the number of possible sequences you can end up with if you do exactly $i$ operations. Since this number can be very large, print the remainder when it's divided by $10^9+7$.
-----Examples-----
Input
2 3
Output
1 1 1
Input
3 2
Output
3 3
Input
4 2
Output
6 12
-----Note-----
In the second example, there are $3$ sequences he can get after $1$ swap, because there are $3$ pairs of cubes he can swap. Also, there are $3$ sequences he can get after $2$ swaps:
$[1,2,3]$,
$[3,1,2]$,
$[2,3,1]$.
|
{"inputs": ["2 3\n", "3 2\n", "4 2\n", "2 200\n", "3 200\n"], "outputs": ["1 1 1 \n", "3 3 \n", "6 12 \n", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n", "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 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 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 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 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 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 \n"]}
| 383
| 870
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than A, C, G and T.
-----Notes-----
A substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.
For example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and (the empty string), but not AC.
-----Constraints-----
- S is a string of length between 1 and 10 (inclusive).
- Each character in S is an uppercase English letter.
-----Input-----
Input is given from Standard Input in the following format:
S
-----Output-----
Print the length of the longest ACGT string that is a substring of S.
-----Sample Input-----
ATCODER
-----Sample Output-----
3
Among the ACGT strings that are substrings of ATCODER, the longest one is ATC.
|
{"inputs": ["A\n", "Z\n", "CG\n", "ABC\n", "ATCPDER", "ATCPCER", "ATCPBER", "REBPCTA"], "outputs": ["1\n", "0\n", "2\n", "1\n", "3\n", "3\n", "3\n", "3\n"]}
| 234
| 76
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese here
Read problems statements in Russian here
------ Problem Statement ------
One day Chef is waiting his girlfriend on the bus station. The girlfriend said that she will be at time_{1}. Chef went to the bus station at time_{2}. When Chef has reached the bus station he realized that he forgot a gift for his better half in his home.
Chef knows that someone can reach his home in dist minutes (his girlfriend also needs dist minutes to get Chef's home after she arrived at the bus station). So, Chef came up with two plans for present the gift:
i. The first one is to wait for his girlfriend at the bus station. And then go to the home together with her. When Chef and his girlfriend will reach the home he will present his gift.
ii. The second one is to call the girlfriend and ask her to go to his home when she will reach the bus station. And after calling he will go to the home, take the gift, and go towards the girlfriend. When they meet each other he will present his gift (they can meet at any position of the road or at the bus station). It's known that girlfriend and Chef uses the same road between bus station and Chef's home.
Please, help Chef to estimate the time in minutes for each of his plans.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
Each test case contains of three lines. The first line contains time_{1}, the second line contains time_{2}, and the third line contains dist.
------ Output ------
For each test case output a single line containing two real numbers - the time for the first plan and the time for the second one. Print real numbers with exactly one decimal digit after the dot.
------ Constraints ------
$1 ≤ T ≤ 10000;$
$1 ≤ dist ≤ 180.$
$Two times are given in form HH:MM (usual time from 00:00 to 23:59), and these two times are from the same day. It's guaranteed that Chef will be at bus station strictly earlier that his girlfriend.$
----- Sample Input 1 ------
3
10:00
09:00
10
10:00
09:00
30
10:00
09:00
60
----- Sample Output 1 ------
70.0 60.0
90.0 60.0
120.0 90.0
|
{"inputs": ["3\n10:00\n09:00\n6\n10:00\n09:00\n48\n10:00\n09:00\n60", "3\n10:00\n09:00\n6\n10:00\n09:00\n56\n10:00\n09:00\n60", "3\n10:00\n09:00\n6\n10:00\n09:00\n56\n10:00\n09:00\n54", "3\n10:01\n09:00\n7\n10:00\n09:00\n48\n10:00\n09:00\n60", "3\n10:00\n09:00\n8\n10:00\n08:00\n48\n10:00\n09:00\n60", "3\n10:01\n09:00\n3\n10:00\n09:00\n48\n10:10\n09:00\n60", "3\n10:00\n09:00\n6\n10:00\n09:00\n88\n10:00\n09:00\n60", "3\n10:00\n09:00\n6\n10:00\n09:00\n56\n10:00\n09:00\n22"], "outputs": ["66.0 60.0\n108.0 78.0\n120.0 90.0\n", "66.0 60.0\n116.0 86.0\n120.0 90.0\n", "66.0 60.0\n116.0 86.0\n114.0 84.0\n", "68.0 61.0\n108.0 78.0\n120.0 90.0\n", "68.0 60.0\n168.0 120.0\n120.0 90.0\n", "64.0 61.0\n108.0 78.0\n130.0 95.0\n", "66.0 60.0\n148.0 118.0\n120.0 90.0\n", "66.0 60.0\n116.0 86.0\n82.0 60.0\n"]}
| 564
| 655
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A chef has collected data on the satisfaction level of his n dishes. Chef can cook any dish in 1 unit of time.
Like-time coefficient of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level i.e. time[i] * satisfaction[i].
Return the maximum sum of like-time coefficient that the chef can obtain after preparing some amount of dishes.
Dishes can be prepared in any order and the chef can discard some dishes to get this maximum value.
Please complete the following python code precisely:
```python
class Solution:
def maxSatisfaction(self, satisfaction: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(satisfaction = [-1,-8,0,5,-9]) == 14\n assert candidate(satisfaction = [4,3,2]) == 20\n assert candidate(satisfaction = [-1,-4,-5]) == 0\n\n\ncheck(Solution().maxSatisfaction)"}
| 150
| 77
|
coding
|
Solve the programming task below in a Python markdown code block.
Mr. Scrooge has a sum of money 'P' that he wants to invest. Before he does, he wants to know how many years 'Y' this sum 'P' has to be kept in the bank in order for it to amount to a desired sum of money 'D'.
The sum is kept for 'Y' years in the bank where interest 'I' is paid yearly. After paying taxes 'T' for the year the new sum is re-invested.
Note to Tax: not the invested principal is taxed, but only the year's accrued interest
Example:
Let P be the Principal = 1000.00
Let I be the Interest Rate = 0.05
Let T be the Tax Rate = 0.18
Let D be the Desired Sum = 1100.00
After 1st Year -->
P = 1041.00
After 2nd Year -->
P = 1083.86
After 3rd Year -->
P = 1128.30
Thus Mr. Scrooge has to wait for 3 years for the initial principal to amount to the desired sum.
Your task is to complete the method provided and return the number of years 'Y' as a whole in order for Mr. Scrooge to get the desired sum.
Assumption: Assume that Desired Principal 'D' is always greater than the initial principal. However it is best to take into consideration that if Desired Principal 'D' is equal to Principal 'P' this should return 0 Years.
Also feel free to reuse/extend the following starter code:
```python
def calculate_years(principal, interest, tax, desired):
```
|
{"functional": "_inputs = [[1000, 0.05, 0.18, 1100], [1000, 0.01625, 0.18, 1200], [1000, 0.05, 0.18, 1000]]\n_outputs = [[3], [14], [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(calculate_years(*i), o[0])"}
| 386
| 234
|
coding
|
Solve the programming task below in a Python markdown code block.
A generalization of Bézier surfaces, called the S-patch, uses an interesting scheme for indexing its control points.
In the case of an n-sided surface of degree d, each index has n non-negative integers that sum to d, and all possible configurations are used.
For example, for a 3-sided quadratic (degree 2) surface the control points are:
> indices 3 2 => [[0,0,2],[0,1,1],[0,2,0],[1,0,1],[1,1,0],[2,0,0]]
Given the degree and the number of sides, generate all control point indices.
The order of the indices in the list can be arbitrary, so for the above example
> [[1,1,0],[2,0,0],[0,0,2],[0,2,0],[0,1,1],[1,0,1]]
is also a good solution.
Also feel free to reuse/extend the following starter code:
```python
def indices(n, d):
```
|
{"functional": "_inputs = [[1, 0], [3, 0]]\n_outputs = [[[[0]]], [[[0, 0, 0]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(indices(*i), o[0])"}
| 232
| 174
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well.
Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants.
Help Chef find the minimum possible P with which he can create a valid sequence.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'.
-----Output-----
For each test case, output a single line containing an integer corresponding to the minimum possible P.
-----Constraints-----
- 1 ≤ T, |s| ≤ 105
- 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106
-----Subtasks-----
Subtask #1 (30 points)
- 1 ≤ T, |s| ≤ 103
- 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104
Subtask #2 (70 points)
- Original constraints
-----Example-----
Input:
4
<<<
<><
<=>
<=<
Output:
4
2
2
3
-----Explanation-----
Here are some possible valid sequences which can be formed with the minimum P for each of the test cases:
1 < 2 < 3 < 4
1 < 2 > 1 < 2
1 < 2 = 2 > 1
1 < 2 = 2 < 3
|
{"inputs": ["4\n<<<\n<><\n<=>\n<=<"], "outputs": ["4\n2\n2\n3"]}
| 452
| 32
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.
Each node has an associated price. You are given an integer array price, where price[i] is the price of the ith node.
The price sum of a given path is the sum of the prices of all nodes lying on that path.
Additionally, you are given a 2D integer array trips, where trips[i] = [starti, endi] indicates that you start the ith trip from the node starti and travel to the node endi by any path you like.
Before performing your first trip, you can choose some non-adjacent nodes and halve the prices.
Return the minimum total price sum to perform all the given trips.
Please complete the following python code precisely:
```python
class Solution:
def minimumTotalPrice(self, n: int, edges: List[List[int]], price: List[int], trips: List[List[int]]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 4, edges = [[0,1],[1,2],[1,3]], price = [2,2,10,6], trips = [[0,3],[2,1],[2,3]]) == 23\n assert candidate(n = 2, edges = [[0,1]], price = [2,2], trips = [[0,0]]) == 1\n\n\ncheck(Solution().minimumTotalPrice)"}
| 266
| 108
|
coding
|
Solve the programming task below in a Python markdown code block.
We have N integers. The i-th number is A_i.
\{A_i\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\leq i < j \leq N.
\{A_i\} is said to be setwise coprime when \{A_i\} is not pairwise coprime but GCD(A_1,\ldots,A_N)=1.
Determine if \{A_i\} is pairwise coprime, setwise coprime, or neither.
Here, GCD(\ldots) denotes greatest common divisor.
-----Constraints-----
- 2 \leq N \leq 10^6
- 1 \leq A_i\leq 10^6
-----Input-----
Input is given from Standard Input in the following format:
N
A_1 \ldots A_N
-----Output-----
If \{A_i\} is pairwise coprime, print pairwise coprime; if \{A_i\} is setwise coprime, print setwise coprime; if neither, print not coprime.
-----Sample Input-----
3
3 4 5
-----Sample Output-----
pairwise coprime
GCD(3,4)=GCD(3,5)=GCD(4,5)=1, so they are pairwise coprime.
|
{"inputs": ["3\n4 4 2", "3\n4 3 1", "3\n4 4 5", "3\n4 8 2", "3\n8 8 2", "3\n4 4 1", "3\n4 4 4", "3\n6 8 2"], "outputs": ["not coprime\n", "pairwise coprime\n", "setwise coprime\n", "not coprime\n", "not coprime\n", "setwise coprime\n", "not coprime\n", "not coprime\n"]}
| 318
| 137
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s and array queries where queries[i] = [lefti, righti, ki]. We may rearrange the substring s[lefti...righti] for each query and then choose up to ki of them to replace with any lowercase English letter.
If the substring is possible to be a palindrome string after the operations above, the result of the query is true. Otherwise, the result is false.
Return a boolean array answer where answer[i] is the result of the ith query queries[i].
Note that each letter is counted individually for replacement, so if, for example s[lefti...righti] = "aaa", and ki = 2, we can only replace two of the letters. Also, note that no query modifies the initial string s.
Please complete the following python code precisely:
```python
class Solution:
def canMakePaliQueries(self, s: str, queries: List[List[int]]) -> List[bool]:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"abcda\", queries = [[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]]) == [True,False,False,True,True]\n\n\ncheck(Solution().canMakePaliQueries)"}
| 215
| 73
|
coding
|
Solve the programming task below in a Python markdown code block.
# Introduction:
Reversi is a game usually played by 2 people on a 8x8 board.
Here we're only going to consider a single 8x1 row.
Players take turns placing pieces, which are black on one side and white on the
other, onto the board with their colour facing up. If one or more of the
opponents pieces are sandwiched by the piece just played and another piece of
the current player's colour, the opponents pieces are flipped to the
current players colour.
Note that the flipping stops when the first piece of the player's colour is reached.
# Task:
Your task is to take an array of moves and convert this into a string
representing the state of the board after all those moves have been played.
# Input:
The input to your function will be an array of moves.
Moves are represented by integers from 0 to 7 corresponding to the 8 squares on the board.
Black plays first, and black and white alternate turns.
Input is guaranteed to be valid. (No duplicates, all moves in range, but array may be empty)
# Output:
8 character long string representing the final state of the board.
Use '*' for black and 'O' for white and '.' for empty.
# Examples:
```python
reversi_row([]) # '........'
reversi_row([3]) # '...*....'
reversi_row([3,4]) # '...*O...'
reversi_row([3,4,5]) # '...***..'
```
Also feel free to reuse/extend the following starter code:
```python
def reversi_row(moves):
```
|
{"functional": "_inputs = [[[]], [[0]], [[0, 1]], [[0, 7, 4]], [[3]], [[3, 4]], [[3, 4, 5]], [[2, 1, 0]], [[0, 1, 4, 3, 2]], [[0, 1, 7, 2, 3]], [[3, 2, 7, 1, 0]], [[3, 4, 5, 6, 0, 2]], [[0, 1, 2, 3, 4, 5, 6, 7]], [[7, 0, 1]], [[0, 7, 6]], [[1, 0, 2, 3, 4, 5, 6, 7]], [[5, 1, 3, 4, 6]], [[1, 7, 0, 5, 6, 4]]]\n_outputs = [['........'], ['*.......'], ['*O......'], ['*...*..O'], ['...*....'], ['...*O...'], ['...***..'], ['***.....'], ['*****...'], ['****...*'], ['****...*'], ['*.OOOOO.'], ['*******O'], ['O*.....*'], ['*.....*O'], ['OOOOOOOO'], ['.O.*O**.'], ['**..OO*O']]\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(reversi_row(*i), o[0])"}
| 360
| 456
|
coding
|
Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is the constraints.
Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of $n$ consecutive pictures (with kittens, of course). Vova likes all these pictures, but some are more beautiful than the others: the $i$-th picture has beauty $a_i$.
Vova wants to repost exactly $x$ pictures in such a way that: each segment of the news feed of at least $k$ consecutive pictures has at least one picture reposted by Vova; the sum of beauty values of reposted pictures is maximum possible.
For example, if $k=1$ then Vova has to repost all the pictures in the news feed. If $k=2$ then Vova can skip some pictures, but between every pair of consecutive pictures Vova has to repost at least one of them.
Your task is to calculate the maximum possible sum of values of reposted pictures if Vova follows conditions described above, or say that there is no way to satisfy all conditions.
-----Input-----
The first line of the input contains three integers $n, k$ and $x$ ($1 \le k, x \le n \le 200$) — the number of pictures in the news feed, the minimum length of segment with at least one repost in it and the number of pictures Vova is ready to repost.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the beauty of the $i$-th picture.
-----Output-----
Print -1 if there is no way to repost some pictures to satisfy all the conditions in the problem statement.
Otherwise print one integer — the maximum sum of values of reposted pictures if Vova follows conditions described in the problem statement.
-----Examples-----
Input
5 2 3
5 1 3 10 1
Output
18
Input
6 1 5
10 30 30 70 10 10
Output
-1
Input
4 3 1
1 100 1 1
Output
100
|
{"inputs": ["1 1 1\n7082632\n", "1 1 1\n1027282\n", "1 1 1\n1469884\n", "1 1 1\n99996055\n", "1 1 1\n41731973\n", "1 1 1\n74257449\n", "1 1 1\n69799202\n", "4 3 1\n1 100 1 1\n"], "outputs": ["7082632", "1027282\n", "1469884\n", "99996055", "41731973\n", "74257449\n", "69799202\n", "100\n"]}
| 499
| 218
|
coding
|
Solve the programming task below in a Python markdown code block.
Vacations have arrived and Chef wants to go to his home in ChefLand. There are two types of routes he can take:
Take a flight from his college to ChefArina which takes X minutes and then take a bus from ChefArina to ChefLand which takes Y minutes.
Take a direct train from his college to ChefLand which takes Z minutes.
Which of these two options is faster?
------ Input Format ------
- The first line of the input contains a single integer T - the number of test cases. The test cases then follow.
- The first line of the test case contains three space-separated integers X, Y, and Z.
------ Output Format ------
For each test case, if Chef takes the train output TRAIN, if Chef takes the plane and the bus output PLANEBUS, if both are equal output EQUAL.
You may print each character of the string in uppercase or lowercase (for example, the strings train, tRAiN, TrAin, and TRAIN will all be treated as identical).
------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ X,Y,Z ≤ 10^{9}$
------ subtasks ------
Subtask $1$ (100 points): Original constraints
----- Sample Input 1 ------
3
10 12 11
3 5 15
9 4 13
----- Sample Output 1 ------
TRAIN
PLANEBUS
EQUAL
----- explanation 1 ------
- Test Case $1$: It will take $10 + 12 = 22$ minutes to travel using Plane and Bus. The train journey takes $11$ minutes. Since the train is faster, Chef will choose the train.
- Test Case $2$: It will take $3 + 5 = 8$ minutes to travel using Plane and Bus. The train journey takes $15$ minutes. Since the plane and bus are faster, Chef will choose the plane and bus.
- Test Case $3$: It will take $9 + 4 = 13$ minutes to travel using Plane and Bus. The train journey takes $13$ minutes. Since they both are equal, Chef can choose either.
|
{"inputs": ["3\n10 12 11\n3 5 15\n9 4 13\n"], "outputs": ["TRAIN\nPLANEBUS\nEQUAL\n"]}
| 474
| 43
|
coding
|
Solve the programming task below in a Python markdown code block.
For the multiset of positive integers $s=\{s_1,s_2,\dots,s_k\}$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $s$ as follow: $\gcd(s)$ is the maximum positive integer $x$, such that all integers in $s$ are divisible on $x$. $\textrm{lcm}(s)$ is the minimum positive integer $x$, that divisible on all integers from $s$.
For example, $\gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6$ and $\textrm{lcm}(\{4,6\})=12$. Note that for any positive integer $x$, $\gcd(\{x\})=\textrm{lcm}(\{x\})=x$.
Orac has a sequence $a$ with length $n$. He come up with the multiset $t=\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\}$, and asked you to find the value of $\gcd(t)$ for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence.
-----Input-----
The first line contains one integer $n\ (2\le n\le 100\,000)$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 200\,000$).
-----Output-----
Print one integer: $\gcd(\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\})$.
-----Examples-----
Input
2
1 1
Output
1
Input
4
10 24 40 80
Output
40
Input
10
540 648 810 648 720 540 594 864 972 648
Output
54
-----Note-----
For the first example, $t=\{\textrm{lcm}(\{1,1\})\}=\{1\}$, so $\gcd(t)=1$.
For the second example, $t=\{120,40,80,120,240,80\}$, and it's not hard to see that $\gcd(t)=40$.
|
{"inputs": ["2\n1 1\n", "2\n4 6\n", "2\n3 3\n", "2\n3 3\n", "2\n4 6\n", "2\n3 5\n", "2\n1 2\n", "2\n1 1\n"], "outputs": ["1\n", "12\n", "3\n", "3\n", "12\n", "15\n", "2\n", "1\n"]}
| 565
| 105
|
coding
|
Solve the programming task below in a Python markdown code block.
Sam has opened a new sushi train restaurant - a restaurant where sushi is served on plates that travel around the bar on a conveyor belt and customers take the plate that they like.
Sam is using Glamazon's new visual recognition technology that allows a computer to record the number of plates at a customer's table and the colour of those plates. The number of plates is returned as a string. For example, if a customer has eaten 3 plates of sushi on a red plate the computer will return the string 'rrr'.
Currently, Sam is only serving sushi on red plates as he's trying to attract customers to his restaurant. There are also small plates on the conveyor belt for condiments such as ginger and wasabi - the computer notes these in the string that is returned as a space ('rrr r' //denotes 4 plates of red sushi and a plate of condiment).
Sam would like your help to write a program for the cashier's machine to read the string and return the total amount a customer has to pay when they ask for the bill. The current price for the dishes are as follows:
* Red plates of sushi ('r') - $2 each, but if a customer eats 5 plates the 5th one is free.
* Condiments (' ') - free.
```
Input: String
Output: Number
Examples:
Input: 'rr' Output: 4
Input: 'rr rrr' Output: 8
Input: 'rrrrr rrrrr' Output: 16
```
Also feel free to reuse/extend the following starter code:
```python
def total_bill(s):
```
|
{"functional": "_inputs = [['rr'], ['rr rrr'], ['rr rrr rrr rr'], ['rrrrrrrrrrrrrrrrrr rr r'], ['']]\n_outputs = [[4], [8], [16], [34], [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(total_bill(*i), o[0])"}
| 352
| 197
|
coding
|
Solve the programming task below in a Python markdown code block.
An n × n square matrix is special, if: it is binary, that is, each cell contains either a 0, or a 1; the number of ones in each row and column equals 2.
You are given n and the first m rows of the matrix. Print the number of special n × n matrices, such that the first m rows coincide with the given ones.
As the required value can be rather large, print the remainder after dividing the value by the given number mod.
-----Input-----
The first line of the input contains three integers n, m, mod (2 ≤ n ≤ 500, 0 ≤ m ≤ n, 2 ≤ mod ≤ 10^9). Then m lines follow, each of them contains n characters — the first rows of the required special matrices. Each of these lines contains exactly two characters '1', the rest characters are '0'. Each column of the given m × n table contains at most two numbers one.
-----Output-----
Print the remainder after dividing the required value by number mod.
-----Examples-----
Input
3 1 1000
011
Output
2
Input
4 4 100500
0110
1010
0101
1001
Output
1
-----Note-----
For the first test the required matrices are:
011
101
110
011
110
101
In the second test the required matrix is already fully given, so the answer is 1.
|
{"inputs": ["5 0 13\n", "5 0 13\n", "2 0 1000\n", "2 0 1000\n", "2 0 1010\n", "4 0 1100\n", "99 0 757\n", "2 0 1100\n"], "outputs": ["12\n", "12\n", "1\n", "1\n", "1\n", "90\n", "613\n", "1\n"]}
| 347
| 127
|
coding
|
Solve the programming task below in a Python markdown code block.
Rohit collects coins: he has exactly one coin for every year from 1 to n. Naturally, Rohit keeps all the coins in his collection in the order in which they were released. Once Rohit's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order. That is, he took a certain segment [l, r] and reversed it. At that, the segment's endpoints did not coincide. For example, if n = 8, then initially Rohit's coins were kept in the order 1 2 3 4 5 6 7 8. If Rohit's younger brother chose the segment [2, 6], then after the reversal the coin order will change to 1 6 5 4 3 2 7 8. Rohit suspects that someone else could have spoilt the permutation after his brother. Help him to find that out. Check if the given permutation can be obtained from the permutation 1 2 … n using exactly one segment reversal. If it is possible, find the segment itself.
-----Input:-----
- The first line contains an integer N which is the number of coins in Rohit's collection.
- The second line contains space-separated n integers which are the spoilt sequence of coins. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to n, and every number is used exactly 1 time.
-----Output:-----
If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers l, r (1 ≤ l < r ≤ n) which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 … n the given one.
-----Constraints-----
- $1 \leq N \leq 1000$
- $1 \leq A[N] \leq 10^9$
-----Sample Input:-----
8
1 6 5 4 3 2 7 8
-----Sample Output:-----
2 6
|
{"inputs": ["8\n1 6 5 4 3 2 7 8"], "outputs": ["2 6"]}
| 483
| 30
|
coding
|
Solve the programming task below in a Python markdown code block.
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a_1, a_2, ..., a_{n}.
While Vasya was walking, his little brother Stepan played with Vasya's cubes and changed their order, so now the sequence of numbers written on the cubes became equal to b_1, b_2, ..., b_{n}.
Stepan said that he swapped only cubes which where on the positions between l and r, inclusive, and did not remove or add any other cubes (i. e. he said that he reordered cubes between positions l and r, inclusive, in some way).
Your task is to determine if it is possible that Stepan said the truth, or it is guaranteed that Stepan deceived his brother.
-----Input-----
The first line contains three integers n, l, r (1 ≤ n ≤ 10^5, 1 ≤ l ≤ r ≤ n) — the number of Vasya's cubes and the positions told by Stepan.
The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ n) — the sequence of integers written on cubes in the Vasya's order.
The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≤ b_{i} ≤ n) — the sequence of integers written on cubes after Stepan rearranged their order.
It is guaranteed that Stepan did not remove or add other cubes, he only rearranged Vasya's cubes.
-----Output-----
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
-----Examples-----
Input
5 2 4
3 4 2 3 1
3 2 3 4 1
Output
TRUTH
Input
3 1 2
1 2 3
3 1 2
Output
LIE
Input
4 2 4
1 1 1 1
1 1 1 1
Output
TRUTH
-----Note-----
In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and 4 (after that the sequence of integers on cubes became equal to [3, 2, 3, 4, 1]).
In the second example it is not possible that Stepan said truth because he said that he swapped cubes only between positions 1 and 2, but we can see that it is guaranteed that he changed the position of the cube which was on the position 3 at first. So it is guaranteed that Stepan deceived his brother.
In the third example for any values l and r there is a situation when Stepan said the truth.
|
{"inputs": ["1 1 1\n1\n1\n", "1 1 1\n1\n1\n", "3 1 2\n1 2 3\n3 1 2\n", "3 1 2\n1 2 5\n3 1 2\n", "3 1 2\n1 2 3\n3 1 2\n", "4 2 4\n1 1 1 1\n1 1 1 1\n", "4 3 4\n1 2 3 4\n2 1 3 4\n", "4 2 2\n2 1 2 2\n1 2 2 2\n"], "outputs": ["TRUTH\n", "TRUTH\n", "LIE\n", "LIE\n", "LIE\n", "TRUTH\n", "LIE\n", "LIE\n"]}
| 709
| 202
|
coding
|
Solve the programming task below in a Python markdown code block.
Given are N integers A_1,\ldots,A_N.
We will choose exactly K of these elements. Find the maximum possible product of the chosen elements.
Then, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).
-----Constraints-----
- 1 \leq K \leq N \leq 2\times 10^5
- |A_i| \leq 10^9
-----Input-----
Input is given from Standard Input in the following format:
N K
A_1 \ldots A_N
-----Output-----
Print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).
-----Sample Input-----
4 2
1 2 -3 -4
-----Sample Output-----
12
The possible products of the two chosen elements are 2, -3, -4, -6, -8, and 12, so the maximum product is 12.
|
{"inputs": ["4 2\n1 2 -3 0", "4 2\n1 2 -3 -1", "4 4\n1 2 -3 -4", "4 2\n1 2 -4 -1", "4 2\n1 2 -3 -4", "4 2\n1 2 -3 -4\n", "4 2\n0 -3 -2 -1", "4 3\n-1 -3 -3 -4"], "outputs": ["2\n", "3\n", "24\n", "4\n", "12", "12\n", "6\n", "999999998\n"]}
| 238
| 154
|
coding
|
Solve the programming task below in a Python markdown code block.
Problem
Given the integer n, output the smallest m such that nCm (the number of combinations that choose m out of n different ones) is even.
Constraints
The input satisfies the following conditions.
* 1 ≤ n ≤ 1018
Input
The input is given in the following format.
n
Output
Output the minimum m such that nCm is an even number on one line.
Examples
Input
2
Output
1
Input
111
Output
16
Input
3
Output
4
|
{"inputs": ["4", "7", "6", "5", "0", "8", "9", "3"], "outputs": ["1\n", "8\n", "1\n", "2\n", "1\n", "1\n", "2\n", "4"]}
| 127
| 61
|
coding
|
Solve the programming task below in a Python markdown code block.
Given $n$ strings, each of length $2$, consisting of lowercase Latin alphabet letters from 'a' to 'k', output the number of pairs of indices $(i, j)$ such that $i < j$ and the $i$-th string and the $j$-th string differ in exactly one position.
In other words, count the number of pairs $(i, j)$ ($i < j$) such that the $i$-th string and the $j$-th string have exactly one position $p$ ($1 \leq p \leq 2$) such that ${s_{i}}_{p} \neq {s_{j}}_{p}$.
The answer may not fit into 32-bit integer type, so you should use 64-bit integers like long long in C++ to avoid integer overflow.
-----Input-----
The first line of the input contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer $n$ ($1 \le n \le 10^5$) — the number of strings.
Then follows $n$ lines, the $i$-th of which containing a single string $s_i$ of length $2$, consisting of lowercase Latin letters from 'a' to 'k'.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print a single integer — the number of pairs $(i, j)$ ($i < j$) such that the $i$-th string and the $j$-th string have exactly one position $p$ ($1 \leq p \leq 2$) such that ${s_{i}}_{p} \neq {s_{j}}_{p}$.
Please note, that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
-----Examples-----
Input
4
6
ab
cb
db
aa
cc
ef
7
aa
bb
cc
ac
ca
bb
aa
4
kk
kk
ab
ab
5
jf
jf
jk
jk
jk
Output
5
6
0
6
-----Note-----
For the first test case the pairs that differ in exactly one position are: ("ab", "cb"), ("ab", "db"), ("ab", "aa"), ("cb", "db") and ("cb", "cc").
For the second test case the pairs that differ in exactly one position are: ("aa", "ac"), ("aa", "ca"), ("cc", "ac"), ("cc", "ca"), ("ac", "aa") and ("ca", "aa").
For the third test case, the are no pairs satisfying the conditions.
|
{"inputs": ["2\n1\nab\n1\ncf\n", "4\n6\nab\ncb\ndb\naa\ncc\nef\n7\naa\nbb\ncc\nac\nca\nbb\naa\n4\nkk\nkk\nab\nab\n5\njf\njf\njk\njk\njk\n"], "outputs": ["0\n0\n", "5\n6\n0\n6\n"]}
| 650
| 94
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums, and you are allowed to traverse between its indices. You can traverse between index i and index j, i != j, if and only if gcd(nums[i], nums[j]) > 1, where gcd is the greatest common divisor.
Your task is to determine if for every pair of indices i and j in nums, where i < j, there exists a sequence of traversals that can take us from i to j.
Return true if it is possible to traverse between all such pairs of indices, or false otherwise.
Please complete the following python code precisely:
```python
class Solution:
def canTraverseAllPairs(self, nums: List[int]) -> bool:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,6]) == True\n assert candidate(nums = [3,9,5]) == False\n assert candidate(nums = [4,3,12,8]) == True\n\n\ncheck(Solution().canTraverseAllPairs)"}
| 167
| 70
|
coding
|
Solve the programming task below in a Python markdown code block.
In this problem you will write a simple generator of Brainfuck (https://en.wikipedia.org/wiki/Brainfuck) calculators.
You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, when executed, will print the result of evaluating this expression.
We use a fairly standard Brainfuck interpreter for checking the programs:
30000 memory cells.
memory cells store integers from 0 to 255 with unsigned 8-bit wraparound.
console input (, command) is not supported, but it's not needed for this problem.
-----Input-----
The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. The calculations result is guaranteed to be an integer between 0 and 255, inclusive (results of intermediary calculations might be outside of these boundaries).
-----Output-----
Output a Brainfuck program which, when executed, will print the result of evaluating this expression. The program must be at most 5000000 characters long (including the non-command characters), and its execution must be complete in at most 50000000 steps.
-----Examples-----
Input
2+3
Output
++>
+++>
<[<+>-]<
++++++++++++++++++++++++++++++++++++++++++++++++.
Input
9-7
Output
+++++++++>
+++++++>
<[<->-]<
++++++++++++++++++++++++++++++++++++++++++++++++.
-----Note-----
You can download the source code of the Brainfuck interpreter by the link http://assets.codeforces.com/rounds/784/bf.cpp. We use this code to interpret outputs.
|
{"inputs": ["7\n", "3\n", "6\n", "1\n", "2\n", "0\n", "2+3\n", "9-7\n"], "outputs": ["+++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n", "+++++++++++++++++++++++++++++++++++++++++++++++++++.>\n", "++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n", "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n", "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n", "++++++++++++++++++++++++++++++++++++++++++++++++.>\n", "+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n", "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"]}
| 382
| 103
|
coding
|
Solve the programming task below in a Python markdown code block.
Johnny is a boy who likes to open and close lockers. He loves it so much that one day, when school was out, he snuck in just to play with the lockers.
Each locker can either be open or closed. If a locker is closed when Johnny gets to it, he opens it, and vice versa.
The lockers are numbered sequentially, starting at 1.
Starting at the first locker, Johnny runs down the row, opening each locker.
Then he runs all the way back to the beginning and runs down the row again, this time skipping to every other locker. (2,4,6, etc)
Then he runs all the way back and runs through again, this time skipping two lockers for every locker he opens or closes. (3,6,9, etc)
He continues this until he has finished running past the last locker (i.e. when the number of lockers he skips is greater than the number of lockers he has).
------
The equation could be stated as follows:
> Johnny runs down the row of lockers `n` times, starting at the first locker each run and skipping `i` lockers as he runs, where `n` is the number of lockers there are in total and `i` is the current run.
The goal of this kata is to determine which lockers are open at the end of Johnny's running.
The program accepts an integer giving the total number of lockers, and should output an array filled with the locker numbers of those which are open at the end of his run.
Also feel free to reuse/extend the following starter code:
```python
def locker_run(lockers):
```
|
{"functional": "_inputs = [[1], [5], [10], [20]]\n_outputs = [[[1]], [[1, 4]], [[1, 4, 9]], [[1, 4, 9, 16]]]\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(locker_run(*i), o[0])"}
| 357
| 194
|
coding
|
Solve the programming task below in a Python markdown code block.
One of Chef's friends offered him a deal: during $D$ days, they are going to exchange money. For each $i$ ($1 \le i \le D$), on the $i$-th day, Chef's friend would give Chef $A$ rupees, while Chef would give his friend $2^{i-1}$ rupees ($1$ rupee on day $1$, $2$ rupees on day $2$, $4$ rupees on day $3$, and so on). Chef's profit from the deal is the total number of rupees he received from his friend minus the total number of rupees he gave his friend.
Chef decided to ask for your advice before accepting the deal. You want to help him by telling him two numbers $D_1$ and $D_2$, where $D_1$ is the maximum value of $D$ such that Chef should accept the deal, i.e. his profit from the deal is positive if $D = D_1$, and $D_2$ is the value of $D$ that leads to the maximum possible profit for Chef. If there are multiple values of $D$ that lead to the maximum profit, $D_2$ is the smallest of these values.
-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first and only line of each test case contains a single integer $A$.
-----Output-----
For each test case, print a single line containing two space-separated integers $D_1$ and $D_2$.
-----Constraints-----
- $1 \le T \le 100,000$
- $5 \le A \le 10^9$
-----Subtasks-----
Subtask #1 (100 points): original constraints
-----Example Input-----
4
5
8
9
1000000000
-----Example Output-----
4 3
5 3
5 4
35 30
|
{"inputs": ["4\n5\n8\n9\n1000000000"], "outputs": ["4 3\n5 3\n5 4\n35 30"]}
| 452
| 45
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s of lower and upper case English letters.
A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where:
0 <= i <= s.length - 2
s[i] is a lower-case letter and s[i + 1] is the same letter but in upper-case or vice-versa.
To make the string good, you can choose two adjacent characters that make the string bad and remove them. You can keep doing this until the string becomes good.
Return the string after making it good. The answer is guaranteed to be unique under the given constraints.
Notice that an empty string is also good.
Please complete the following python code precisely:
```python
class Solution:
def makeGood(self, s: str) -> str:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"leEeetcode\") == \"leetcode\"\n assert candidate(s = \"abBAcC\") == \"\"\n assert candidate(s = \"s\") == \"s\"\n\n\ncheck(Solution().makeGood)"}
| 183
| 63
|
coding
|
Solve the programming task below in a Python markdown code block.
-----Coal Company -----
The Tunisian Coal Mining company uses a train to ferry out coal blocks from its coal mines. The train has N containers numbered from 1 to N which need to
be filled with blocks of coal. Assume there are infinite coal blocks. The containers are arranged in increasing order of capacity, and the ith container
has capacity i. Every container has a specific loading cost ci. The workers fill the containers in rounds. In every round, they choose a subset of
containers and load them with coal blocks. This subset should be such that each subsequent container chosen in a round should be more spacious than the
previous one. Also, the difference in loading cost of consecutive containers should be at least K.
What is the least number of rounds in which all containers can be filled?
-----
Input
-----
The first line contains the number of test cases T. T test cases follow.
Each case contains an integer N and K on the first line, followed by integers c1,...,cn on the second line.
1 <= T <= 100
1 <= N <= 300
1 <= ci <= 1000
1 <= K <= 1000
-----
Output
-----
Output T lines, one for each test case, containing the minimum number of rounds in which all containers could be filled.
-----
Example
-----
Input:
2
3 2
5 4 7
5 1
5 3 4 5 6
Output:
2
1
Explanation:
For the first example, workers can fill the containers of cost 5 and 7 in the first round and the container with cost 4 in the next round. Note that the
containers with cost 5 and 4 cannot be filled consecutively because the loading costs should differ by at least K (which is 2). Also, the containers cannot
be filled in order 5, 7, 4 in one round because the containers filled in a round should be in increasing capacity.
|
{"inputs": ["2\n3 2\n5 4 7\n5 1\n5 3 4 5 6"], "outputs": ["2\n1"]}
| 427
| 38
|
coding
|
Solve the programming task below in a Python markdown code block.
A wildlife study involving ducks is taking place in North America. Researchers are visiting some wetlands in a certain area taking a survey of what they see. The researchers will submit reports that need to be processed by your function.
## Input
The input for your function will be an array with a list of common duck names along with the counts made by the researchers. The names and counts are separated by spaces in one array element. The number of spaces between the name and the count could vary; but, there will always be at least one. A name may be repeated because a report may be a combination of surveys from different locations.
An example of an input array would be:
```
["Redhead 3", "Gadwall 1", "Smew 4", "Greater Scaup 10", "Redhead 3", "Gadwall 9", "Greater Scaup 15", "Common Eider 6"]
```
## Processing
Your function should change the names of the ducks to a six-letter code according to given rules (see below). The six-letter code should be in upper case. The counts should be summed for a species if it is repeated.
## Output
The final data to be returned from your function should be an array sorted by the species codes and the total counts as integers. The codes and the counts should be individual elements.
An example of an array to be returned (based on the example input array above) would be:
```
["COMEID", 6, "GADWAL", 10, "GRESCA", 25, "REDHEA", 6, "SMEW", 4]
```
The codes are strings in upper case and the totaled counts are integers.
### Special Note
If someone has `"Labrador Duck"` in their list, the whole list should be thrown out as this species has been determined to be extinct. The person who submitted the list is obviously unreliable. Their lists will not be included in the final data. In such cases, return an array with a single string element in it: `"Disqualified data"`
Rules for converting a common name to a six-letter code:
* Hyphens should be considered as spaces.
* If a name has only one word, use the first six letters of the name. If that name has less than six letters, use what is there.
* If a name has two words, take the first three letters of each word.
* If a name has three words, take the first two letters of each word.
* If a name has four words, take the first letters from the first two words, and the first two letters from the last two words.
Also feel free to reuse/extend the following starter code:
```python
def create_report(names):
```
|
{"functional": "_inputs = [[['Redhead 5', 'Labrador Duck 9', 'Blue-Winged Teal 25', \"Steller's Eider 200\"]], [['Canvasback 10', 'Mallard 150', 'American Wigeon 45', 'Baikal Teal 3', \"Barrow's Goldeneye 6\", 'Surf Scoter 12']], [['Redhead 3', 'Gadwall 1', 'Smew 4', 'Greater Scaup 10', 'Redhead 3', 'Gadwall 9', 'Greater Scaup 15', 'Common Eider 6']], [['King Eider 20', 'Labrador Duck 2', 'Lesser Scaup 25', 'Masked Duck 2', 'Mottled Duck 10', 'Muscovy Duck 1', 'Northern Pintail 3', 'Northern Shoveler 30']], [['King Eider 20', 'King Eider 2', 'Lesser Scaup 25', 'Masked Duck 2', 'Mottled Duck 10', 'Muscovy Duck 1', 'Northern Pintail 3', 'Northern Shoveler 30']], [['Black-Bellied Whistling-Duck 5', 'Bufflehead 200', \"Steller's Eider 1\", 'Bufflehead 2', 'Spectacled Eider 11', 'Bufflehead 33', 'Eastern Spot-billed Duck 116']], [['Harlequin Duck 6', 'Harlequin Duck 5', 'Red-breasted Merganser 3000', 'Surf Scoter 1', 'Surf Scoter 600']]]\n_outputs = [[['Disqualified data']], [['AMEWIG', 45, 'BAITEA', 3, 'BARGOL', 6, 'CANVAS', 10, 'MALLAR', 150, 'SURSCO', 12]], [['COMEID', 6, 'GADWAL', 10, 'GRESCA', 25, 'REDHEA', 6, 'SMEW', 4]], [['Disqualified data']], [['KINEID', 22, 'LESSCA', 25, 'MASDUC', 2, 'MOTDUC', 10, 'MUSDUC', 1, 'NORPIN', 3, 'NORSHO', 30]], [['BBWHDU', 5, 'BUFFLE', 235, 'ESBIDU', 116, 'SPEEID', 11, 'STEEID', 1]], [['HARDUC', 11, 'REBRME', 3000, 'SURSCO', 601]]]\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(create_report(*i), o[0])"}
| 588
| 794
|
coding
|
Solve the programming task below in a Python markdown code block.
Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and carries the "instructions" for the development and functioning of living organisms.
If you want to know more http://en.wikipedia.org/wiki/DNA
In DNA strings, symbols "A" and "T" are complements of each other, as "C" and "G".
You have function with one side of the DNA (string, except for Haskell); you need to get the other complementary side. DNA strand is never empty or there is no DNA at all (again, except for Haskell).
More similar exercise are found here http://rosalind.info/problems/list-view/ (source)
```python
DNA_strand ("ATTGC") # return "TAACG"
DNA_strand ("GTAT") # return "CATA"
```
Also feel free to reuse/extend the following starter code:
```python
def DNA_strand(dna):
```
|
{"functional": "_inputs = [['AAAA'], ['ATTGC'], ['GTAT'], ['AAGG'], ['CGCG'], ['GTATCGATCGATCGATCGATTATATTTTCGACGAGATTTAAATATATATATATACGAGAGAATACAGATAGACAGATTA']]\n_outputs = [['TTTT'], ['TAACG'], ['CATA'], ['TTCC'], ['GCGC'], ['CATAGCTAGCTAGCTAGCTAATATAAAAGCTGCTCTAAATTTATATATATATATGCTCTCTTATGTCTATCTGTCTAAT']]\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(DNA_strand(*i), o[0])"}
| 208
| 278
|
coding
|
Solve the programming task below in a Python markdown code block.
There is an automatic door at the entrance of a factory. The door works in the following way: when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside, when one or several people come to the door and it is open, all people immediately come inside, opened door immediately closes in d seconds after its opening, if the door is closing and one or several people are coming to the door at the same moment, then all of them will have enough time to enter and only after that the door will close.
For example, if d = 3 and four people are coming at four different moments of time t_1 = 4, t_2 = 7, t_3 = 9 and t_4 = 13 then the door will open three times: at moments 4, 9 and 13. It will close at moments 7 and 12.
It is known that n employees will enter at moments a, 2·a, 3·a, ..., n·a (the value a is positive integer). Also m clients will enter at moments t_1, t_2, ..., t_{m}.
Write program to find the number of times the automatic door will open. Assume that the door is initially closed.
-----Input-----
The first line contains four integers n, m, a and d (1 ≤ n, a ≤ 10^9, 1 ≤ m ≤ 10^5, 1 ≤ d ≤ 10^18) — the number of the employees, the number of the clients, the moment of time when the first employee will come and the period of time in which the door closes.
The second line contains integer sequence t_1, t_2, ..., t_{m} (1 ≤ t_{i} ≤ 10^18) — moments of time when clients will come. The values t_{i} are given in non-decreasing order.
-----Output-----
Print the number of times the door will open.
-----Examples-----
Input
1 1 3 4
7
Output
1
Input
4 3 4 2
7 9 11
Output
4
-----Note-----
In the first example the only employee will come at moment 3. At this moment the door will open and will stay open until the moment 7. At the same moment of time the client will come, so at first he will enter and only after it the door will close. Thus the door will open one time.
|
{"inputs": ["1 1 3 4\n7\n", "2 1 3 4\n7\n", "2 1 3 8\n7\n", "1 1 3 4\n7\n", "4 3 4 2\n7 9 11\n", "4 3 4 2\n3 9 11\n", "5 3 4 2\n7 9 11\n", "5 3 4 4\n7 9 11\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "4\n", "4\n", "5\n", "3\n"]}
| 554
| 154
|
coding
|
Solve the programming task below in a Python markdown code block.
Let x be a string of length at least 1.
We will call x a good string, if for any string y and any integer k (k \geq 2), the string obtained by concatenating k copies of y is different from x.
For example, a, bbc and cdcdc are good strings, while aa, bbbb and cdcdcd are not.
Let w be a string of length at least 1.
For a sequence F=(\,f_1,\,f_2,\,...,\,f_m) consisting of m elements,
we will call F a good representation of w, if the following conditions are both satisfied:
- For any i \, (1 \leq i \leq m), f_i is a good string.
- The string obtained by concatenating f_1,\,f_2,\,...,\,f_m in this order, is w.
For example, when w=aabb, there are five good representations of w:
- (aabb)
- (a,abb)
- (aab,b)
- (a,ab,b)
- (a,a,b,b)
Among the good representations of w, the ones with the smallest number of elements are called the best representations of w.
For example, there are only one best representation of w=aabb: (aabb).
You are given a string w. Find the following:
- the number of elements of a best representation of w
- the number of the best representations of w, modulo 1000000007 \, (=10^9+7)
(It is guaranteed that a good representation of w always exists.)
-----Constraints-----
- 1 \leq |w| \leq 500000 \, (=5 \times 10^5)
- w consists of lowercase letters (a-z).
-----Partial Score-----
- 400 points will be awarded for passing the test set satisfying 1 \leq |w| \leq 4000.
-----Input-----
The input is given from Standard Input in the following format:
w
-----Output-----
Print 2 lines.
- In the first line, print the number of elements of a best representation of w.
- In the second line, print the number of the best representations of w, modulo 1000000007.
-----Sample Input-----
aab
-----Sample Output-----
1
1
|
{"inputs": ["ddc", "aaa", "dec", "aa`", "eec", "aa_", "cee", "ba_"], "outputs": ["1\n1\n", "3\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n"]}
| 518
| 81
|
coding
|
Solve the programming task below in a Python markdown code block.
The Fibonacci sequence is defined as F(n) = F(n-1) + F(n-2). You have developed two sequences of numbers. The first sequence that uses the bitwise XOR operation instead of the addition method is called the Xoronacci number. It is described as follows:
X(n) = X(n-1) XOR X(n-2)
The second sequence that uses the bitwise XNOR operation instead of the addition method is called the XNoronacci number. It is described as follows:
E(n) = E(n-1) XNOR E(n-2)
The first and second numbers of the sequence are as follows:
X(1) = E(1) = a
X(2) = E(2) = b
Your task is to determine the value of max(X(n),E(n)), where n is the n th term of the Xoronacci and XNoronacci sequence.
-----Input:-----
The first line consists of a single integer T denoting the number of test cases.
The first and the only line of each test case consists of three space separated integers a, b and n.
-----Output:-----
For each test case print a single integer max(X(n),E(n)).
-----Constraints-----
- $1 \leq T \leq 1000$
- $2 \leq a,b,n \leq 1000000000000$
-----Sample Input:-----
1
3 4 2
-----Sample Output:-----
4
-----EXPLANATION:-----
Xoronacci Sequence : 3 4 7 …….
XNoronacci Sequence : 3 4 0 …….
Here n = 2. Hence max(X(2),E(2)) = 4
|
{"inputs": ["1\n3 4 2"], "outputs": ["4"]}
| 383
| 18
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Spring is interesting season of year. Chef is thinking about different things, but last time he thinks about interesting game - "Strange Matrix".
Chef has a matrix that consists of n rows, each contains m elements. Initially, the element a_{i}_{j} of matrix equals j. (1 ≤ i ≤ n, 1 ≤ j ≤ m).
Then p times some element a_{i}_{j} is increased by 1.
Then Chef needs to calculate the following:
For each row he tries to move from the last element (with number m) to the first one (with the number 1).
While staying in a_{i}_{j} Chef can only move to a_{i}_{j - 1} only if a_{i}_{j - 1} ≤ a_{i}_{j}.
The cost of such a movement is a_{i}_{j} - a_{i}_{j - 1}.
Otherwise Chef can't move and lose (in this row).
If Chef can move from the last element of the row to the first one, then the answer is the total cost of all the movements.
If Chef can't move from the last element of the row to the first one, then the answer is -1.
Help Chef to find answers for all the rows after P commands of increasing.
------ Input ------
The first line contains three integers n, m and p denoting the number of rows, the number of elements a single row and the number of increasing commands.
Each of next p lines contains two integers i and j denoting that the element a_{i}_{j } is increased by one.
------ Output ------
For each row in a single line print the answer after the P increasing commands.
------ Constraints ------
$1 ≤ n, m, p ≤ 10 ^ 5$
$1 ≤ i ≤ n$
$1 ≤ j ≤ m$
----- Sample Input 1 ------
4 4 6
2 2
3 2
3 2
4 3
4 4
4 3
----- Sample Output 1 ------
3
3
-1
4
----- explanation 1 ------
Here is the whole matrix after P commands:
1 2 3 4
1 3 3 4
1 4 3 4
1 2 5 5
Explanations to the answer:
The first line is without changes: 4-3=1, 3-2=1, 2-1=1. answer = 3.
The second line: 4-3=1, 3-3=0, 3-1=2. The answer is 3.
The third line: 4-3=1, 3-4=-1, Chef can't move to the first number here. Therefore, the answer is -1.
The fourth line: 5-5=0, 5-2=3, 2-1=1. The answer is 4.
|
{"inputs": ["4 4 6\n2 2\n3 2 \n3 2 \n4 3\n4 4\n4 3", "4 4 6\n3 2\n3 2 \n3 2 \n4 3\n4 4\n4 3", "4 4 6\n3 2\n3 2 \n3 2 \n4 3\n4 4\n4 1", "4 4 6\n3 2\n3 3 \n3 2 \n4 3\n4 4\n4 3", "4 6 6\n3 2\n2 3 \n3 2 \n4 3\n4 4\n4 3", "4 6 2\n3 2\n2 3 \n3 2 \n4 3\n4 4\n4 3", "3 6 2\n1 2\n3 0 \n6 2 \n4 3\n1 1\n5 3", "3 4 2\n1 2\n3 0 \n6 2 \n4 3\n1 1\n5 3"], "outputs": ["3\n3\n-1\n4", "3\n3\n-1\n4\n", "3\n3\n-1\n3\n", "3\n3\n3\n4\n", "5\n5\n-1\n5\n", "5\n5\n5\n5\n", "5\n5\n5\n", "3\n3\n3\n"]}
| 661
| 349
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Russian.
Chef has prepared a feast with N dishes for you. You like Chef's cooking, and so you want to eat all the dishes he has prepared for you. You are also given an array A of size N, where A_{i} represents the happiness you get by eating the i-th dish.You will eat all the dishes in a series of steps. In each step, you pick a non empty subset of the remaining dishes and eat them. The happiness you get from eating these dishes is the size of the subset multiplied by the sum of the individual happiness from the dishes in the subset. You want to maximize the happiness you get from the entire feast, which is the sum of happiness in each step.
------ Input ------
The first line contains T, the number of test cases.
The first line of each test case contains a single integer N, denoting the number of dishes prepared by the Chef.
The second line of each test case contains contains N space-separated integers: A_{1}, A_{2}, ..., A_{N} denoting the happiness gained by eating the dishes.
------ Output ------
Output a single number denoting the maximum happiness you can get from the feast.
------ Constraints ------
1 ≤ T ≤ 8
1 ≤ N ≤ 10^{5}
-10^{8} ≤ A_{i} ≤ 10^{8}
------ Subtasks ------
Subtask #1: A_{i} ≤ 0 (30 points)
Subtask #2: Original Constraints (70 points)
----- Sample Input 1 ------
1
3
-8 0 -2
----- Sample Output 1 ------
-10
----- explanation 1 ------
Example case 1. You can eat the first dish in the first step,
the second dish in the second step and the third dish in the third step.
total happiness = 1*(-8) + 1*0 + 1*(-2) = -10
----- Sample Input 2 ------
1
3
1 2 3
----- Sample Output 2 ------
18
----- explanation 2 ------
|
{"inputs": ["1\n3\n1 2 3", "1\n3\n-8 0 -2"], "outputs": ["18", "-10"]}
| 455
| 37
|
coding
|
Solve the programming task below in a Python markdown code block.
This is the easy version of this problem. In this version, we do not have queries. Note that we have multiple test cases in this version. You can make hacks only if both versions of the problem are solved.
An array $b$ of length $m$ is good if for all $i$ the $i$-th element is greater than or equal to $i$. In other words, $b$ is good if and only if $b_i \geq i$ for all $i$ ($1 \leq i \leq m$).
You are given an array $a$ consisting of $n$ positive integers. Find the number of pairs of indices $(l, r)$, where $1 \le l \le r \le n$, such that the array $[a_l, a_{l+1}, \ldots, a_r]$ is good.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \leq t \leq 2 \cdot 10^5$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \leq n \leq 2 \cdot 10^5$), the length of the array $a$.
The second line of each test case contains $n$ space-separated integers $a_1,a_2,\ldots,a_n$ ($1 \leq a_i \leq n$), representing the array $a$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the number of suitable pairs of indices.
-----Examples-----
Input
3
3
1 2 3
3
1 1 1
4
2 1 4 3
Output
6
3
7
-----Note-----
In the first test case, all subarrays of $a$ are good, so all pairs are suitable.
In the second test case, the pairs $(1, 1)$, $(2, 2)$, and $(3, 3)$ are suitable. For example, when $(l, r) = (1, 2)$, the array $b=[1,1]$ is not good because $b_2 < 2$.
|
{"inputs": ["3\n3\n1 2 3\n3\n1 1 1\n4\n2 1 4 3\n"], "outputs": ["6\n3\n7\n"]}
| 515
| 44
|
coding
|
Solve the programming task below in a Python markdown code block.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and the contest is not carried out;
2. on this day the gym is closed and the contest is carried out;
3. on this day the gym is open and the contest is not carried out;
4. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 3) separated by space, where:
* ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
* ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
* ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
* ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
* to do sport on any two consecutive days,
* to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
|
{"inputs": ["1\n2\n", "1\n0\n", "1\n3\n", "1\n1\n", "2\n0 2\n", "2\n1 2\n", "2\n2 3\n", "2\n0 0\n"], "outputs": ["0\n", "1\n", "0\n", "0\n", "1\n", "0\n", "0\n", "2\n"]}
| 686
| 94
|
coding
|
Solve the programming task below in a Python markdown code block.
Write a function which reduces fractions to their simplest form! Fractions will be presented as an array/tuple (depending on the language), and the reduced fraction must be returned as an array/tuple:
```
input: [numerator, denominator]
output: [newNumerator, newDenominator]
example: [45, 120] --> [3, 8]
```
All numerators and denominators will be positive integers.
Note: This is an introductory Kata for a series... coming soon!
Also feel free to reuse/extend the following starter code:
```python
def reduce_fraction(fraction):
```
|
{"functional": "_inputs = [[[60, 20]], [[80, 120]], [[4, 2]], [[45, 120]], [[1000, 1]], [[1, 1]], [[10956590, 13611876]], [[35884747, 5576447]], [[24622321, 24473455]], [[4255316, 11425973]]]\n_outputs = [[[3, 1]], [[2, 3]], [[2, 1]], [[3, 8]], [[1000, 1]], [[1, 1]], [[30605, 38022]], [[76841, 11941]], [[42673, 42415]], [[17228, 46259]]]\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(reduce_fraction(*i), o[0])"}
| 143
| 369
|
coding
|
Solve the programming task below in a Python markdown code block.
Ivan is developing his own computer game. Now he tries to create some levels for his game. But firstly for each level he needs to draw a graph representing the structure of the level.
Ivan decided that there should be exactly n_{i} vertices in the graph representing level i, and the edges have to be bidirectional. When constructing the graph, Ivan is interested in special edges called bridges. An edge between two vertices u and v is called a bridge if this edge belongs to every path between u and v (and these vertices will belong to different connected components if we delete this edge). For each level Ivan wants to construct a graph where at least half of the edges are bridges. He also wants to maximize the number of edges in each constructed graph.
So the task Ivan gave you is: given q numbers n_1, n_2, ..., n_{q}, for each i tell the maximum number of edges in a graph with n_{i} vertices, if at least half of the edges are bridges. Note that the graphs cannot contain multiple edges or self-loops.
-----Input-----
The first line of input file contains a positive integer q (1 ≤ q ≤ 100 000) — the number of graphs Ivan needs to construct.
Then q lines follow, i-th line contains one positive integer n_{i} (1 ≤ n_{i} ≤ 2·10^9) — the number of vertices in i-th graph.
Note that in hacks you have to use q = 1.
-----Output-----
Output q numbers, i-th of them must be equal to the maximum number of edges in i-th graph.
-----Example-----
Input
3
3
4
6
Output
2
3
6
-----Note-----
In the first example it is possible to construct these graphs: 1 - 2, 1 - 3; 1 - 2, 1 - 3, 2 - 4; 1 - 2, 1 - 3, 2 - 3, 1 - 4, 2 - 5, 3 - 6.
|
{"inputs": ["3\n3\n4\n6\n", "3\n1\n4\n6\n", "1\n15320\n", "1\n14179\n", "3\n3\n4\n6\n", "1\n164568\n", "1\n844906\n", "1\n8027497\n"], "outputs": ["2\n3\n6\n", "0\n3\n6\n", "30290\n", "28022\n", "2\n3\n6\n", "327988\n", "1687212\n", "16046980\n"]}
| 455
| 160
|
coding
|
Solve the programming task below in a Python markdown code block.
In this Kata we focus on finding a sum S(n) which is the total number of divisors taken for all natural numbers less or equal to n. More formally, we investigate the sum of n components denoted by d(1) + d(2) + ... + d(n) in which for any i starting from 1 up to n the value of d(i) tells us how many distinct numbers divide i without a remainder.
Your solution should work for possibly large values of n without a timeout.
Assume n to be greater than zero and not greater than 999 999 999 999 999.
Brute force approaches will not be feasible options in such cases. It is fairly simple to conclude that for every n>1 there holds a recurrence S(n) = S(n-1) + d(n) with initial case S(1) = 1.
For example:
S(1) = 1
S(2) = 3
S(3) = 5
S(4) = 8
S(5) = 10
But is the fact useful anyway? If you find it is rather not, maybe this will help:
Try to convince yourself that for any natural k, the number S(k) is the same as the number of pairs (m,n) that solve the inequality mn <= k in natural numbers.
Once it becomes clear, we can think of a partition of all the solutions into classes just by saying that a pair (m,n) belongs to the class indexed by n.
The question now arises if it is possible to count solutions of n-th class. If f(n) stands for the number of solutions that belong to n-th class, it means that S(k) = f(1) + f(2) + f(3) + ...
The reasoning presented above leads us to some kind of a formula for S(k), however not necessarily the most efficient one. Can you imagine that all the solutions to inequality mn <= k can be split using sqrt(k) as pivotal item?
Also feel free to reuse/extend the following starter code:
```python
def count_divisors(n):
```
|
{"functional": "_inputs = [[5], [10], [20], [59], [105], [785], [1001], [8009], [9999999999999], [9999999999998], [9999999999995], [9999999949950]]\n_outputs = [[10], [27], [66], [249], [510], [5364], [7077], [73241], [300880375389561], [300880375389537], [300880375389493], [300880373832097]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(count_divisors(*i), o[0])"}
| 466
| 355
|
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 with the following properties:
nums.length == 2 * n.
nums contains n + 1 unique elements.
Exactly one element of nums is repeated n times.
Return the element that is repeated n times.
Please complete the following python code precisely:
```python
class Solution:
def repeatedNTimes(self, nums: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,3]) == 3\n assert candidate(nums = [2,1,2,5,3,2]) == 2\n assert candidate(nums = [5,1,5,2,5,3,5,4]) == 5\n\n\ncheck(Solution().repeatedNTimes)"}
| 97
| 87
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a tree consisting of $n$ vertices. A number is written on each vertex; the number on vertex $i$ is equal to $a_i$.
Recall that a simple path is a path that visits each vertex at most once. Let the weight of the path be the bitwise XOR of the values written on vertices it consists of. Let's say that a tree is good if no simple path has weight $0$.
You can apply the following operation any number of times (possibly, zero): select a vertex of the tree and replace the value written on it with an arbitrary positive integer. What is the minimum number of times you have to apply this operation in order to make the tree good?
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of vertices.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i < 2^{30}$) — the numbers written on vertices.
Then $n - 1$ lines follow, each containing two integers $x$ and $y$ ($1 \le x, y \le n; x \ne y$) denoting an edge connecting vertex $x$ with vertex $y$. It is guaranteed that these edges form a tree.
-----Output-----
Print a single integer — the minimum number of times you have to apply the operation in order to make the tree good.
-----Examples-----
Input
6
3 2 1 3 2 1
4 5
3 4
1 4
2 1
6 1
Output
2
Input
4
2 1 1 1
1 2
1 3
1 4
Output
0
Input
5
2 2 2 2 2
1 2
2 3
3 4
4 5
Output
2
-----Note-----
In the first example, it is enough to replace the value on the vertex $1$ with $13$, and the value on the vertex $4$ with $42$.
|
{"inputs": ["1\n25\n", "4\n2 1 1 1\n1 2\n1 3\n1 4\n", "5\n2 2 2 2 2\n1 2\n2 3\n3 4\n4 5\n", "6\n3 2 1 3 2 1\n4 5\n3 4\n1 4\n2 1\n6 1\n", "10\n7 4 6 7 6 6 7 5 7 5\n8 7\n4 5\n9 6\n2 5\n4 8\n9 10\n4 3\n9 4\n1 8\n", "20\n4 1 3 4 7 3 8 7 7 3 1 1 7 1 9 5 1 10 6 3\n6 15\n12 11\n18 1\n9 17\n8 1\n1 20\n13 7\n10 15\n20 19\n10 16\n8 5\n2 11\n14 3\n6 1\n1 12\n3 18\n6 4\n8 13\n9 18\n"], "outputs": ["0\n", "0\n", "2\n", "2\n", "1\n", "3\n"]}
| 472
| 330
|
coding
|
Solve the programming task below in a Python markdown code block.
Baby is getting his frst tooth. This means more sleepless nights, but with the fun of feeling round his gums and trying to guess which will be first out!
Probably best have a sweepstake with your friends - because you have the best chance of knowing. You can feel the gums and see where the raised bits are - most raised, most likely tooth to come through first!
Given an array of numbers (t) to represent baby's gums, you need to return the index of the lump that is most pronounced.
The most pronounced lump is the one that has the biggest differential to its surrounding values. e.g.:
```
[1, 2, 4] = 2
index 0 has a differential of -1 to its right (it is lower so the figure is negative)
index 1 has a differential of +1 to its left, and -2 to its right. Total is -1.
index 2 has a differential of +2 to its left, and nothing to its right,
```
If there is no distinct highest value (more than one occurence of the largest differential), return -1.
Also feel free to reuse/extend the following starter code:
```python
def first_tooth(array):
```
|
{"functional": "_inputs = [[[1, 2, 3, 4]], [[1, 2, 6, 4]], [[1, 2, 5, 7, 1, 0, 9]], [[9, 2, 8, 1]], [[1, 1, 1, 1]], [[20, 9, 16, 19]], [[15]]]\n_outputs = [[3], [2], [6], [2], [-1], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(first_tooth(*i), o[0])"}
| 270
| 258
|
coding
|
Solve the programming task below in a Python markdown code block.
The solution of $ x ^ 3 = q $ is to calculate the recurrence formula $ x_ {n + 1} = x_n-\ frac {x_ {n} ^ 3 --q} {3x_ {n} ^ 2} $ It can be calculated approximately with.
Put a positive number $ \ frac {q} {2} $ in $ x_1 $
$ x_2 = x_1-\ frac {x_ {1} ^ 3 --q} {3x_ {1} ^ 2} $, $ x_3 = x_2-\ frac {x_ {2} ^ 3 --q} {3x_ {2} ^ Calculate as 2} $,….
While doing this calculation
When the value of $ | x ^ 3 --q | $ becomes small enough, stop the calculation and use the last calculated $ x_n $ as an approximate solution of $ x ^ 3 = q $.
Follow this method to create a program that outputs an approximation of the cube root of $ q $ for the input positive integer $ q $. However, use $ | x ^ 3-q | <0.00001 q $ to determine that it is "small enough".
input
Multiple datasets are given. For each dataset, $ q $ ($ 1 \ leq q <2 ^ {31} $) (integer) is given on one line. The end of the input is -1.
The number of datasets does not exceed 50.
output
Print $ x $ (real number) on one line for each dataset. The output result may contain an error of 0.00001 or less.
Example
Input
15
15
-1
Output
2.466212
2.466212
|
{"inputs": ["15\n8\n-1", "15\n3\n-1", "15\n1\n-1", "15\n5\n-1", "15\n9\n-1", "15\n2\n-1", "15\n6\n-1", "15\n4\n-1"], "outputs": ["2.466212\n2.000000\n", "2.466212\n1.442253\n", "2.466212\n1.000002\n", "2.466212\n1.709976\n", "2.466212\n2.080084\n", "2.466212\n1.259921\n", "2.466212\n1.817124\n", "2.466212\n1.587401\n"]}
| 401
| 238
|
coding
|
Solve the programming task below in a Python markdown code block.
Given is a number sequence A of length N.
Find the number of integers i \left(1 \leq i \leq N\right) with the following property:
- For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.
-----Constraints-----
- All values in input are integers.
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^6
-----Input-----
Input is given from Standard Input in the following format:
N
A_1 A_2 \cdots A_N
-----Output-----
Print the answer.
-----Sample Input-----
5
24 11 8 3 16
-----Sample Output-----
3
The integers with the property are 2, 3, and 4.
|
{"inputs": ["4\n6 8 5 5", "4\n5 8 5 5", "4\n6 8 2 5", "4\n7 8 5 5", "4\n8 8 5 5", "4\n3 8 2 5", "4\n7 9 5 5", "4\n7 9 8 5"], "outputs": ["2\n", "1\n", "2\n", "2\n", "0\n", "3\n", "2\n", "4\n"]}
| 209
| 126
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an integer sequence $A_1, A_2, \ldots, A_N$. For any pair of integers $(l, r)$ such that $1 \le l \le r \le N$, let's define $\mathrm{OR}(l, r)$ as $A_l \lor A_{l+1} \lor \ldots \lor A_r$. Here, $\lor$ is the bitwise OR operator.
In total, there are $\frac{N(N+1)}{2}$ possible pairs $(l, r)$, i.e. $\frac{N(N+1)}{2}$ possible values of $\mathrm{OR}(l, r)$. Determine if all these values are pairwise distinct.
-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$.
-----Output-----
For each test case, print a single line containing the string "YES" if all values of $\mathrm{OR}(l, r)$ are pairwise distinct or "NO" otherwise (without quotes).
-----Constraints-----
- $1 \le T \le 300$
- $1 \le N \le 10^5$
- $0 \le A_i \le 10^{18}$ for each valid $i$
- the sum of $N$ over all test cases does not exceed $3 \cdot 10^5$
-----Example Input-----
4
3
1 2 7
2
1 2
3
6 5 8
5
12 32 45 23 47
-----Example Output-----
NO
YES
YES
NO
-----Explanation-----
Example case 1: The values of $\mathrm{OR}(l, r)$ are $1, 2, 7, 3, 7, 7$ (corresponding to the contiguous subsequences $[1], [2], [7], [1,2], [2,7], [1,2,7]$ respectively). We can see that these values are not pairwise distinct.
Example case 2: The values of $\mathrm{OR}(l, r)$ are $1, 2, 3$ (corresponding to the contiguous subsequences $[1], [2], [1, 2]$ respectively) and they are pairwise distinct.
|
{"inputs": ["4\n3\n1 2 7\n2\n1 2\n3\n6 5 8\n5\n12 32 45 23 47"], "outputs": ["NO\nYES\nYES\nNO"]}
| 564
| 57
|
coding
|
Solve the programming task below in a Python markdown code block.
The number `1035` is the smallest integer that exhibits a non frequent property: one its multiples, `3105 = 1035 * 3`, has its same digits but in different order, in other words, `3105`, is one of the permutations of `1035`.
The number `125874` is the first integer that has this property when the multiplier is `2`, thus: `125874 * 2 = 251748`
Make the function `search_permMult()`, that receives an upper bound, nMax and a factor k and will output the amount of pairs bellow nMax that are permuted when an integer of this range is multiplied by `k`. The pair will be counted if the multiple is less than `nMax`, too
Let'see some cases:
```python
search_permMult(10000, 7) === 1 # because we have the pair 1359, 9513
search_permMult(5000, 7) === 0 # no pairs found, as 9513 > 5000
search_permMult(10000, 4) === 2 # we have two pairs (1782, 7128) and (2178, 8712)
search_permMult(8000, 4) === 1 # only the pair (1782, 7128)
search_permMult(5000, 3) === 1 # only the pair (1035, 3105)
search_permMult(10000, 3) === 2 # found pairs (1035, 3105) and (2475, 7425)
```
Features of the random Tests:
```
10000 <= nMax <= 100000
3 <= k <= 7
```
Enjoy it and happy coding!!
Also feel free to reuse/extend the following starter code:
```python
def search_permMult(nMax, k):
```
|
{"functional": "_inputs = [[10000, 7], [5000, 7], [10000, 4], [8000, 4], [5000, 3], [10000, 3]]\n_outputs = [[1], [0], [2], [1], [1], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(search_permMult(*i), o[0])"}
| 489
| 224
|
coding
|
Solve the programming task below in a Python markdown code block.
Let us define the FizzBuzz sequence a_1,a_2,... as follows:
- If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}.
- If the above does not hold but 3 divides i, a_i=\mbox{Fizz}.
- If none of the above holds but 5 divides i, a_i=\mbox{Buzz}.
- If none of the above holds, a_i=i.
Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
-----Constraints-----
- 1 \leq N \leq 10^6
-----Input-----
Input is given from Standard Input in the following format:
N
-----Output-----
Print the sum of all numbers among the first N terms of the FizzBuzz sequence.
-----Sample Input-----
15
-----Sample Output-----
60
The first 15 terms of the FizzBuzz sequence are:
1,2,\mbox{Fizz},4,\mbox{Buzz},\mbox{Fizz},7,8,\mbox{Fizz},\mbox{Buzz},11,\mbox{Fizz},13,14,\mbox{FizzBuzz}
Among them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.
|
{"inputs": ["3", "4", "8", "1", "7", "0", "1\n", "16"], "outputs": ["3\n", "7\n", "22\n", "1\n", "14\n", "0\n", "1\n", "76\n"]}
| 299
| 67
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in nums.
The next greater number of a number x is the first greater number to its traversing-order next in the array, which means you could search circularly to find its next greater number. If it doesn't exist, return -1 for this number.
Please complete the following python code precisely:
```python
class Solution:
def nextGreaterElements(self, nums: List[int]) -> List[int]:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,1]) == [2,-1,2]\n assert candidate(nums = [1,2,3,4,3]) == [2,3,4,-1,4]\n\n\ncheck(Solution().nextGreaterElements)"}
| 138
| 70
|
coding
|
Solve the programming task below in a Python markdown code block.
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter.
Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva.
You are given an encoding s of some word, your task is to decode it.
-----Input-----
The first line contains a positive integer n (1 ≤ n ≤ 2000) — the length of the encoded word.
The second line contains the string s of length n consisting of lowercase English letters — the encoding.
-----Output-----
Print the word that Polycarp encoded.
-----Examples-----
Input
5
logva
Output
volga
Input
2
no
Output
no
Input
4
abba
Output
baba
-----Note-----
In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva.
In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same.
In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba.
|
{"inputs": ["1\nw\n", "1\nw\n", "1\nv\n", "1\nu\n", "1\nt\n", "1\ns\n", "2\nno\n", "2\ncb\n"], "outputs": ["w\n", "w\n", "v\n", "u\n", "t\n", "s\n", "no\n", "cb\n"]}
| 527
| 87
|
coding
|
Solve the programming task below in a Python markdown code block.
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:
Operation ++ increases the value of variable x by 1. Operation -- decreases the value of variable x by 1.
A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.
A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.
You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.
Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
-----Output-----
Print a single integer — the final value of x.
-----Examples-----
Input
1
++X
Output
1
Input
2
X++
--X
Output
0
|
{"inputs": ["1\n++X\n", "1\nX--\n", "1\nX--\n", "1\n--X\n", "1\nX++\n", "1\n++X\n", "2\nX++\n--X\n", "2\n--X\n--X\n"], "outputs": ["1\n", "-1\n", "-1\n", "-1\n", "1\n", "1\n", "0\n", "-2\n"]}
| 323
| 104
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a string containing characters $\mbox{A}$ and $\mbox{B}$ only. Your task is to change it into a string such that there are no matching adjacent characters. To do this, you are allowed to delete zero or more characters in the string.
Your task is to find the minimum number of required deletions.
Example
$\textbf{s}=\textit{AABAAB}$
Remove an $\mbox{A}$ at positions $0$ and $3$ to make $\textbf{s}=\textit{ABAB}$ in $2$ deletions.
Function Description
Complete the alternatingCharacters function in the editor below.
alternatingCharacters has the following parameter(s):
string s: a string
Returns
int: the minimum number of deletions required
Input Format
The first line contains an integer $\textit{q}$, the number of queries.
The next $\textit{q}$ lines each contain a string $\boldsymbol{\mathrm{~S~}}$ to analyze.
Constraints
$1\leq q\leq10$
$1\leq\:\text{length of s}\:\leq10^5$
Each string $\boldsymbol{\mathrm{~S~}}$ will consist only of characters $\mbox{A}$ and $\mbox{B}$.
Sample Input
5
AAAA
BBBBB
ABABABAB
BABABA
AAABBB
Sample Output
3
4
0
0
4
Explanation
The characters marked red are the ones that can be deleted so that the string does not have matching adjacent characters.
|
{"inputs": ["5\nAAAA\nBBBBB\nABABABAB\nBABABA\nAAABBB\n"], "outputs": ["3\n4\n0\n0\n4\n"]}
| 356
| 39
|
coding
|
Solve the programming task below in a Python markdown code block.
Everyone knows what a square looks like. Mathematically, a square is a regular quadrilateral. This means that it has four equal sides and four equal angles (90 degree angles).
One beautiful day, Johnny eagerly examined the interesting properties of squares. He did not forget you, his best friend and a talented programmer and thus made a problem about squares to challenge your programming ability. The problem is: given a set of N points in the plane, how many squares are there such that all their corners belong to this set?
Now let's show Johnny your skill!
------ Input ------
The first line contains t, the number of test cases (about 10). Then t test cases follow.
Each test case has the following form:
The first line contains an integer N, the number of points in the given set (4 ≤ N ≤ 500).
Then N lines follow, each line contains two integers X, Y describing coordinates of a point (-50 ≤ X, Y ≤ 50).
------ Output ------
For each test case, print in a single line the number of squares that have vertices belong to the given set.
----- Sample Input 1 ------
1
7
0 0
0 1
1 0
1 1
1 2
2 1
2 2
----- Sample Output 1 ------
3
----- explanation 1 ------
The three squares are: (0 0), (0 1), (1 1), (1 0)(1 1), (1 2), (2 2), (2 1)(0 1), (1 0), (2 1), (1 2)
|
{"inputs": ["1\n7\n0 0\n0 1\n1 0\n1 1\n1 2\n2 1\n2 2"], "outputs": ["3"]}
| 362
| 42
|
coding
|
Solve the programming task below in a Python markdown code block.
For every string, after every occurrence of `'and'` and `'but'`, insert the substring `'apparently'` directly after the occurrence.
If input does not contain 'and' or 'but', return the original string. If a blank string, return `''`.
If substring `'apparently'` is already directly after an `'and'` and/or `'but'`, do not add another. (Do not add duplicates).
# Examples:
Input 1
'It was great and I've never been on live television before but sometimes I don't watch this.'
Output 1
'It was great and apparently I've never been on live television before but apparently sometimes I don't watch this.'
Input 2
'but apparently'
Output 2
'but apparently'
(no changes because `'apparently'` is already directly after `'but'` and there should not be a duplicate.)
An occurrence of `'and'` and/or `'but'` only counts when it is at least one space separated. For example `'andd'` and `'bbut'` do not count as occurrences, whereas `'b but'` and `'and d'` does count.
reference that may help:
https://www.youtube.com/watch?v=rz5TGN7eUcM
Also feel free to reuse/extend the following starter code:
```python
def apparently(string):
```
|
{"functional": "_inputs = [['A fast-food resteraunt down the street was grumbling my tummy but I could not go.'], ['apparently'], ['and'], ['but'], ['but apparently'], ['and apparently'], ['but but but and and and'], [''], ['but and apparently apparently apparently apparently'], ['and apparentlybutactuallynot voilewtfman'], ['and unapparently'], ['but apparentlx and apparentlx'], ['but the bread and butter apparently brand apparently']]\n_outputs = [['A fast-food resteraunt down the street was grumbling my tummy but apparently I could not go.'], ['apparently'], ['and apparently'], ['but apparently'], ['but apparently'], ['and apparently'], ['but apparently but apparently but apparently and apparently and apparently and apparently'], [''], ['but apparently and apparently apparently apparently apparently'], ['and apparently apparentlybutactuallynot voilewtfman'], ['and apparently unapparently'], ['but apparently apparentlx and apparently apparentlx'], ['but apparently the bread and apparently butter apparently brand apparently']]\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(apparently(*i), o[0])"}
| 303
| 354
|
coding
|
Solve the programming task below in a Python markdown code block.
One suggestion to build a satisfactory password is to start with a memorable phrase or sentence and make a password by extracting the first letter of each word.
Even better is to replace some of those letters with numbers (e.g., the letter `O` can be replaced with the number `0`):
* instead of including `i` or `I` put the number `1` in the password;
* instead of including `o` or `O` put the number `0` in the password;
* instead of including `s` or `S` put the number `5` in the password.
## Examples:
```
"Give me liberty or give me death" --> "Gml0gmd"
"Keep Calm and Carry On" --> "KCaC0"
```
Also feel free to reuse/extend the following starter code:
```python
def make_password(phrase):
```
|
{"functional": "_inputs = [['Give me liberty or give me death'], ['Keep Calm and Carry On']]\n_outputs = [['Gml0gmd'], ['KCaC0']]\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(make_password(*i), o[0])"}
| 199
| 178
|
coding
|
Solve the programming task below in a Python markdown code block.
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.
-----Input-----
The first line contains a non-empty string s — the sum Xenia needs to count. String s contains no spaces. It only contains digits and characters "+". Besides, string s is a correct sum of numbers 1, 2 and 3. String s is at most 100 characters long.
-----Output-----
Print the new sum that Xenia can count.
-----Examples-----
Input
3+2+1
Output
1+2+3
Input
1+1+3+1+3
Output
1+1+1+3+3
Input
2
Output
2
|
{"inputs": ["2\n", "1\n", "3\n", "1\n", "3\n", "2\n", "1+1\n", "1+2\n"], "outputs": ["2\n", "1\n", "3\n", "1\n", "3\n", "2\n", "1+1\n", "1+2\n"]}
| 306
| 78
|
coding
|
Solve the programming task below in a Python markdown code block.
The educational program (AHK Education) of the Aiz Broadcasting Corporation broadcasts a program called "Play with Tsukuro" for children. Today is the time to make a box with drawing paper, but I would like to see if the rectangular drawing paper I prepared can make a rectangular parallelepiped. However, do not cut or fold the drawing paper.
Given six rectangles, write a program to determine if you can make a rectangular parallelepiped using them.
Input
The input is given in the following format.
h1 w1
h2 w2
h3 w3
h4 w4
h5 w5
h6 w6
The input consists of 6 lines, each line given the integer hi (1 ≤ hi ≤ 1000) for the vertical length of each rectangle and the integer wi (1 ≤ wi ≤ 1000) for the horizontal length.
Output
If a rectangular parallelepiped can be created, "yes" is output, and if it cannot be created, "no" is output. However, since a cube is a kind of rectangular parallelepiped, "yes" is output even if it is a cube.
Examples
Input
2 2
2 3
2 3
2 3
2 2
3 2
Output
yes
Input
2 2
2 3
2 3
2 3
2 2
2 2
Output
no
|
{"inputs": ["2 2\n2 3\n2 3\n2 3\n2 2\n5 2", "2 2\n2 3\n2 2\n2 3\n2 2\n2 2", "2 2\n2 3\n2 3\n2 2\n2 2\n5 2", "2 2\n2 3\n2 2\n2 3\n2 2\n2 3", "2 2\n2 3\n4 2\n2 3\n2 2\n2 3", "2 2\n2 3\n4 4\n2 3\n2 2\n2 3", "2 2\n2 3\n4 4\n2 3\n1 2\n2 3", "2 2\n2 3\n4 4\n2 3\n1 1\n2 3"], "outputs": ["no\n", "no\n", "no\n", "no\n", "no\n", "no\n", "no\n", "no\n"]}
| 317
| 238
|
coding
|
Solve the programming task below in a Python markdown code block.
CQXYM found a rectangle A of size n × m. There are n rows and m columns of blocks. Each block of the rectangle is an obsidian block or empty. CQXYM can change an obsidian block to an empty block or an empty block to an obsidian block in one operation.
A rectangle M size of a × b is called a portal if and only if it satisfies the following conditions:
* a ≥ 5,b ≥ 4.
* For all 1 < x < a, blocks M_{x,1} and M_{x,b} are obsidian blocks.
* For all 1 < x < b, blocks M_{1,x} and M_{a,x} are obsidian blocks.
* For all 1<x<a,1<y<b, block M_{x,y} is an empty block.
* M_{1, 1}, M_{1, b}, M_{a, 1}, M_{a, b} can be any type.
Note that the there must be a rows and b columns, not b rows and a columns.
Note that corners can be any type
CQXYM wants to know the minimum number of operations he needs to make at least one sub-rectangle a portal.
Input
The first line contains an integer t (t ≥ 1), which is the number of test cases.
For each test case, the first line contains two integers n and m (5 ≤ n ≤ 400, 4 ≤ m ≤ 400).
Then n lines follow, each line contains m characters 0 or 1. If the j-th character of i-th line is 0, block A_{i,j} is an empty block. Otherwise, block A_{i,j} is an obsidian block.
It is guaranteed that the sum of n over all test cases does not exceed 400.
It is guaranteed that the sum of m over all test cases does not exceed 400.
Output
Output t answers, and each answer in a line.
Examples
Input
1
5 4
1000
0000
0110
0000
0001
Output
12
Input
1
9 9
001010001
101110100
000010011
100000001
101010101
110001111
000001111
111100000
000110000
Output
5
Note
In the first test case, the final portal is like this:
1110
1001
1001
1001
0111
|
{"inputs": ["1\n5 4\n1000\n0000\n0110\n0001\n0001\n", "1\n5 4\n1000\n0000\n1110\n0001\n0000\n", "1\n5 4\n1011\n0000\n1010\n0000\n1000\n", "1\n5 4\n1000\n0010\n0110\n0001\n0001\n", "1\n5 4\n1011\n0000\n1010\n0001\n1000\n", "1\n5 4\n1000\n0100\n0110\n0101\n0000\n", "1\n5 4\n1011\n0000\n1010\n1001\n1000\n", "1\n5 4\n0011\n0001\n0010\n1001\n1101\n"], "outputs": ["11\n", "10\n", "9\n", "12\n", "8\n", "13\n", "7\n", "6\n"]}
| 639
| 306
|
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.
In one move, you can choose one element of nums and change it to any value.
Return the minimum difference between the largest and smallest value of nums after performing at most three moves.
Please complete the following python code precisely:
```python
class Solution:
def minDifference(self, nums: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [5,3,2,4]) == 0\n assert candidate(nums = [1,5,0,10,14]) == 1\n assert candidate(nums = [3,100,20]) == 0\n\n\ncheck(Solution().minDifference)"}
| 93
| 78
|
coding
|
Solve the programming task below in a Python markdown code block.
In this Kata, we are going to determine if the count of each of the characters in a string can be equal if we remove a single character from that string.
For example:
```
solve('abba') = false -- if we remove any character, the count of each character will not be equal.
solve('abbba') = true -- if we remove one b, the count of each character becomes 2.
solve('aaaa') = true -- if we remove one character, the remaining characters have same count.
solve('wwwf') = true -- if we remove f, the remaining letters have same count.
```
More examples in the test cases. Empty string is not tested.
Good luck!
Also feel free to reuse/extend the following starter code:
```python
def solve(s):
```
|
{"functional": "_inputs = [['aaaa'], ['abba'], ['abbba'], ['aabbcc'], ['aaaabb'], ['aabbccddd'], ['aabcde'], ['abcde'], ['aaabcde'], ['abbccc']]\n_outputs = [[True], [False], [True], [False], [False], [True], [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(solve(*i), o[0])"}
| 176
| 222
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese , Russian and Vietnamese
Churu is taking the course called “Introduction to Data Structures”. Yesterday, he learned how to use a stack to check is a given parentheses expression is balanced or not. He finds it intriguing, and more importantly, he was given an assignment. The professor gave him a string S containing characters “(” and “)”, and asked him numerous queries of the form (x, y), i.e., if the substring S[x, y] represents a balanced parentheses expression or not. Here, S[x, y] refers to the substring of S from index x to y (both inclusive), assuming 0-based indexing. Diligently working through his assignment, our ace student Churu finds that all the queries given by the professor represented balanced substrings. Later, Churu lost his original string but he has all the queries.
Churu wants to restore his original string. As there can be many valid strings, print any one among them.
------ Input ------
First line of input contains an integer T denoting the number of test cases.
First line of each of test case contains two space-separated integers: N, K representing the length of the string and number of queries asked by professor, respectively.
Each of the next K lines contains a space-separated pair of integers: x and y, denoting a query.
------ Output ------
Print T lines, with the i^{th} one containing the solution string for the i^{th} test case.
------ Constraints ------
Subtask #1: 20 points
$1 ≤ T ≤ 5, 2 ≤ N ≤ 16, 1 ≤ K ≤ 20, x ≤ y$
Subtask #2: 80 points
$1 ≤ T ≤ 5, 2 ≤ N ≤ 2000, 1 ≤ K ≤ 30, x ≤ y$
----- Sample Input 1 ------
2
4 1
0 3
4 2
0 3
1 2
----- Sample Output 1 ------
()()
(())
----- explanation 1 ------
For the first sample case, "(())" are "()()" are two possible outputs. Printing anyone will do.
|
{"inputs": ["2\n4 1\n0 3\n4 2\n0 3\n1 2", "2\n4 1\n0 3\n4 1\n0 3\n1 2", "2\n4 1\n1 2\n4 2\n0 3\n2 1", "2\n4 1\n0 3\n4 2\n0 3\n2 2", "2\n4 1\n0 3\n4 2\n0 3\n2 0", "2\n4 1\n0 3\n4 1\n0 3\n1 0", "2\n4 1\n0 3\n4 1\n0 3\n1 1", "2\n4 1\n0 3\n4 1\n0 3\n2 0"], "outputs": ["()()\n(())", "()()\n()()\n", "(())\n()()\n", "()()\n()()\n", "()()\n()()\n", "()()\n()()\n", "()()\n()()\n", "()()\n()()\n"]}
| 479
| 247
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well.
Chef aims to be the richest person in Chefland by his new restaurant franchise. Currently, his assets are worth $A$ billion dollars and have no liabilities. He aims to increase his assets by $X$ billion dollars per year.
Also, all the richest people in Chefland are not planning to grow and maintain their current worth.
To be the richest person in Chefland, he needs to be worth at least $B$ billion dollars. How many years will it take Chef to reach his goal if his value increases by $X$ billion dollars each year?
------ Input ------
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, three integers $A$, $B$, $X$.
------ Output ------
For each test case, output in a single line the answer to the problem.
------ Constraints ------
$1 ≤ T ≤ 21\ 000$
$100 ≤ A < B ≤ 200$
$1 ≤ X ≤ 50$
$X$ divides $B - A$
------ Subtasks ------
Subtask #1 (100 points): Original constraints
----- Sample Input 1 ------
3
100 200 10
111 199 11
190 200 10
----- Sample Output 1 ------
10
8
1
----- explanation 1 ------
Test Case $1$: Chef needs to increase his worth by $200 - 100 = 100$ billion dollars and his increment per year being $10$ billion dollars, so it will take him $\frac{100}{10} = 10$ years to do so.
Test Case $2$: Chef needs to increase his worth by $199 - 111 = 88$ billion dollars and his increment per year being $11$ billion dollars, so it will take him $\frac{88}{11} = 8$ years to do so.
Test Case $3$: Chef needs to increase his worth by $200 - 190 = 10$ billion dollars and his increment per year being $10$ billion dollars, so it will take him $\frac{10}{10} = 1$ year to do so.
|
{"inputs": ["3\n100 200 10\n111 199 11\n190 200 10"], "outputs": ["10\n8\n1"]}
| 552
| 50
|
coding
|
Solve the programming task below in a Python markdown code block.
Write a function, which takes a non-negative integer (seconds) as input and returns the time in a human-readable format (`HH:MM:SS`)
* `HH` = hours, padded to 2 digits, range: 00 - 99
* `MM` = minutes, padded to 2 digits, range: 00 - 59
* `SS` = seconds, padded to 2 digits, range: 00 - 59
The maximum time never exceeds 359999 (`99:59:59`)
You can find some examples in the test fixtures.
Also feel free to reuse/extend the following starter code:
```python
def make_readable(seconds):
```
|
{"functional": "_inputs = [[0], [59], [60], [3599], [3600], [86399], [86400], [359999]]\n_outputs = [['00:00:00'], ['00:00:59'], ['00:01:00'], ['00:59:59'], ['01:00:00'], ['23:59:59'], ['24:00:00'], ['99:59:59']]\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(make_readable(*i), o[0])"}
| 168
| 273
|
coding
|
Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game with a binary string S of length N and an empty string T.
They both take turns and Alice plays first.
In Alice's turn, she picks the first character of string S, appends the character to either the front or back of string T and deletes the chosen character from string S.
In Bob's turn, he picks the last character of string S, appends the character to either the front or back of string T and deletes the chosen character from string S.
The game stops when S becomes empty.
Alice wants the resultant string T to be lexicographically smallest, while Bob wants the resultant string T to be lexicographically largest possible.
Find the resultant string T, if both of them play optimally.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N - the length of the string S.
- The next line is the binary string S.
------ Output Format ------
For each test case, print the the resultant string T, if both of them play optimally.
------ Constraints ------
$1 ≤ T ≤ 100$
$1 ≤ N ≤ 1000$
$S$ can only contain the characters $0$ or $1$.
----- Sample Input 1 ------
4
2
10
4
0001
6
010111
10
1110000010
----- Sample Output 1 ------
10
0100
101101
0011011000
----- explanation 1 ------
Test case $1$: Alice picks the first bit which is $1$ and appends it to the empty string $T$. Bob then picks the last bit $0$ and appends it to the back of $T$ making the resultant string to be $10$.
Test case $2$:
- Alice picks $0$ and adds it to $T$. Thus, $S$ becomes $001$ and $T$ becomes $0$.
- Bob picks $1$ and adds it to front of $T$. Thus, $S$ becomes $00$ and $T$ becomes $10$.
- Alice picks $0$ and adds it to front of $T$. Thus, $S$ becomes $0$ and $T$ becomes $010$.
- Bob picks $0$ and adds it to back of $T$. Thus, $S$ becomes empty and $T$ becomes $0100$.
|
{"inputs": ["4\n2\n10\n4\n0001\n6\n010111\n10\n1110000010"], "outputs": ["10\n0100\n101101\n0011011000"]}
| 583
| 71
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
It is a sweltering summer day, and a boy wants to buy some ice cream bars.
At the store, there are n ice cream bars. You are given an array costs of length n, where costs[i] is the price of the ith ice cream bar in coins. The boy initially has coins coins to spend, and he wants to buy as many ice cream bars as possible.
Note: The boy can buy the ice cream bars in any order.
Return the maximum number of ice cream bars the boy can buy with coins coins.
You must solve the problem by counting sort.
Please complete the following python code precisely:
```python
class Solution:
def maxIceCream(self, costs: List[int], coins: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(costs = [1,3,2,4,1], coins = 7) == 4\n assert candidate(costs = [10,6,8,7,7,8], coins = 5) == 0\n assert candidate(costs = [1,6,3,1,2,5], coins = 20) == 6\n\n\ncheck(Solution().maxIceCream)"}
| 172
| 104
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef has a binary string S of length N.
Chef can perform the following operation on the string:
Choose any substring of S;
Remove the chosen substring from S;
Concatenate the remaining parts of the string S, obtained after removing the substring.
Find the length of the longest prefix having all 1s you can achieve, by performing the above operation at most once.
Note: A prefix of a string is obtained by deleting some (possibly zero) characters from the end of string S.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N, the length of the binary string.
- The next line contains the binary string S.
------ Output Format ------
For each test case, print in a new line, the length of the longest prefix having all 1s you can achieve, by performing the operation at most once.
------ Constraints ------
$1 ≤ T ≤ 1000$
$2 ≤ N ≤ 2 \cdot 10^{5}$
$S$ contains $0$ and $1$ only.
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1010
6
011011
11
01011011101
----- Sample Output 1 ------
2
2
3
----- explanation 1 ------
Test case $1$: Chef can choose the substring $S[2, 2] = 0$. On removal of the substring, the remaining parts are $1$ and $10$. On concatenating these parts, the final string obtained is $110$.
The longest prefix in the final string having all $1$s is $11$, having a length $2$.
It can be proven that we cannot obtain a prefix of length greater than $2$ having all $1$s using at most one operation.
Test case $2$: Chef can choose the substring $S[1, 4] = 0110$. On removal of the substring, the remaining part is $11$.
The longest prefix in the final string having all $1$s is $11$, having a length $2$.
It can be proven that we cannot obtain a prefix of length greater than $2$ having all $1$s using at most one operation.
Test case $3$: Chef can choose the substring $S[1, 6] = 010110$. On removal of the substring, the remaining part is $11101$.
The longest prefix in the final string having all $1$s is $111$, having a length $3$.
It can be proven that we cannot obtain a prefix of length greater than $3$ having all $1$s using at most one operation.
|
{"inputs": ["3\n4\n1010\n6\n011011\n11\n01011011101\n"], "outputs": ["2\n2\n3\n"]}
| 645
| 49
|
coding
|
Solve the programming task below in a Python markdown code block.
You work in the best consumer electronics corporation, and your boss wants to find out which three products generate the most revenue.
Given 3 lists of the same length like these:
* products: `["Computer", "Cell Phones", "Vacuum Cleaner"]`
* amounts: `[3, 24, 8]`
* prices: `[199, 299, 399]`
return the three product names with the highest revenue (`amount * price`).
**Note**: if multiple products have the same revenue, order them according to their original positions in the input list.
Also feel free to reuse/extend the following starter code:
```python
def top3(products, amounts, prices):
```
|
{"functional": "_inputs = [[['Computer', 'Cell Phones', 'Vacuum Cleaner'], [3, 24, 8], [199, 299, 399]], [['Cell Phones', 'Vacuum Cleaner', 'Computer', 'Autos', 'Gold', 'Fishing Rods', 'Lego', ' Speakers'], [5, 25, 2, 7, 10, 3, 2, 24], [51, 225, 22, 47, 510, 83, 82, 124]], [['Cell Phones', 'Vacuum Cleaner', 'Computer', 'Autos', 'Gold', 'Fishing Rods', 'Lego', ' Speakers'], [0, 12, 24, 17, 19, 23, 120, 8], [9, 24, 29, 31, 51, 8, 120, 14]], [['Speakers', 'Games', 'Radios', 'Drones', 'Scooter'], [1, 1, 1, 1, 1], [10, 10, 10, 10, 10]]]\n_outputs = [[['Cell Phones', 'Vacuum Cleaner', 'Computer']], [['Vacuum Cleaner', 'Gold', ' Speakers']], [['Lego', 'Gold', 'Computer']], [['Speakers', 'Games', 'Radios']]]\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(top3(*i), o[0])"}
| 162
| 475
|
coding
|
Solve the programming task below in a Python markdown code block.
Ibis is fighting with a monster.
The health of the monster is H.
Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points.
The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health.
Ibis wins when the health of the monster becomes 0 or below.
Find the minimum total Magic Points that have to be consumed before winning.
-----Constraints-----
- 1 \leq H \leq 10^4
- 1 \leq N \leq 10^3
- 1 \leq A_i \leq 10^4
- 1 \leq B_i \leq 10^4
- All values in input are integers.
-----Input-----
Input is given from Standard Input in the following format:
H N
A_1 B_1
:
A_N B_N
-----Output-----
Print the minimum total Magic Points that have to be consumed before winning.
-----Sample Input-----
9 3
8 3
4 2
2 1
-----Sample Output-----
4
First, let us cast the first spell to decrease the monster's health by 8, at the cost of 3 Magic Points. The monster's health is now 1.
Then, cast the third spell to decrease the monster's health by 2, at the cost of 1 Magic Point. The monster's health is now -1.
In this way, we can win at the total cost of 4 Magic Points.
|
{"inputs": ["9 3\n8 3\n4 4\n2 1", "9 3\n8 3\n4 4\n4 1", "9 3\n2 3\n4 4\n1 1", "9 3\n8 3\n4 2\n2 1", "9 3\n8 3\n4 2\n2 1\n", "10000 1\n1 10000\n", "9999 2\n2 9999\n2 10000\n", "10000 2\n1 9999\n1 10000\n"], "outputs": ["4\n", "3\n", "9\n", "4", "4\n", "100000000\n", "49995000\n", "99990000\n"]}
| 350
| 212
|
coding
|
Solve the programming task below in a Python markdown code block.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
There are $n$ books standing in a row on the shelf, the $i$-th book has color $a_i$.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 5 \cdot 10^5$) — the number of books.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) — the book colors.
-----Output-----
Output the minimum number of operations to make the shelf beautiful.
-----Examples-----
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
-----Note-----
In the first example, we have the bookshelf $[1, 2, 2, 1, 3]$ and can, for example:
take a book on position $4$ and move to the right end: we'll get $[1, 2, 2, 3, 1]$;
take a book on position $1$ and move to the right end: we'll get $[2, 2, 3, 1, 1]$.
In the second example, we can move the first book to the end of the bookshelf and get $[2,2,1,1,1]$.
|
{"inputs": ["5\n1 2 2 1 3\n", "5\n1 2 2 1 1\n", "5\n1 2 4 1 3\n", "5\n1 2 1 1 1\n", "5\n2 2 2 1 3\n", "5\n1 2 1 2 1\n", "5\n1 2 1 1 2\n", "5\n2 1 2 1 3\n"], "outputs": ["2\n", "1\n", "2\n", "1\n", "0\n", "2\n", "1\n", "2\n"]}
| 419
| 150
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a sequence a_1, a_2, ..., a_n, consisting of integers.
You can apply the following operation to this sequence: choose some integer x and move all elements equal to x either to the beginning, or to the end of a. Note that you have to move all these elements in one direction in one operation.
For example, if a = [2, 1, 3, 1, 1, 3, 2], you can get the following sequences in one operation (for convenience, denote elements equal to x as x-elements):
* [1, 1, 1, 2, 3, 3, 2] if you move all 1-elements to the beginning;
* [2, 3, 3, 2, 1, 1, 1] if you move all 1-elements to the end;
* [2, 2, 1, 3, 1, 1, 3] if you move all 2-elements to the beginning;
* [1, 3, 1, 1, 3, 2, 2] if you move all 2-elements to the end;
* [3, 3, 2, 1, 1, 1, 2] if you move all 3-elements to the beginning;
* [2, 1, 1, 1, 2, 3, 3] if you move all 3-elements to the end;
You have to determine the minimum number of such operations so that the sequence a becomes sorted in non-descending order. Non-descending order means that for all i from 2 to n, the condition a_{i-1} ≤ a_i is satisfied.
Note that you have to answer q independent queries.
Input
The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of the queries. Each query is represented by two consecutive lines.
The first line of each query contains one integer n (1 ≤ n ≤ 3 ⋅ 10^5) — the number of elements.
The second line of each query contains n integers a_1, a_2, ... , a_n (1 ≤ a_i ≤ n) — the elements.
It is guaranteed that the sum of all n does not exceed 3 ⋅ 10^5.
Output
For each query print one integer — the minimum number of operation for sorting sequence a in non-descending order.
Example
Input
3
7
3 1 6 6 3 1 1
8
1 1 4 4 4 7 8 8
7
4 2 5 2 6 2 7
Output
2
0
1
Note
In the first query, you can move all 1-elements to the beginning (after that sequence turn into [1, 1, 1, 3, 6, 6, 3]) and then move all 6-elements to the end.
In the second query, the sequence is sorted initially, so the answer is zero.
In the third query, you have to move all 2-elements to the beginning.
|
{"inputs": ["3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 7 8 8\n7\n2 2 5 2 6 2 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 7 8 2\n7\n2 2 5 2 6 2 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 3 8 2\n7\n2 2 5 2 6 2 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 3 8 2\n7\n2 2 5 4 6 2 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 5 8 8\n7\n4 2 5 2 6 4 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 8 4 7 8 8\n7\n4 2 5 2 6 2 7\n", "3\n7\n3 1 6 6 5 2 1\n8\n1 1 4 4 4 3 8 2\n7\n2 2 4 2 6 2 7\n", "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 1 8 2\n7\n2 2 5 4 6 2 7\n"], "outputs": ["2\n0\n1\n", "2\n2\n1\n", "2\n3\n1\n", "2\n3\n2\n", "2\n0\n2\n", "2\n1\n1\n", "3\n3\n1\n", "2\n2\n2\n"]}
| 711
| 502
|
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 s consisting of only lowercase English letters, and an integer count. A substring of s is said to be an equal count substring if, for each unique letter in the substring, it appears exactly count times in the substring.
Return the number of equal count substrings in s.
A substring is a contiguous non-empty sequence of characters within a string.
Please complete the following python code precisely:
```python
class Solution:
def equalCountSubstrings(self, s: str, count: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"aaabcbbcc\", count = 3) == 3\n assert candidate(s = \"abcd\", count = 2) == 0\n assert candidate(s = \"a\", count = 5) == 0\n\n\ncheck(Solution().equalCountSubstrings)"}
| 131
| 75
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a binary string s, and two integers num1 and num2. num1 and num2 are coprime numbers.
A ratio substring is a substring of s where the ratio between the number of 0's and the number of 1's in the substring is exactly num1 : num2.
For example, if num1 = 2 and num2 = 3, then "01011" and "1110000111" are ratio substrings, while "11000" is not.
Return the number of non-empty ratio substrings of s.
Note that:
A substring is a contiguous sequence of characters within a string.
Two values x and y are coprime if gcd(x, y) == 1 where gcd(x, y) is the greatest common divisor of x and y.
Please complete the following python code precisely:
```python
class Solution:
def fixedRatio(self, s: str, num1: int, num2: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"0110011\", num1 = 1, num2 = 2) == 4\n assert candidate(s = \"10101\", num1 = 3, num2 = 1) == 0\n\n\ncheck(Solution().fixedRatio)"}
| 235
| 77
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once.
Return the single element that appears only once.
Your solution must run in O(log n) time and O(1) space.
Please complete the following python code precisely:
```python
class Solution:
def singleNonDuplicate(self, nums: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1,1,2,3,3,4,4,8,8]) == 2\n assert candidate(nums = [3,3,7,7,10,11,11]) == 10\n\n\ncheck(Solution().singleNonDuplicate)"}
| 101
| 76
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got duplicated to another number in the set, which results in repetition of one number and loss of another number.
You are given an integer array nums representing the data status of this set after the error.
Find the number that occurs twice and the number that is missing and return them in the form of an array.
Please complete the following python code precisely:
```python
class Solution:
def findErrorNums(self, nums: List[int]) -> List[int]:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,2,4]) == [2,3]\n assert candidate(nums = [1,1]) == [1,2]\n\n\ncheck(Solution().findErrorNums)"}
| 146
| 59
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.