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.
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$$$.
For each test case, output $$$n \cdot m$$$ integers — any suitable matrix $$$b$$$, or $$$-1$$$ if such a matrix does not exist.
51 112 1211 52 4 5 3 12 41 2 3 45 6 7 83 34 2 19 8 36 7 5
-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
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}$$$.
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$$$.
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$$$.
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).
6101701101000110100910010101010111111040011101140100000181011011101100000
NO YES YES NO YES YES
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:
Yaroslav is playing a computer game, and at one of the levels, he encountered $$$n$$$ mushrooms arranged in a row. Each mushroom has its own level of toxicity; the $$$i$$$-th mushroom from the beginning has a toxicity level of $$$a_i$$$. Yaroslav can choose two integers $$$1 \le l \le r \le n$$$, and then his character will take turns from left to right to eat mushrooms from this subsegment one by one, i.e., the mushrooms with numbers $$$l, l+1, l+2, \ldots, r$$$.
The character has a toxicity level $$$g$$$, initially equal to $$$0$$$. The computer game is defined by the number $$$x$$$ — the maximum toxicity level at any given time. When eating a mushroom with toxicity level $$$k$$$, the following happens:
Yaroslav became interested in how many ways there are to choose the values of $$$l$$$ and $$$r$$$ such that the final value of $$$g$$$ is not zero. Help Yaroslav find this number!
Each test consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^{4}$$$) — the number of test cases. Then follows the description of the test cases.
The first line of each test case contains two integers $$$n$$$, $$$x$$$ ($$$1 \leq n \leq 2 \cdot 10^5, 1 \le x \le 10^9$$$) — the number of mushrooms and the maximum toxicity level.
The second line of each test case contains $$$n$$$ numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output a single number — the number of subsegments such that the final value of $$$g$$$ will not be zero.
54 21 1 1 13 21 2 31 6106 31 2 1 4 3 85 999999999999999999 999999998 1000000000 1000000000 500000000
8 2 0 10 7
In the first test case, the subsegments $$$(1, 1)$$$, $$$(1, 2)$$$, $$$(1, 4)$$$, $$$(2, 2)$$$, $$$(2, 3)$$$, $$$(3, 3)$$$, $$$(3, 4)$$$ and $$$(4, 4)$$$ are suitable.
In the second test case, non-zero $$$g$$$ will remain only on the subsegments $$$(1, 1)$$$ and $$$(2, 2)$$$.
In the third test case, on the only possible subsegment, $$$g$$$ will be zero.
Vanya has a graph with $$$n$$$ vertices (numbered from $$$1$$$ to $$$n$$$) and an array $$$a$$$ of $$$n$$$ integers; initially, there are no edges in the graph. Vanya got bored, and to have fun, he decided to perform $$$n - 1$$$ operations.
Operation number $$$x$$$ (operations are numbered in order starting from $$$1$$$) is as follows:
Help Vanya get a connected$$$^{\text{∗}}$$$ graph using the $$$n - 1$$$ operations, or determine that it is impossible.
$$$^{\text{∗}}$$$A graph is called connected if it is possible to reach any vertex from any other by moving along the edges.
Each test consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^{3}$$$) — the number of test cases. Then follows the description of the test cases.
The first line of each test case contains the number $$$n$$$ ($$$1 \leq n \leq 2000$$$) — the number of vertices in the graph.
The second line of each test case contains $$$n$$$ numbers $$$a_1, a_2, \cdots a_n$$$ ($$$1 \leq a_i \leq 10^9$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$.
For each test case, if there is no solution, then output "No" (without quotes).
Otherwise, output "Yes" (without quotes), and then output $$$n - 1$$$ lines, where in the $$$i$$$-th line, output the numbers $$$u$$$ and $$$v$$$ that need to be chosen for operation $$$i$$$.
You can output each letter in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).
821 4499 7 1 13510 2 31 44 73587 6 81 44 32562 35 33 79 1656 51 31 69 42552 63 25 21 51233 40 3 11 31 43 37 8 50 5 12 22
YES 2 1 YES 4 1 2 1 3 2 YES 5 1 4 1 3 1 2 1 YES 4 1 3 1 2 1 5 4 YES 3 1 5 1 2 1 4 2 YES 4 1 5 1 2 1 3 2 YES 2 1 5 2 3 1 4 3 YES 9 1 12 9 11 1 10 1 6 1 7 6 2 1 8 2 5 2 3 1 4 1
Let's consider the second test case.
From the picture, it can be seen that a connected graph is obtained.
You are given a forest of $$$k$$$ rooted trees$$$^{\text{∗}}$$$. Lumberjack Timofey wants to cut down the entire forest by applying the following operation:
Timofey loves bitwise operations, so he wants the bitwise OR of the sizes of the subtrees he removed to be maximum. Help him and find the maximum result he can obtain.
$$$^{\text{∗}}$$$ A tree is a connected graph without cycles, loops, or multiple edges. In a rooted tree, a selected vertex is called a root. A forest is a collection of one or more trees.
$$$^{\text{†}}$$$ The subtree of a vertex $$$v$$$ is the set of vertices for which $$$v$$$ lies on the shortest path from this vertex to the root, including $$$v$$$ itself.
Each test consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 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 $$$k$$$ ($$$1 \leq k \leq 10^6$$$) — the number of trees in the forest.
This is followed by a description of each of the $$$k$$$ trees:
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^6$$$) — the size of the tree. The vertices of the tree are numbered with integers from $$$1$$$ to $$$n$$$. The root of the tree is vertex number $$$1$$$.
The second line contains $$$n - 1$$$ integers $$$p_2, p_3, \ldots p_n$$$ ($$$1 \leq p_i \lt i$$$), where $$$p_i$$$ — the parent of vertex $$$i$$$.
It is guaranteed that the sum of $$$k$$$ and $$$n$$$ for all sets of input data does not exceed $$$10^6$$$.
For each test case, output a single integer — the maximum result that can be obtained.
311241 2 261 1 3 1 31101 2 2 1 1 5 7 6 4
1 7 10
In the second test case, the trees look like this:

The first operation removes the entire second tree.

The second operation removes vertex $$$4$$$ from the first tree.

The third operation removes the first tree. The result is $$$6|1|3 = 7$$$ ($$$|$$$ denotes bitwise OR).
In the third test case, the entire tree needs to be removed.
Pelican Town represents $$$n$$$ houses connected by $$$m$$$ bidirectional roads. Some roads have NPCs standing on them. Farmer Buba needs to walk on each road with an NPC and talk to them.
Help the farmer find a route satisfying the following properties:
It is guaranteed that you can reach any house from any other by walking on the roads with NPCs only.
Each test consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^{4}$$$) — 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$$$ ($$$2 \leq n \leq 5 \cdot 10^5, 1 \leq m \leq 5 \cdot 10^5$$$) — the number of houses and roads in Pelican Town respectively.
In each of the next $$$m$$$ lines, three integers $$$u$$$, $$$v$$$, and $$$c$$$ ($$$1 \leq u, v \leq n, c = 0/1$$$) are given — the ends of the road and whether an NPC is on this road. If $$$c = 1$$$, then the road has an NPC. If $$$c = 0$$$, then the road has no NPC.
The graph may contain multiple edges and loops, and if there are multiple edges with NPCs standing on them, the route must follow each of these roads.
It is guaranteed that you can reach any house from any other by walking on the roads with NPCs only.
It is guaranteed that the sum of $$$n$$$ and $$$m$$$ for all test cases does not exceed $$$5 \cdot 10^5$$$.
For each test case, if there is no solution, then output "No" (without quotes).
Otherwise, output "Yes" (without quotes), and then output $$$k$$$ — the number of roads in the route. In the next line, output $$$k + 1$$$ numbers — the houses of the route in the order of traversal. Note that the first house should match the last one, as the route is cyclic.
If there are multiple answers, you can print any of them.
You can output each letter in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).
33 21 2 12 3 13 31 2 11 3 12 3 05 91 2 05 2 15 4 15 1 12 3 15 2 14 1 04 3 05 2 0
NO YES 3 1 2 3 1 YES 7 1 2 5 4 3 2 5 1
Note that in the third test case, there are multiple edges $$$(5, 2)$$$. You must walk on two of them.
After winning another Bed Wars game, Masha and Olya wanted to relax and decided to play a new game. Masha gives Olya an array $$$a$$$ of length $$$n$$$ and a number $$$s$$$. Now Olya's task is to find a non-negative number $$$x$$$ such that $$$\displaystyle\sum_{i=1}^{n} a_i \oplus x = s$$$. But she is very tired after a tight round, so please help her with this.
But this task seemed too simple to them, so they decided to make the numbers larger (up to $$$2^k$$$) and provide you with their binary representation.
Each test consists of several test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — 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 $$$k$$$ ($$$1 \le n, k, n \cdot k \le 2 \cdot 10^6$$$) — the length of the array $$$a$$$ and the length of the binary representation of all numbers.
The second line contains a string of length $$$k$$$, consisting of zeros and ones — the binary representation of the number $$$s$$$, starting from the most significant bits.
The next $$$n$$$ lines also contain strings of length $$$k$$$, consisting of zeros and ones, the $$$i$$$-th of these strings contains the binary representation of the number $$$a_i$$$, starting from the most significant bits.
It is guaranteed that the sum of the values $$$n \cdot k$$$ for all test cases does not exceed $$$2 \cdot 10^6$$$.
For each test case, output a string of length $$$k$$$ on a separate line, consisting of zeros or ones — the binary representation of any suitable number $$$x$$$ ($$$x \ge 0$$$), starting from the most significant bits, or $$$-1$$$ if such $$$x$$$ does not exist.
44 501011011100011001100011112 80010100110111111100111105 40101001000000000001000116 500011101101100101010111001001110000
01110 10011010 0010 -1
In the first test case, $$$s = 11, a = [14, 6, 12, 15]$$$, if $$$x = 14$$$, then $$$\displaystyle\sum_{i=1}^{n} a_i \oplus x = (14 \oplus 14) + (6 \oplus 14) + (12 \oplus 14) + (15 \oplus 14) = 0 + 8 + 2 + 1 = 11 = s$$$.
In the second test case, $$$s = 41, a = [191, 158]$$$, if $$$x = 154$$$, then $$$\displaystyle\sum_{i=1}^{n} a_i \oplus x = (191 \oplus 154) + (158 \oplus 154) = 37 + 4 = 41 = s$$$.
This is an interactive problem!
Timofey is writing a competition called Capture the Flag (or CTF for short). He has one task left, which involves hacking a security system. The entire system is based on polynomial hashes$$$^{\text{∗}}$$$.
Timofey can input a string consisting of lowercase Latin letters into the system, and the system will return its polynomial hash. To hack the system, Timofey needs to find the polynomial hash parameters ($$$p$$$ and $$$m$$$) that the system uses.
Timofey doesn't have much time left, so he will only be able to make $$$3$$$ queries. Help him solve the task.
$$$^{\text{∗}}$$$ The polynomial hash of a string $$$s$$$, consisting of lowercase Latin letters of length $$$n$$$, based on $$$p$$$ and modulo $$$m$$$ is $$$(\mathrm{ord}(s_1) \cdot p ^ 0 + \mathrm{ord}(s_2) \cdot p ^ 1 + \mathrm{ord}(s_3) \cdot p ^ 2 + \ldots + \mathrm{ord}(s_n) \cdot p ^ {n - 1}) \bmod m$$$. Where $$$s_i$$$ denotes the $$$i$$$-th character of the string $$$s$$$, $$$\mathrm{ord}(\mathrm{chr})$$$ denotes the ordinal number of the character $$$\mathrm{chr}$$$ in the English alphabet, and $$$x \bmod m$$$ is the remainder of $$$x$$$ when divided by $$$m$$$.
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.
It is guaranteed that the $$$p$$$ and $$$m$$$ used by the system satisfy the conditions: $$$26 \lt p \leq 50$$$ and $$$p + 1 \lt m \leq 2 \cdot 10^9$$$.
To make a query to the system, output ? $$$s$$$, where $$$s$$$ is a string of no more than $$$50$$$ characters in length, the hash of which you want to know. In response to this query, you will receive the polynomial hash of the string $$$s$$$.
To output the answer, output ! $$$p$$$ $$$m$$$, where $$$p$$$ is the base of the hash, and $$$m$$$ is the modulus. After that, immediately proceed to the next test case.
You have to make not more than $$$3$$$ queries ?, otherwise you will get verdict Wrong Answer.
After outputting a query, do not forget to output a newline and flush the output buffer. Otherwise, you will receive the verdict Idleness limit exceeded. To flush the buffer, use:
1 32 28
? aa ? yb ! 31 59
Answer for the first query is $$$(ord(a) \cdot 31^0 + ord(a) \cdot 31^1) \mod 59 = (1 + 1 \cdot 31) \mod 59 = 32$$$.
Answer for the second query is $$$(ord(y) \cdot 31^0 + ord(b) \cdot 31^1) \mod 59 = (25 + 2 \cdot 31) \mod 59 = 28$$$.