apaz/codeforces-genesys huggingface dataset:
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in python3.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```python
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
Bob decided to open a bakery. On the opening day, he baked $$$n$$$ buns that he can sell. The usual price of a bun is $$$a$$$ coins, but to attract customers, Bob organized the following promotion:

- Bob chooses some integer $$$k$$$ ($$$0 \le k \le \min(n, b)$$$).
- Bob sells the first $$$k$$$ buns at a modified price. In this case, the price of the $$$i$$$-th ($$$1 \le i \le k$$$) sold bun is $$$(b - i + 1)$$$ coins.
- The remaining $$$(n - k)$$$ buns are sold at $$$a$$$ coins each.

Note that $$$k$$$ can be equal to $$$0$$$. In this case, Bob will sell all the buns at $$$a$$$ coins each.

Help Bob determine the maximum profit he can obtain by selling all $$$n$$$ buns.

## Input Format
Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of the test cases follows.

The only line of each test case contains three integers $$$n$$$, $$$a$$$, and $$$b$$$ ($$$1 \le n, a, b \le 10^9$$$) — the number of buns, the usual price of a bun, and the price of the first bun to be sold at a modified price.

## Output Format
For each test case, output a single integer — the maximum profit that Bob can obtain.

## Examples
```input
7
4 4 5
5 5 9
10 10 5
5 5 11
1000000000 1000000000 1000000000
1000000000 1000000000 1
1000 1 1000
```
```output
17
35
100
45
1000000000000000000
1000000000000000000
500500
```

## Note
In the first test case, it is optimal for Bob to choose $$$k = 1$$$. Then he will sell one bun for $$$5$$$ coins, and three buns at the usual price for $$$4$$$ coins each. Then the profit will be $$$5 + 4 + 4 + 4 = 17$$$ coins.

In the second test case, it is optimal for Bob to choose $$$k = 5$$$. Then he will sell all the buns at the modified price and obtain a profit of $$$9 + 8 + 7 + 6 + 5 = 35$$$ coins.

In the third test case, it is optimal for Bob to choose $$$k = 0$$$. Then he will sell all the buns at the usual price and obtain a profit of $$$10 \cdot 10 = 100$$$ coins.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in python3.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```python
<your code here>
```

Execution time limit: 2.0 seconds
Memory limit: 256.0 MB

# Problem
Let's call the Manhattan value of a permutation$$$^{\dagger}$$$ $$$p$$$ the value of the expression $$$|p_1 - 1| + |p_2 - 2| + \ldots + |p_n - n|$$$.

For example, for the permutation $$$[1, 2, 3]$$$, the Manhattan value is $$$|1 - 1| + |2 - 2| + |3 - 3| = 0$$$, and for the permutation $$$[3, 1, 2]$$$, the Manhattan value is $$$|3 - 1| + |1 - 2| + |2 - 3| = 2 + 1 + 1 = 4$$$.

You are given integers $$$n$$$ and $$$k$$$. Find a permutation $$$p$$$ of length $$$n$$$ such that its Manhattan value is equal to $$$k$$$, or determine that no such permutation exists.

$$$^{\dagger}$$$A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array), and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).

## Input Format
Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^{4}$$$) — the number of test cases. The description of the test cases follows.

The only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^{5}, 0 \le k \le 10^{12}$$$) — the length of the permutation and the required Manhattan value.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^{5}$$$.

## Output Format
For each test case, if there is no suitable permutation, output "No". Otherwise, in the first line, output "Yes", and in the second line, output $$$n$$$ distinct integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \le p_i \le n$$$) — a suitable permutation.

If there are multiple solutions, output any of them.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).

## Examples
```input
8
3 4
4 5
7 0
1 1000000000000
8 14
112 777
5 12
5 2
```
```output
Yes
3 1 2
No
Yes
1 2 3 4 5 6 7
No
Yes
8 2 3 4 5 6 1 7
No
Yes
5 4 3 1 2
Yes
2 1 3 4 5
```

## Note
In the first test case, the permutation $$$[3, 1, 2]$$$ is suitable, its Manhattan value is $$$|3 - 1| + |1 - 2| + |2 - 3| = 2 + 1 + 1 = 4$$$.

In the second test case, it can be proven that there is no permutation of length $$$4$$$ with a Manhattan value of $$$5$$$.

In the third test case, the permutation $$$[1,2,3,4,5,6,7]$$$ is suitable, its Manhattan value is $$$|1-1|+|2-2|+|3-3|+|4-4|+|5-5|+|6-6|+|7-7|=0$$$.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in python3.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```python
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
You are given an array $$$a$$$ of $$$n$$$ integers, where $$$n$$$ is odd.

In one operation, you will remove two adjacent elements from the array $$$a$$$, and then concatenate the remaining parts of the array. For example, given the array $$$[4,7,4,2,9]$$$, we can obtain the arrays $$$[4,2,9]$$$ and $$$[4,7,9]$$$ by the operations $$$[\underline{4,7}, 4,2,9] \to [4,2,9]$$$ and $$$[4,7,\underline{4,2},9] \to [4,7,9]$$$ respectively. However, we cannot obtain the array $$$[7,2,9]$$$ as it requires deleting non-adjacent elements $$$[\underline{4},7,\underline{4},2,9]$$$.

You will repeatedly perform this operation until exactly one element remains in $$$a$$$.

Find the maximum possible value of the remaining element in $$$a$$$.

## Input Format
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 99$$$; $$$n$$$ is odd) — the length of the array $$$a$$$.

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 100$$$) — the elements of the array $$$a$$$.

Note that there is no bound on the sum of $$$n$$$ over all test cases.

## Output Format
For each test case, output a single integer — the maximum possible value of the remaining element in $$$a$$$.

## Examples
```input
4
1
6
3
1 3 2
5
4 7 4 2 9
7
3 1 4 1 5 9 2
```
```output
6
2
9
5
```

## Note
In the first test case, the array $$$a$$$ is $$$[6]$$$. Since there is only one element, no operations are needed. The maximum possible value of the remaining element is $$$6$$$.

In the second test case, the array $$$a$$$ is $$$[1, 3, 2]$$$. We can remove the first two elements $$$[\underline{1, 3}, 2] \to [2]$$$, or remove the last two elements $$$[1, \underline{3, 2}] \to [1]$$$. Therefore, the maximum possible value of the remaining element is $$$2$$$.

In the third test case, the array $$$a$$$ is $$$[4, 7, 4, 2, 9]$$$. One way to maximize the remaining element is $$$[4, \underline{7, 4}, 2, 9] \to [\underline{4, 2}, 9] \to [9]$$$. Therefore, the maximum possible value of the remaining element is $$$9$$$.

In the fourth test case, the array $$$a$$$ is $$$[3, 1, 4, 1, 5, 9, 2]$$$. It can be shown that the maximum possible value of the remaining element is $$$5$$$.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in python3.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```python
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
You are given an array $$$b$$$ of $$$n - 1$$$ integers.

An array $$$a$$$ of $$$n$$$ integers is called good if $$$b_i = a_i \, \& \, a_{i + 1}$$$ for $$$1 \le i \le n-1$$$, where $$$\&$$$ denotes the bitwise AND operator.

Construct a good array, or report that no good arrays exist.

## Input Format
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the length of the array $$$a$$$.

The second line of each test case contains $$$n - 1$$$ integers $$$b_1, b_2, \ldots, b_{n - 1}$$$ ($$$0 \le b_i < 2^{30}$$$) — the elements of the array $$$b$$$.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

## Output Format
For each test case, output a single integer $$$-1$$$ if no good arrays exist.

Otherwise, output $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i < 2^{30}$$$) — the elements of a good array $$$a$$$.

If there are multiple solutions, you may output any of them.

## Examples
```input
4
2
1
3
2 0
4
1 2 3
5
3 5 4 2
```
```output
5 3
3 2 1
-1
3 7 5 6 3
```

## Note
In the first test case, $$$b = [1]$$$. A possible good array is $$$a=[5, 3]$$$, because $$$a_1 \, \& \, a_2 = 5 \, \& \, 3 = 1 = b_1$$$.

In the second test case, $$$b = [2, 0]$$$. A possible good array is $$$a=[3, 2, 1]$$$, because $$$a_1 \, \& \, a_2 = 3 \, \& \, 2 = 2 = b_1$$$ and $$$a_2 \, \& \, a_3 = 2 \, \& \, 1 = 0 = b_2$$$.

In the third test case, $$$b = [1, 2, 3]$$$. It can be shown that no good arrays exist, so the output is $$$-1$$$.

In the fourth test case, $$$b = [3, 5, 4, 2]$$$. A possible good array is $$$a=[3, 7, 5, 6, 3]$$$.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in python3.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```python
<your code here>
```

Execution time limit: 2.0 seconds
Memory limit: 256.0 MB

# Problem
You are given an undirected graph with $$$n$$$ vertices, numbered from $$$1$$$ to $$$n$$$. There is an edge between vertices $$$u$$$ and $$$v$$$ if and only if $$$u \oplus v$$$ is a prime number, where $$$\oplus$$$ denotes the bitwise XOR operator.

Color all vertices of the graph using the minimum number of colors, such that no two vertices directly connected by an edge have the same color.

## Input Format
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). The description of test cases follows.

The only line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the graph.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

## Output Format
For each test case, output two lines.

The first line should contain a single integer $$$k$$$ ($$$1 \le k \le n$$$) — the minimum number of colors required.

The second line should contain $$$n$$$ integers $$$c_1, c_2, \ldots, c_n$$$ ($$$1 \le c_i \le k$$$) — the color of each vertex.

If there are multiple solutions, output any of them.

## Examples
```input
6
1
2
3
4
5
6
```
```output
1
1
2
1 2
2
1 2 2
3
1 2 2 3
3
1 2 2 3 3
4
1 2 2 3 3 4
```

## Note
In the first test case, the minimum number of colors is $$$1$$$, because there is only one vertex.

In the second test case, the minimum number of colors is $$$2$$$, because there is an edge connecting $$$1$$$ and $$$2$$$ ($$$1 \oplus 2 = 3$$$, which is a prime number).

In the third test case, the minimum number of colors is still $$$2$$$, because $$$2$$$ and $$$3$$$ can be colored the same since there is no edge between $$$2$$$ and $$$3$$$ ($$$2 \oplus 3 = 1$$$, which is not a prime number).

In the fourth test case, it can be shown that the minimum number of colors is $$$3$$$.

In the fifth test case, it can be shown that the minimum number of colors is $$$3$$$.

In the sixth test case, it can be shown that the minimum number of colors is $$$4$$$.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in python3.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```python
<your code here>
```

Execution time limit: 5.0 seconds
Memory limit: 256.0 MB

# Problem
You are given $$$n$$$ sticks, numbered from $$$1$$$ to $$$n$$$. The length of the $$$i$$$-th stick is $$$a_i$$$.

You need to answer $$$q$$$ queries. In each query, you are given two integers $$$l$$$ and $$$r$$$ ($$$1 \le l < r \le n$$$, $$$r - l + 1 \ge 6$$$). Determine whether it is possible to choose $$$6$$$ distinct sticks from the sticks numbered $$$l$$$ to $$$r$$$, to form $$$2$$$ non-degenerate triangles$$$^{\text{∗}}$$$.

## Input Format
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$6 \le n \le 10^5$$$, $$$1 \le q \le 10^5$$$) — the number of sticks and the number of queries respectively.

The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — $$$a_i$$$ denotes the length of the $$$i$$$-th stick.

Each of the following $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l < r \le n$$$, $$$r - l + 1 \ge 6$$$) — the parameters of each query.

## Output Format
For each query, output "YES" (without quotes) if it is possible to form $$$2$$$ triangles, and "NO" (without quotes) otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

## Examples
```input
10 5
5 2 2 10 4 10 6 1 5 3
1 6
2 7
2 8
5 10
4 10
```
```output
YES
NO
YES
NO
YES
```

## Note
In the first query, the lengths of the sticks are $$$[5, 2, 2, 10, 4, 10]$$$. Two sets of sticks $$$[2, 4, 5]$$$ and $$$[2, 10, 10]$$$ can be selected to form $$$2$$$ non-degenerate triangles.

In the second query, the lengths of the sticks are $$$[2, 2, 10, 4, 10, 6]$$$. It can be shown that it is impossible to form $$$2$$$ non-degenerate triangles.

In the third query, the lengths of the sticks are $$$[2, 2, 10, 4, 10, 6, 1]$$$. Two sets of sticks $$$[1, 2, 2]$$$ and $$$[4, 10, 10]$$$ can be selected to form $$$2$$$ non-degenerate triangles.

In the fourth query, the lengths of the sticks are $$$[4, 10, 6, 1, 5, 3]$$$. It can be shown that it is impossible to form $$$2$$$ non-degenerate triangles.

In the fifth query, the lengths of the sticks are $$$[10, 4, 10, 6, 1, 5, 3]$$$. Two sets of sticks $$$[1, 10, 10]$$$ and $$$[3, 4, 5]$$$ can be selected to form $$$2$$$ non-degenerate triangles.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in python3.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```python
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
Petr, watching Sergey's stream, came up with a matrix $$$a$$$, consisting of $$$n$$$ rows and $$$m$$$ columns (the number in the $$$i$$$-th row and $$$j$$$-th column is denoted as $$$a_{i, j}$$$), which contains all integers from $$$1$$$ to $$$n \cdot m$$$. But he didn't like the arrangement of the numbers, and now he wants to come up with a new matrix $$$b$$$, consisting of $$$n$$$ rows and $$$m$$$ columns, which will also contain all integers from $$$1$$$ to $$$n \cdot m$$$, such that for any $$$1 \leq i \leq n, 1 \leq j \leq m$$$ it holds that $$$a_{i, j} \ne b_{i, j}$$$.

You are given the matrix $$$a$$$, construct any matrix $$$b$$$ that meets Petr's requirements, or determine that it is impossible.

Hurry up! Otherwise, he will donate all his money to the stream in search of an answer to his question.

## Input Format
Each test consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. Then follows the description of the test cases.

The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 10$$$) — the number of rows and columns of matrix $$$a$$$.

The next $$$n$$$ lines contain $$$m$$$ integers each, describing matrix $$$a$$$. The $$$i$$$-th of these lines contains the elements of matrix $$$a_{i, 1}, a_{i, 2}, \ldots, a_{i, m}$$$.

It is guaranteed that all numbers in matrix $$$a$$$ are distinct and $$$1 \leq a_{i, j} \leq n \cdot m$$$.

It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$5 \cdot 10^4$$$.

## Output Format
For each test case, output $$$n \cdot m$$$ integers — any suitable matrix $$$b$$$, or $$$-1$$$ if such a matrix does not exist.

## Examples
```input
5
1 1
1
2 1
2
1
1 5
2 4 5 3 1
2 4
1 2 3 4
5 6 7 8
3 3
4 2 1
9 8 3
6 7 5
```
```output
-1
1 
2 
4 5 3 1 2 
6 7 8 5 
2 3 4 1 
8 3 9 
7 5 6 
2 1 4
```

## Note
In the first test case, there is only one element in the matrix, so matrix $$$b$$$ is the only matrix and it does not fit.

In the second test case $$$a_{1, 1} = 2 \neq 1 = b_{1, 1}$$$, $$$a_{2, 1} = 1 \neq 2 = b_{2, 1}$$$.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in python3.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```python
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
Vova really loves the XOR operation (denoted as $$$\oplus$$$). Recently, when he was going to sleep, he came up with a fun game.

At the beginning of the game, Vova chooses two binary sequences $$$s$$$ and $$$t$$$ of length $$$n$$$ and gives them to Vanya. A binary sequence is a sequence consisting only of the numbers $$$0$$$ and $$$1$$$. Vanya can choose integers $$$l, r$$$ such that $$$1 \leq l \leq r \leq n$$$, and for all $$$l \leq i \leq r$$$ simultaneously replace $$$s_i$$$ with $$$s_i \oplus s_{i - l + 1}$$$, where $$$s_i$$$ is the $$$i$$$-th element of the sequence $$$s$$$.

In order for the game to be interesting, there must be a possibility to win. Vanya wins if, with an unlimited number of actions, he can obtain the sequence $$$t$$$ from the sequence $$$s$$$. Determine if the game will be interesting for the sequences $$$s$$$ and $$$t$$$.

## Input Format
Each test consists of multiple test cases. The first line contains an integer $$$q$$$ ($$$1 \le q \le 10^{4}$$$) — the number of test cases. Then follows the description of the test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the length of the sequences $$$s$$$ and $$$t$$$.

The second line of each test case contains a binary sequence $$$s$$$ of length $$$n$$$.

The third line of each test case contains a binary sequence $$$t$$$ of length $$$n$$$.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

## Output Format
For each test case, output "Yes" if the game will be interesting, otherwise output "No".

You can output each letter in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).

## Examples
```input
6
1
0
1
7
0110100
0110100
9
100101010
101111110
4
0011
1011
4
0100
0001
8
10110111
01100000
```
```output
NO
YES
YES
NO
YES
YES
```

## Note
In the first test case, Vanya will not be able to change the sequence $$$s$$$ with the only possible action of choosing $$$l = r = 1$$$.

In the second test case, the sequences $$$s$$$ and $$$t$$$ are already equal.

In the third test case, Vanya can act as follows:

1. Choose $$$l = 3$$$ and $$$r = 5$$$, then $$$s$$$ will become $$$\mathtt{101101010}$$$.
2. Choose $$$l = 5$$$ and $$$r = 6$$$, then $$$s$$$ will become $$$\mathtt{101111010}$$$.
3. Choose $$$l = 7$$$ and $$$r = 7$$$, then $$$s$$$ will become $$$\mathtt{101111110}$$$.

Now solve the problem and return the code.