Alice and Bob are playing a game on a $$$1 \times n$$$ grid, where:
For example, $$$n=8$$$, $$$x=4$$$ and $$$y=7$$$, where Alice moves first:
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.
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$$$).
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".
32 1 25 1 510 7 3
NO YES YES
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.
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:
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).
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)$$$.
Print the max number of line segments you can add such that no two segments intersect (except possibly at their endpoints).
235
0 2
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.
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:
Here $$$\operatorname{gcd}$$$ denotes the greatest common divisor.
If there is no such integer $$$x$$$, output $$$-1$$$ instead.
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$$$).
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.
36 5 710 1 102 3 4
6 1 -1
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$$$.
There's a $$$1 \times n$$$ grid. For a string $$$y$$$ of length $$$l$$$, a robot moves according to the following pattern.
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.
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$$$.
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.
41 1L2 1?3 5LR?R?50 5?????
YES L NO YES LRRRL NO
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".
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.
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$$$.
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.
22 31 23 42 23 44 52 21 11 13 12 5
9 10 11 3 7
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$$$ |
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:
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.
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.
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.
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:
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.
2 3 2 2 )( 3 4 2 ()() ()
1 (( )) 0 )(
In the first test case, $$$n=3$$$, $$$a=2$$$, and $$$b=2$$$. And you choose to be Alice.
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.
You are given three integers $$$n$$$, $$$L$$$, and $$$R$$$.
You need to do the following:
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.
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$$$.
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.
55 3 47 3 48 3 43 1 113 7 13
-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
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.
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:
You need to find the maximum possible value of $$$x$$$ for each query.
The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 10^5$$$), the number of test cases.
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$$$.
For each query, output an integer in a new line — the maximum possible value of $$$x$$$.
14 510 2 3 -120 24 28 -108 1 217 1 219 2 325 2 3-2 4 4
24 29 28 30 -2
15 5756829654 557600139 843962687 -24632597 -866775049505319834 616877613 657487273 912786344 924284486481299777 1 3-566119234 2 4478992801 1 2-694494781 3 5-579759578 1 4
2639692257 1460840300 1793422594 924284486 1906882660
In the first query of the first test case, we have $$$x=8$$$ at first. We can do the following operations:
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:
It can be proven that $$$29$$$ is the maximum possible value of $$$x$$$.