task_type
stringclasses 1
value | problem
stringlengths 209
3.39k
| answer
stringlengths 35
6.15k
| problem_tokens
int64 60
774
| answer_tokens
int64 12
2.04k
|
|---|---|---|---|---|
coding
|
Solve the programming task below in a Python markdown code block.
We have a grid with H rows and W columns, where all the squares are initially white.
You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions:
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column black.
At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.
Constraints
* 1 \leq H \leq 100
* 1 \leq W \leq 100
* 1 \leq N \leq H \times W
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
H
W
N
Output
Print the minimum number of operations needed.
Examples
Input
3
7
10
Output
2
Input
14
12
112
Output
8
Input
2
100
200
Output
2
|
{"inputs": ["3\n7\n15", "3\n7\n45", "3\n7\n76", "3\n7\n54", "3\n0\n76", "3\n2\n43", "3\n2\n59", "3\n1\n34"], "outputs": ["3\n", "7\n", "11\n", "8\n", "26\n", "15\n", "20\n", "12\n"]}
| 266
| 107
|
coding
|
Solve the programming task below in a Python markdown code block.
Bohan loves milk tea so much and he drinks one cup of milk tea every day. The local shop sells milk tea in two sizes: a Medium cup for $3 and a Large cup for $4. For every cup of milk tea purchased Bohan receives a promotional stamp. Bohan may redeem 6 stamps for a free drink of milk tea regardless of the size. No stamp will be given for a free drink.
Determine the amount of money Bohan have spent on milk tea, given a sequence of milk tea sizes he got in the past a few days. Assume Bohan had no stamps in the beginning and he always redeemed the stamps for the next drink once he had collected 6 stamps.
-----Input-----
The input begins with the number of test cases T.
Each test case has a single line of letters. The i-th letter is either 'M' or 'L' denoting a Medium cup or a Large cup of milk tea Bohan got on the i-th day.
-----Output-----
For each case, output the amount of money in dollars Bohan have spent on milk tea.
-----Constraints-----
- T ≤ 100
- 1 ≤ length of each sequence ≤ 100
-----Example-----
Input:
3
MLM
MMLLMMLL
MMMMMMML
Output:
10
24
22
-----Explanation-----
Example 1: Bohan didn't redeem any stamps.
Example 2: Bohan redeemed 6 stamps for the Large cup of milk tea on the 7th day.
Example 3: Bohan redeemed 6 stamps for the Medium cup of milk tea on the 7th day.
|
{"inputs": ["3\nMLM\nMMLLMMLL\nMMMMMMML"], "outputs": ["10\n24\n22"]}
| 355
| 32
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef is here with another matrix A having N rows and M columns,
such that A_{(i,j)} = (i-1)\cdot M+j.
Chef decided to make this matrix interesting. He performed K operations on the matrix. In each operation, he will choose either a row or column and multiply all values in that row/column with a non-negative integer V.
An operation is of the form Q, X, V:
- If Q=0: Multiply each element of the X^{th} row with V.
- If Q=1: Multiply each element of the X^{th} column with V.
Find the sum of all values in the matrix after all K operations are done. Since the value can be large, print it modulo 10^{9} + 7.
------ 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 three space-separated integers N, M, and K — the number of rows, columns, and the operations to be done, respectively.
- The next K lines describe the operations. The i^{th} of these K lines contain three space-separated integers Q_{i}, X_{i}, and V_{i}, as mentioned in the statement.
------ Output Format ------
For each test case, output on a new line, the sum of all elements of the matrix after performing the operations, modulo 10^{9} + 7.
------ Constraints ------
$1 ≤ T ≤ 100$
$1 ≤ N, M ≤ 10^{9}$
$1 ≤ K ≤ 2\cdot 10^{5}$
$0 ≤ Q_{i} ≤ 1$
$1 ≤ X ≤ N$ if $Q_{i}=0$
$1 ≤ X ≤ M$ if $Q_{i}=1$
$0 ≤ V_{i} ≤ 10^{9}$
- The sum of $K$ over all test cases won't exceed $2\cdot 10^{5}$
----- Sample Input 1 ------
2
2 2 2
1 2 0
0 1 2
1 3 1
1 2 6
----- Sample Output 1 ------
5
16
----- explanation 1 ------
Test case $1$ : The initial matrix is $[[1, 2], [3, 4]]$.
- In the first operation, multiply all elements of the second column with $0$. Thus, the matrix becomes $[[1, 0], [3, 0]]$.
- In the second operation, multiply all elements of the first row with $2$. Thus, the matrix becomes $[[2, 0], [3, 0]]$.
The sum of the elements of the updated matrix is $2+3 = 5$.
Test case $2$: The initial matrix is $[[1, 2, 3]]$.
- In the first operation, multiply all elements of the second column with $6$. Thus, the matrix becomes $[[1, 12, 3]]$.
The sum of the elements of the updated matrix is $1+12+3 = 16$.
|
{"inputs": ["2\n2 2 2\n1 2 0\n0 1 2\n1 3 1\n1 2 6"], "outputs": ["5\n16\n"]}
| 712
| 46
|
coding
|
Solve the programming task below in a Python markdown code block.
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are:
2332
110011
54322345
You'll be given 2 numbers as arguments: ```(num,s)```. Write a function which returns an array of ```s``` number of numerical palindromes that come after ```num```. If ```num``` is a palindrome itself, it should be included in the count.
Return "Not valid" instead if any one of the inputs is not an integer or is less than 0.
For this kata, single digit numbers will NOT be considered numerical palindromes.
```
palindrome(6,4) => [11,22,33,44]
palindrome(59,3) => [66,77,88]
palindrome(101,2) => [101,111]
palindrome("15651",5) => "Not valid"
palindrome(1221,"8") => "Not valid"
```
```Haskell
In Haskell, the return type is a Maybe which returns Nothing if either of the inputs is negative."
```
Other Kata in this Series:
Numerical Palindrome #1
Numerical Palindrome #1.5
Numerical Palindrome #2
Numerical Palindrome #3
Numerical Palindrome #3.5
Numerical Palindrome #4
Numerical Palindrome #5
Also feel free to reuse/extend the following starter code:
```python
def palindrome(num,s):
```
|
{"functional": "_inputs = [[6, 4], [75, 1], [19, 3], [101, 2], ['ACCDDCCA', 3], [773, '1551'], [-4505, 15]]\n_outputs = [[[11, 22, 33, 44]], [[77]], [[22, 33, 44]], [[101, 111]], ['Not valid'], ['Not valid'], ['Not valid']]\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(palindrome(*i), o[0])"}
| 370
| 260
|
coding
|
Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show, the episode of which will be shown in $i$-th day.
The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.
How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows $d$ ($1 \le d \le n$) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of $d$ consecutive days in which all episodes belong to the purchased shows.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10000$) — the number of test cases in the input. Then $t$ test case descriptions follow.
The first line of each test case contains three integers $n, k$ and $d$ ($1 \le n \le 2\cdot10^5$, $1 \le k \le 10^6$, $1 \le d \le n$). The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show that is broadcasted on the $i$-th day.
It is guaranteed that the sum of the values of $n$ for all test cases in the input does not exceed $2\cdot10^5$.
-----Output-----
Print $t$ integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for $d$ consecutive days. Please note that it is permissible that you will be able to watch more than $d$ days in a row.
-----Example-----
Input
4
5 2 2
1 2 1 2 1
9 3 3
3 3 3 2 2 2 1 1 1
4 10 4
10 8 6 4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
Output
2
1
4
5
-----Note-----
In the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show $1$ and on show $2$. So the answer is two.
In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.
In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.
In the fourth test case, you can buy subscriptions to shows $3,5,7,8,9$, and you will be able to watch shows for the last eight days.
|
{"inputs": ["4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n", "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 4 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 4 2 6 5 6 5 8 9 8 9 3\n", "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 4 2 6 5 3 5 8 9 7 9 3\n", "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 4 2 6 5 6 5 8 9 7 9 3\n", "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 4 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 4 2 6 5 6 5 8 9 7 9 3\n", "4\n5 2 4\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 6 1 1 1\n4 26 4\n7 8 6 4\n16 10 8\n3 1 4 1 5 4 2 6 5 6 5 8 9 8 9 3\n", "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 7 9 2 6 5 3 5 8 9 7 9 3\n", "4\n5 2 2\n1 2 1 2 1\n9 6 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 4 2 6 5 3 5 8 9 7 9 3\n"], "outputs": ["2\n1\n4\n5\n", "2\n1\n4\n4\n", "2\n1\n4\n5\n", "2\n1\n4\n5\n", "2\n1\n4\n5\n", "2\n1\n4\n4\n", "2\n1\n4\n5\n", "2\n1\n4\n5\n"]}
| 755
| 878
|
coding
|
Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game. Initially, they are given a non-empty string $s$, consisting of lowercase Latin letters. The length of the string is even. Each player also has a string of their own, initially empty.
Alice starts, then they alternate moves. In one move, a player takes either the first or the last letter of the string $s$, removes it from $s$ and prepends (adds to the beginning) it to their own string.
The game ends when the string $s$ becomes empty. The winner is the player with a lexicographically smaller string. If the players' strings are equal, then it's a draw.
A string $a$ is lexicographically smaller than a string $b$ if there exists such position $i$ that $a_j = b_j$ for all $j < i$ and $a_i < b_i$.
What is the result of the game if both players play optimally (e. g. both players try to win; if they can't, then try to draw)?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of testcases.
Each testcase consists of a single line — a non-empty string $s$, consisting of lowercase Latin letters. The length of the string $s$ is even.
The total length of the strings over all testcases doesn't exceed $2000$.
-----Output-----
For each testcase, print the result of the game if both players play optimally. If Alice wins, print "Alice". If Bob wins, print "Bob". If it's a draw, print "Draw".
-----Examples-----
Input
2
forces
abba
Output
Alice
Draw
-----Note-----
One of the possible games Alice and Bob can play in the first testcase:
Alice picks the first letter in $s$: $s=$"orces", $a=$"f", $b=$"";
Bob picks the last letter in $s$: $s=$"orce", $a=$"f", $b=$"s";
Alice picks the last letter in $s$: $s=$"orc", $a=$"ef", $b=$"s";
Bob picks the first letter in $s$: $s=$"rc", $a=$"ef", $b=$"os";
Alice picks the last letter in $s$: $s=$"r", $a=$"cef", $b=$"os";
Bob picks the remaining letter in $s$: $s=$"", $a=$"cef", $b=$"ros".
Alice wins because "cef" < "ros". Neither of the players follows any strategy in this particular example game, so it doesn't show that Alice wins if both play optimally.
|
{"inputs": ["2\nforces\nabba\n"], "outputs": ["Alice\nDraw\n"]}
| 597
| 21
|
coding
|
Solve the programming task below in a Python markdown code block.
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the following operations:
* add(i, x): add x to ai.
* getSum(s, t): print the sum of as, as+1,...,at.
Note that the initial values of ai (i = 1, 2, . . . , n) are 0.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* If comi is 0, then 1 ≤ xi ≤ n, 0 ≤ yi ≤ 1000.
* If comi is 1, then 1 ≤ xi ≤ n, 1 ≤ yi ≤ n.
Input
n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes add(xi, yi) and '1' denotes getSum(xi, yi).
Output
For each getSum operation, print the sum in a line.
Example
Input
3 5
0 1 1
0 2 2
0 3 3
1 1 2
1 2 2
Output
3
2
|
{"inputs": ["4 5\n0 1 1\n0 2 2\n0 3 3\n1 1 2\n1 2 2", "4 5\n0 1 1\n0 2 2\n0 1 5\n1 1 2\n1 2 2", "4 5\n0 1 0\n0 2 2\n0 1 5\n1 1 2\n1 2 2", "4 5\n0 1 1\n0 2 4\n0 3 3\n1 1 2\n1 2 2", "4 5\n0 1 1\n0 4 4\n0 3 3\n1 1 2\n1 2 2", "4 5\n0 1 1\n0 2 2\n0 3 9\n1 1 2\n0 2 2", "4 5\n0 1 0\n0 2 2\n0 1 5\n1 1 0\n1 2 3", "4 5\n0 1 1\n0 4 4\n0 3 3\n1 1 2\n1 2 3"], "outputs": ["3\n2\n", "8\n2\n", "7\n2\n", "5\n4\n", "1\n0\n", "3\n", "0\n2\n", "1\n3\n"]}
| 322
| 332
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of positive integers price where price[i] denotes the price of the ith candy and a positive integer k.
The store sells baskets of k distinct candies. The tastiness of a candy basket is the smallest absolute difference of the prices of any two candies in the basket.
Return the maximum tastiness of a candy basket.
Please complete the following python code precisely:
```python
class Solution:
def maximumTastiness(self, price: List[int], k: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(price = [13,5,1,8,21,2], k = 3) == 8\n assert candidate(price = [1,3,1], k = 2) == 2\n assert candidate(price = [7,7,7,7], k = 2) == 0\n\n\ncheck(Solution().maximumTastiness)"}
| 122
| 94
|
coding
|
Solve the programming task below in a Python markdown code block.
Lord Omkar has permitted you to enter the Holy Church of Omkar! To test your worthiness, Omkar gives you a password which you must interpret!
A password is an array $a$ of $n$ positive integers. You apply the following operation to the array: pick any two adjacent numbers that are not equal to each other and replace them with their sum. Formally, choose an index $i$ such that $1 \leq i < n$ and $a_{i} \neq a_{i+1}$, delete both $a_i$ and $a_{i+1}$ from the array and put $a_{i}+a_{i+1}$ in their place.
For example, for array $[7, 4, 3, 7]$ you can choose $i = 2$ and the array will become $[7, 4+3, 7] = [7, 7, 7]$. Note that in this array you can't apply this operation anymore.
Notice that one operation will decrease the size of the password by $1$. What is the shortest possible length of the password after some number (possibly $0$) of operations?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). 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 password.
The second line of each test case contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ($1 \leq a_{i} \leq 10^9$) — the initial contents of your password.
The sum of $n$ over all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each password, print one integer: the shortest possible length of the password after some number of operations.
-----Example-----
Input
2
4
2 1 3 1
2
420 420
Output
1
2
-----Note-----
In the first test case, you can do the following to achieve a length of $1$:
Pick $i=2$ to get $[2, 4, 1]$
Pick $i=1$ to get $[6, 1]$
Pick $i=1$ to get $[7]$
In the second test case, you can't perform any operations because there is no valid $i$ that satisfies the requirements mentioned above.
|
{"inputs": ["1\n1\n1\n", "1\n1\n1\n", "1\n3\n3 4 7\n", "1\n3\n3 1 2\n", "1\n3\n1 2 3\n", "1\n3\n1 3 4\n", "1\n3\n3 2 1\n", "1\n3\n4 3 1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
| 581
| 126
|
coding
|
Solve the programming task below in a Python markdown code block.
Your task is to write a program which reads a date (from 2004/1/1 to 2004/12/31) and prints the day of the date. Jan. 1, 2004, is Thursday. Note that 2004 is a leap year and we have Feb. 29.
Input
The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset consists of two integers m and d separated by a single space in a line. These integers respectively represent the month and the day.
The number of datasets is less than or equal to 50.
Output
For each dataset, print the day (please see the following words) in a line.
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
Example
Input
1 1
2 29
0 0
Output
Thursday
Sunday
|
{"inputs": ["2 2\n2 8\n0 0", "4 1\n2 7\n0 0", "6 2\n7 8\n0 0", "3 3\n2 1\n0 0", "5 1\n2 7\n0 0", "4 4\n6 4\n0 0", "4 1\n3 8\n0 0", "5 1\n1 7\n0 0"], "outputs": ["Monday\nSunday\n", "Thursday\nSaturday\n", "Wednesday\nThursday\n", "Wednesday\nSunday\n", "Saturday\nSaturday\n", "Sunday\nFriday\n", "Thursday\nMonday\n", "Saturday\nWednesday\n"]}
| 212
| 158
|
coding
|
Solve the programming task below in a Python markdown code block.
Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from his trolley. To steal one item Bob needs exactly 1 second. What is the minimum amount of money that Bob will have to pay to the checkout assistant? Remember, please, that it is Bob, who determines the order of items for the checkout assistant.
Input
The first input line contains number n (1 ≤ n ≤ 2000). In each of the following n lines each item is described by a pair of numbers ti, ci (0 ≤ ti ≤ 2000, 1 ≤ ci ≤ 109). If ti is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item i.
Output
Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay.
Examples
Input
4
2 10
0 20
1 5
1 3
Output
8
Input
3
0 1
0 10
0 100
Output
111
|
{"inputs": ["3\n0 1\n0 10\n0 100\n", "4\n2 1\n0 0\n1 5\n1 3\n", "4\n2 0\n0 0\n1 5\n2 3\n", "4\n2 1\n0 0\n1 5\n2 3\n", "4\n2 1\n0 0\n1 5\n4 3\n", "4\n2 1\n1 0\n1 5\n4 3\n", "4\n2 1\n1 0\n1 5\n2 3\n", "4\n2 0\n1 0\n1 5\n2 3\n"], "outputs": ["111", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n", "0\n"]}
| 293
| 198
|
coding
|
Solve the programming task below in a Python markdown code block.
Whereas humans nowadays read fewer and fewer books on paper, book readership among marmots has surged. Heidi has expanded the library and is now serving longer request sequences.
-----Input-----
Same as the easy version, but the limits have changed: 1 ≤ n, k ≤ 400 000.
-----Output-----
Same as the easy version.
-----Examples-----
Input
4 100
1 2 2 1
Output
2
Input
4 1
1 2 2 1
Output
3
Input
4 2
1 2 3 1
Output
3
|
{"inputs": ["1 1\n1\n", "1 1\n1\n", "4 1\n1 2 2 1\n", "4 2\n1 2 3 1\n", "4 2\n1 2 3 2\n", "4 2\n1 2 3 2\n", "4 3\n1 1 1 1\n", "4 2\n2 2 3 1\n"], "outputs": ["1\n", "1\n", "3\n", "3\n", "3\n", "3\n", "1\n", "3\n"]}
| 146
| 138
|
coding
|
Solve the programming task below in a Python markdown code block.
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
-----Input-----
The first line of the input contains three integers n, m and T (2 ≤ n ≤ 5000, 1 ≤ m ≤ 5000, 1 ≤ T ≤ 10^9) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers u_{i}, v_{i}, t_{i} (1 ≤ u_{i}, v_{i} ≤ n, u_{i} ≠ v_{i}, 1 ≤ t_{i} ≤ 10^9), meaning that there is a road starting from showplace u_{i} and leading to showplace v_{i}, and Irina spends t_{i} time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
-----Output-----
Print the single integer k (2 ≤ k ≤ n) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line — indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
-----Examples-----
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4
Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6
Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5
|
{"inputs": ["2 1 1\n1 2 1\n", "2 1 1\n1 2 1\n", "2 1 2\n1 2 1\n", "4 3 13\n1 2 5\n2 3 7\n2 4 8\n", "4 3 13\n1 2 5\n2 3 7\n2 4 8\n", "4 4 3\n1 2 1\n2 3 1\n3 4 1\n1 3 1\n", "4 4 2\n1 2 1\n2 3 1\n3 4 1\n1 3 1\n", "4 4 2\n1 2 1\n2 3 1\n3 4 1\n1 3 1\n"], "outputs": ["2\n1 2 \n", "2\n1 2 ", "2\n1 2\n", "3\n1 2 4 \n", "3\n1 2 4 ", "4\n1 2 3 4 \n", "3\n1 3 4 \n", "3\n1 3 4 "]}
| 665
| 276
|
coding
|
Solve the programming task below in a Python markdown code block.
A company has N members, who are assigned ID numbers 1, ..., N.
Every member, except the member numbered 1, has exactly one immediate boss with a smaller ID number.
When a person X is the immediate boss of a person Y, the person Y is said to be an immediate subordinate of the person X.
You are given the information that the immediate boss of the member numbered i is the member numbered A_i. For each member, find how many immediate subordinates it has.
-----Constraints-----
- 2 \leq N \leq 2 \times 10^5
- 1 \leq A_i < i
-----Input-----
Input is given from Standard Input in the following format:
N
A_2 ... A_N
-----Output-----
For each of the members numbered 1, 2, ..., N, print the number of immediate subordinates it has, in its own line.
-----Sample Input-----
5
1 1 2 2
-----Sample Output-----
2
2
0
0
0
The member numbered 1 has two immediate subordinates: the members numbered 2 and 3.
The member numbered 2 has two immediate subordinates: the members numbered 4 and 5.
The members numbered 3, 4, and 5 do not have immediate subordinates.
|
{"inputs": ["5\n1 1 2 3", "5\n1 2 2 3", "5\n1 2 2 2", "5\n1 1 2 5", "5\n1 2 4 3", "5\n1 2 4 2", "5\n2 1 2 5", "5\n1 2 4 5"], "outputs": ["2\n1\n1\n0\n0\n", "1\n2\n1\n0\n0\n", "1\n3\n0\n0\n0\n", "2\n1\n0\n0\n1\n", "1\n1\n1\n1\n0\n", "1\n2\n0\n1\n0\n", "1\n2\n0\n0\n1\n", "1\n1\n0\n1\n1\n"]}
| 290
| 190
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an undirected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.
You are given 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. You are also given an integer array restricted which represents restricted nodes.
Return the maximum number of nodes you can reach from node 0 without visiting a restricted node.
Note that node 0 will not be a restricted node.
Please complete the following python code precisely:
```python
class Solution:
def reachableNodes(self, n: int, edges: List[List[int]], restricted: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 7, edges = [[0,1],[1,2],[3,1],[4,0],[0,5],[5,6]], restricted = [4,5]) == 4\n assert candidate(n = 7, edges = [[0,1],[0,2],[0,5],[0,4],[3,2],[6,5]], restricted = [4,2,1]) == 3\n\n\ncheck(Solution().reachableNodes)"}
| 168
| 113
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Convert a non-negative integer num to its English words representation.
Please complete the following python code precisely:
```python
class Solution:
def numberToWords(self, num: int) -> str:
```
|
{"functional": "def check(candidate):\n assert candidate(num = 123) == \"One Hundred Twenty Three\"\n assert candidate(num = 12345) == \"Twelve Thousand Three Hundred Forty Five\"\n assert candidate(num = 1234567) == \"One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven\"\n\n\ncheck(Solution().numberToWords)"}
| 60
| 91
|
coding
|
Solve the programming task below in a Python markdown code block.
Joisino is planning to open a shop in a shopping street.
Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.
There are already N stores in the street, numbered 1 through N.
You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2.
Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}.
Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.
-----Constraints-----
- 1≤N≤100
- 0≤F_{i,j,k}≤1
- For every integer i such that 1≤i≤N, there exists at least one pair (j,k) such that F_{i,j,k}=1.
- -10^7≤P_{i,j}≤10^7
- All input values are integers.
-----Input-----
Input is given from Standard Input in the following format:
N
F_{1,1,1} F_{1,1,2} ... F_{1,5,1} F_{1,5,2}
:
F_{N,1,1} F_{N,1,2} ... F_{N,5,1} F_{N,5,2}
P_{1,0} ... P_{1,10}
:
P_{N,0} ... P_{N,10}
-----Output-----
Print the maximum possible profit of Joisino's shop.
-----Sample Input-----
1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2
-----Sample Output-----
8
If her shop is open only during the periods when Shop 1 is opened, the profit will be 8, which is the maximum possible profit.
|
{"inputs": ["1\n1 1 0 1 0 0 0 1 0 1\n3 4 5 6 7 8 9 -4 -3 4 -2", "1\n1 1 0 1 0 0 0 1 0 0\n3 1 5 6 7 8 9 -7 -3 4 -2", "1\n1 1 0 1 0 0 1 1 0 1\n3 1 5 6 7 8 9 -7 -3 4 -2", "1\n1 1 0 1 0 0 0 1 0 1\n3 1 5 6 7 8 9 -4 -3 4 -2", "1\n1 1 0 1 0 0 0 1 0 1\n3 1 5 6 7 8 9 -7 -3 4 -2", "1\n1 1 0 1 0 0 0 1 0 0\n3 1 5 2 7 8 9 -7 -3 4 -2", "1\n1 1 0 1 0 0 0 1 0 0\n3 1 5 2 7 8 9 -7 -3 0 -2", "1\n1 1 0 1 0 0 0 1 0 1\n3 4 5 6 7 8 9 -2 -3 4 -2"], "outputs": ["8\n", "7\n", "9\n", "8\n", "8\n", "7\n", "7\n", "8"]}
| 615
| 397
|
coding
|
Solve the programming task below in a Python markdown code block.
Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is given by a pair li and ri and asks you to count the number of pairs of integers i and j, such that l ≤ i ≤ j ≤ r and the xor of the numbers ai, ai + 1, ..., aj is equal to k.
Input
The first line of the input contains integers n, m and k (1 ≤ n, m ≤ 100 000, 0 ≤ k ≤ 1 000 000) — the length of the array, the number of queries and Bob's favorite number respectively.
The second line contains n integers ai (0 ≤ ai ≤ 1 000 000) — Bob's array.
Then m lines follow. The i-th line contains integers li and ri (1 ≤ li ≤ ri ≤ n) — the parameters of the i-th query.
Output
Print m lines, answer the queries in the order they appear in the input.
Examples
Input
6 2 3
1 2 1 1 0 3
1 6
3 5
Output
7
0
Input
5 3 1
1 1 1 1 1
1 5
2 4
1 3
Output
9
4
4
Note
In the first sample the suitable pairs of i and j for the first query are: (1, 2), (1, 4), (1, 5), (2, 3), (3, 6), (5, 6), (6, 6). Not a single of these pairs is suitable for the second query.
In the second sample xor equals 1 for all subarrays of an odd length.
|
{"inputs": ["6 2 4\n1 2 1 1 0 3\n1 6\n3 5\n", "6 2 3\n1 4 1 1 0 3\n1 6\n3 5\n", "6 2 4\n1 2 1 1 1 5\n1 6\n3 5\n", "6 2 3\n1 2 0 1 0 3\n1 6\n3 5\n", "6 2 3\n1 4 1 2 0 3\n1 6\n2 5\n", "6 2 7\n1 2 1 1 1 5\n1 6\n3 5\n", "6 2 1\n1 2 0 1 0 3\n1 6\n3 5\n", "6 2 3\n1 4 1 2 0 3\n1 4\n2 5\n"], "outputs": ["0\n0\n", "3\n0\n", "2\n0\n", "6\n0\n", "4\n2\n", "1\n0\n", "6\n4\n", "1\n2\n"]}
| 397
| 278
|
coding
|
Solve the programming task below in a Python markdown code block.
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?
-----Input-----
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 10^9; 0 ≤ p ≤ q ≤ 10^9; y > 0; q > 0).
It is guaranteed that p / q is an irreducible fraction.
Hacks. For hacks, an additional constraint of t ≤ 5 must be met.
-----Output-----
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
-----Example-----
Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4
10
0
-1
-----Note-----
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.
In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.
In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.
In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
|
{"inputs": ["1\n1 1 1 1\n", "1\n7 7 1 1\n", "1\n2 2 1 1\n", "1\n0 5 0 1\n", "1\n2 2 1 1\n", "1\n1 1 1 1\n", "1\n0 5 0 1\n", "1\n7 7 1 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
| 458
| 134
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
Given a sequence of n distinct numbers a[1..n], we want to sort them in an ascending order.
An interesting property of some sequences is that all numbers are almost at their correct position! More formally, the distance between the current position of any value is at most 1 from its correct position in a sorted order.
Now, you want to verify whether the input sequence has such a property.
Note that the time limit for this problem is 0.2 seconds. Please try to write a very efficient algorithm and implementation.
------ Input ------
The first line contains an integer T denoting the total number of test cases.
For each test case, the first line contains a single integer n, and the second line contains a[1..n] as a single space-separated list.
------ Output ------
For each test case, output "YES" or "NO" (without quotes) to indicate whether the input sequence has such a property.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ n ≤ 10^{6}$
$1 ≤ a[i] ≤ 10^{9}$
----- Sample Input 1 ------
2
3
1 2 3
5
2 4 1 3 5
----- Sample Output 1 ------
YES
NO
|
{"inputs": ["2\n3\n1 2 3\n5\n2 4 1 3 5"], "outputs": ["YES\nNO"]}
| 294
| 34
|
coding
|
Solve the programming task below in a Python markdown code block.
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.
Kolya remembers that at the beginning of the game his game-coin score was equal to n and that he have bought only some houses (for 1 234 567 game-coins each), cars (for 123 456 game-coins each) and computers (for 1 234 game-coins each).
Kolya is now interested, whether he could have spent all of his initial n game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers a, b and c such that a × 1 234 567 + b × 123 456 + c × 1 234 = n?
Please help Kolya answer this question.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 10^9) — Kolya's initial game-coin score.
-----Output-----
Print "YES" (without quotes) if it's possible that Kolya spent all of his initial n coins buying only houses, cars and computers. Otherwise print "NO" (without quotes).
-----Examples-----
Input
1359257
Output
YES
Input
17851817
Output
NO
-----Note-----
In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total.
|
{"inputs": ["6\n", "4\n", "2\n", "11\n", "11\n", "58\n", "30\n", "26\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO", "NO\n", "NO\n", "NO\n", "NO\n"]}
| 415
| 74
|
coding
|
Solve the programming task below in a Python markdown code block.
Mid semesters are nearly here. In order to pass the time waiting for the question paper malfunctions, the students have organized a betting pool on students that will pass the semester and the students that will fail.
Students place their bets on the sum of the students that will pass and students that will fail, or on the absolute difference between the students that will pass and students that will fail.
Given the winning numbers for each type of bet, can you deduce the final counts?
SAMPLE INPUT
2
40 20
20 40
SAMPLE OUTPUT
30 10
impossible
Explanation
The first line of input contains n, the number of test cases. n lines follow, each representing a test case. Each test case gives s and d, non-negative integers representing the sum and (absolute) difference between the two final counts.
For each test case, output a line giving the two final counts, largest first. If there are no such counts possible, output a line containing “impossible”. Recall that the count (number of students) are always non-negative integers.
Do not worry about the constraints.
|
{"inputs": ["100\n387 384\n416 278\n336 294\n493 387\n422 150\n28 363\n60 191\n427 264\n427 41\n237 173\n369 212\n430 68\n31 283\n124 363\n136 68\n303 430\n59 23\n168 70\n457 394\n43 12\n374 230\n420 422\n38 285\n325 199\n371 316\n27 414\n481 92\n374 457\n171 363\n282 497\n426 306\n328 85\n6 337\n230 347\n358 314\n396 125\n46 83\n368 315\n365 435\n251 44\n309 88\n179 277\n85 289\n152 404\n400 255\n61 433\n369 177\n13 240\n87 227\n40 95\n71 296\n379 435\n102 468\n403 98\n493 318\n257 153\n281 302\n442 287\n190 366\n120 445\n230 441\n118 32\n272 98\n176 482\n428 210\n357 68\n354 498\n466 87\n184 307\n125 220\n372 29\n330 233\n20 4\n369 271\n216 209\n150 341\n224 297\n246 119\n452 347\n56 422\n489 380\n229 265\n351 342\n1 194\n265 35\n415 125\n357 488\n492 244\n366 228\n437 360\n52 433\n229 438\n408 276\n122 475\n396 359\n238 30\n294 236\n429 319\n12 144\n30 429"], "outputs": ["impossible\n347 69\n315 21\n440 53\n286 136\nimpossible\nimpossible\nimpossible\n234 193\n205 32\nimpossible\n249 181\nimpossible\nimpossible\n102 34\nimpossible\n41 18\n119 49\nimpossible\nimpossible\n302 72\nimpossible\nimpossible\n262 63\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\n366 60\nimpossible\nimpossible\nimpossible\n336 22\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\n273 96\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\n205 52\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\n75 43\n185 87\nimpossible\n319 109\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\n12 8\n320 49\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\nimpossible\n150 115\n270 145\nimpossible\n368 124\n297 69\nimpossible\nimpossible\nimpossible\n342 66\nimpossible\nimpossible\n134 104\n265 29\n374 55\nimpossible\nimpossible"]}
| 245
| 1,187
|
coding
|
Solve the programming task below in a Python markdown code block.
Many cats live on the campus of a school. Natsume's daily routine is to pet those cats. However, the cats may be capricious and go for a walk off campus.
The campus site is a rectangle with each side parallel to the x-axis or y-axis and is surrounded by a fence except for the gate, but cats can freely enter and exit through the gate and move over the fence. Sometimes.
One day, Natsume wanted to know how many cats were on campus in order to pet the cats on campus as equally as possible. Your job is to find the number of cats on campus given the location of the campus on the coordinate plane and the coordinates of the cats. However, cats walking on the fence and cats just passing through the gate are also considered to be on campus.
Notes on Submission
Multiple datasets are given in the above format. The first line of input data gives the number of datasets. Create a program that outputs the output for each data set in order in the above format.
Input
On the first line of input, four integers X, Y, W, H are given, separated by a space character. These represent the x-coordinate of the southwestern end of the campus, the y-coordinate of the same point, the east-west width of the campus, and the north-south length of the campus, respectively. These values satisfy -10000 <= X, Y <= 10000 and 0 <W, H <= 10000.
The second line of input is given the number of cats N (0 <N <= 100).
The following N lines are given a set of integers (-50000 <= x, y <= 50000) representing the x, y coordinates of the cat's position, one per line for each cat.
The positive direction on the x-axis is east, the positive direction on the y-axis is north, and all numbers given are integers.
Output
Output the number of cats on campus.
Example
Input
2
1 3 20 10
4
21 13
1 15
10 10
25 10
1 3 20 10
4
21 13
1 15
10 10
25 10
Output
2
2
|
{"inputs": ["2\n1 3 11 11\n4\n13 13\n2 15\n10 9\n5 10\n1 3 20 18\n4\n6 13\n2 15\n1 10\n25 4", "2\n1 3 20 16\n4\n13 13\n2 15\n10 10\n5 10\n0 3 20 0\n4\n1 8\n1 15\n10 10\n25 4", "2\n1 1 11 11\n4\n13 25\n2 15\n10 9\n5 14\n1 3 20 18\n4\n6 13\n2 15\n1 10\n25 4", "2\n1 3 6 10\n4\n21 13\n1 7\n10 10\n8 10\n1 0 20 10\n4\n21 6\n1 15\n7 10\n25 10", "2\n0 2 6 10\n4\n36 13\n1 15\n10 10\n25 10\n1 3 4 10\n4\n21 3\n1 15\n10 10\n25 0", "2\n1 3 20 21\n4\n13 13\n1 15\n10 10\n5 10\n2 3 20 18\n4\n5 13\n1 15\n10 1\n25 4", "2\n1 3 6 10\n4\n21 13\n1 15\n14 10\n25 1\n1 3 20 10\n4\n21 7\n1 15\n10 5\n25 10", "2\n1 3 6 10\n4\n21 13\n1 7\n10 10\n8 10\n1 0 20 10\n4\n21 6\n1 15\n10 10\n25 10"], "outputs": ["2\n3\n", "4\n0\n", "1\n3\n", "1\n2\n", "0\n0\n", "4\n1\n", "0\n2\n", "1\n2\n"]}
| 510
| 602
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef has to attend an exam that starts in X minutes, but of course, watching shows takes priority.
Every episode of the show that Chef is watching, is 24 minutes long.
If he starts watching a new episode now, will he finish watching it strictly before the exam starts?
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of one line of input, containing a single integer X — the amount of time from now at which Chef's exam starts.
------ Output Format ------
For each test case, output on a new line the answer — YES if Chef will finish his episode before the exam starts, and NO otherwise.
Each character of the output may be printed in either lowercase or uppercase, i.e, the string Yes, YES, yes, YeS will all be treated as equivalent.
------ Constraints ------
$1 ≤ T ≤ 100$
$1 ≤ X ≤ 100$
----- Sample Input 1 ------
4
30
23
60
24
----- Sample Output 1 ------
Yes
No
Yes
No
----- explanation 1 ------
Test case $1$: Chef has $30$ minutes of free time, which is easily enough to finish watching a $24$-minute episode. Hence, the answer is Yes.
Test case $2$: Chef has $23$ minutes of free time, which is not enough to finish watching a $24$-minute episode. Hence, the answer is No.
Test case $3$: Chef has $60$ minutes of free time, which is easily enough to finish watching a $24$-minute episode. Hence, the answer is Yes.
Test case $4$: Chef has $24$ minutes of free time. He will finish watching the episode exactly when the exam starts, and not strictly before it. Hence, the answer is No.
|
{"inputs": ["4\n30\n23\n60\n24\n"], "outputs": ["Yes\nNo\nYes\nNo\n"]}
| 420
| 32
|
coding
|
Solve the programming task below in a Python markdown code block.
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
-----Input-----
The only line of the input contains a single integer n (1 ≤ n ≤ 1000) — the position of the digit you need to print.
-----Output-----
Print the n-th digit of the line.
-----Examples-----
Input
3
Output
3
Input
11
Output
0
-----Note-----
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
|
{"inputs": ["3\n", "8\n", "2\n", "1\n", "8\n", "1\n", "2\n", "7\n"], "outputs": ["3\n", "8\n", "2\n", "1\n", "8\n", "1\n", "2\n", "7\n"]}
| 239
| 70
|
coding
|
Solve the programming task below in a Python markdown code block.
Given is a md5 hash of a five digits long PIN. It is given as string.
Md5 is a function to hash your password:
"password123" ===> "482c811da5d5b4bc6d497ffa98491e38"
Why is this useful?
Hash functions like md5 can create a hash from string in a short time and it is impossible to find out the password, if you only got the hash. The only way is cracking it, means try every combination, hash it and compare it with the hash you want to crack. (There are also other ways of attacking md5 but that's another story)
Every Website and OS is storing their passwords as hashes, so if a hacker gets access to the database, he can do nothing, as long the password is safe enough.
What is a hash:
https://en.wikipedia.org/wiki/Hash_function#:~:text=A%20hash%20function%20is%20any,table%20called%20a%20hash%20table.
What is md5:
https://en.wikipedia.org/wiki/MD5
Note: Many languages have build in tools to hash md5. If not, you can write your own md5 function or google for an example.
Here is another kata on generating md5 hashes:
https://www.codewars.com/kata/password-hashes
Your task is to return the cracked PIN as string.
This is a little fun kata, to show you, how weak PINs are and how important a bruteforce protection is, if you create your own login.
If you liked this kata, here is an extension with short passwords:
https://www.codewars.com/kata/59146f7b4670ba520900000a
Also feel free to reuse/extend the following starter code:
```python
def crack(hash):
```
|
{"functional": "_inputs = [['827ccb0eea8a706c4c34a16891f84e7b'], ['86aa400b65433b608a9db30070ec60cd']]\n_outputs = [['12345'], ['00078']]\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(crack(*i), o[0])"}
| 425
| 222
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Roma gave Chef an array of intergers.
Chef wants to make all integers in the array equal to 1.
In a single operation, he can select a prime number p and a subset of the integers, and then divide all of the integers in the subset by p.
Chef can make this operation only if every integer in the selected subset is divisible by p.
Please help Chef to make all the integers in the array equal to 1 with minimum number of operations.
------ Input ------
The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the length of the array that Roma gave Chef.
The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N} denoting the integers in the array.
------ Output ------
For each test case, output a single line containing one integer - the minimum number of operations needed to make all numbers equal to 1.
------ Constraints ------
$Subtask 1 (10 points): T = 5, 1 ≤ N ≤ 10^{5}, 1 ≤ A_{i} ≤ 3$
$Subtask 2 (40 points): T = 3, 1 ≤ N ≤ 10, 1 ≤ A_{i} ≤ 10^{6}$
$Subtask 3 (50 points): T = 3, 1 ≤ N ≤ 10^{5}, 1 ≤ A_{i} ≤ 10^{6}$
----- Sample Input 1 ------
1
3
1 2 4
----- Sample Output 1 ------
2
|
{"inputs": ["1\n3\n1 2 4"], "outputs": ["2"]}
| 380
| 20
|
coding
|
Solve the programming task below in a Python markdown code block.
You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor).
What is the minimum number of operations you need to make all of the elements equal to 1?
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements in the array.
The second line contains n space separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array.
Output
Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1.
Examples
Input
5
2 2 3 4 6
Output
5
Input
4
2 4 6 8
Output
-1
Input
3
2 6 9
Output
4
Note
In the first sample you can turn all numbers to 1 using the following 5 moves:
* [2, 2, 3, 4, 6].
* [2, 1, 3, 4, 6]
* [2, 1, 3, 1, 6]
* [2, 1, 1, 1, 6]
* [1, 1, 1, 1, 6]
* [1, 1, 1, 1, 1]
We can prove that in this case it is not possible to make all numbers one using less than 5 moves.
|
{"inputs": ["1\n1\n", "1\n3\n", "1\n5\n", "1\n6\n", "1\n8\n", "1\n11\n", "1\n10\n", "2\n1 1\n"], "outputs": ["0\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "0\n"]}
| 397
| 90
|
coding
|
Solve the programming task below in a Python markdown code block.
Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it G) initially has n vertices and 0 edges. During Bubble Sort execution, edges appear as described in the following algorithm (pseudocode).
procedure bubbleSortGraph()
build a graph G with n vertices and 0 edges
repeat
swapped = false
for i = 1 to n - 1 inclusive do:
if a[i] > a[i + 1] then
add an undirected edge in G between a[i] and a[i + 1]
swap( a[i], a[i + 1] )
swapped = true
end if
end for
until not swapped
/* repeat the algorithm as long as swapped value is true. */
end procedure
For a graph, an independent set is a set of vertices in a graph, no two of which are adjacent (so there are no edges between vertices of an independent set). A maximum independent set is an independent set which has maximum cardinality. Given the permutation, find the size of the maximum independent set of graph G, if we use such permutation as the premutation a in procedure bubbleSortGraph.
Input
The first line of the input contains an integer n (2 ≤ n ≤ 105). The next line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n).
Output
Output a single integer — the answer to the problem.
Examples
Input
3
3 1 2
Output
2
Note
Consider the first example. Bubble sort swaps elements 3 and 1. We add edge (1, 3). Permutation is now [1, 3, 2]. Then bubble sort swaps elements 3 and 2. We add edge (2, 3). Permutation is now sorted. We have a graph with 3 vertices and 2 edges (1, 3) and (2, 3). Its maximal independent set is [1, 2].
|
{"inputs": ["3\n3 2 1\n", "3\n2 1 3\n", "3\n1 2 3\n", "3\n3 1 2\n", "5\n4 2 1 3 5\n", "5\n3 2 1 4 5\n", "5\n4 1 2 3 5\n", "10\n1 9 8 10 2 3 4 6 5 7\n"], "outputs": ["1\n", "2\n", "3\n", "2\n", "3\n", "3\n", "4\n", "6\n"]}
| 487
| 146
|
coding
|
Solve the programming task below in a Python markdown code block.
Igor is in 11th grade. Tomorrow he will have to write an informatics test by the strictest teacher in the school, Pavel Denisovich.
Igor knows how the test will be conducted: first of all, the teacher will give each student two positive integers $a$ and $b$ ($a < b$). After that, the student can apply any of the following operations any number of times:
$a := a + 1$ (increase $a$ by $1$),
$b := b + 1$ (increase $b$ by $1$),
$a := a \ | \ b$ (replace $a$ with the bitwise OR of $a$ and $b$).
To get full marks on the test, the student has to tell the teacher the minimum required number of operations to make $a$ and $b$ equal.
Igor already knows which numbers the teacher will give him. Help him figure out what is the minimum number of operations needed to make $a$ equal to $b$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). Description of the test cases follows.
The only line for each test case contains two integers $a$ and $b$ ($1 \le a < b \le 10^6$).
It is guaranteed that the sum of $b$ over all test cases does not exceed $10^6$.
-----Output-----
For each test case print one integer — the minimum required number of operations to make $a$ and $b$ equal.
-----Examples-----
Input
5
1 3
5 8
2 5
3 19
56678 164422
Output
1
3
2
1
23329
-----Note-----
In the first test case, it is optimal to apply the third operation.
In the second test case, it is optimal to apply the first operation three times.
In the third test case, it is optimal to apply the second operation and then the third operation.
|
{"inputs": ["1\n99999 1000000\n", "1\n999999 1000000\n", "5\n1 3\n5 8\n2 5\n3 19\n56678 164422\n", "3\n186850 373693\n1 4\n313129 626299\n", "6\n1 4\n1 4\n4 5\n631059 999974\n1 2\n1 2\n", "4\n2 3\n183887 367789\n3 4\n316073 632198\n", "5\n2 3\n39710 210498\n394744 789486\n1 5\n2 4\n", "6\n1 4\n11286 22574\n488702 977404\n2 3\n1 5\n2 3\n"], "outputs": ["17504\n", "1\n", "1\n3\n2\n1\n23329\n", "75295\n2\n211119\n", "2\n2\n1\n24302\n1\n1\n", "1\n78243\n1\n208164\n", "1\n25821\n129545\n1\n2\n", "2\n5097\n35587\n1\n1\n1\n"]}
| 462
| 404
|
coding
|
Solve the programming task below in a Python markdown code block.
Mr. X stays in a mansion whose door opens in the North. He travels every morning to meet his friend Ms. Y walking a predefined path.
To cut the distance short, one day he decides to construct a skywalk from his place to his friend’s place. Help him to find the shortest distance between the two residences.
-----Input-----
The first line contains a single positive integer T <= 100, the number of test cases. T test cases follow. The only line of each test case contains a string which is the path from X to Y. The integer value represents the distance. The character R or L represents a Right or a Left respectively.
-----Output-----
For each test case, output a single line containing the minimum distance and the direction(N,S,W,E,NE,NW,SE,SW) of Y’s residence with respect to X’s residence. The output distance should have only 1 decimal place with no approximation. Print “0.0” if X’s and Y’s residence coincide.
-----Example-----
Input:
1
2 L 2 R 2 L 1
Output:
5.0NW
Explanation
Mr. X travels 2units and then takes a Left, and then he travels 2units and takes a Right, then after travelling 2units he takes a Left and finally travels 1unit to reach Y’s residence.
(Unlike Input, Output does not have spaces between the distance and direction)
|
{"inputs": ["1\n2 L 2 R 2 L 1"], "outputs": ["5.0NW"]}
| 308
| 26
|
coding
|
Solve the programming task below in a Python markdown code block.
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces.
Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met: Each piece of each cake is put on some plate; Each plate contains at least one piece of cake; No plate contains pieces of both cakes.
To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number x such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least x pieces of cake.
Help Ivan to calculate this number x!
-----Input-----
The first line contains three integers n, a and b (1 ≤ a, b ≤ 100, 2 ≤ n ≤ a + b) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.
-----Output-----
Print the maximum possible number x such that Ivan can distribute the cake in such a way that each plate will contain at least x pieces of cake.
-----Examples-----
Input
5 2 3
Output
1
Input
4 7 10
Output
3
-----Note-----
In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3.
|
{"inputs": ["5 2 3\n", "5 5 6\n", "2 4 3\n", "2 1 1\n", "5 6 7\n", "5 2 8\n", "3 2 3\n", "5 7 8\n"], "outputs": ["1\n", "2\n", "3\n", "1\n", "2\n", "2\n", "1\n", "2\n"]}
| 419
| 102
|
coding
|
Solve the programming task below in a Python markdown code block.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
- For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
- For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
-----Constraints-----
- 2 \leq p \leq 2999
- p is a prime number.
- 0 \leq a_i \leq 1
-----Input-----
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
-----Output-----
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
-----Sample Input-----
2
1 0
-----Sample Output-----
1 1
f(x) = x + 1 satisfies the conditions, as follows:
- f(0) = 0 + 1 = 1 \equiv 1 \pmod 2
- f(1) = 1 + 1 = 2 \equiv 0 \pmod 2
|
{"inputs": ["2\n0 0", "2\n0 1", "2\n1 1", "2\n1 1", "2\n0 1", "2\n0 0", "2\n1 0", "2\n1 0\n"], "outputs": ["0 0\n", "0 1\n", "1 0\n", "1 0\n", "0 1\n", "0 0\n", "1 1", "1 1\n"]}
| 380
| 110
|
coding
|
Solve the programming task below in a Python markdown code block.
Teddy and Freddy are two friends. Teddy has a pile of strings of size $N$. Each string $Si$ in the pile has length less or equal to $100$ ($len(Si) \leq 100$).
Teddy and Freddy like playing with strings. Teddy gives Freddy a string $B$ of size $M$.
Teddy and Freddy like playing with strings. Teddy gives Freddy a string $B$ of size $M$.
He asks Freddy to find the count of the unique substrings of $B$ present in pile of strings of size $N$.
Freddy is busy with the some task, so he asks for your help.Help Freddy by giving the unique substrings of $B$ present in pile of strings of size $N$.
Note: The substrings having same permutation of characters are considered same.
-----Input:-----
- First line will contain $N$, number of strings. Then the strings follow.
- Next $N$ lines will contain a string
- $N+2$ line contains the $M$ - length of string B
- Following line contains the string B
-----Output:-----
For each testcase, output in a single line number of unique strings of B.
-----Constraints-----
- $1 \leq N \leq 100$
- $2 \leq len(Si) \leq 100$
- $2 \leq M \leq 100$
-----Sample Input:-----
4
a
abc
abcd
abcde
5
aaaaa
-----Sample Output:-----
1
-----Sample Input:-----
4
a
aa
aaa
aaaa
5
aaaaa
-----Sample Output:-----
4
-----EXPLANATION:-----
TestCase 1: Only substring of $aaaaa$ that is present in the pile of strings is $a$. So the answer is 1
|
{"inputs": ["4\na\naa\naaa\naaaa\n5\naaaaa", "4\na\nabc\nabcd\nabcde\n5\naaaaa"], "outputs": ["4", "1"]}
| 412
| 45
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an unweighted, undirected graph. Write a program to check if it's a tree topology.
-----Input-----
The first line of the input file contains two integers N and M --- number of nodes and number of edges in the graph (0 < N <= 10000, 0 <= M <= 20000). Next M lines contain M edges of that graph --- Each line contains a pair (u, v) means there is an edge between node u and node v (1 <= u,v <= N).
-----Output-----
Print YES if the given graph is a tree, otherwise print NO.
-----Example-----
Input:
3 2
1 2
2 3
Output:
YES
|
{"inputs": ["3 2\n1 2\n2 3"], "outputs": ["YES"]}
| 163
| 22
|
coding
|
Solve the programming task below in a Python markdown code block.
We have the following sequence:
```python
f(0) = 0
f(1) = 1
f(2) = 1
f(3) = 2
f(4) = 4;
f(n) = f(n-1) + f(n-2) + f(n-3) + f(n-4) + f(n-5);
```
Your task is to give the number of total values for the odd terms of the sequence up to the n-th term (included). (The number n (of n-th term) will be given as a positive integer)
The values 1 (one) is the only that is duplicated in the sequence and should be counted only once.
E.g.
```
count_odd_pentaFib(5) -----> 1 # because the terms up to 5 are: 0, 1, 1, 2, 4, 8 (only 1 is odd and counted once)
```
Other examples:
```
count_odd_pentaFib(10) ------> 3 #because the odds terms are: [1, 1, 31, 61] (three different values)
count_odd_pentaFib(15) ------> 5 # beacause the odd terms are: [1, 1, 31, 61, 1793, 3525] (five different values)
```
Good luck !!
(Your code should be fast. Many moderate high values will be waiting to test it.)
Also feel free to reuse/extend the following starter code:
```python
def count_odd_pentaFib(n):
```
|
{"functional": "_inputs = [[0], [1], [2]]\n_outputs = [[0], [1], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(count_odd_pentaFib(*i), o[0])"}
| 369
| 170
|
coding
|
Solve the programming task below in a Python markdown code block.
Given are integer sequences A and B of length 3N. Each of these two sequences contains three copies of each of 1, 2, \dots, N. In other words, A and B are both arrangements of (1, 1, 1, 2, 2, 2, \dots, N, N, N).
Tak can perform the following operation to the sequence A arbitrarily many times:
* Pick a value from 1, 2, \dots, N and call it x. A contains exactly three copies of x. Remove the middle element of these three. After that, append x to the beginning or the end of A.
Check if he can turn A into B. If he can, print the minimum required number of operations to achieve that.
Constraints
* 1 \leq N \leq 33
* A and B are both arrangements of (1, 1, 1, 2, 2, 2, \dots, N, N, N).
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_{3N}
B_1 B_2 ... B_{3N}
Output
If Tak can turn A into B, print the minimum required number of operations to achieve that. Otherwise, print -1.
Examples
Input
3
2 3 1 1 3 2 2 1 3
1 2 2 3 1 2 3 1 3
Output
4
Input
3
1 1 1 2 2 2 3 3 3
1 1 1 2 2 2 3 3 3
Output
0
Input
3
2 3 3 1 1 1 2 2 3
3 2 2 1 1 1 3 3 2
Output
-1
Input
8
3 6 7 5 4 8 4 1 1 3 8 7 3 8 2 4 7 5 2 2 6 5 6 1
7 5 8 1 3 6 7 5 4 8 1 3 3 8 2 4 2 6 5 6 1 4 7 2
Output
7
|
{"inputs": ["3\n2 3 3 1 2 1 2 1 3\n3 2 2 1 1 1 3 3 2", "3\n1 1 1 2 2 2 3 3 3\n2 1 1 1 2 2 3 3 3", "3\n1 1 1 2 2 2 3 3 3\n1 1 1 2 3 2 3 3 2", "3\n2 3 3 1 2 1 2 1 3\n3 2 1 2 1 1 3 3 2", "3\n2 3 1 1 3 2 2 1 3\n1 2 1 3 1 2 3 2 3", "3\n3 3 1 1 3 2 2 1 2\n1 1 2 3 2 2 3 1 3", "3\n2 3 3 1 1 1 3 2 2\n3 2 2 1 1 1 3 3 2", "3\n1 1 2 2 1 2 3 3 3\n1 1 1 2 3 2 3 3 2"], "outputs": ["-1\n", "1\n", "4\n", "5\n", "7\n", "6\n", "-1\n", "-1\n"]}
| 538
| 351
|
coding
|
Solve the programming task below in a Python markdown code block.
William arrived at a conference dedicated to cryptocurrencies. Networking, meeting new people, and using friends' connections are essential to stay up to date with the latest news from the world of cryptocurrencies.
The conference has $n$ participants, who are initially unfamiliar with each other. William can introduce any two people, $a$ and $b$, who were not familiar before, to each other.
William has $d$ conditions, $i$'th of which requires person $x_i$ to have a connection to person $y_i$. Formally, two people $x$ and $y$ have a connection if there is such a chain $p_1=x, p_2, p_3, \dots, p_k=y$ for which for all $i$ from $1$ to $k - 1$ it's true that two people with numbers $p_i$ and $p_{i + 1}$ know each other.
For every $i$ ($1 \le i \le d$) William wants you to calculate the maximal number of acquaintances one person can have, assuming that William satisfied all conditions from $1$ and up to and including $i$ and performed exactly $i$ introductions. The conditions are being checked after William performed $i$ introductions. The answer for each $i$ must be calculated independently. It means that when you compute an answer for $i$, you should assume that no two people have been introduced to each other yet.
-----Input-----
The first line contains two integers $n$ and $d$ ($2 \le n \le 10^3, 1 \le d \le n - 1$), the number of people, and number of conditions, respectively.
Each of the next $d$ lines each contain two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n, x_i \neq y_i$), the numbers of people which must have a connection according to condition $i$.
-----Output-----
Output $d$ integers. $i$th number must equal the number of acquaintances the person with the maximal possible acquaintances will have, if William performed $i$ introductions and satisfied the first $i$ conditions.
-----Examples-----
Input
7 6
1 2
3 4
2 4
7 6
6 5
1 7
Output
1
1
3
3
3
6
Input
10 8
1 2
2 3
3 4
1 4
6 7
8 9
8 10
1 4
Output
1
2
3
4
5
5
6
8
-----Note-----
The explanation for the first test case:
In this explanation, the circles and the numbers in them denote a person with the corresponding number. The line denotes that William introduced two connected people. The person marked with red has the most acquaintances. These are not the only correct ways to introduce people.
|
{"inputs": ["2 1\n1 2\n", "3 1\n2 3\n", "4 1\n2 4\n", "3 2\n1 3\n3 1\n", "4 2\n2 4\n3 4\n", "4 3\n2 1\n4 1\n1 2\n", "7 6\n1 2\n3 4\n2 4\n7 6\n6 5\n1 7\n", "10 8\n1 2\n2 3\n3 4\n1 4\n6 7\n8 9\n8 10\n1 4\n"], "outputs": ["1\n", "1\n", "1\n", "1\n2\n", "1\n2\n", "1\n2\n3\n", "1\n1\n3\n3\n3\n6\n", "1\n2\n3\n4\n5\n5\n6\n8\n"]}
| 645
| 216
|
coding
|
Solve the programming task below in a Python markdown code block.
You already know that Valery's favorite sport is biathlon. Due to your help, he learned to shoot without missing, and his skills are unmatched at the shooting range. But now a smaller task is to be performed, he should learn to complete the path fastest.
The track's map is represented by a rectangle n × m in size divided into squares. Each square is marked with a lowercase Latin letter (which means the type of the plot), with the exception of the starting square (it is marked with a capital Latin letters S) and the terminating square (it is marked with a capital Latin letter T). The time of movement from one square to another is equal to 1 minute. The time of movement within the cell can be neglected. We can move from the cell only to side-adjacent ones, but it is forbidden to go beyond the map edges. Also the following restriction is imposed on the path: it is not allowed to visit more than k different types of squares (squares of one type can be visited an infinite number of times). Squares marked with S and T have no type, so they are not counted. But S must be visited exactly once — at the very beginning, and T must be visited exactly once — at the very end.
Your task is to find the path from the square S to the square T that takes minimum time. Among all shortest paths you should choose the lexicographically minimal one. When comparing paths you should lexicographically represent them as a sequence of characters, that is, of plot types.
Input
The first input line contains three integers n, m and k (1 ≤ n, m ≤ 50, n·m ≥ 2, 1 ≤ k ≤ 4). Then n lines contain the map. Each line has the length of exactly m characters and consists of lowercase Latin letters and characters S and T. It is guaranteed that the map contains exactly one character S and exactly one character T.
Pretest 12 is one of the maximal tests for this problem.
Output
If there is a path that satisfies the condition, print it as a sequence of letters — the plot types. Otherwise, print "-1" (without quotes). You shouldn't print the character S in the beginning and T in the end.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted.
Examples
Input
5 3 2
Sba
ccc
aac
ccc
abT
Output
bcccc
Input
3 4 1
Sxyy
yxxx
yyyT
Output
xxxx
Input
1 3 3
TyS
Output
y
Input
1 4 1
SxyT
Output
-1
|
{"inputs": ["1 2 4\nST\n", "1 2 1\nST\n", "2 1 4\nS\nT\n", "1 3 3\nSaT\n", "2 1 1\nS\nT\n", "1 3 3\nTyS\n", "1 4 1\nSxyT\n", "3 3 1\naaa\naaa\nTSa\n"], "outputs": ["\n", "\n", "\n", "a\n", "\n", "y\n", "-1\n", "\n"]}
| 592
| 127
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have n robots. You are given two 0-indexed integer arrays, chargeTimes and runningCosts, both of length n. The ith robot costs chargeTimes[i] units to charge and costs runningCosts[i] units to run. You are also given an integer budget.
The total cost of running k chosen robots is equal to max(chargeTimes) + k * sum(runningCosts), where max(chargeTimes) is the largest charge cost among the k robots and sum(runningCosts) is the sum of running costs among the k robots.
Return the maximum number of consecutive robots you can run such that the total cost does not exceed budget.
Please complete the following python code precisely:
```python
class Solution:
def maximumRobots(self, chargeTimes: List[int], runningCosts: List[int], budget: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(chargeTimes = [3,6,1,3,4], runningCosts = [2,1,3,4,5], budget = 25) == 3\n assert candidate(chargeTimes = [11,12,19], runningCosts = [10,8,7], budget = 19) == 0\n\n\ncheck(Solution().maximumRobots)"}
| 197
| 102
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
We call a positive integer special if all of its digits are distinct.
Given a positive integer n, return the number of special integers that belong to the interval [1, n].
Please complete the following python code precisely:
```python
class Solution:
def countSpecialNumbers(self, n: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 20) == 19\n assert candidate(n = 5) == 5\n assert candidate(n = 135) == 110\n\n\ncheck(Solution().countSpecialNumbers)"}
| 84
| 62
|
coding
|
Solve the programming task below in a Python markdown code block.
Polycarp has a string $s[1 \dots n]$ of length $n$ consisting of decimal digits. Polycarp performs the following operation with the string $s$ no more than once (i.e. he can perform operation $0$ or $1$ time):
Polycarp selects two numbers $i$ and $j$ ($1 \leq i \leq j \leq n$) and removes characters from the $s$ string at the positions $i, i+1, i+2, \ldots, j$ (i.e. removes substring $s[i \dots j]$). More formally, Polycarp turns the string $s$ into the string $s_1 s_2 \ldots s_{i-1} s_{j+1} s_{j+2} \ldots s_{n}$.
For example, the string $s = $"20192020" Polycarp can turn into strings:
"2020" (in this case $(i, j)=(3, 6)$ or $(i, j)=(1, 4)$);
"2019220" (in this case $(i, j)=(6, 6)$);
"020" (in this case $(i, j)=(1, 5)$);
other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string $s$ into a string "2020" in no more than one operation? Note that you can perform zero operations.
-----Input-----
The first line contains a positive integer $t$ ($1 \leq t \leq 1000 $) — number of test cases in the test. Then $t$ test cases follow.
The first line of each test case contains an integer $n$ ($4 \leq n \leq 200$) — length of the string $s$. The next line contains a string $s$ of length $n$ consisting of decimal digits. It is allowed that the string $s$ starts with digit 0.
-----Output-----
For each test case, output on a separate line:
"YES" if Polycarp can turn the string $s$ into a string "2020" in no more than one operation (i.e. he can perform $0$ or $1$ operation);
"NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
-----Examples-----
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
-----Note-----
In the first test case, Polycarp could choose $i=3$ and $j=6$.
In the second test case, Polycarp could choose $i=2$ and $j=5$.
In the third test case, Polycarp did not perform any operations with the string.
|
{"inputs": ["1\n4\n2021\n", "1\n4\n2029\n", "1\n4\n2030\n", "1\n4\n2040\n", "1\n4\n2050\n", "1\n4\n2090\n", "1\n4\n2080\n", "1\n4\n2070\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
| 730
| 126
|
coding
|
Solve the programming task below in a Python markdown code block.
We will define the median of a sequence b of length M, as follows:
- Let b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th element of b' is the median of b. Here, / is integer division, rounding down.
For example, the median of (10, 30, 20) is 20; the median of (10, 30, 20, 40) is 30; the median of (10, 10, 10, 20, 30) is 10.
Snuke comes up with the following problem.
You are given a sequence a of length N.
For each pair (l, r) (1 \leq l \leq r \leq N), let m_{l, r} be the median of the contiguous subsequence (a_l, a_{l + 1}, ..., a_r) of a.
We will list m_{l, r} for all pairs (l, r) to create a new sequence m.
Find the median of m.
-----Constraints-----
- 1 \leq N \leq 10^5
- a_i is an integer.
- 1 \leq a_i \leq 10^9
-----Input-----
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N
-----Output-----
Print the median of m.
-----Sample Input-----
3
10 30 20
-----Sample Output-----
30
The median of each contiguous subsequence of a is as follows:
- The median of (10) is 10.
- The median of (30) is 30.
- The median of (20) is 20.
- The median of (10, 30) is 30.
- The median of (30, 20) is 30.
- The median of (10, 30, 20) is 20.
Thus, m = (10, 30, 20, 30, 30, 20) and the median of m is 30.
|
{"inputs": ["1\n4", "1\n2", "1\n7", "1\n3", "1\n6", "1\n1", "1\n5", "1\n8"], "outputs": ["4\n", "2\n", "7\n", "3\n", "6\n", "1\n", "5\n", "8\n"]}
| 508
| 78
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a non-negative integer array nums. In one operation, you must:
Choose a positive integer x such that x is less than or equal to the smallest non-zero element in nums.
Subtract x from every positive element in nums.
Return the minimum number of operations to make every element in nums equal to 0.
Please complete the following python code precisely:
```python
class Solution:
def minimumOperations(self, nums: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1,5,0,3,5]) == 3\n assert candidate(nums = [0]) == 0\n\n\ncheck(Solution().minimumOperations)"}
| 114
| 51
|
coding
|
Solve the programming task below in a Python markdown code block.
D: Sunburn-Suntan-
story
Aizunyan is a second-year student who belongs to the programming contest club of Wakagamatsu High School, commonly known as the Prokon club. Cute like an angel. Aizu Nyan is planning to participate in this summer festival, so I made a schedule for the band to go to listen to. I'm worried about sunburn here. All live performances are held outdoors, but Aizu Nyan has a constitution that makes it easy to get sunburned, so if you are exposed to too much ultraviolet rays outdoors for a long time, you will get sunburned immediately. I plan to avoid UV rays as much as possible by evacuating indoors while there is no live performance, but during the live performance, it will inevitably hit the sun. Therefore, Aizu Nyan thought about taking measures against ultraviolet rays by applying sunscreen.
problem
If you apply sunscreen, you can get the effect for T minutes from the time you apply it. Sunscreen can only be applied once, so I want to use it effectively. Aizu Nyan is outdoors from the start time to the end time of the live, and is indoors at other times. You'll be given a live schedule that Aizu Nyan will listen to, so find the maximum amount of time you can get the sunscreen effect while you're outdoors.
Input format
The input can be given in the following format.
T
N
s_1 t_1
...
s_N t_N
The first line is given an integer T that represents the time it takes to get the sunscreen effect. The second line is given an integer N that represents the number of live concerts Aizu Nyan listens to. The following N lines are given the integer s_i, which represents the start time of the live that Aizu Nyan listens to thi, and the integer t_i, which represents the end time, separated by spaces.
Constraint
* 1 ≤ T ≤ 10 ^ {15}
* 1 ≤ N ≤ 10 ^ 5
* 0 ≤ s_i <t_i ≤ 10 ^ {15} (1 ≤ i ≤ N)
* The start time of the (i + 1) th live is the same as or later than the end time of the i-th live. That is, t_i ≤ s_ {i + 1} (1 ≤ i <N)
output
Print one line for the maximum amount of time you can get the sunscreen effect while you're outdoors.
Input example 1
20
1
0 10
Output example 1
Ten
Input example 2
20
1
0 100
Output example 2
20
Input example 3
9
3
1 5
9 11
13 20
Output example 3
7
Input example 4
twenty five
Five
9 12
15 20
21 25
28 40
45 60
Output example 4
twenty one
Example
Input
20
1
0 10
Output
10
|
{"inputs": ["20\n1\n0 7", "20\n1\n3 7", "20\n1\n2 7", "20\n1\n0 3", "20\n1\n4 6", "20\n1\n6 7", "20\n1\n0 4", "20\n1\n1 4"], "outputs": ["7\n", "4\n", "5\n", "3\n", "2\n", "1\n", "4\n", "3\n"]}
| 679
| 118
|
coding
|
Solve the programming task below in a Python markdown code block.
There are N islands and M bridges.
The i-th bridge connects the A_i-th and B_i-th islands bidirectionally.
Initially, we can travel between any two islands using some of these bridges.
However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge.
Let the inconvenience be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining.
For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses.
-----Constraints-----
- All values in input are integers.
- 2 \leq N \leq 10^5
- 1 \leq M \leq 10^5
- 1 \leq A_i < B_i \leq N
- All pairs (A_i, B_i) are distinct.
- The inconvenience is initially 0.
-----Input-----
Input is given from Standard Input in the following format:
N M
A_1 B_1
A_2 B_2
\vdots
A_M B_M
-----Output-----
In the order i = 1, 2, ..., M, print the inconvenience just after the i-th bridge collapses.
Note that the answer may not fit into a 32-bit integer type.
-----Sample Input-----
4 5
1 2
3 4
1 3
2 3
1 4
-----Sample Output-----
0
0
4
5
6
For example, when the first to third bridges have collapsed, the inconvenience is 4 since we can no longer travel between the pairs (1, 2), (1, 3), (2, 4) and (3, 4).
|
{"inputs": ["2 1\n2 2", "2 1\n1 2", "2 1\n1 2\n", "6 5\n3 3\n1 2\n5 6\n3 4\n4 5", "4 5\n1 2\n3 4\n1 3\n3 3\n1 4", "6 5\n3 3\n1 2\n5 6\n3 4\n2 5", "4 5\n1 2\n3 4\n1 3\n3 3\n1 1", "6 5\n2 3\n1 2\n5 6\n3 4\n4 3"], "outputs": ["1\n", "1", "1\n", "8\n9\n12\n14\n15\n", "3\n3\n5\n5\n6\n", "8\n11\n13\n14\n15\n", "3\n5\n6\n6\n6\n", "12\n13\n14\n14\n15\n"]}
| 411
| 242
|
coding
|
Solve the programming task below in a Python markdown code block.
Every number may be factored in prime factors.
For example, the number 18 may be factored by its prime factors ``` 2 ``` and ```3```
```
18 = 2 . 3 . 3 = 2 . 3²
```
The sum of the prime factors of 18 is ```2 + 3 + 3 = 8```
But some numbers like 70 are divisible by the sum of its prime factors:
```
70 = 2 . 5 . 7 # sum of prime factors = 2 + 5 + 7 = 14
and 70 is a multiple of 14
```
Of course that primes would fulfill this property, but is obvious, because the prime decomposition of a number, is the number itself and every number is divisible by iself. That is why we will discard every prime number in the results
We are interested in collect the integer positive numbers (non primes) that have this property in a certain range ```[a, b]``` (inclusive).
Make the function ```mult_primefactor_sum()```, that receives the values ```a```, ```b``` as limits of the range ```[a, b]``` and ```a < b``` and outputs the sorted list of these numbers.
Let's see some cases:
```python
mult_primefactor_sum(10, 100) == [16, 27, 30, 60, 70, 72, 84]
mult_primefactor_sum(1, 60) == [1, 4, 16, 27, 30, 60]
```
Also feel free to reuse/extend the following starter code:
```python
def mult_primefactor_sum(a, b):
```
|
{"functional": "_inputs = [[10, 100], [80, 150], [90, 200]]\n_outputs = [[[16, 27, 30, 60, 70, 72, 84]], [[84, 105, 150]], [[105, 150, 180]]]\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(mult_primefactor_sum(*i), o[0])"}
| 399
| 235
|
coding
|
Solve the programming task below in a Python markdown code block.
Timmy & Sarah think they are in love, but around where they live, they will only know once they pick a flower each. If one of the flowers has an even number of petals and the other has an odd number of petals it means they are in love.
Write a function that will take the number of petals of each flower and return true if they are in love and false if they aren't.
Also feel free to reuse/extend the following starter code:
```python
def lovefunc( flower1, flower2 ):
```
|
{"functional": "_inputs = [[1, 4], [2, 2], [0, 1], [0, 0]]\n_outputs = [[True], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(lovefunc(*i), o[0])"}
| 122
| 185
|
coding
|
Solve the programming task below in a Python markdown code block.
Complete the function that accepts a string parameter, and reverses each word in the string. **All** spaces in the string should be retained.
## Examples
```
"This is an example!" ==> "sihT si na !elpmaxe"
"double spaces" ==> "elbuod secaps"
```
Also feel free to reuse/extend the following starter code:
```python
def reverse_words(text):
```
|
{"functional": "_inputs = [['The quick brown fox jumps over the lazy dog.'], ['apple'], ['a b c d'], ['double spaced words'], ['stressed desserts'], ['hello hello']]\n_outputs = [['ehT kciuq nworb xof spmuj revo eht yzal .god'], ['elppa'], ['a b c d'], ['elbuod decaps sdrow'], ['desserts stressed'], ['olleh olleh']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(reverse_words(*i), o[0])"}
| 102
| 242
|
coding
|
Solve the programming task below in a Python markdown code block.
A person is said to be sleep deprived if he slept strictly less than 7 hours in a day.
Chef was only able to sleep X hours yesterday. Determine if he is sleep deprived or not.
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains one integer X — the number of hours Chef slept.
------ Output Format ------
For each test case, output YES if Chef is sleep-deprived. Otherwise, output NO.
You may print each character of YES and NO in uppercase or lowercase (for example, yes, yEs, Yes will be considered identical).
------ Constraints ------
$1 ≤ T ≤ 20$
$1 ≤X ≤15$
----- Sample Input 1 ------
3
4
7
10
----- Sample Output 1 ------
YES
NO
NO
----- explanation 1 ------
Test Case 1: Since $4 < 7$, Chef is sleep deprived.
Test Case 2: Since $7 ≥ 7$, Chef is not sleep deprived.
Test Case 3: Since $10 ≥ 7$, Chef is not sleep deprived.
|
{"inputs": ["3\n4\n7\n10\n"], "outputs": ["YES\nNO\nNO\n"]}
| 265
| 25
|
coding
|
Solve the programming task below in a Python markdown code block.
Polycarpus has a sequence, consisting of n non-negative integers: a1, a2, ..., an.
Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = al | al + 1 | ... | ar.
Polycarpus took a piece of paper and wrote out the values of function f(l, r) for all l, r (l, r are integer, 1 ≤ l ≤ r ≤ n). Now he wants to know, how many distinct values he's got in the end.
Help Polycarpus, count the number of distinct values of function f(l, r) for the given sequence a.
Expression x | y means applying the operation of bitwise OR to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "|", in Pascal — as "or".
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of elements of sequence a. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 106) — the elements of sequence a.
Output
Print a single integer — the number of distinct values of function f(l, r) for the given sequence a.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
3
1 2 0
Output
4
Input
10
1 2 3 4 5 6 1 2 9 10
Output
11
Note
In the first test case Polycarpus will have 6 numbers written on the paper: f(1, 1) = 1, f(1, 2) = 3, f(1, 3) = 3, f(2, 2) = 2, f(2, 3) = 2, f(3, 3) = 0. There are exactly 4 distinct numbers among them: 0, 1, 2, 3.
|
{"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n5\n", "1\n6\n", "1\n51\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
| 517
| 87
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A happy string is a string that:
consists only of letters of the set ['a', 'b', 'c'].
s[i] != s[i + 1] for all values of i from 1 to s.length - 1 (string is 1-indexed).
For example, strings "abc", "ac", "b" and "abcbabcbcb" are all happy strings and strings "aa", "baa" and "ababbc" are not happy strings.
Given two integers n and k, consider a list of all happy strings of length n sorted in lexicographical order.
Return the kth string of this list or return an empty string if there are less than k happy strings of length n.
Please complete the following python code precisely:
```python
class Solution:
def getHappyString(self, n: int, k: int) -> str:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 1, k = 3) == \"c\"\n assert candidate(n = 1, k = 4) == \"\"\n assert candidate(n = 3, k = 9) == \"cab\"\n assert candidate(n = 2, k = 7) == \"\"\n assert candidate(n = 10, k = 100) == \"abacbabacb\"\n\n\ncheck(Solution().getHappyString)"}
| 204
| 114
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string word to which you can insert letters "a", "b" or "c" anywhere and any number of times, return the minimum number of letters that must be inserted so that word becomes valid.
A string is called valid if it can be formed by concatenating the string "abc" several times.
Please complete the following python code precisely:
```python
class Solution:
def addMinimum(self, word: str) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(word = \"b\") == 2\n assert candidate(word = \"aaa\") == 6\n assert candidate(word = \"abc\") == 0\n\n\ncheck(Solution().addMinimum)"}
| 111
| 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. Reorder the string using the following algorithm:
Remove the smallest character from s and append it to the result.
Remove the smallest character from s that is greater than the last appended character, and append it to the result.
Repeat step 2 until no more characters can be removed.
Remove the largest character from s and append it to the result.
Remove the largest character from s that is smaller than the last appended character, and append it to the result.
Repeat step 5 until no more characters can be removed.
Repeat steps 1 through 6 until all characters from s have been removed.
If the smallest or largest character appears more than once, you may choose any occurrence to append to the result.
Return the resulting string after reordering s using this algorithm.
Please complete the following python code precisely:
```python
class Solution:
def sortString(self, s: str) -> str:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"aaaabbbbcccc\") == \"abccbaabccba\"\n assert candidate(s = \"rat\") == \"art\"\n assert candidate(s = \"leetcode\") == \"cdelotee\"\n assert candidate(s = \"ggggggg\") == \"ggggggg\"\n assert candidate(s = \"spo\") == \"ops\"\n\n\ncheck(Solution().sortString)"}
| 207
| 101
|
coding
|
Solve the programming task below in a Python markdown code block.
Alex is transitioning from website design to coding and wants to sharpen his skills with CodeWars.
He can do ten kata in an hour, but when he makes a mistake, he must do pushups. These pushups really tire poor Alex out, so every time he does them they take twice as long. His first set of redemption pushups takes 5 minutes. Create a function, `alexMistakes`, that takes two arguments: the number of kata he needs to complete, and the time in minutes he has to complete them. Your function should return how many mistakes Alex can afford to make.
Also feel free to reuse/extend the following starter code:
```python
def alex_mistakes(number_of_katas, time_limit):
```
|
{"functional": "_inputs = [[10, 120], [11, 120], [3, 45], [8, 120], [6, 60], [9, 180], [20, 120], [20, 125], [20, 130], [20, 135]]\n_outputs = [[3], [3], [2], [3], [2], [4], [0], [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(alex_mistakes(*i), o[0])"}
| 164
| 265
|
coding
|
Solve the programming task below in a Python markdown code block.
Not everyone probably knows that Chef has younder brother Jeff. Currently Jeff learns to read.
He knows some subset of the letter of Latin alphabet. In order to help Jeff to study, Chef gave him a book with the text consisting of N words. Jeff can read a word iff it consists only of the letters he knows.
Now Chef is curious about which words his brother will be able to read, and which are not. Please help him!
-----Input-----
The first line of the input contains a lowercase Latin letter string S, consisting of the letters Jeff can read. Every letter will appear in S no more than once.
The second line of the input contains an integer N denoting the number of words in the book.
Each of the following N lines contains a single lowecase Latin letter string Wi, denoting the ith word in the book.
-----Output-----
For each of the words, output "Yes" (without quotes) in case Jeff can read it, and "No" (without quotes) otherwise.
-----Constraints-----
- 1 ≤ |S| ≤ 26
- 1 ≤ N ≤ 1000
- 1 ≤ |Wi| ≤ 12
- Each letter will appear in S no more than once.
- S, Wi consist only of lowercase Latin letters.
-----Subtasks-----
- Subtask #1 (31 point): |S| = 1, i.e. Jeff knows only one letter.
- Subtask #2 (69 point) : no additional constraints
-----Example-----
Input:act
2
cat
dog
Output:Yes
No
-----Explanation-----
The first word can be read.
The second word contains the letters d, o and g that aren't known by Jeff.
|
{"inputs": ["act\n2\ncat\ndog"], "outputs": ["Yes\nNo"]}
| 373
| 22
|
coding
|
Solve the programming task below in a Python markdown code block.
And where the are the phone numbers?
You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s is lexicographically smaller than t.
It's guaranteed that the answer exists.
Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {a, b, d}.
String p is lexicographically smaller than string q, if p is a prefix of q, is not equal to q or there exists i, such that p_{i} < q_{i} and for all j < i it is satisfied that p_{j} = q_{j}. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a.
-----Input-----
The first line of input contains two space separated integers n and k (1 ≤ n, k ≤ 100 000) — the length of s and the required length of t.
The second line of input contains the string s consisting of n lowercase English letters.
-----Output-----
Output the string t conforming to the requirements above.
It's guaranteed that the answer exists.
-----Examples-----
Input
3 3
abc
Output
aca
Input
3 2
abc
Output
ac
Input
3 3
ayy
Output
yaa
Input
2 3
ba
Output
baa
-----Note-----
In the first example the list of strings t of length 3, such that the set of letters of t is a subset of letters of s is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca.
|
{"inputs": ["1 3\nf\n", "1 3\nf\n", "1 3\ne\n", "1 6\ne\n", "2 3\nba\n", "2 3\ngi\n", "2 3\ngi\n", "2 3\nhi\n"], "outputs": ["fff\n", "fff\n", "eee\n", "eeeeee\n", "baa\n", "gig\n", "gig\n", "hih\n"]}
| 447
| 109
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well.
There are three distinct points - A, B, C in the X-Y plane. Initially, you are located at point A. You want to reach the point C satisfying the following conditions:
You have to go through point B.
You can move in any of the four axis-parallel directions (+X, -X, +Y, -Y direction). However, you can make at most one turn in the path from A to C.
Determine if it is possible to reach the destination C satisfying the above conditions.
NOTE:
One turn means 90 ^ \circ clockwise or anticlockwise rotation along the direction of movement. For example, if you are moving towards the +X direction, after one turn you can move either in the +Y direction or in the -Y direction. Changing the direction by 180 ^ \circ is not allowed.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains two space-separated integers X_{A}, Y_{A}, denoting the coordinates of the starting point A.
- The second line of each test case contains two space-separated integers X_{B}, Y_{B}, denoting the coordinates of the point B.
- The third line of each test case contains two space-separated integers X_{C}, Y_{C}, denoting the coordinates of the finishing point C.
------ Output Format ------
For each test case, print a single line containing one string - "YES"(without quotes) if it is possible to reach the finishing point satisfying the above conditions, otherwise print "NO"(without quotes).
------ Constraints ------
$1 ≤ T ≤ 2 \cdot 10^{5}$
$-10^{9} ≤ X_{A}, Y_{A}, X_{B}, Y_{B}, X_{C}, Y_{C} ≤ 10^{9}$
- Three points are pairwise distinct
----- Sample Input 1 ------
4
1 1
1 3
3 3
0 0
2 2
3 4
5 2
3 2
1 2
1 1
-1 1
10000 10000
----- Sample Output 1 ------
YES
NO
YES
NO
----- explanation 1 ------
- Test case $1$: You start moving in the $+Y$ direction from $A = (1, 1)$, after two-unit steps you reach the point $B = (1, 3)$. Then you make a clockwise turn at point $B$ and start moving towards the $+X$ direction. After two-unit steps, you reach the finishing point $C = (3, 3)$.
- Test case $2$: There is no possible way to reach the finishing point $C$ satisfying the above conditions. You have to make at least two turns in the path.
- Test case $3$: You start moving in the $-X$ direction from $A = (5, 2)$ . After 4 unit steps, you reach the finish point $C = (1, 2)$. In the path from $A$ to $C$, you go through the point $B = (3,2)$ and don't make any turn.
|
{"inputs": ["4\n1 1\n1 3\n3 3\n0 0\n2 2\n3 4\n5 2\n3 2\n1 2\n1 1\n-1 1\n10000 10000\n"], "outputs": ["YES\nNO\nYES\nNO"]}
| 746
| 76
|
coding
|
Solve the programming task below in a Python markdown code block.
A family of kookaburras are in my backyard.
I can't see them all, but I can hear them!
# How many kookaburras are there?
## Hint
The trick to counting kookaburras is to listen carefully
* The males go ```HaHaHa```...
* The females go ```hahaha```...
* And they always alternate male/female
^ Kata Note : No validation is necessary; only valid input will be passed :-)
Also feel free to reuse/extend the following starter code:
```python
def kooka_counter(laughing):
```
|
{"functional": "_inputs = [[''], ['hahahahaha'], ['hahahahahaHaHaHa'], ['HaHaHahahaHaHa'], ['hahahahahahahaHaHa']]\n_outputs = [[0], [1], [2], [3], [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(kooka_counter(*i), o[0])"}
| 139
| 200
|
coding
|
Solve the programming task below in a Python markdown code block.
Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so.
Operation: Choose one character of S and replace it with a different character.
-----Constraints-----
- S and T have lengths between 1 and 2\times 10^5 (inclusive).
- S and T consists of lowercase English letters.
- S and T have equal lengths.
-----Input-----
Input is given from Standard Input in the following format:
S
T
-----Output-----
Print the answer.
-----Sample Input-----
cupofcoffee
cupofhottea
-----Sample Output-----
4
We can achieve the objective in four operations, such as the following:
- First, replace the sixth character c with h.
- Second, replace the eighth character f with t.
- Third, replace the ninth character f with t.
- Fourth, replace the eleventh character e with a.
|
{"inputs": ["apple\nelppa", "abcdd\nbcdea", "elppa\nelppa", "elppa\nelppb", "elpap\nelppb", "ddc`a\nbbcfa", "ddcba\nbcdea", "cdcba\nbcdea"], "outputs": ["4\n", "5\n", "0\n", "1\n", "2\n", "3\n", "4\n", "4\n"]}
| 203
| 101
|
coding
|
Solve the programming task below in a Python markdown code block.
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second.
He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
Constraints
* -10^9 \leq A,B \leq 10^9
* 1 \leq V,W \leq 10^9
* 1 \leq T \leq 10^9
* A \neq B
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A V
B W
T
Output
If "it" can catch the other child, print `YES`; otherwise, print `NO`.
Examples
Input
1 2
3 1
3
Output
YES
Input
1 2
3 2
3
Output
NO
Input
1 2
3 3
3
Output
NO
|
{"inputs": ["1 0\n3 3\n3", "1 3\n3 2\n3", "1 2\n3 0\n3", "1 0\n3 6\n3", "0 3\n3 2\n3", "1 2\n5 0\n3", "1 0\n3 8\n3", "0 2\n5 0\n3"], "outputs": ["NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n"]}
| 287
| 126
|
coding
|
Solve the programming task below in a Python markdown code block.
The Ackermann function is a famous function that played a big role in computability theory as the first example of a total computable function that is not primitive recursive.
Since then the function has been a bit simplified but is still of good use. Due to its definition in terms of extremely deep recursion it can be used as a benchmark of a compiler's ability to optimize recursion.
The goal of this kata is to code a function which will be given two inputs, m and n, and will return the Ackermann number A(m,n) defined by:
```
A(m,n) = n+1 if m=0
A(m,n) = A(m-1,1) if m>0 , n=0
A(m,n) = A(m-1,A(m,n-1)) if m,n > 0
```
m,n should be non-negative integers, the function should return null (Javascript), None (Python), or nil (Ruby) for other type, non-integer and negative numbers. In C, input is restricted to integer type.
Also feel free to reuse/extend the following starter code:
```python
def Ackermann(m,n):
```
|
{"functional": "_inputs = [[1, 1], [4, 0], [3, 3]]\n_outputs = [[3], [13], [61]]\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(Ackermann(*i), o[0])"}
| 255
| 178
|
coding
|
Solve the programming task below in a Python markdown code block.
**This Kata is intended as a small challenge for my students**
All Star Code Challenge #18
Create a function called that accepts 2 string arguments and returns an integer of the count of occurrences the 2nd argument is found in the first one.
If no occurrences can be found, a count of 0 should be returned.
Notes:
* The first argument can be an empty string
* The second string argument will always be of length 1
Also feel free to reuse/extend the following starter code:
```python
def str_count(strng, letter):
```
|
{"functional": "_inputs = [['hello', 'l'], ['hello', 'e'], ['codewars', 'c'], ['ggggg', 'g'], ['hello world', 'o']]\n_outputs = [[2], [1], [1], [5], [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(str_count(*i), o[0])"}
| 130
| 198
|
coding
|
Solve the programming task below in a Python markdown code block.
Patlu has recently got a new problem based on Pallindromes. A Pallindrome is a number that is same from front and back, example $121$ is pallindrome but $123$ is not . He wants to calculate sum of all $N$ digit number which are Pallindromic in nature and divisible by $9$ and does not contain any zero in their decimal representation. As the answer can be very large so print the sum modulo $10^9 + 7$.
-----Input:-----
- First line of input contain $T$, number of testcases. Then the testcases follow.
- Each testcase contains single line of input , one integer $N$.
-----Output:-----
- For each testcase, output in a single line answer having $N$ digits pallindromic string.
-----Constraints-----
- $1\leq T \leq 100$
- $1\leq N \leq 10^5$
-----Sample Input:-----
2
1
2
-----Sample Output:-----
9
99
|
{"inputs": ["2\n1\n2"], "outputs": ["9\n99"]}
| 238
| 19
|
coding
|
Solve the programming task below in a Python markdown code block.
In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are m_{i} tasks assigned to the i-th server.
In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression m_{a} - m_{b}, where a is the most loaded server and b is the least loaded one.
In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another.
Write a program to find the minimum number of seconds needed to balance the load of servers.
-----Input-----
The first line contains positive number n (1 ≤ n ≤ 10^5) — the number of the servers.
The second line contains the sequence of non-negative integers m_1, m_2, ..., m_{n} (0 ≤ m_{i} ≤ 2·10^4), where m_{i} is the number of tasks assigned to the i-th server.
-----Output-----
Print the minimum number of seconds required to balance the load.
-----Examples-----
Input
2
1 6
Output
2
Input
7
10 11 10 11 10 11 11
Output
0
Input
5
1 2 3 4 5
Output
3
-----Note-----
In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2.
In the second example the load is already balanced.
A possible sequence of task movements for the third example is: move a task from server #4 to server #1 (the sequence m becomes: 2 2 3 3 5); then move task from server #5 to server #1 (the sequence m becomes: 3 2 3 3 4); then move task from server #5 to server #2 (the sequence m becomes: 3 3 3 3 3).
The above sequence is one of several possible ways to balance the load of servers in three seconds.
|
{"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n6\n", "1\n5\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
| 519
| 86
|
coding
|
Solve the programming task below in a Python markdown code block.
An array $b$ is good if the sum of elements of $b$ is even.
You are given an array $a$ consisting of $n$ positive integers. In one operation, you can select an index $i$ and change $a_i := \lfloor \frac{a_i}{2} \rfloor$. $^\dagger$
Find the minimum number of operations (possibly $0$) needed to make $a$ good. It can be proven that it is always possible to make $a$ good.
$^\dagger$ $\lfloor x \rfloor$ denotes the floor function — the largest integer less than or equal to $x$. For example, $\lfloor 2.7 \rfloor = 2$, $\lfloor \pi \rfloor = 3$ and $\lfloor 5 \rfloor =5$.
-----Input-----
Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 1000$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 50$) — 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 10^6$) — representing the array $a$.
Do note that the sum of $n$ over all test cases is not bounded.
-----Output-----
For each test case, output the minimum number of operations needed to make $a$ good.
-----Examples-----
Input
4
4
1 1 1 1
2
7 4
3
1 2 4
1
15
Output
0
2
1
4
-----Note-----
In the first test case, array $a$ is already good.
In the second test case, we can perform on index $2$ twice. After the first operation, array $a$ becomes $[7,2]$. After performing on index $2$ again, $a$ becomes $[7,1]$, which is good. It can be proved that it is not possible to make $a$ good in less number of operations.
In the third test case, $a$ becomes $[0,2,4]$ if we perform the operation on index $1$ once. As $[0,2,4]$ is good, answer is $1$.
In the fourth test case, we need to perform the operation on index $1$ four times. After all operations, $a$ becomes $[0]$. It can be proved that it is not possible to make $a$ good in less number of operations.
|
{"inputs": ["1\n1\n524287\n", "4\n4\n1 1 1 1\n2\n7 4\n3\n1 2 4\n1\n15\n"], "outputs": ["19\n", "0\n2\n1\n4\n"]}
| 616
| 67
|
coding
|
Solve the programming task below in a Python markdown code block.
## Task
Given a string, add the fewest number of characters possible from the front or back to make it a palindrome.
## Example
For the input `cdcab`, the output should be `bacdcab`
## Input/Output
Input is a string consisting of lowercase latin letters with length 3 <= str.length <= 10
The output is a palindrome string satisfying the task.
For s = `ab` either solution (`aba` or `bab`) will be accepted.
Also feel free to reuse/extend the following starter code:
```python
def build_palindrome(s):
```
|
{"functional": "_inputs = [['abcdc'], ['ababa']]\n_outputs = [['abcdcba'], ['ababa']]\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(build_palindrome(*i), o[0])"}
| 135
| 165
|
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 S:
Insert any character (0 or 1) at any position in S.
Find the minimum number of operations Chef needs to perform so that no two consecutive characters are same in S.
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N — the length of the binary string S.
- The second line of each test case contains a binary string S of length N containing 0s and 1s only.
------ Output Format ------
For each test case, output on a new line the minimum number of operations Chef needs to perform so that no two consecutive characters are same in S.
------ Constraints ------
$1 ≤ T ≤ 100$
$1 ≤N ≤1000$
----- Sample Input 1 ------
3
2
11
4
0101
5
00100
----- Sample Output 1 ------
1
0
2
----- explanation 1 ------
Test case 1: We can perform the following operations: $11 \rightarrow 1\underline{0}1$.
Test case 2: We do not need to perform any operations.
Test case 3: We can perform the following operations: $00100 \rightarrow 0\underline{1}0100 \rightarrow 01010\underline{1}0$.
|
{"inputs": ["3\n2\n11\n4\n0101\n5\n00100\n"], "outputs": ["1\n0\n2\n"]}
| 339
| 38
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a sequence of N integer numbers A. Calculate the sum of A_{i} AND A_{j} for all the pairs (i, j) where i < j.
The AND operation is the Bitwise AND operation, defined as in here.
------ Input ------
The first line of input consists of the integer N.
The second line contains N integer numbers - the sequence A.
------ Output ------
Output the answer to the problem on the first line of the output.
------ Scoring ------
Subtask 1 (13 points): N ≤ 1000, A_{i} ≤ 1.
Subtask 2 (39 points): N ≤ 1000, A_{i} ≤ 10^{9}.
Subtask 3 (21 points): N ≤ 10^{5}, A_{i} ≤ 1.
Subtask 4 (27 points): N ≤ 10^{5}, A_{i} ≤ 10^{6}.
----- Sample Input 1 ------
5
1 2 3 4 5
----- Sample Output 1 ------
9
|
{"inputs": ["5\n1 2 3 4 5", "5\n2 2 3 4 5", "5\n2 2 6 4 5", "5\n0 2 6 4 5", "5\n1 2 5 4 6", "5\n0 2 3 4 5", "5\n2 2 6 6 5", "5\n1 2 8 4 6"], "outputs": ["9", "11\n", "18\n", "14\n", "15\n", "7\n", "24\n", "6\n"]}
| 256
| 146
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an integer $n$. Find a sequence of $n$ integers $a_1, a_2, \dots, a_n$ such that $1 \leq a_i \leq 10^9$ for all $i$ and $$a_1 \oplus a_2 \oplus \dots \oplus a_n = \frac{a_1 + a_2 + \dots + a_n}{n},$$ where $\oplus$ represents the bitwise XOR .
It can be proven that there exists a sequence of integers that satisfies all the conditions above.
-----Input-----
The first line of input contains $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
The first and only line of each test case contains one integer $n$ ($1 \leq n \leq 10^5$) — the length of the sequence you have to find.
The sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, output $n$ space-separated integers $a_1, a_2, \dots, a_n$ satisfying the conditions in the statement.
If there are several possible answers, you can output any of them.
-----Examples-----
Input
3
1
4
3
Output
69
13 2 8 1
7 7 7
-----Note-----
In the first test case, $69 = \frac{69}{1} = 69$.
In the second test case, $13 \oplus 2 \oplus 8 \oplus 1 = \frac{13 + 2 + 8 + 1}{4} = 6$.
|
{"inputs": ["3\n1\n4\n3\n"], "outputs": ["2 \n1 3 2 2 \n2 2 2 \n"]}
| 391
| 37
|
coding
|
Solve the programming task below in a Python markdown code block.
The Little Elephant loves to play with color cards.
He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered).
Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the card, the second one — of the back. The color of the front of the card may coincide with the color of the back of the card.
The numbers in the lines are separated by single spaces.
Output
On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1.
Examples
Input
3
4 7
4 7
7 4
Output
0
Input
5
4 7
7 4
2 11
9 7
1 1
Output
2
Note
In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.
In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.
|
{"inputs": ["1\n1 2\n", "1\n1 1\n", "1\n1 4\n", "1\n2 1\n", "2\n1 1\n1 1\n", "2\n1 2\n2 3\n", "2\n1 2\n2 1\n", "2\n1 1\n0 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
| 421
| 118
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Let's define a function countUniqueChars(s) that returns the number of unique characters in s.
For example, calling countUniqueChars(s) if s = "LEETCODE" then "L", "T", "C", "O", "D" are the unique characters since they appear only once in s, therefore countUniqueChars(s) = 5.
Given a string s, return the sum of countUniqueChars(t) where t is a substring of s. The test cases are generated such that the answer fits in a 32-bit integer.
Notice that some substrings can be repeated so in this case you have to count the repeated ones too.
Please complete the following python code precisely:
```python
class Solution:
def uniqueLetterString(self, s: str) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"LEETCODE\") == 92\n\n\ncheck(Solution().uniqueLetterString)"}
| 185
| 35
|
coding
|
Solve the programming task below in a Python markdown code block.
You have managed to intercept an important message and you are trying to read it.
You realise that the message has been encoded and can be decoded by switching each letter with a corresponding letter.
You also notice that each letter is paired with the letter that it coincides with when the alphabet is reversed.
For example: "a" is encoded with "z", "b" with "y", "c" with "x", etc
You read the first sentence:
```
"r slkv mlylwb wvxlwvh gsrh nvhhztv"
```
After a few minutes you manage to decode it:
```
"i hope nobody decodes this message"
```
Create a function that will instantly decode any of these messages
You can assume no punctuation or capitals, only lower case letters, but remember spaces!
Also feel free to reuse/extend the following starter code:
```python
def decode(message):
```
|
{"functional": "_inputs = [['sr'], ['svool'], ['r slkv mlylwb wvxlwvh gsrh nvhhztv'], ['qzezxirkg rh z srts ovevo wbmznrx fmgbkvw zmw rmgvikivgvw kiltiznnrmt ozmtfztv rg szh yvvm hgzmwziwravw rm gsv vxnzxirkg ozmtfztv hkvxrurxzgrlm zolmthrwv sgno zmw xhh rg rh lmv lu gsv gsivv vhhvmgrzo gvxsmloltrvh lu dliow drwv dvy xlmgvmg kilwfxgrlm gsv nzqlirgb lu dvyhrgvh vnkolb rg zmw rg rh hfkkligvw yb zoo nlwvim dvy yildhvih drgslfg koftrmh'], ['gsv vrtsgs hbnkslmb dzh qvzm hryvorfh urmzo nzqli xlnklhrgrlmzo kilqvxg lxxfkbrmt srn rmgvinrggvmgob'], ['husbands ask repeated resolved but laughter debating'], ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'], [' '], [''], ['thelastrandomsentence']]\n_outputs = [['hi'], ['hello'], ['i hope nobody decodes this message'], ['javacript is a high level dynamic untyped and interpreted programming language it has been standardized in the ecmacript language specification alongside html and css it is one of the three essential technologies of world wide web content production the majority of websites employ it and it is supported by all modern web browsers without plugins'], ['the eighth symphony was jean sibelius final major compositional project occupying him intermittently'], ['sfhyzmwh zhp ivkvzgvw ivhloevw yfg ozftsgvi wvyzgrmt'], ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'], [' '], [''], ['gsvozhgizmwlnhvmgvmxv']]\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(decode(*i), o[0])"}
| 203
| 614
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array of strings nums, where each string is of equal length and consists of only digits.
You are also given a 0-indexed 2D integer array queries where queries[i] = [ki, trimi]. For each queries[i], you need to:
Trim each number in nums to its rightmost trimi digits.
Determine the index of the kith smallest trimmed number in nums. If two trimmed numbers are equal, the number with the lower index is considered to be smaller.
Reset each number in nums to its original length.
Return an array answer of the same length as queries, where answer[i] is the answer to the ith query.
Note:
To trim to the rightmost x digits means to keep removing the leftmost digit, until only x digits remain.
Strings in nums may contain leading zeros.
Please complete the following python code precisely:
```python
class Solution:
def smallestTrimmedNumbers(self, nums: List[str], queries: List[List[int]]) -> List[int]:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [\"102\",\"473\",\"251\",\"814\"], queries = [[1,1],[2,3],[4,2],[1,2]]) == [2,2,1,0]\n assert candidate(nums = [\"24\",\"37\",\"96\",\"04\"], queries = [[2,1],[2,2]]) == [3,0]\n\n\ncheck(Solution().smallestTrimmedNumbers)"}
| 230
| 114
|
coding
|
Solve the programming task below in a Python markdown code block.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
- There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
-----Constraints-----
- 1 \leq N \leq 10^5
- 1 \leq M \leq 10^9
- 2 \leq a_i \leq 10^9
- a_i is an even number.
- All values in input are integers.
-----Input-----
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
-----Output-----
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
-----Sample Input-----
2 50
6 10
-----Sample Output-----
2
- 15 = 6 \times 2.5
- 15 = 10 \times 1.5
- 45 = 6 \times 7.5
- 45 = 10 \times 4.5
Thus, 15 and 45 are semi-common multiples of A. There are no other semi-common multiples of A between 1 and 50, so the answer is 2.
|
{"inputs": ["2 46\n6 10", "2 85\n6 10", "2 50\n4 10", "2 62\n6 10", "2 50\n6 10", "2 50\n6 10\n", "2 46\n10 10", "2 12\n10 10"], "outputs": ["2\n", "3\n", "0\n", "2\n", "2", "2\n", "5\n", "1\n"]}
| 354
| 128
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an array A of N integers . You want to convert the array A into a permutation of N integers. To do this, you can apply the following operation on array A exactly once .
Pick an integer X, where 1 ≤ X ≤ 2\cdot 10^{7}. For each i , 1 ≤ i ≤ N , replace A_{i} by A_{i} \% X.
Find out whether it is possible to convert A into a permutation of N integers. If it is possible, print YES (all uppercase alphabets) and any possible value of X for which it is possible. Otherwise, print NO (all uppercase alphabets).
Note - An array of N integers is called a permutation if it contains all integers from 1 to N exactly once.
------ Input Format ------
- The first line contains an integer T denoting the number of test cases. The T test cases then follow.
- The first line of each test case contains an integer N.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}.
------ Output Format ------
For each testcase, output the required answer in a single line. If an answer exists, print YES and an integer X (1 ≤ X ≤ 2 \cdot 10^{7}) separated by a single space. Otherwise, print NO.
Note that the strings are case-sensitive and must be in uppercase alphabets.
------ Constraints ------
$1 ≤ T ≤ 100$
$1 ≤ N ≤ 10^{5}$
$1 ≤ A_{i} ≤ 10^{7}$
- Sum of $N$ over all cases won't exceed $10^{5}$
------ subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
3
2 7 1
2
2 2
----- Sample Output 1 ------
YES 4
NO
----- explanation 1 ------
- In the first case, choosing $X=4$ yields $A$ as $[ 2\% 4, 7\% 4 , 1\% 4] = [2,3,1]$ which is a permutation of $N=3$.
- In the second case, we can't make $A_{i}$ = $1$ for any $i$ and for any value of $X$.
|
{"inputs": ["2\n3\n2 7 1\n2\n2 2"], "outputs": ["YES 4\nNO"]}
| 528
| 30
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a certain integer, ```n, n > 0```. You have to search the partition or partitions, of n, with maximum product value.
Let'see the case for ```n = 8```.
```
Partition Product
[8] 8
[7, 1] 7
[6, 2] 12
[6, 1, 1] 6
[5, 3] 15
[5, 2, 1] 10
[5, 1, 1, 1] 5
[4, 4] 16
[4, 3, 1] 12
[4, 2, 2] 16
[4, 2, 1, 1] 8
[4, 1, 1, 1, 1] 4
[3, 3, 2] 18 <---- partition with maximum product value
[3, 3, 1, 1] 9
[3, 2, 2, 1] 12
[3, 2, 1, 1, 1] 6
[3, 1, 1, 1, 1, 1] 3
[2, 2, 2, 2] 16
[2, 2, 2, 1, 1] 8
[2, 2, 1, 1, 1, 1] 4
[2, 1, 1, 1, 1, 1, 1] 2
[1, 1, 1, 1, 1, 1, 1, 1] 1
```
So our needed function will work in that way for Python and Ruby:
```
find_part_max_prod(8) == [[3, 3, 2], 18]
```
For javascript
```
findPartMaxProd(8) --> [[3, 3, 2], 18]
```
If there are more than one partition with maximum product value, the function should output the patitions in a length sorted way.
Python and Ruby
```
find_part_max_prod(10) == [[4, 3, 3], [3, 3, 2, 2], 36]
```
Javascript
```
findPartMaxProd(10) --> [[4, 3, 3], [3, 3, 2, 2], 36]
```
Enjoy it!
Also feel free to reuse/extend the following starter code:
```python
def find_part_max_prod(n):
```
|
{"functional": "_inputs = [[8], [10]]\n_outputs = [[[[3, 3, 2], 18]], [[[4, 3, 3], [3, 3, 2, 2], 36]]]\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_part_max_prod(*i), o[0])"}
| 630
| 196
|
coding
|
Solve the programming task below in a Python markdown code block.
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows:
Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries.
Find the absolute value of each element in the array and print the sum of the absolute values on a new line.
Tip: The Input/Output for this challenge is very large, so you'll have to be creative in your approach to pass all test cases.
Function Description
Complete the playingWithNumbers function in the editor below. It should return an array of integers that represent the responses to each query.
playingWithNumbers has the following parameter(s):
arr: an array of integers
queries: an array of integers
Input Format
The first line contains an integer $n$ the number of elements in $\textbf{arr}$.
The second line contains $n$ space-separated integers $arr\left[i\right]$.
The third line contains an integer $\textit{q}$, the number of queries.
The fourth line contains $\textit{q}$ space-separated integers $\boldsymbol{x}$ where $qumeries[j]=x$.
Constraints
$1\leq n\leq5\times10^5$
$1\leq q\leq5\times10^5$
$-2000\leq arr[i]\leq2000$, where $0\leq i<n$.
$-2000\leq\textit{queries}[j]\leq2000$, where $0\leq j<q$
Output Format
For each query, print the sum of the absolute values of all the array's elements on a new line.
Sample Input
3
-1 2 -3
3
1 -2 3
Sample Output
5
7
6
Explanation
Query 0: $x=1$
Array: $[-1,2,-3]\rightarrow[0,3,-2]$
The sum of the absolute values of the updated array's elements is $|0|+|3|+|-2|=0+3+2=5$.
Query 1: $x=-2$
Array: $[0,3,-2]\rightarrow[-2,1,-4]$
The sum of the absolute values of the updated array's elements is $|-2|+|1|+|-4|=2+1+4=7$.
Query 2: $x=3$
Array: $[-2,1,-4]\rightarrow[1,4,-1]$
The sum of the absolute values of the updated array's elements is $|1|+|4|+|-1|=1+4+1=6$.
|
{"inputs": ["3\n-1 2 -3\n3\n1 -2 3 \n"], "outputs": ["5\n7\n6\n"]}
| 612
| 34
|
coding
|
Solve the programming task below in a Python markdown code block.
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws n sticks in a row. After that the players take turns crossing out exactly k sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than k sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him.
-----Input-----
The first line contains two integers n and k (1 ≤ n, k ≤ 10^18, k ≤ n) — the number of sticks drawn by Sasha and the number k — the number of sticks to be crossed out on each turn.
-----Output-----
If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower).
-----Examples-----
Input
1 1
Output
YES
Input
10 4
Output
NO
-----Note-----
In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.
|
{"inputs": ["1 1\n", "6 2\n", "6 3\n", "6 4\n", "6 5\n", "6 6\n", "2 2\n", "6 1\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n"]}
| 363
| 86
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a sequence of non-negative integers $A_1, A_2, \ldots, A_N$. At most once, you may choose a non-negative integer $X$ and for each valid $i$, change $A_i$ to $A_i \oplus X$ ($\oplus$ denotes bitwise XOR).
Find the minimum possible value of the sum of all elements of the resulting sequence.
-----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 the input 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 one integer ― the minimum possible sum.
-----Constraints-----
- $1 \le T \le 1,000$
- $1 \le N \le 10^5$
- $1 \le A_i \le 10^9$ for each valid $i$
- the sum of $N$ over all test cases does not exceed $10^6$
-----Subtasks-----
Subtask #1 (50 points):
- $1 \le N \le 10^3$
- $1 \le A_i \le 10^3$ for each valid $i$
Subtask #2 (50 points): original constraints
-----Example Input-----
3
5
2 3 4 5 6
4
7 7 7 7
3
1 1 3
-----Example Output-----
14
0
2
-----Explanation-----
Example case 1: If we choose $X = 6$, the sequence becomes $(4, 5, 2, 3, 0)$.
Example case 2: We can choose $X = 7$ to make all elements of the resulting sequence equal to $0$.
Example case 3: We can choose $X = 1$. The sequence becomes $(0, 0, 2)$, with sum $2$.
|
{"inputs": ["3\n5\n2 3 4 5 6\n4\n7 7 7 7\n3\n1 1 3"], "outputs": ["14\n0\n2"]}
| 473
| 47
|
coding
|
Solve the programming task below in a Python markdown code block.
We have N points numbered 1 to N arranged in a line in this order.
Takahashi decides to make an undirected graph, using these points as the vertices. In the beginning, the graph has no edge. Takahashi will do M operations to add edges in this graph. The i-th operation is as follows:
* The operation uses integers L_i and R_i between 1 and N (inclusive), and a positive integer C_i. For every pair of integers (s, t) such that L_i \leq s < t \leq R_i, add an edge of length C_i between Vertex s and Vertex t.
The integers L_1, ..., L_M, R_1, ..., R_M, C_1, ..., C_M are all given as input.
Takahashi wants to solve the shortest path problem in the final graph obtained. Find the length of the shortest path from Vertex 1 to Vertex N in the final graph.
Constraints
* 2 \leq N \leq 10^5
* 1 \leq M \leq 10^5
* 1 \leq L_i < R_i \leq N
* 1 \leq C_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N M
L_1 R_1 C_1
:
L_M R_M C_M
Output
Print the length of the shortest path from Vertex 1 to Vertex N in the final graph. If there is no shortest path, print `-1` instead.
Examples
Input
4 3
1 3 2
2 4 3
1 4 6
Output
5
Input
4 2
1 2 1
3 4 2
Output
-1
Input
10 7
1 5 18
3 4 8
1 3 5
4 7 10
5 9 8
6 10 5
8 10 3
Output
28
|
{"inputs": ["4 2\n1 2 2\n3 4 2", "4 2\n1 2 1\n1 4 2", "3 1\n1 3 4\n6 0 0", "4 2\n1 4 1\n3 4 2", "1 2\n2 2 2\n3 3 2", "4 2\n1 2 2\n3 4 0", "3 2\n1 2 2\n3 4 0", "3 2\n1 2 2\n6 4 0"], "outputs": ["-1\n", "2\n", "4\n", "1\n", "0\n", "-1\n", "-1\n", "-1\n"]}
| 456
| 175
|
coding
|
Solve the programming task below in a Python markdown code block.
__Definition:__ According to Wikipedia, a [complete binary tree](https://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees) is a binary tree _"where every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible."_
The Wikipedia page referenced above also mentions that _"Binary trees can also be stored in breadth-first order as an implicit data structure in arrays, and if the tree is a complete binary tree, this method wastes no space."_
Your task is to write a method (or function) that takes an array (or list, depending on language) of integers and, assuming that the array is ordered according to an _in-order_ traversal of a complete binary tree, returns an array that contains the values of the tree in breadth-first order.
__Example 1:__
Let the input array be `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]`. This array contains the values of the following complete binary tree.
```
_ 7_
/ \
4 9
/ \ / \
2 6 8 10
/ \ /
1 3 5
```
In this example, the input array happens to be sorted, but that is _not_ a requirement.
__Output 1:__ The output of the function shall be an array containing the values of the nodes of the binary tree read top-to-bottom, left-to-right. In this example, the returned array should be:
```[7, 4, 9, 2, 6, 8, 10, 1, 3, 5]```
__Example 2:__
Let the input array be `[1, 2, 2, 6, 7, 5]`. This array contains the values of the following complete binary tree.
```
6
/ \
2 5
/ \ /
1 2 7
```
Note that an in-order traversal of this tree produces the input array.
__Output 2:__ The output of the function shall be an array containing the values of the nodes of the binary tree read top-to-bottom, left-to-right. In this example, the returned array should be:
```[6, 2, 5, 1, 2, 7]```
Also feel free to reuse/extend the following starter code:
```python
def complete_binary_tree(a):
```
|
{"functional": "_inputs = [[[1]], [[1, 2, 3, 4, 5, 6]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]]\n_outputs = [[[1]], [[4, 2, 6, 1, 3, 5]], [[7, 4, 9, 2, 6, 8, 10, 1, 3, 5]]]\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(complete_binary_tree(*i), o[0])"}
| 571
| 254
|
coding
|
Solve the programming task below in a Python markdown code block.
In this Kata, you will count the number of times the first string occurs in the second.
```Haskell
solve("zaz","zazapulz") = 4 because they are ZAZapulz, ZAzapulZ, ZazApulZ, zaZApulZ
```
More examples in test cases.
Good luck!
Please also try [Simple time difference](https://www.codewars.com/kata/5b76a34ff71e5de9db0000f2)
Also feel free to reuse/extend the following starter code:
```python
def solve(a, b):
```
|
{"functional": "_inputs = [['zaz', 'zazapulz'], ['rat', 'ratatoulie'], ['kata', 'katakatak'], ['code', 'codeodecode'], ['kata', 'kataxxxxkatak'], ['code', 'cozzdezodeczzode'], ['zaaz', 'zazaapulz'], ['defg', 'dsedsfsgsg'], ['defg', 'dvsxvevdvsvfvsvgvsvgg']]\n_outputs = [[4], [3], [7], [11], [7], [11], [4], [2], [3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(solve(*i), o[0])"}
| 152
| 277
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A string s is nice if, for every letter of the alphabet that s contains, it appears both in uppercase and lowercase. For example, "abABB" is nice because 'A' and 'a' appear, and 'B' and 'b' appear. However, "abA" is not because 'b' appears, but 'B' does not.
Given a string s, return the longest substring of s that is nice. If there are multiple, return the substring of the earliest occurrence. If there are none, return an empty string.
Please complete the following python code precisely:
```python
class Solution:
def longestNiceSubstring(self, s: str) -> str:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"YazaAay\") == \"aAa\"\n assert candidate(s = \"Bb\") == \"Bb\"\n assert candidate(s = \"c\") == \"\"\n assert candidate(s = \"dDzeE\") == \"dD\"\n\n\ncheck(Solution().longestNiceSubstring)"}
| 161
| 83
|
coding
|
Solve the programming task below in a Python markdown code block.
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS:
You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold.
Since the number of possible arrays may be too large, you need to find the answer modulo $m$.
-----Input-----
The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input.
Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$).
Note that $m$ is not necessary the prime!
-----Output-----
For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$.
-----Example-----
Input
10
1 1000000000
2 999999999
3 99999998
4 9999997
5 999996
6 99995
7 9994
8 993
9 92
10 1
Output
1
3
5
11
17
23
29
59
89
0
|
{"inputs": ["10\n1 1000000000\n2 999999999\n3 99999998\n4 9999997\n5 999996\n6 99995\n7 9994\n8 993\n9 92\n10 1\n", "10\n1 1000000000\n2 999999999\n3 99999998\n4 9999997\n5 999996\n6 99995\n7 9994\n8 993\n9 92\n10 1\n", "10\n1 1000000000\n2 999999999\n3 170267273\n4 9999997\n5 999996\n6 99995\n7 9994\n8 993\n9 92\n10 1\n", "10\n1 1000000000\n2 999999999\n3 170267273\n2 9999997\n5 999996\n6 99995\n7 9994\n8 993\n9 92\n10 1\n", "10\n1 1000000000\n2 999999999\n3 60966517\n2 9999997\n5 999996\n6 99995\n7 14099\n8 993\n9 92\n10 2\n", "10\n1 1000000000\n2 999999999\n3 60966517\n2 9999997\n2 999996\n6 99995\n7 14099\n8 993\n9 92\n10 2\n", "10\n1 1000000000\n2 999999999\n3 99999998\n4 9999997\n5 999996\n6 99995\n7 9994\n8 993\n15 92\n10 1\n", "10\n1 1000000000\n2 999999999\n3 170267273\n4 9999997\n5 999996\n6 99995\n7 9994\n8 993\n9 31\n10 1\n"], "outputs": ["1\n3\n5\n11\n17\n23\n29\n59\n89\n0\n", "1\n3\n5\n11\n17\n23\n29\n59\n89\n0\n", "1\n3\n5\n11\n17\n23\n29\n59\n89\n0\n", "1\n3\n5\n3\n17\n23\n29\n59\n89\n0\n", "1\n3\n5\n3\n17\n23\n29\n59\n89\n1\n", "1\n3\n5\n3\n3\n23\n29\n59\n89\n1\n", "1\n3\n5\n11\n17\n23\n29\n59\n85\n0\n", "1\n3\n5\n11\n17\n23\n29\n59\n27\n0\n"]}
| 450
| 960
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius.
You should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = [kelvin, fahrenheit].
Return the array ans. Answers within 10-5 of the actual answer will be accepted.
Note that:
Kelvin = Celsius + 273.15
Fahrenheit = Celsius * 1.80 + 32.00
Please complete the following python code precisely:
```python
class Solution:
def convertTemperature(self, celsius: float) -> List[float]:
```
|
{"functional": "def check(candidate):\n assert candidate(celsius = 36.50) == [309.65000,97.70000]\n assert candidate(celsius = 122.11) == [395.26000,251.79800]\n\n\ncheck(Solution().convertTemperature)"}
| 150
| 91
|
coding
|
Solve the programming task below in a Python markdown code block.
Welcome young Jedi! In this Kata you must create a function that takes an amount of US currency in `cents`, and returns a dictionary/hash which shows the least amount of coins used to make up that amount. The only coin denominations considered in this exercise are: `Pennies (1¢), Nickels (5¢), Dimes (10¢) and Quarters (25¢)`.
Therefor the dictionary returned should contain exactly 4 key/value pairs.
Notes:
* If the function is passed either 0 or a negative number, the function should return the dictionary with all values equal to 0.
* If a float is passed into the function, its value should be be rounded down, and the resulting dictionary should never contain fractions of a coin.
## Examples
```
loose_change(56) ==> {'Nickels': 1, 'Pennies': 1, 'Dimes': 0, 'Quarters': 2}
loose_change(-435) ==> {'Nickels': 0, 'Pennies': 0, 'Dimes': 0, 'Quarters': 0}
loose_change(4.935) ==> {'Nickels': 0, 'Pennies': 4, 'Dimes': 0, 'Quarters': 0}
```
Also feel free to reuse/extend the following starter code:
```python
def loose_change(cents):
```
|
{"functional": "_inputs = [[56], [0], [100], [-3], [7.9]]\n_outputs = [[{'Nickels': 1, 'Pennies': 1, 'Dimes': 0, 'Quarters': 2}], [{'Nickels': 0, 'Pennies': 0, 'Dimes': 0, 'Quarters': 0}], [{'Nickels': 0, 'Pennies': 0, 'Dimes': 0, 'Quarters': 4}], [{'Nickels': 0, 'Pennies': 0, 'Dimes': 0, 'Quarters': 0}], [{'Nickels': 1, 'Pennies': 2, 'Dimes': 0, 'Quarters': 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(loose_change(*i), o[0])"}
| 315
| 311
|
coding
|
Solve the programming task below in a Python markdown code block.
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define i modulo j as the remainder of division of i by j and denote it by $i \operatorname{mod} j$. A Modular Equation, as Hamed's teacher described, is an equation of the form $a \operatorname{mod} x = b$ in which a and b are two non-negative integers and x is a variable. We call a positive integer x for which $a \operatorname{mod} x = b$ a solution of our equation.
Hamed didn't pay much attention to the class since he was watching a movie. He only managed to understand the definitions of these equations.
Now he wants to write his math exercises but since he has no idea how to do that, he asked you for help. He has told you all he knows about Modular Equations and asked you to write a program which given two numbers a and b determines how many answers the Modular Equation $a \operatorname{mod} x = b$ has.
-----Input-----
In the only line of the input two space-separated integers a and b (0 ≤ a, b ≤ 10^9) are given.
-----Output-----
If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation $a \operatorname{mod} x = b$.
-----Examples-----
Input
21 5
Output
2
Input
9435152 272
Output
282
Input
10 10
Output
infinity
-----Note-----
In the first sample the answers of the Modular Equation are 8 and 16 since $21 \operatorname{mod} 8 = 21 \operatorname{mod} 16 = 5$
|
{"inputs": ["1 0\n", "0 0\n", "5 2\n", "2 0\n", "2 0\n", "5 2\n", "1 0\n", "0 0\n"], "outputs": ["1\n", "infinity\n", "1\n", "2\n", "2", "1", "1", "infinity"]}
| 407
| 82
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers arr, and three integers a, b and c. You need to find the number of good triplets.
A triplet (arr[i], arr[j], arr[k]) is good if the following conditions are true:
0 <= i < j < k < arr.length
|arr[i] - arr[j]| <= a
|arr[j] - arr[k]| <= b
|arr[i] - arr[k]| <= c
Where |x| denotes the absolute value of x.
Return the number of good triplets.
Please complete the following python code precisely:
```python
class Solution:
def countGoodTriplets(self, arr: List[int], a: int, b: int, c: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(arr = [3,0,1,1,9,7], a = 7, b = 2, c = 3) == 4\n assert candidate(arr = [1,1,2,2,3], a = 0, b = 0, c = 1) == 0\n\n\ncheck(Solution().countGoodTriplets)"}
| 179
| 93
|
coding
|
Solve the programming task below in a Python markdown code block.
John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.
There are $n$ students, each of them has a unique id (from $1$ to $n$). Thomas's id is $1$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.
In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids.
Please help John find out the rank of his son.
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 1000$) — the number of students.
Each of the next $n$ lines contains four integers $a_i$, $b_i$, $c_i$, and $d_i$ ($0\leq a_i, b_i, c_i, d_i\leq 100$) — the grades of the $i$-th student on English, German, Math, and History. The id of the $i$-th student is equal to $i$.
-----Output-----
Print the rank of Thomas Smith. Thomas's id is $1$.
-----Examples-----
Input
5
100 98 100 100
100 100 100 100
100 100 99 99
90 99 90 100
100 98 60 99
Output
2
Input
6
100 80 90 99
60 60 60 60
90 60 100 60
60 100 60 80
100 100 0 100
0 0 0 0
Output
1
-----Note-----
In the first sample, the students got total scores: $398$, $400$, $398$, $379$, and $357$. Among the $5$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $2$.
In the second sample, the students got total scores: $369$, $240$, $310$, $300$, $300$, and $0$. Among the $6$ students, Thomas got the highest score, so his rank is $1$.
|
{"inputs": ["1\n0 0 0 0\n", "1\n0 0 0 0\n", "1\n0 1 0 0\n", "1\n0 0 0 1\n", "1\n0 0 0 2\n", "1\n0 2 3 1\n", "1\n0 2 1 1\n", "1\n1 2 1 1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
| 630
| 134
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well.
Chef's brother Chefu is a competitive programmer. Every day, he practices for ICPC (International Chefs' Programming Contest) by solving problems. Today, Chef challenged his brother to solve a certain problem, promising to bake an apple pie for him if he succeeds. Chefu has successfully solved the problem, but can you solve it?
You are given an integer sequence $A_{1}, A_{2}, \ldots, A_{N}$. In one move, you must select two adjacent elements of this sequence (i.e. $A_{i}$ and $A_{i+1}$ for some valid $i$) and swap them. Let's call a sequence *orderly* if it contains a contiguous subsequence with length at least $K$ such that all of its elements have identical values. Find the minimum number of moves required to make the given sequence orderly or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer — the minimum required number of moves, or $-1$ if it is impossible to make the sequence orderly.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$2 ≤ K ≤ N ≤ 300,000$
$1 ≤ A_{i} ≤ 300,000$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (30 points):
$N ≤ 100$
the sum of $N$ over all test cases does not exceed $1,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
2
8 3
1 2 2 1 3 3 2 1
5 3
1 1 2 2 3
----- Sample Output 1 ------
3
-1
|
{"inputs": ["2\n8 3\n1 2 2 1 3 3 2 1\n5 3\n1 1 2 2 3"], "outputs": ["3\n-1"]}
| 541
| 49
|
coding
|
Solve the programming task below in a Python markdown code block.
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.
For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.
Write a program that will print the name of a man who will drink the n-th can.
Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.
Input
The input data consist of a single integer n (1 ≤ n ≤ 109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.
Output
Print the single line — the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.
Examples
Input
1
Output
Sheldon
Input
6
Output
Sheldon
Input
1802
Output
Penny
|
{"inputs": ["4\n", "5\n", "3\n", "2\n", "8\n", "6\n", "1\n", "24\n"], "outputs": ["Rajesh", "Howard", "Penny", "Leonard", "Leonard\n", "Sheldon", "Sheldon", "Penny"]}
| 362
| 72
|
coding
|
Solve the programming task below in a Python markdown code block.
Natasha's favourite numbers are $n$ and $1$, and Sasha's favourite numbers are $m$ and $-1$. One day Natasha and Sasha met and wrote down every possible array of length $n+m$ such that some $n$ of its elements are equal to $1$ and another $m$ elements are equal to $-1$. For each such array they counted its maximal prefix sum, probably an empty one which is equal to $0$ (in another words, if every nonempty prefix sum is less to zero, then it is considered equal to zero). Formally, denote as $f(a)$ the maximal prefix sum of an array $a_{1, \ldots ,l}$ of length $l \geq 0$. Then:
$$f(a) = \max (0, \smash{\displaystyle\max_{1 \leq i \leq l}} \sum_{j=1}^{i} a_j )$$
Now they want to count the sum of maximal prefix sums for each such an array and they are asking you to help. As this sum can be very large, output it modulo $998\: 244\: 853$.
-----Input-----
The only line contains two integers $n$ and $m$ ($0 \le n,m \le 2\,000$).
-----Output-----
Output the answer to the problem modulo $998\: 244\: 853$.
-----Examples-----
Input
0 2
Output
0
Input
2 0
Output
2
Input
2 2
Output
5
Input
2000 2000
Output
674532367
-----Note-----
In the first example the only possible array is [-1,-1], its maximal prefix sum is equal to $0$.
In the second example the only possible array is [1,1], its maximal prefix sum is equal to $2$.
There are $6$ possible arrays in the third example:
[1,1,-1,-1], f([1,1,-1,-1]) = 2
[1,-1,1,-1], f([1,-1,1,-1]) = 1
[1,-1,-1,1], f([1,-1,-1,1]) = 1
[-1,1,1,-1], f([-1,1,1,-1]) = 1
[-1,1,-1,1], f([-1,1,-1,1]) = 0
[-1,-1,1,1], f([-1,-1,1,1]) = 0
So the answer for the third example is $2+1+1+1+0+0 = 5$.
|
{"inputs": ["0 2\n", "2 0\n", "2 2\n", "0 0\n", "1 4\n", "0 0\n", "1 4\n", "6 2\n"], "outputs": ["0\n", "2\n", "5\n", "0\n", "1\n", "0\n", "1\n", "121\n"]}
| 610
| 88
|
coding
|
Solve the programming task below in a Python markdown code block.
Peter can see a clock in the mirror from the place he sits in the office.
When he saw the clock shows 12:22
1
2
3
4
5
6
7
8
9
10
11
12
He knows that the time is 11:38
1
2
3
4
5
6
7
8
9
10
11
12
in the same manner:
05:25 --> 06:35
01:50 --> 10:10
11:58 --> 12:02
12:01 --> 11:59
Please complete the function `WhatIsTheTime(timeInMirror)`, where `timeInMirror` is the mirrored time (what Peter sees) as string.
Return the _real_ time as a string.
Consider hours to be between 1 <= hour < 13.
So there is no 00:20, instead it is 12:20.
There is no 13:20, instead it is 01:20.
Also feel free to reuse/extend the following starter code:
```python
def what_is_the_time(time_in_mirror):
```
|
{"functional": "_inputs = [['06:35'], ['11:59'], ['12:02'], ['04:00'], ['06:00'], ['12:00']]\n_outputs = [['05:25'], ['12:01'], ['11:58'], ['08:00'], ['06:00'], ['12:00']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(what_is_the_time(*i), o[0])"}
| 289
| 235
|
coding
|
Solve the programming task below in a Python markdown code block.
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.
Input
The input contains of a single integer n (0 ≤ n < 109) — the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.
Output
Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Examples
Input
3
Output
1 1 1
Input
13
Output
2 3 8
|
{"inputs": ["5\n", "1\n", "2\n", "0\n", "8\n", "3\n", "34\n", "55\n"], "outputs": ["0 0 5\n", "0 0 1\n", "0 0 2\n", "0 0 0\n", "0 0 8\n", "0 0 3\n", "0 0 34\n", "0 0 55\n"]}
| 286
| 106
|
coding
|
Solve the programming task below in a Python markdown code block.
ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birthday. ZS the Coder finds this very interesting, and decides to test this with the inhabitants of Udayland.
In Udayland, there are 2^{n} days in a year. ZS the Coder wants to interview k people from Udayland, each of them has birthday in one of 2^{n} days (each day with equal probability). He is interested in the probability of at least two of them have the birthday at the same day.
ZS the Coder knows that the answer can be written as an irreducible fraction $\frac{A}{B}$. He wants to find the values of A and B (he does not like to deal with floating point numbers). Can you help him?
-----Input-----
The first and only line of the input contains two integers n and k (1 ≤ n ≤ 10^18, 2 ≤ k ≤ 10^18), meaning that there are 2^{n} days in a year and that ZS the Coder wants to interview exactly k people.
-----Output-----
If the probability of at least two k people having the same birthday in 2^{n} days long year equals $\frac{A}{B}$ (A ≥ 0, B ≥ 1, $\operatorname{gcd}(A, B) = 1$), print the A and B in a single line.
Since these numbers may be too large, print them modulo 10^6 + 3. Note that A and B must be coprime before their remainders modulo 10^6 + 3 are taken.
-----Examples-----
Input
3 2
Output
1 8
Input
1 3
Output
1 1
Input
4 3
Output
23 128
-----Note-----
In the first sample case, there are 2^3 = 8 days in Udayland. The probability that 2 people have the same birthday among 2 people is clearly $\frac{1}{8}$, so A = 1, B = 8.
In the second sample case, there are only 2^1 = 2 days in Udayland, but there are 3 people, so it is guaranteed that two of them have the same birthday. Thus, the probability is 1 and A = B = 1.
|
{"inputs": ["3 2\n", "1 3\n", "4 3\n", "2 4\n", "2 4\n", "1 3\n", "4 3\n", "3 2\n"], "outputs": ["1 8", "1 1", "23 128", "29 32", "29 32", "1 1", "23 128", "1 8\n"]}
| 551
| 105
|
coding
|
Solve the programming task below in a Python markdown code block.
Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?
Input
The first input line contains integer n (1 ≤ n ≤ 105) — amount of squares in the stripe. The second line contains n space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.
Output
Output the amount of ways to cut the stripe into three non-empty pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.
Examples
Input
4
1 2 3 3
Output
1
Input
5
1 2 3 4 5
Output
0
|
{"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n-3\n", "1\n-4\n", "1\n-1\n", "2\n0 0\n", "2\n0 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
| 255
| 93
|
coding
|
Solve the programming task below in a Python markdown code block.
This is an easier version of the next problem. The difference is only in constraints.
You are given a rectangular $n \times m$ matrix $a$. In one move you can choose any column and cyclically shift elements in this column. You can perform this operation as many times as you want (possibly zero). You can perform this operation to a column multiple times.
After you are done with cyclical shifts, you compute for every row the maximal value in it. Suppose that for $i$-th row it is equal $r_i$. What is the maximal possible value of $r_1+r_2+\ldots+r_n$?
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 40$), the number of test cases in the input.
The first line of each test case contains integers $n$ and $m$ ($1 \le n \le 4$, $1 \le m \le 100$) — the number of rows and the number of columns in the given matrix $a$.
Each of the following $n$ lines contains $m$ integers, the elements of $a$ ($1 \le a_{i, j} \le 10^5$).
-----Output-----
Print $t$ integers: answers for all test cases in the order they are given in the input.
-----Example-----
Input
2
2 3
2 5 7
4 2 4
3 6
4 1 5 2 10 4
8 6 6 4 9 10
5 4 9 5 8 7
Output
12
29
-----Note-----
In the first test case, you can shift the third column down by one, this way there will be $r_1 = 5$ and $r_2 = 7$.
In the second case you can don't rotate anything at all, this way there will be $r_1 = r_2 = 10$ and $r_3 = 9$.
|
{"inputs": ["1\n4 2\n1 1\n2 1\n1 2\n2 2\n", "1\n4 2\n1 1\n2 1\n1 2\n2 2\n", "1\n4 2\n1 2\n2 1\n1 2\n2 2\n", "1\n4 2\n1 1\n2 1\n1 2\n2 1\n", "1\n4 2\n1 2\n2 1\n1 3\n2 2\n", "1\n4 2\n1 2\n2 1\n1 5\n2 2\n", "1\n4 2\n1 2\n3 1\n1 5\n2 2\n", "1\n3 2\n1 1\n2 1\n1 2\n2 1\n"], "outputs": ["7\n", "7\n", "8\n", "7\n", "9\n", "11\n", "12\n", "5\n"]}
| 453
| 232
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
Given an integer array nums, return the sum of Hamming distances between all the pairs of the integers in nums.
Please complete the following python code precisely:
```python
class Solution:
def totalHammingDistance(self, nums: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [4,14,2]) == 6\n assert candidate(nums = [4,14,4]) == 4\n\n\ncheck(Solution().totalHammingDistance)"}
| 93
| 55
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a grid with n rows and m columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number k > 0 written on it, then exactly k of its neighboring cells have a number greater than 0 written on them. Note that if the number in the cell is 0, there is no such restriction on neighboring cells.
You are allowed to take any number in the grid and increase it by 1. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.
Two cells are considered to be neighboring if they have a common edge.
Input
The input consists of multiple test cases. The first line contains an integer t (1 ≤ t ≤ 5000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers n and m (2 ≤ n, m ≤ 300) — the number of rows and columns, respectively.
The following n lines contain m integers each, the j-th element in the i-th line a_{i, j} is the number written in the j-th cell of the i-th row (0 ≤ a_{i, j} ≤ 10^9).
It is guaranteed that the sum of n ⋅ m over all test cases does not exceed 10^5.
Output
If it is impossible to obtain a good grid, print a single line containing "NO".
Otherwise, print a single line containing "YES", followed by n lines each containing m integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero).
If there are multiple possible answers, you may print any of them.
Example
Input
5
3 4
0 0 0 0
0 1 0 0
0 0 0 0
2 2
3 0
0 0
2 2
0 0
0 0
2 3
0 0 0
0 4 0
4 4
0 0 0 0
0 2 0 1
0 0 0 0
0 0 0 0
Output
YES
0 0 0 0
0 1 1 0
0 0 0 0
NO
YES
0 0
0 0
NO
YES
0 1 0 0
1 4 2 1
0 2 0 0
1 3 1 0
Note
In the first test case, we can obtain the resulting grid by increasing the number in row 2, column 3 once. Both of the cells that contain 1 have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid
$$$0\;1\;0\;0 0\;2\;1\;0 0\;0\;0\;0$$$
All of them are accepted as valid answers.
In the second test case, it is impossible to make the grid good.
In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good.
|
{"inputs": ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 1\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0\n", "5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n5 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 1\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0\n", "5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n1 2 0 1\n0 0 0 0\n0 0 0 0\n", "5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n1 4 1\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0\n", "5\n3 4\n0 0 0 0\n0 1 0 0\n0 1 0 0\n2 2\n5 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 1\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0\n", "5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n1 2 0 1\n1 0 0 0\n0 0 0 0\n", "5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n1 0 0\n1 4 1\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0\n", "5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n5 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 1\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 1\n0 0 0 0\n"], "outputs": ["YES\n2 3 3 2\n3 4 4 3\n2 3 3 2\nNO\nYES\n2 2\n2 2\nNO\nYES\n2 3 3 2\n3 4 4 3\n3 4 4 3\n2 3 3 2\n", "YES\n2 3 3 2\n3 4 4 3\n2 3 3 2\nNO\nYES\n2 2\n2 2\nNO\nYES\n2 3 3 2\n3 4 4 3\n3 4 4 3\n2 3 3 2\n", "YES\n2 3 3 2\n3 4 4 3\n2 3 3 2\nNO\nYES\n2 2\n2 2\nNO\nYES\n2 3 3 2\n3 4 4 3\n3 4 4 3\n2 3 3 2\n", "YES\n2 3 3 2\n3 4 4 3\n2 3 3 2\nNO\nYES\n2 2\n2 2\nNO\nYES\n2 3 3 2\n3 4 4 3\n3 4 4 3\n2 3 3 2\n", "YES\n2 3 3 2\n3 4 4 3\n2 3 3 2\nNO\nYES\n2 2\n2 2\nNO\nYES\n2 3 3 2\n3 4 4 3\n3 4 4 3\n2 3 3 2\n", "YES\n2 3 3 2\n3 4 4 3\n2 3 3 2\nNO\nYES\n2 2\n2 2\nNO\nYES\n2 3 3 2\n3 4 4 3\n3 4 4 3\n2 3 3 2\n", "YES\n2 3 3 2\n3 4 4 3\n2 3 3 2\nNO\nYES\n2 2\n2 2\nNO\nYES\n2 3 3 2\n3 4 4 3\n3 4 4 3\n2 3 3 2\n", "YES\n2 3 3 2\n3 4 4 3\n2 3 3 2\nNO\nYES\n2 2\n2 2\nNO\nYES\n2 3 3 2\n3 4 4 3\n3 4 4 3\n2 3 3 2\n"]}
| 758
| 1,478
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.