TheForces Round #44 (DIV3.5-Forces)
A. Three Moves Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Alice and Bob are playing a game on a $$$1 \times n$$$ grid, where:

  • Alice starts at cell $$$x$$$, Bob starts at cell $$$y$$$, where $$$1 \le x,y \le n$$$ and $$$x \neq y$$$.
  • Alice and Bob alternate turns, with Alice moving first.
  • A turn consists of exactly $$$3$$$ moves, where each move is either move one unit to the left or move one unit to the right.
  • A player can't jump onto or over another player, and all moves cannot exceed the boundary.

For example, $$$n=8$$$, $$$x=4$$$ and $$$y=7$$$, where Alice moves first:

  • $$$4 \rightarrow 3 \rightarrow 2 \rightarrow 1$$$ is considered as Alice's valid moves.
  • $$$4 \rightarrow 5 \rightarrow 6 \rightarrow 5$$$ is considered as Alice's valid moves.
  • $$$4 \rightarrow 5 \rightarrow 6$$$ is considered as Alice's invalid moves because this violates the rule of exactly $$$3$$$ moves.
  • $$$4 \rightarrow 5 \rightarrow 6 \rightarrow 7$$$ is considered as Alice's invalid moves because this violates the rule that a player can't jump onto another player.

A player loses if no valid move exists on their turn. The game terminates when a player cannot move.

Your task is to determine whether Alice will win, assuming that the strategies of the two players are optimal.

Input

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

The only line of each test case contains three integers $$$n$$$, $$$x$$$, and $$$y$$$ ($$$1 \le n \le 10$$$, $$$1 \le x, y \le 10$$$, $$$x \neq y$$$).

Output

For each test case, if Alice will win assuming that the strategies of the two players are optimal, output "YES" (without quotes) in a new line. Otherwise, output "NO".

Example
Input
3
2 1 2
5 1 5
10 7 3
Output
NO
YES
YES
Note

In the first test case, Alice can not do any valid move from the beginning. Thus, Alice will lose.

In the second test case, Alice can do move $$$1 \rightarrow 2 \rightarrow 3 \rightarrow 4$$$. After that, Bob can not do any valid move. Thus, Alice will win.

B. Kaosar and Segments
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is a regular $$$n$$$-sided shape with vertices labeled from $$$1$$$ to $$$n$$$ in clockwise order.

You can add a line segment with vertices $$$i$$$ and $$$j$$$ as endpoints only if:

  • $$$|i-j| \gt 1$$$.
  • $$$\gcd(i, j) = 1$$$.

Here $$$\operatorname{gcd}$$$ denotes the greatest common divisor.

Find the max number of line segments you can add such that no two segments intersect (except possibly at their endpoints).

Input

The first line will contain a single integer $$$t$$$ $$$(1\le t \le 10^4)$$$.

Each line will contain a single integer $$$n$$$ $$$(3 \le n \le 10^5)$$$.

Output

Print the max number of line segments you can add such that no two segments intersect (except possibly at their endpoints).

Example
Input
2
3
5
Output
0
2
Note

In the first test case, you can not add any line segment.

Figure for the first test case.

In the second test case, you can add a line segment with vertices $$$1$$$ and $$$3$$$ as endpoints, and add a line segment with vertices $$$3$$$ and $$$5$$$ as endpoints. It can be proven that up to $$$2$$$ line segments can be added.

Figure for the second test case.

C. Alyona Loves Ranges
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Alyona always plays with the numbers and the numbers that are between two numbers. Alyona's teacher notices this and gives her a mini assessment.

The teacher gives her three numbers $$$n$$$, $$$l$$$, and $$$r$$$ ($$$l \le r$$$). Alyona has to find the minimum integer $$$x$$$ such that:

  • $$$x \in [l,r]$$$.
  • $$$\gcd(n,x) \in [l,r]$$$.

Here $$$\operatorname{gcd}$$$ denotes the greatest common divisor.

If there is no such integer $$$x$$$, output $$$-1$$$ instead.

Input

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

The only line of each test case contains three integers $$$n$$$, $$$l$$$, and $$$r$$$ ($$$1 \le n \le 10^9$$$, $$$1 \le l \le r \le 10^9$$$).

Output

For each test case, output an integer — the minimum integer $$$x$$$ satisfying the conditions above. If there is no such integer $$$x$$$, output $$$-1$$$ instead.

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

In the first test case, the smallest integer in the range $$$[5, 7]$$$ is $$$5$$$. However, $$$\gcd(6, 5) = 1$$$, which is not in $$$[5, 7]$$$. Next, for $$$x = 6$$$, $$$\gcd(6, 6) = 6$$$, which is in $$$[5, 7]$$$. Therefore, the answer is $$$6$$$.

D. Explosive String
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There's a $$$1 \times n$$$ grid. For a string $$$y$$$ of length $$$l$$$, a robot moves according to the following pattern.

  • Initially, the robot selects a cell as the starting point.
  • Then, in the $$$i$$$-th $$$(1 \leq i \leq l)$$$ move, if $$$y_i = \mathtt{L}$$$, the robot moves one cell to the left; if $$$y_i = \mathtt{R}$$$, it moves one cell to the right. If the robot moves out of bounds, it explodes.

You are given a possibly incomplete string $$$x$$$ of length $$$m$$$. Your task is to complete the string $$$x$$$ such that, regardless of which cell the robot selects as the starting point, it will always explode. If there's no such string, output "NO" instead.

Input

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

The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n,m \le 50$$$).

The second line of each test case contains a string $$$x_1x_2 \ldots x_{m}$$$ of length $$$m$$$ consisting of characters 'L', 'R' and '?'. If $$$x_i=\mathtt{?}$$$ ($$$1 \le i \le m$$$), it means you need to choose 'L' or 'R' as the value of $$$x_i$$$.

Output

For each test case, if there's no such string, output "NO" in a new line. Otherwise, output "YES" in a new line, then output the complete string $$$x$$$ in the next line.

Example
Input
4
1 1
L
2 1
?
3 5
LR?R?
50 5
?????
Output
YES
L
NO
YES
LRRRL
NO
Note

In the first test case, the robot can only choose the first cell as the start point. Then, in the first move, the robot moves one cell to the left, which is out of bounds. After the first move, the robot will explode, so the answer is "YES".

In the second test case, if $$$x=\mathtt{L}$$$, the robot can choose the second cell as the start point. If $$$x=\mathtt{R}$$$, the robot can choose the first cell as the start point. In both cases, the robot will not explode. Thus, the answer is "NO".

E. Diagonal Modification
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is a classical problem: given an $$$n \times n$$$ grid, where the value of each cell $$$(i, j)$$$ is $$$a_{i,j}$$$. You need to find the path with the maximum sum from $$$(1, 1)$$$ to $$$(n, n)$$$ when you can only move right or down.

Support $$$q$$$ modifications: each modification gives an integer $$$k$$$, where $$$2 \le k \le 2n$$$. For all cells $$$(i, j)$$$ such that $$$i + j = k$$$ ($$$1 \le i$$$, $$$j \le n$$$), modify $$$a_{i,j}$$$ to $$$v$$$. You need to output the answer after each modification. Note the impact of a modification is permanent.

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$$$ and $$$q$$$ ($$$2 \le n \le 200$$$, $$$1 \le q \le 10^5$$$).

The $$$i$$$-th of the following $$$n$$$ lines contains $$$n$$$ integers $$$a_{i,1}, a_{i,2}, \ldots, a_{i,n}$$$ ($$$1 \le a_{i,j} \le 10^9$$$).

The $$$i$$$-th of the following $$$q$$$ lines contains two integers $$$k$$$ and $$$v$$$ ($$$2 \le k \le 2n$$$, $$$1 \le v \le 10^9$$$).

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

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

Output

For each test case, output a single integer in a new line  — the maximum path sum from $$$(1, 1)$$$ to $$$(n, n)$$$ after the modification.

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

In the first test case, after the first modification, the grid becomes

$$$2$$$$$$2$$$
$$$3$$$$$$4$$$

The optimal path is $$$(1,1) \rightarrow (2,1) \rightarrow (2,2)$$$. The maximum path sum is $$$2+3+4=9$$$.

After the second modification, the grid becomes

$$$2$$$$$$4$$$
$$$4$$$$$$4$$$

After the third modification, the grid becomes

$$$2$$$$$$4$$$
$$$4$$$$$$5$$$

F. RBS Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

This is an interactive problem.

Alice and Bob are playing a bracket game with a sequence $$$s$$$. Initially, $$$s$$$ is empty. The game lasts for $$$n$$$ rounds in total.

In the $$$i$$$-th turn:

  • If $$$i$$$ is odd, Alice adds exactly $$$a$$$ brackets (left or right bracket) to the back of $$$s$$$;
  • Otherwise, Bob adds exactly $$$b$$$ brackets (left or right bracket) to the back of $$$s$$$.

After $$$n$$$ rounds, if $$$s$$$ is a regular bracket sequence, Alice wins. Otherwise, Bob wins.

It is guaranteed that $$$n$$$ is odd and both $$$a$$$ and $$$b$$$ are even.

A bracket sequence is called regular if it can be constructed by the following formal grammar.

  1. The empty sequence $$$\varnothing$$$ is regular.
  2. If the bracket sequence $$$A$$$ is regular, then $$$\mathtt{(}A\mathtt{)}$$$ is also regular.
  3. If the bracket sequences $$$A$$$ and $$$B$$$ are regular, then the concatenated sequence $$$A B$$$ is also regular.

For example, the sequences "(())()", "()", "(()(()))", and the empty sequence are regular, while "(()" and "(()))(" are not.

Choose to be Alice or Bob, and play the game with the jury.

Input

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

Interaction

The first line of each test case contains three integers $$$n$$$, $$$a$$$, and $$$b$$$ ($$$3 \le n \le 49$$$, $$$2 \le a,b \le 50$$$). It is guaranteed that $$$n$$$ is odd and both $$$a$$$ and $$$b$$$ are even.

To choose to be Alice or Bob, you need to print an integer $$$x$$$ $$$(0 \le x \le 1)$$$, where $$$x=1$$$ means you choose Alice, and $$$x=0$$$ means you choose Bob.

If you choose to be Alice, you need to output a string containing exactly $$$a$$$ brackets in each $$$i$$$-th turn, where $$$i$$$ is odd. And read Bob's string containing exactly $$$b$$$ brackets in each $$$i$$$-th turn, where $$$i$$$ is even.

If you choose to be Bob, you need to output a string containing exactly $$$b$$$ brackets in each $$$i$$$-th turn, where $$$i$$$ is even. And read Alice's string containing exactly $$$a$$$ brackets in each $$$i$$$-th turn, where $$$i$$$ is odd.

After printing a query or the answer for a test case, do not forget to output the end of line and flush the output. Otherwise, you will get the verdict Idleness Limit Exceeded. To do this, use:

  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • see the documentation for other languages.

Hacks

To hack, follow the test format below.

The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10$$$).

The first line of each test case contains three integers $$$n$$$, $$$a$$$, and $$$b$$$ ($$$3 \le n \le 49$$$, $$$2 \le a,b \le 50$$$).

It must be guaranteed that $$$n$$$ is odd and both $$$a$$$ and $$$b$$$ are even.

Example
Input
2
3 2 2


)(

3 4 2

()()

()
Output


1
((

))

0

)(
Note

In the first test case, $$$n=3$$$, $$$a=2$$$, and $$$b=2$$$. And you choose to be Alice.

  1. In the first turn, you (Alice) add "((" to the back of $$$s$$$. Currently, $$$s=$$$ "((".
  2. In the second turn, the jury (Bob) adds ")(" to the back of $$$s$$$. Currently, $$$s=$$$ "(()(".
  3. In the third turn, you (Alice) add "))" to the back of $$$s$$$. Currently, $$$s=$$$ "(()())".

Because $$$s=$$$ "(()())" is a regular bracket sequence, you win this game.

Note that the example is only for understanding the statement and does not guarantee that the strategies of both players are optimal.

G. Product Partition
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given three integers $$$n$$$, $$$L$$$, and $$$R$$$.

You need to do the following:

  • Pick an integer $$$m$$$ such that $$$1 \leq m \leq n$$$;
  • Partition the interval $$$[1, n]$$$ into $$$m$$$ intervals $$$[l_1, r_1], [l_2, r_2], \ldots, [l_m, r_m]$$$ such that:
    • $$$l_1 = 1$$$ and $$$r_m = n$$$;
    • $$$l_i \leq r_i$$$ for all $$$1 \leq i \leq m$$$;
    • $$$r_i = l_{i+1} - 1$$$ for all $$$1 \leq i \lt m$$$;
    • $$$L \leq r_i - l_i + 1 \leq R$$$.

Note $$$P_i= \Pi_{l_i}^{r_i}i$$$. Find the minimum of $$$\gcd(P_1, P_2,\ldots,P_m)$$$, and output your interval partition scheme. Here, $$$\gcd$$$ means greatest common divisor.

For example, $$$n=7$$$, $$$L=3$$$ and $$$R=4$$$, one optimal scheme is to choose $$$m=2$$$ and intervals $$$[1,4]$$$ and $$$[5,7]$$$. In this case, $$$\gcd(P_1,P_2)=\gcd(1 \cdot 2 \cdot 3 \cdot 4,5 \cdot 6 \cdot 7)=\gcd(24,210)=6$$$, which can be proven to be the minimum value.

Since the value of $$$\gcd(P_1, P_2,\ldots,P_m)$$$ may be large, you need to output it modulo $$$998\,244\,353$$$. If there is not any valid interval partition scheme, output $$$-1$$$ instead.

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 only line of each test case contains three integers $$$n$$$, $$$L$$$, and $$$R$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le L \le R \le n$$$).

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

Output

For each test case, if there is not any valid interval partition scheme, output $$$-1$$$.

Otherwise, in the first line output two integers $$$m$$$ and $$$g$$$, where $$$m$$$ is the number of intervals and $$$g$$$ is the minimum value of $$$\gcd(P_1, P_2,\ldots,P_m)$$$ modulo $$$998\,244\,353$$$.

In the following $$$m$$$ lines, output two numbers $$$l_i$$$ and $$$r_i$$$, representing the left and right endpoints of the intervals. The intervals must satisfy all the conditions in the statement.

If there are multiple answers, output any.

Example
Input
5
5 3 4
7 3 4
8 3 4
3 1 1
13 7 13
Output
-1
2 6
1 4
5 7
2 24
1 4
5 8
3 1
1 1
2 2
3 3
1 237554682
1 13
Note

In the first test case, there is not any valid interval partition scheme.

In the second test case, the explanation is shown in the statement above.

H. Cool Operations
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You're given two integers $$$n$$$ and $$$q$$$ and two arrays $$$a$$$ and $$$b$$$ of size $$$n$$$.

You need to answer $$$q$$$ queries. In the $$$i$$$-th query, you're given three integers $$$k_i, l_i$$$, and $$$r_i$$$.

At first, a variable $$$x$$$ is set to $$$k_i$$$. Then, for each $$$j$$$ from $$$l_i$$$ to $$$r_i$$$, you must choose exactly one of the following two types of operations:

  1. set $$$x := x + a_j$$$;
  2. set $$$x := \max(x, b_j)$$$.

You need to find the maximum possible value of $$$x$$$ for each query.

Input

The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 10^5$$$), the number of test cases.

  • The first line contains two integers $$$n$$$ and $$$q$$$ ($$$2 \leq n,q \leq 5 \cdot 10^5$$$);
  • The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$-10^9 \leq a_i \leq 10^9$$$);
  • The third line contains $$$n$$$ integers $$$b_1,b_2,\ldots,b_n$$$ ($$$-10^9 \leq b_i \leq 10^9$$$).

Each of the next $$$q$$$ lines contains three integers $$$k_i, l_i$$$, and $$$r_i$$$ ($$$-10^9 \leq k_i \leq 10^9, 1 \le l_i \le r_i \le n$$$).

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

Output

For each query, output an integer in a new line  — the maximum possible value of $$$x$$$.

Examples
Input
1
4 5
10 2 3 -1
20 24 28 -10
8 1 2
17 1 2
19 2 3
25 2 3
-2 4 4
Output
24
29
28
30
-2
Input
1
5 5
756829654 557600139 843962687 -24632597 -866775049
505319834 616877613 657487273 912786344 924284486
481299777 1 3
-566119234 2 4
478992801 1 2
-694494781 3 5
-579759578 1 4
Output
2639692257
1460840300
1793422594
924284486
1906882660
Note

In the first query of the first test case, we have $$$x=8$$$ at first. We can do the following operations:

  1. for $$$j=1$$$, set $$$x := x+a_1 =8+10=18$$$;
  2. for $$$j=2$$$, set $$$x := \max(x, b_2)=\max(18,24)=24$$$.

It can be proven that $$$24$$$ is the maximum possible value of $$$x$$$.

In the second query of the first test case, we have $$$x=17$$$ at first. We can do the following operations:

  1. for $$$j=1$$$, set $$$x := x+a_1 =17+10=27$$$;
  2. for $$$j=2$$$, set $$$x := x+a_2 =27+2=29$$$.

It can be proven that $$$29$$$ is the maximum possible value of $$$x$$$.