Bitshift2026-IITM,ProgClub
A. Complete Subarrays
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

You are given an integer array $$$a$$$ of length $$$n$$$, where each element is an integer between $$$1$$$ and $$$10^9$$$.

For a value $$$x$$$, let $$$\text{freq}(x)$$$ denote the number of times $$$x$$$ appears in the entire array $$$a$$$.

A contiguous subarray $$$a[l \ldots r]$$$ is called complete if the following condition holds:

  • For every value $$$x$$$ that appears in $$$a[l \ldots r]$$$, the number of times $$$x$$$ appears in $$$a[l \ldots r]$$$ is exactly $$$\text{freq}(x)$$$.

In other words, if a value appears in the subarray, then all of its occurrences in the whole array must be contained within that subarray.

You are given multiple test cases. For each test case, determine the total number of complete subarrays of $$$a$$$.

Input

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases.

For each test case:

  • The first line contains an integer $$$n$$$($$$1 \le n \le 2 \times 10^5$$$) — the length of the array.
  • The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$).

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

Output

For each test case, print a single integer — the number of complete subarrays of $$$a$$$.

Example
Input
5
5
3 2 3 1 1
2
2 2
9
7 2 5 2 9 9 3 3 5
10
5 10 6 1 9 2 7 2 4 3
9
7 1 6 5 1 2 9 6 3
Output
4
1
6
37
10
Note

In the first test case, subarrays $$$[2]$$$,$$$[1,1]$$$,$$$[3,2,3]$$$ and $$$[3,2,3,1,1]$$$ are complete while $$$[2,3]$$$ is not as it does not contain all occurrences of $$$3$$$.Thus,there are $$$4$$$ complete subarrays.

In the second test case, there is only one complete subarray, $$$[2,2]$$$.

B. Tread Lightly
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

This is a run-twice (communication) interactive problem.

There are two players: Player A and Player B. The jury (otherwise known as the interactor of this problem) will first interact with player A. After player A ends their interaction, the jury will interact with player B. Note that player A and player B may not directly pass information to each other; both players are only able to send information to or receive information from the jury.

There is a hidden $$$n \times n$$$ grid. It contains two special points: a pile of money at $$$M = (x_M, y_M)$$$ and a bomb at $$$B = (x_B, y_B)$$$. This setup is determined by the jury before the interaction, and is consistent across both players.

Player A receives the value of $$$n$$$ and the points $$$M$$$ and $$$B$$$ from the jury. Then, Player A must send an integer $$$k$$$ ($$$1 \le k \le x$$$) back to the jury, where $$$x$$$ is the limit on $$$k$$$.

Player B receives the value of $$$n$$$ and the value of $$$k$$$ (the same integer that Player A sent) from the jury. Their task is to determine the coordinates of point $$$M$$$. To do so, Player B can make at most $$$100$$$ queries of the form $$$(x, y, d)$$$ where $$$(x, y)$$$ is a point on the grid and $$$d$$$ is a direction (up/down/left/right).

  • If $$$(x, y)$$$ is in the same row or column as $$$B$$$ (i.e., $$$x = x_B$$$ or $$$y = y_B$$$ or both), then the jury will return "Boom" as the bomb explodes and burns down the money. Note that this can happen even if $$$(x, y) = M$$$, as long as $$$(x, y)$$$ is in the same row or column as $$$B$$$. Player B should give up (terminate gracefully) after a "Boom" as the money is gone.
  • Otherwise, the jury will return "Yes" or "No" depending on whether the point $$$M$$$ is in $$$d$$$ direction of $$$(x, y)$$$.
    • For $$$d = U$$$ (up), $$$M$$$ is in $$$U$$$ direction of $$$(x, y)$$$ if $$$x_M \lt x$$$.
    • For $$$d = D$$$ (down), $$$M$$$ is in $$$D$$$ direction of $$$(x, y)$$$ if $$$x_M \gt x$$$.
    • For $$$d = L$$$ (left), $$$M$$$ is in $$$L$$$ direction of $$$(x, y)$$$ if $$$y_M \lt y$$$.
    • For $$$d = R$$$ (right), $$$M$$$ is in $$$R$$$ direction of $$$(x, y)$$$ if $$$y_M \gt y$$$.

Player A wants to ensure that player B can determine the coordinates of $$$M$$$. Let $$$x_{min}$$$ be the minimum value of the limit $$$x$$$ for which Player B can always do so safely, for any value $$$2 \le n \le 10^9$$$ and any valid coordinates for $$$M$$$ and $$$B$$$. Note that this value $$$x_{min}$$$ is a provable constant and is known to the jury — although you do not have to prove it (your solution only needs to respect the $$$x_{min}$$$ limit).

Your task is to act as both players and determine an optimal interaction strategy for both players so that player B determines the coordinates correctly, such that the integer $$$k$$$ follows the constraints $$$1 \le k \le x_{min}$$$.

FIRST RUN

Your code will run exactly twice on each test. On the first run, you will be Player A.

Input

The first line of the input contains the string "first". The purpose of this is so your program recognises that this is its first run, and it should act as Player A.

The second line of the input contains exactly one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases.

The first line of each test case contains exactly one integer $$$n$$$ ($$$2 \le n \le 10^9$$$) — the dimension of the grid.

The second line of each test case contains two space-separated integers $$$x_M$$$ and $$$y_M$$$ ($$$1 \le x_M, y_M \le n$$$) — the coordinates of $$$M$$$.

The third line of each test case contains two space-separated integers $$$x_B$$$ and $$$y_B$$$ ($$$1 \le x_B, y_B \le n$$$) — the coordinates of $$$B$$$.

Output

For each test case, print an integer $$$k$$$ ($$$1 \le k \le x_{min}$$$) on a new line. This is the integer that will be sent to you in the second run.

After this, proceed to the next test case, or terminate your program if it was the last test case.

SECOND RUN

On the second run, you are Player B.

Input

The first line of the input contains the string "second". The purpose of this is so your program recognises that this is its second run, and it should act as Player B.

The second line of the input contains exactly one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Note that this number is equal to $$$t$$$ from the first run input.

The first line of each test case contains exactly one integer $$$n$$$ ($$$2 \le n \le 10^9$$$) — the dimension of the grid. Note that this number is equal to $$$n$$$ from the first run input.

The second line of each test case contains exactly one integer $$$k$$$ ($$$1 \le k \le x_{min}$$$) — the integer that was sent by Player A from the first run.

Note that the test cases in the second run may be shuffled. Please see the example test case for further illustration.

Interaction

For each test case, recall you will first receive $$$n$$$ and $$$k$$$ in the input from the jury according to the input format above.

After receiving those inputs, you will be able to make at most $$$100$$$ queries of the following format: "? x y d" ($$$1 \le x, y \le n$$$ and $$$d \in \{U, D, L, R\}$$$).

After each query, the jury will respond with "Boom", "Yes", or "No" as described in the statement above. If you receive a "Boom" response in the same test case, your program should immediately terminate to receive the verdict Wrong Answer. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.

Once you are ready to report the coordinates of $$$M$$$, you may do so in the format: "! x y" ($$$1 \le x, y \le n$$$), where $$$(x, y)$$$ is the coordinates you wish to report.

Then, you will either proceed to the next test case, or your program must terminate if you have processed every test case. Reporting the answer does not count towards the number of queries made.

The interactor is not adaptive. That is, the points $$$M$$$ and $$$B$$$ will not change during the interaction, and will always be the same positions as shown to you in the first run.

After printing each query do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded verdict.

Examples
Input
first
3
# Test case 1
2
1 1
2 2

# Test case 2
4
4 4
4 2

# Test case 3
3
2 1
3 2
Output
# Test case 1
1000000000

# Test case 2
1

# Test case 3
6
Input
second
3
# Test case 1
3
6
No
Yes
Yes

# Test case 2
2
1000000000
No

# Test case 3
4
1
Yes
No
Output
# Test case 1
? 2 1 R
? 1 3 L
? 1 1 D
! 2 1

# Test case 2
? 1 1 R
! 1 1

# Test case 3
? 3 3 D
? 3 3 L
! 4 4
Note
  1. You do not have to handle comments (lines starting with #) in the input; they are only for presentation purposes and will not be present in the test cases.
  2. The queries given in the sample input and output are for demonstrating the interaction, and may not logically lead to a correct output.
  3. The values of $$$k$$$ used in the sample output may not respect the limit $$$x_{min}$$$, and are only for demonstrating the interaction.

For the first run:

  • Test case 1: $$$n = 2$$$, $$$M = (1, 1)$$$, $$$B = (2, 2)$$$. According to some strategy between the players, Player A sends the integer $$$k = 1000000000$$$.
  • Test case 2: $$$n = 4$$$, $$$M = (4, 4)$$$, $$$B = (4, 2)$$$. According to some strategy between the players, Player A sends the integer $$$k = 1$$$.
  • Test case 3: $$$n = 3$$$, $$$M = (2, 1)$$$, $$$B = (3, 2)$$$. According to some strategy between the players, Player A sends the integer $$$k = 6$$$.

For the second run: Note that the test cases are re-ordered between runs. However, note that the integer $$$k$$$ for each test case is the same as what is given in the first run.

  • Test case 1 (previously test case 3 in the first run): $$$n = 4$$$, $$$M = (2, 1)$$$, $$$B = (3, 2)$$$, $$$k = 6$$$.
    • Player B queries $$$(2, 1, R)$$$. Since $$$(2, 1)$$$ is not right of $$$(2, 1)$$$ (as $$$1 \gt 1$$$ isn't true), the jury replies "No".
    • Player B queries $$$(1, 3, L)$$$. Since $$$(2, 1)$$$ is left of $$$(1, 3)$$$ (as $$$1 \lt 3$$$), the jury replies "Yes".
    • Player B queries $$$(1, 1, D)$$$. Since $$$(2, 1)$$$ is down of $$$(1, 1)$$$ (as $$$2 \gt 1$$$), the jury replies "Yes".
    • Player B correctly determines and reports the coordinates $$$(2, 1)$$$ for $$$M$$$.
  • Test case 2 (previously test case 1 in the first run): $$$n = 2$$$, $$$M = (1, 1)$$$, $$$B = (2, 2)$$$, $$$k = 1000000000$$$.
    • Player B queries $$$(1, 1, R)$$$. Since $$$(1, 1)$$$ is not right of $$$(1, 1)$$$ (as $$$1 \gt 1$$$ isn't true), the jury replies "No".
    • Player B correctly determines and reports the coordinates $$$(1, 1)$$$ for $$$M$$$.
  • Test case 3 (previously test case 2 in the first run): $$$n = 4$$$, $$$M = (4, 4)$$$, $$$B = (4, 2)$$$, $$$k = 1$$$.
    • Player B queries $$$(3, 3, D)$$$. Since $$$(4, 4)$$$ is down of $$$(3, 3)$$$ (as $$$4 \gt 3$$$), the jury replies "Yes".
    • Player B queries $$$(3, 3, L)$$$. Since $$$(4, 4)$$$ is not left of $$$(3, 3)$$$ (as $$$4 \lt 3$$$ isn't true), the jury replies "No".
    • Player B correctly determines and reports the coordinates $$$(4, 4)$$$ for $$$M$$$.

C. Divide it all again
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

As usual, as always, once again, Alice and Bob play a game with an array of integers. Both of them have a score of $$$0$$$ at the start of the game.

They start with an array $$$A$$$ of $$$n$$$ positive integers and play in turns. In each turn, the player must:

  • Choose an element $$$x$$$ present in the current array.
  • Choose an integer $$$k ~ \mathbf{(2 \leq k \leq 5)}$$$ such that $$$ x \bmod k = 0 $$$ ($$$k$$$ divides $$$x$$$). If no such $$$k$$$ exists, then the element $$$x$$$ is removed from the array and the player's score increases by 1.
  • If a valid $$$k$$$ is chosen, then the number $$$x$$$ is removed from the array and is then repeatedly divided by $$$k$$$ until it is not possible to divide by $$$k$$$. The value that remains is inserted back into the array.

    Equivalently, let $$$$$$x = t \cdot k^{p}$$$$$$ where $$$p \ge 1$$$ is the largest integer such that $$$k^{p}$$$ divides $$$x$$$, and $$$t \bmod k \neq 0$$$. Then, the original $$$x$$$ is removed from the array and the number $$$t$$$ is added back to the array.

The game ends when the array becomes empty. The winner is the player with the lower score at the end. If the scores are equal, the game is considered a tie.

Alice goes first. Given the initial array $$$A$$$, determine whether Alice wins the game or not, if both the players play optimally.

Input

The first line of each test contains a single integer $$$t ~ (1 \leq t \leq 10^3 )$$$ — the number of test cases.

The first line of each test case contains a positive integer $$$n ~ (1 \leq n \leq 2 \cdot 10^5)$$$ — the number of elements in the array $$$A$$$.

The second line of each test case contains $$$n$$$ positive integers $$$a_1 , a_2 , ... , a_n ~ (1 \leq a_i \leq 10^9)$$$ — denoting the array elements.

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

Output

For each test case, output a single line containing the word "YES" — if Alice wins the game and "NO" — otherwise.

Example
Input
4
1
8
4
13 26 39 52
3
70 30 70
2
10 20
Output
YES
NO
YES
NO
Note

For the first test case, the game proceeds as follows:

  • Initially $$$A= [8]$$$. Alice has to choose $$$x = 8$$$. Then, Alice chooses $$$k = 2$$$. After repeatedly dividing $$$x = 8$$$ with $$$k = 2$$$ , we get $$$8 \rightarrow 4 \rightarrow 2 \rightarrow 1$$$. Therefore, the array $$$A$$$ becomes $$$[1]$$$ .
  • Now, Bob has to choose $$$x = 1$$$. For this $$$x$$$ , since Bob cannot choose a $$$k ~(2 \leq k \leq 5)$$$ such that $$$x \bmod k = 0$$$, therefore $$$x$$$ is removed from the $$$A$$$ , and Bob's score is increased by $$$1$$$.
  • The array $$$A$$$ is empty and therefore the game ends. Since Alice has the lower score, therefore she wins and the answer is "YES".

For the second test case, a possible game proceeds as follows:

  • Initially $$$A = [13 , 26 , 39 , 52]$$$ . Alice chooses $$$x = 52$$$ and $$$k = 4$$$. After the repeated division, we get $$$52 \rightarrow 13$$$. Therefore, the array $$$A$$$ becomes $$$[13 , 26 , 39 , 13]$$$.
  • Now, Bob chooses $$$x = 26$$$ and $$$k = 2$$$. The array then becomes $$$[13 , 13 , 39 , 13]$$$.
  • Alice chooses $$$x = 39$$$ and $$$k = 3$$$. The array then becomes $$$[13 , 13 , 13 , 13]$$$.
  • Bob chooses $$$x = 13$$$ . Since there is no valid $$$k$$$, therefore his score gets increased by $$$1$$$. The array then becomes $$$[13 , 13 , 13]$$$.
  • Alice chooses $$$x = 13$$$ . Again, there is no valid $$$k$$$ and her score increases by $$$1$$$. The array becomes $$$[13 , 13]$$$ .
  • Bob chooses $$$x = 13$$$ . Again there is no valid $$$k$$$, and his score gets increased by $$$1$$$. The array then becomes $$$[13]$$$.
  • Alice chooses $$$x = 13$$$ . Again, there is no valid $$$k$$$ and her score increases by $$$1$$$.
  • Since the array becomes empty, and both of them have their scores equal to $$$2$$$, therefore the game is tied and the answer is "NO".

D. Madhav's Supercharging Nodes
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a tree with $$$n$$$ nodes and $$$n-1$$$ edges. Every edge $$$(u,v)$$$ has $$$w$$$ markable points. Each markable point can be marked at most once.

Each node $$$i$$$ has a permitted range $$$[l_i, r_i]$$$. Let $$$m_i$$$ denote the total number of marked points on edges incident to node $$$i$$$. For every node, the condition $$$l_i \le m_i \le r_i$$$ must hold.

You may choose any subset of nodes to supercharge. If node $$$i$$$ is supercharged:

  • Its permitted range becomes $$$[2l_i, 2r_i]$$$
  • The number of markable points on every edge incident to $$$i$$$ reduces by one

If both nodes at the endpoints of an edge $$$(u,v)$$$ are supercharged, then the markable points on that edge reduces by 2 (1 because of each supercharged node).

You are allowed to mark at most $$$x$$$ points in total across the entire tree.

Your task is to compute the number of valid ways (respecting the permitted ranges of all nodes) to choose supercharged nodes and marked points, modulo $$$10^9 + 7$$$.

Two ways are considered identical if and only if:

  • The set of supercharged nodes is the same, and
  • The set of marked points is exactly the same.
If an edge has 3 markable points, then marking the 1st and 3rd is considered distinct to marking the 1st and 2nd.
Input

The first line contains an integer $$$t$$$ $$$(1 \le t \le 250)$$$ — the number of test cases.

For each test case:

The first line contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 250$$$, $$$0 \le x \le 25$$$).

The next $$$n-1$$$ lines describe the edges. Each line contains three integers $$$a$$$, $$$b$$$, and $$$w$$$ ($$$1 \le a,b \le n$$$, $$$a \ne b$$$, $$$2 \le w \le 2 \cdot 10^5$$$), describing an edge between nodes $$$a$$$ and $$$b$$$ of length $$$w$$$. It is guaranteed that the edges provided form a valid tree.

The next $$$n$$$ lines each contain two integers $$$l_i$$$ and $$$r_i$$$ ($$$0 \le l_i \le r_i \le x$$$), describing the permitted range of node $$$i$$$.

Additional Constraints:

  • The sum of $$$n$$$ across all test cases doesn't exceed 250
  • The sum of $$$x$$$ across all test cases doesn't have an additional bound
Output

For each test case, output a single integer, the number of valid ways modulo $$$10^9 + 7$$$.

Example
Input
4
2 1
1 2 2
0 1
0 1
2 2
1 2 2
1 2
0 2
3 1
1 2 10
1 3 20
0 1
1 1
0 0
5 10
1 2 10
1 3 9
2 4 15
2 5 7
1 3
1 2
1 2
0 2
0 2
Output
8
4
38
13510619
Note

If an edge has 1 markable point, let its name be a, and if the edge has 2 markable points, let their names be a and b.

For the first test case:

  • Supercharged Set: {} -> Mark Nothing, a, or b [3 ways]
  • Supercharged Set: {1} -> Mark Nothing or a [2 ways]
  • Supercharged Set: {2} -> Mark Nothing or a [2 ways]
  • Supercharged Set: {1,2} -> Mark Nothing [1 way]
  • Hence we get a total of 8 ways.

For the second test case:

  • Supercharged Set: {} -> Mark a, b or both [3 ways]
  • Supercharged Set: {1} -> No Valid Configuration [0 ways]
  • Supercharged Set: {2} -> Mark a [1 way]
  • Supercharged Set: {1,2} -> No Valid Configuration [0 ways]
  • Hence we get a total of 4 ways.

For the third test case:

  • Supercharged Set: {} -> Mark on edge (1,2) [10 ways]
  • Supercharged Set: {1} -> Mark on edge (1,2) [9 ways]
  • Supercharged Set: {2} -> No Valid Configuration [0 ways]
  • Supercharged Set: {3} -> Mark on edge (1,2) [10 ways]
  • Supercharged Set: {1,2} -> No Valid Configuration [0 ways]
  • Supercharged Set: {1,3} -> Mark on edge (1,2) [9 ways]
  • Supercharged Set: {2,3} -> No Valid Configuration [0 ways]
  • Supercharged Set: {1,2,3} -> No Valid Configuration [0 ways]
  • Hence we get a total of 38 ways.

We will refrain from manually listing out the possibilities of the fourth test case.

E. Delta Propagation
time limit per test
1.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are $$$n$$$ bags labeled $$$1$$$ to $$$n$$$. Each bag contains a set of colored coins. A color is a lowercase letter from a to z. Within a bag, no color appears more than once.

The contents of bag $$$i$$$ are denoted by the set $$$S_i$$$.

You may apply the following operation any number of times:

  1. Choose an index $$$i$$$ such that $$$1 \le i \lt n$$$.
  2. Replace the contents of bag $$$i$$$ by the symmetric difference of $$$S_i$$$ and $$$S_{i+1}$$$: $$$$$$ S_i \leftarrow S_i \,\Delta\, S_{i+1}, $$$$$$ while $$$S_{i+1}$$$ remains unchanged.

The symmetric difference of two sets $$$A$$$ and $$$B$$$ is $$$$$$ A \Delta B = (A \setminus B) \cup (B \setminus A). $$$$$$

For each bag, its set of colors is given as a string of distinct lowercase letters (the order does not matter).

Your task is to determine whether it is possible to transform the initial contents of all bags into their target contents.

Input

The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases.

For each test case:

  • The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$).
  • The second line contains $$$n$$$ space-separated strings — the initial contents of the bags.
  • The third line contains $$$n$$$ space-separated strings — the target contents of the bags.

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

Output

For each test case, print YES if it is possible to reach the target contents of every bag, otherwise print NO.

Example
Input
5
3
a b c
ab bc c
4
a bc d e
abcde bcde de e
3
a b c
a b d
1
abc
ab
2
a b
b b
Output
YES
YES
NO
NO
NO
Note

For the first test case, performing the operation at $$$i = 1$$$ and then at $$$i = 2$$$ is sufficient to reach the target configuration.

For the second test case, the operation can be performed sequentially at $$$i = 3, 2, 1$$$ to obtain the target configuration.

For the third test case, the contents of the last bag in the initial and target configurations are different. Since bag $$$n$$$ is never changed by any operation, it is not possible to reach the target state.

For the fourth test case, the same reasoning applies: when $$$n = 1$$$, no operation can be performed, so the initial set must already match the target set. It does not, hence the target state cannot be reached.

For the fifth test case, the only possible move is at $$$i = 1$$$. After performing it, bag $$$1$$$ becomes $$$\{a\} \Delta \{b\} = \{a,b\}$$$, and further applications just alternate between $$$\{a\}$$$ and $$$\{a,b\}$$$. Therefore, the target state cannot be reached.

F. XOR Permutations
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

This is an interactive problem.

There is a hidden permutation$$$^†$$$ $$$p$$$ of size $$$n$$$.

You can make queries of another permutation $$$q$$$ of size $$$n$$$. The interactor will calculate and give you $$$\sum_{i=1}^{n} p_i \oplus q_i$$$.

Using at most $$$\frac{5n}{2}$$$ queries, find the hidden permutation $$$p$$$ and output it.

$$$^†$$$An array $$$a$$$ is a permutation of size $$$n$$$ if it contains each of the elements $$$0, 1, 2, ..., n-1$$$ exactly once.

Input

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

The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the size of the hidden permutation $$$p$$$.

It is guaranteed that the sum of $$$n$$$ over all test cases is at most $$$1000$$$.

Interaction

You can make queries in the following format — to query a permutation $$$q$$$, output one line of the form "? $$$q_1$$$ $$$q_2$$$ ... $$$q_n$$$" (where $$$q$$$ is a permutation of size $$$n$$$). After that, read a single integer — the value of $$$\Sigma_{i=1}^{n} p_i \oplus q_i$$$.

To report the hidden permutation as $$$q$$$, output "! $$$q_1$$$ $$$q_2$$$ ... $$$q_n$$$" (where $$$q$$$ is a permutation of size $$$n$$$). Then, the interaction continues with the next test case.

Reporting the answer does not count towards the number of queries made.

Note that you have to use the flush operation right after printing each line — otherwise you may get Idleness Limit Exceeded verdict. For example, in C++ you should use the function fflush(stdout) or cout.flush(), in Java or Kotlin — System.out.flush(), and in Python — sys.stdout.flush().

Example
Input
3
# Test case 1
4
0

# Test case 2
3
6
6
2

# Test case 3
6
16
Output
# Test case 1
? 2 0 1 3
! 2 0 1 3

# Test case 2
? 0 1 2
? 1 2 0
? 2 1 0
! 2 0 1

# Test case 3
? 0 1 2 3 4 5
! 3 1 4 2 5 0
Note

You do not have to handle comments (lines starting with #) in the input; they are only for presentation purposes and will not be present in the test cases.

The queries given in the sample input and output are for demonstrating the interaction, and may not logically lead to a correct output.

  • Test case 1: The hidden permutation is $$$p = [2, 0, 1, 3]$$$.
    • The participant's code makes a query with $$$q = [2, 0, 1, 3]$$$. The interactor calculates and returns $$$\sum_{i=1}^{n} p_i \oplus q_i = 0 + 0 + 0 + 0 = 0$$$.

    The participant's code correctly concludes that the hidden permutation is $$$[2, 0, 1, 3]$$$ and outputs it.

  • Test case 2: The hidden permutation is $$$p = [2, 0, 1]$$$.
    • The participant's code makes a query with $$$q = [0, 1, 2]$$$. The interactor calculates and returns $$$\sum_{i=1}^{n} p_i \oplus q_i = 2 + 1 + 3 = 6$$$.
    • The participant's code makes a query with $$$q = [1, 2, 0]$$$. The interactor calculates and returns $$$\sum_{i=1}^{n} p_i \oplus q_i = 3 + 2 + 1 = 6$$$.
    • The participant's code makes a query with $$$q = [2, 1, 0]$$$. The interactor calculates and returns $$$\sum_{i=1}^{n} p_i \oplus q_i = 0 + 1 + 1 = 2$$$.

    The participant's code correctly concludes that the hidden permutation is $$$[2, 0, 1]$$$ and outputs it.

  • Test case 3: The hidden permutation is $$$p = [3, 1, 4, 2, 5, 0]$$$.
    • The participant's code makes a query with $$$q = [0, 1, 2, 3, 4, 5, 6]$$$. The interactor calculates and returns $$$\sum_{i=1}^{n} p_i \oplus q_i = 3 + 0 + 6 + 1 + 0 + 6 = 16$$$.

    The participant's code correctly concludes that the hidden permutation is $$$[3, 1, 4, 2, 5, 0]$$$ and outputs it.

G. Speed Sorting
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

ScepticallySam owns a speed packing service that uses robots to process packages.

Each robot is assigned a pair of indices $$$i \le j$$$ and performs the following operations on a line of packages:

  • stamps all packages in the subarray $$$[i, j]$$$;
  • sorts the packages in $$$[i, j]$$$ in ascending order of weight.

A robot cannot move packages outside its assigned subarray.

Each line of packages is represented as an array of integers. For each line, ScepticallySam assigns robots to several non-overlapping subarrays, and all robots operate simultaneously.

After all robots finish, the entire line must be stamped and sorted in ascending order.

Given $$$t$$$ lines of packages, determine the maximum number of robots that can be assigned to each line while satisfying the above conditions.

Note: No robots were harmed in the making of this question.

Input

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) which represents the number of lines of packages.

The first line of the $$$i^{th}$$$ testcase contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$), the number of packages in the line.

The second line of the $$$i^{th}$$$ testcase contains $$$n$$$ integers $$$a_1, a_2, ..., a_n$$$ ($$$1 \le a_i \le 10^9$$$) representing the weight of each package in the line.

It is guaranteed that the sum of $$$n$$$ (The total number of packages) over all the testcases does not exceed $$$2 \cdot 10^5$$$.

Output

For each line of packages, output one integer, which is the maximum number of robots required to completely stamp and sort all the packages in the array.

Example
Input
3
4
1 2 3 4
4
4 3 2 1
5
1 2 3 5 4
Output
4
1
4
Note

In the first testcase, we can allocate 1 robot to each box since it's already sorted. Hence, 4 robots can be used, which is the maximum number of robots that can be used.

In the second testcase, we must allocate 1 robot to the entire sequence. It is not possible to achieve the goal in any other way.

In the third testcase, we can allocate 1 robot to each of the first three boxes and 1 robot to the last two boxes. So 4 robots in total.

H. GCD Queries with Updates
time limit per test
4 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

You are given an array $$$a$$$ of length $$$n$$$ consisting of positive integers. You have to process $$$q$$$ queries of two types:

  • 1 i g — print the number of indices $$$j$$$ ($$$j \ne i$$$) such that $$$\gcd(a_i,a_j)=g$$$;
  • 2 i x — assign $$$a_i \gets x$$$ (this update affects subsequent queries).

All indices are $$$1$$$-based.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ $$$(1 \le t \le 10^{3})$$$. The first line of each test case contains two integers $$$n$$$ and $$$q$$$ $$$(1 \le n \le 10^{5};\ 1 \le q \le 10^{5})$$$. The second line contains $$$n$$$ integers $$$a_1,\dots,a_n$$$ $$$(1 \le a_i \le 10^{6})$$$. Each of the next $$$q$$$ lines is one of:

  • 1 i g $$$(1 \le i \le n;\ 1 \le g \le 10^{6})$$$
  • 2 i x $$$(1 \le i \le n;\ 1 \le x \le 10^{6})$$$
It is guaranteed that $$$\sum n \le 10^{5}$$$ and $$$\sum q \le 10^{5}$$$ over all test cases.
Output

For each query of type 1, print a single integer — the number of indices $$$j$$$ ($$$j \ne i$$$) such that $$$\gcd(a_i,a_j)=g$$$. Print each answer on a separate line.

Example
Input
2
4 2
12 8 9 18
1 1 12
1 4 2
5 10
1 1 2 3 6
1 1 1
1 5 2
2 2 1
2 3 1
1 5 3
1 4 6
2 1 6
1 1 6
2 1 6
1 2 1
Output
0
1
4
1
1
0
1
4
Note

In the first test case, for the first query we need to find elements in the array that satisfy $$$ \gcd(a_i, 12) = 12 \, \forall \, i \neq 1$$$. No such numbers exist in the array so the answer is 0. For the second query we need to find elements such that $$$ \gcd(a_i, 18) = 2 \, \forall \, i \neq 4$$$

In the second test case, for the first query all the numbers in the given array satisfy $$$ \gcd(a_i, 1) = 1$$$, so the answer is 4. For the second query, only $$$a_3 = 2$$$ satisfies $$$ \gcd (6, a_i) = 2$$$. After the third query, the array remains unchanged and after the fourth query it becomes $$$ [1,1,1,3,6] $$$. For the fifth query, only one element $$$ a_4 = 3 $$$ satisfies $$$ \gcd(6, a_j)=3 $$$

I. Madhav's Mega Terrarium
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Your huge terrarium has a big glass panel. You have several stickers that you can paste onto the glass.

You have $$$n$$$ decorative stickers. For each sticker $$$i$$$ you are given:

  • $$$b[i]$$$ — the beauty provided by the sticker
  • $$$ir[i]$$$ — the amount of IR radiation blocked by the sticker
  • $$$vis[i]$$$ — the amount of Visible Light blocked by the sticker
  • $$$area[i]$$$ — the area of the sticker

You also have $$$m$$$ bottles of UV protecting cream. For each bottle $$$i$$$:

  • $$$u[i]$$$ — the amount of UV radiation blocked by the bottle
  • $$$au[i]$$$ — the area over which the cream must be evenly spread
  • the cream can only be applied on top of decorative stickers (not on the glass directly)
  • one bottle may be split across multiple stickers, but each unit area of a decorative sticker can receive cream from only one bottle
  • if you choose a bottle, you must use all the cream inside it

Example clarification: If you choose bottles 1 and 2, and decorative stickers 2, 4, and 6, then the following must hold: $$$au[1] + au[2] \lt = area[2] + area[4] + area[6]$$$.

Your scientists determine the following:

  • The plants will die if you block more than $$$I$$$ units of IR rays.
  • The plants will die if you block more than $$$V$$$ units of Visible rays.
  • The plants will die if you block less than $$$U$$$ units of UV rays.

Find the maximum total beauty you can obtain. If it is impossible to keep the plants alive, output -1.

Input

The first line contains the integer $$$t$$$ $$$(1 \le t \le 60)$$$, the number of testcases. For each test case we have:

The first line contains five integers $$$n, m, I, V, U$$$.

Then $$$n$$$ lines follow. The $$$i$$$-th of these lines contains four integers: $$$b[i], ir[i], vis[i], area[i]$$$.

Then $$$m$$$ lines follow. The $$$i$$$-th line contains two integers: $$$u[i]$$$, $$$au[i]$$$.

Constraints

Let $$$A_1 = \sum_{i=1}^n area[i]$$$ and $$$A_2 = \sum_{i=1}^n au[i]$$$

  • $$$1 \lt = n, m \lt = 60$$$
  • $$$0 \lt = I, V, U, A_1, A_2 \lt = 150$$$
  • $$$1 \lt = ir[i], vis[i], b[i], area[i], au[i], u[i] \lt = 150$$$

Additionally the following hold:

  • The sum of $$$n,m$$$ across all test cases doesn't exceed 60.
  • The sum of $$$I, V, U, A_1, A_2$$$ across all test cases doesn't exceed 150.
Output

Print a single integer: the maximum achievable total beauty. If it is impossible to keep the plants alive, print -1.

Example
Input
2
3 3 50 3 5
3 2 1 2
4 3 2 3
5 4 10 4
7 1
8 1
10 100
3 2 4 4 3
3 2 1 2
2 1 2 2
4 2 2 3
2 2
3 3
Output
7
7
Note

In the first example test case

  • We see $$$I = 50$$$ and is much higher than our stickers, so we don't need to worry about it.
  • We see $$$V = 3$$$, so selecting sticker 3 is not feasible (it blocks 10 units of visible light)
  • We see $$$U = 5$$$, both bottle 1 and bottle 2 satisfy our requirements, so we can select either bottle (or both). Bottle 3 cannot be selected as it requires at least 100 units of area, which sticker 1 and 2 dont provide.
  • Clearly, we can pick both sticker 1 and sticker 2 in this sutation now. This maximizes our beauty and gives us the answer 7.

The second example test case can also be reasoned out to show that 7 is the best we can do.

J. One Percent
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There are $$$n$$$ types of coins with you. There are $$$c_i$$$ many coins of the $$$i^{\text{th}}$$$ type, each having value $$$v_i$$$. You are interested in knowing the smallest fraction $$$p$$$ such that $$$p$$$ fraction of the coins hold at least $$$1-p$$$ fraction of the total value of all the coins.

More formally, let $$$C = \sum_{i=1}^{n}c_i$$$ and $$$V = \sum_{i=1}^{n}c_i \cdot v_i$$$. You have to find the smallest integer $$$x$$$ such that there exists a subset of $$$x$$$ coins which have at least $$$\left(1-\frac{x}{C}\right)\cdot V$$$ value.

You have to output the integer $$$x$$$.

Input

The first line of each test contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of types of coins.

The second line of each test case contains $$$n$$$ space-separated integers $$$c_i$$$ ($$$1 \le c_i \le 1000$$$) — the number of coins of the $$$i^{\text{th}}$$$ type.

The third line of each test case contains $$$n$$$ space-separated integers $$$v_i$$$ ($$$1 \le v_i \le 1000$$$) — the value of one coin of the $$$i^{\text{th}}$$$ type.

There are no guarantees about the sum of $$$n$$$ over all test cases.

Output

For each test case, output one line containing a single integer $$$x$$$ — the smallest integer as described above.

Example
Input
3
1
1000
1
4
37 37 37 37
1 2 4 2
1
1
1000
Output
500
61
1
Note

For test case 1, there is one type of coin, $$$1000$$$ in number and $$$1$$$ each in value. Here, $$$C = 1000$$$ and $$$V = 1000$$$. If we choose $$$x = 500$$$, we can select a subset of $$$500$$$ coins of type 1 each having value $$$1$$$ (total value is $$$500$$$), so that $$$500 \ge \left(1 - \frac{500}{1000}\right)\cdot 1000$$$ is true. It can be shown that $$$x \lt 500$$$ is not possible, so the minimum answer is $$$500$$$.

For test case 2, there are the following types of coins:

  1. $$$37$$$ many, each having value $$$1$$$.
  2. $$$37$$$ many, each having value $$$2$$$.
  3. $$$37$$$ many, each having value $$$4$$$.
  4. $$$37$$$ many, each having value $$$2$$$.
Here, $$$C = 148$$$ and $$$V = 333$$$. If we choose $$$x = 61$$$, we can select a subset of $$$61$$$ coins ($$$13$$$ of type 2, $$$37$$$ of type 3, and $$$11$$$ of type 4) having total value $$$196$$$, so that $$$196 \ge \left(1 - \frac{61}{148}\right) \cdot 333$$$ is true. It can be shown that $$$x \lt 61$$$ is not possible, so the minimum answer is $$$61$$$.

K. Cellular Automata
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an infinite 1-dimensional binary array of cells, which is indexed from $$$-\infty$$$ to $$$+\infty$$$. Initially, at time $$$t=0$$$, exactly $$$K$$$ distinct indices $$$P_1, P_2, \dots, P_K$$$ have the value $$$1$$$, and all other indices have the value $$$0$$$.

The array evolves over time steps $$$t=0, 1, 2, \dots$$$. The state of the array at time $$$t+1$$$ is derived from the state at time $$$t$$$ using the following rule for every index $$$i$$$:

$$$$$$ C_i^{(t+1)} = C_{i-1}^{(t)} \oplus C_{i+1}^{(t)} $$$$$$

where $$$\oplus$$$ denotes the bitwise XOR operation. (You might recognise this as elementary cellular automata on rule 90)

You must answer $$$Q$$$ queries. Each query consists of a target index $$$X$$$ and a time $$$T$$$. Determine the value of the cell at index $$$X$$$ at time $$$T$$$.

Input

The first line contains two positive integers $$$K$$$ and $$$Q$$$ ($$$1 \le K, Q \le 1000$$$) — the number of initially active cells, and the number of queries respectively.

The second line contains $$$K$$$ distinct integers $$$P_1, P_2, \dots, P_K$$$ ($$$-10^{18} \le P_i \le 10^{18}$$$) — the indices of the cells that are initially $$$1$$$.

The next $$$Q$$$ lines each contains two integers $$$X$$$ and $$$T$$$ ($$$-10^{18} \le X \le 10^{18}$$$, $$$0 \le T \le 1000$$$) — the target index and the time step for the query.

Output

For each query, output a single line containing '1' if the cell at index $$$X$$$ is active at time $$$T$$$, or '0' otherwise.

Example
Input
1 3
0
-2 2
0 2
2 2
Output
1
0
1
Note

The example test case is illustrated below:


index: -3 -2 -1 0 1 2 3
at t=0: ...0 0 0 1 0 0 0...
at t=1: ...0 0 1 0 1 0 0...
at t=2: ...0 1 0 0 0 1 0...

L. Resonant Purity
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Given an array $$$a$$$ of $$$n$$$ integers and a non-negative integer $$$k$$$, find the maximum integer $$$X$$$ such that there exists at least one valid contiguous subarray $$$a[l..r]$$$ satisfying the following conditions :

  • The subarray must contain at least two elements $$$(1 \le l \lt r \le n)$$$.
  • Strictly more than half of the elements in the subarray must be greater than or equal to $$$X$$$.
  • The cost to raise all elements in the subarray to at least $$$X$$$ must not exceed $$$k$$$ i.e. $$$\sum_{i=l}^{r} max(0, X - a_i) \le k$$$.
.
Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ $$$(1 \le t \le 10^4)$$$. The description of the test cases follows.

The first line of each test case contains two integers $$$n$$$ $$$(2 \le n \le 2 \cdot 10^5)$$$ and $$$k$$$ $$$(0 \le k \le 10^8)$$$.

The second line contains $$$n$$$ integers $$$a_1, a_2 ... a_n$$$ $$$(1 \le a_i \le 10^8)$$$.

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

Output

For each test case, output a single integer $$$X$$$ that is the maximum integer satisfying the problem constraints.

Example
Input
5
3 10
20 20 50
3 50
100 5 100
3 1000
100 1 100
3 100
50 60 10
5 20
100 10 100 10 100
Output
20
55
100
50
30
Note

In the first test case, $$$a=[20,20,50]$$$, $$$k=10$$$. We choose the subarray $$$a[1…2]=[20,20]$$$ with target $$$X=20$$$.

Majority: Elements with value $$$\geq 20$$$ is $$$2$$$. Count is $$$2$$$, Length is $$$2$$$. Since Length $$$ \gt 1$$$ (more than half the subarray length), the condition holds.

Cost: All elements are already $$$\geq 20$$$, the cost is $$$0$$$ which is $$$\le 10$$$. It is impossible to achieve $$$X \gt 20$$$. For example, if $$$X = 21$$$, the only element $$$\geq 21$$$ is $$$50$$$. Any subarray including $$$50$$$ (e.g., $$$[20,50]$$$ or $$$[20,20,50]$$$) would have a majority count of only $$$1$$$, which is not strictly greater than half the length.

M. MEX Queries
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

This is an interactive problem.

There is a hidden array $$$a$$$ of size $$$n$$$.

You can make queries of the following form:

  • Provide a subset $$$P \subseteq \{1, 2, ..., n\}$$$ and a subset $$$Q \subseteq \{0, 1, 2, ..., n\}$$$.
  • The interactor will construct a set $$$S = \{a_{p_i} \mid p_i \in P\} \cup Q$$$. It will calculate and give you the MEX$$$^†$$$ of the set $$$S$$$.

Using at most $$$15 n$$$ queries, find the hidden array $$$a$$$ and output it.

$$$^†$$$The MEX of a set is the smallest non-negative integer that is not present in the set. For example, MEX($$$\{0, 1, 4, 5\}$$$) is $$$2$$$ and MEX($$$\{45\}$$$) is $$$0$$$.

Input

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

The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 400$$$) — the size of the hidden array $$$a$$$ (although they will not be provided in the input, the elements of $$$a$$$ satisfy $$$0 \le a_i \le n$$$).

It is guaranteed that the sum of $$$n$$$ over all test cases is at most $$$400$$$.

Interaction

You can make queries in the following format — to query subsets $$$P$$$ and $$$Q$$$, output one line of the form "? $$$x$$$ $$$y$$$" (where $$$x = |P|$$$ and $$$y = |Q|$$$). On the next line, output $$$x$$$ unique space-separated integers — the elements of $$$P$$$. On the next line, output $$$y$$$ unique space-separated integers — the elements of $$$Q$$$. After that, read a single integer — the value of MEX of $$$S$$$ (which is constructed as described above).

To report the hidden array as $$$b$$$, output "! $$$b_1$$$ $$$b_2$$$ ... $$$b_n$$$". Then, the interaction continues with the next test case.

Reporting the answer does not count towards the number of queries made.

Note that you have to use the flush operation right after printing each line — otherwise you may get Idleness Limit Exceeded verdict. For example, in C++ you should use the function fflush(stdout) or cout.flush(), in Java or Kotlin — System.out.flush(), and in Python — sys.stdout.flush().

Example
Input
3
# Test case 1
1
1

# Test case 2
6
3
0

# Test case 3
8
0
Output
# Test case 1
? 1 0
1

! 0

# Test case 2
? 3 1
2 6 4
0
? 3 3
5 3 1
4 5 6
! 3 1 4 2 5 0

# Test case 3
? 8 1
1 2 3 4 5 6 7 8
8
! 8 8 8 8 8 8 8 8
Note

You do not have to handle comments (lines starting with #) in the input; they are only for presentation purposes and will not be present in the test cases.

The queries given in the sample input and output are for demonstrating the interaction, and may not logically lead to a correct output.

  • Test case 1: The hidden array is $$$[0]$$$.

    The participant's code makes one query, with $$$P = \{1\}$$$ and $$$Q = \{\}$$$. The interactor calculates $$$S = \{0\}$$$ and returns its MEX, $$$1$$$.

    The participant's code correctly concludes that the hidden array is $$$[0]$$$ and outputs it.

  • Test case 2: The hidden array is $$$[3, 1, 4, 2, 5, 0]$$$.

    The participant's code makes the first query query, with $$$P = \{2, 6, 4\}$$$ and $$$Q = \{0\}$$$. The interactor calculates $$$S = \{1, 0, 2\}$$$ and returns its MEX, $$$3$$$.

    The participant's code makes the second query, with $$$P = \{5, 3, 1\}$$$ and $$$Q = \{4, 5, 6\}$$$. The interactor calculates $$$S = \{5, 4, 3, 6\}$$$ and returns its MEX, $$$0$$$.

    The participant's code correctly concludes that the hidden array is $$$[3, 1, 4, 2, 5, 0]$$$ and outputs it.

N. BitShift
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a binary string $$$s$$$ of length $$$n$$$. This binary string represents an integer (without trailing zeroes) $$$x$$$.

$$$m$$$ operations are then performed on this integer. In each operation, an integer $$$k$$$ is given, and the value of $$$x$$$ is updated to $$$\lfloor x \cdot 2^{k} \rfloor$$$. Equivalently, this operation can be understood as:

  • If $$$k \ge 0$$$, then $$$x$$$ is replaced by $$$x \lt \lt |k|$$$ (binary left shift by $$$k$$$ bits).
  • If $$$k \lt 0$$$, then $$$x$$$ is replaced by $$$x \gt \gt |k|$$$ (binary right shift by $$$-k$$$ bits).

Output (without leading zeroes) the binary string corresponding to the final value of $$$x$$$ after all $$$m$$$ operations.

Input

The first line of each test contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases.

The first line of each test case contains two space-separated integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the length of the binary string and the number of operations.

The second line of each test case contains a binary string $$$s$$$ (consisting only of the characters 0 and 1). It is guaranteed that $$$|s| = n$$$ and that the first character of $$$s$$$ is 1.

The third line of each test case contains $$$m$$$ space-separated integers $$$k_i$$$ ($$$-2 \cdot 10^5 \le k_i \le 2 \cdot 10^5$$$) — the value of $$$k$$$ for the $$$i^{\text{th}}$$$ operation. It is guaranteed that the sum of $$$k$$$ over all operations lies between $$$-2 \cdot 10^5$$$ and $$$2 \cdot 10^5$$$.

It is guaranteed that the sum of $$$n$$$ over all test cases and the sum of $$$m$$$ over all test cases are both at most $$$2 \cdot 10^5$$$.

Output

For each test case, output a single line containing a binary string corresponding to the final value of $$$x$$$. The binary string should not contain any leading zeroes — it should either be "0" or start with a 1.

Example
Input
2
1 2
1
-1 18
10 5
1111101010
2 -4 6 -8 10
Output
0
1111100000000000
Note

For the first test case, the binary string $$$s$$$ is "1" which corresponds to the integer $$$x = 1$$$.

  • In the first operation, $$$x$$$ is updated to $$$1 \gt \gt 1 = 0$$$.
  • In the second operation, $$$x$$$ is updated to $$$0 \lt \lt 18 = 0$$$.
The final value is $$$x = 0$$$, so the output is "0".

For the second test case, the binary string $$$s$$$ is "1111101010" which corresponds to the integer $$$x = 2026$$$.

  • In the first operation, $$$x$$$ is updated to $$$2026 \lt \lt 2 = 8104$$$.
  • In the second operation, $$$x$$$ is updated to $$$8104 \gt \gt 4 = 506$$$.
  • In the third operation, $$$x$$$ is updated to $$$506 \lt \lt 6 = 32384$$$.
  • In the fourth operation, $$$x$$$ is updated to $$$32384 \gt \gt 8 = 126$$$.
  • In the fifth operation, $$$x$$$ is updated to $$$126 \lt \lt 10 = 129024$$$.
The final value is $$$x = 129024$$$, so the output is "11111100000000000".