inclusionAI/AReaL-boba-2-RL-Code huggingface dataset:
Alice and Bob are playing a game in an array $a$ of size $n$.

They take turns to do operations, with Alice starting first. The player who can not operate will lose. At first, a variable $mx$ is set to $0$.

In one operation, a player can do:

  * Choose an index $i$ ($1 \le i \le n$) such that $a_{i} \geq mx$ and set $mx$ to $a_{i}$. Then, set $a_{i}$ to $0$.

Determine whether Alice has a winning strategy.

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

For each test case:

  * The first line contains an integer $n$ ($2 \leq n \leq 50$) — the size of the array.    * The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq n$) — the elements of the array.

Output Format:
For each test case, if Alice has a winning strategy, output "YES". Otherwise, output "NO".

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

Tags:
['brute force', 'games', 'greedy', 'sortings']

Time Limit: 1000 ms
Memory Limit: 256 MB
For an array $b$ of size $m$, we define:

  * the maximum prefix position of $b$ is the smallest index $i$ that satisfies $b_1+\ldots+b_i=\max_{j=1}^{m}(b_1+\ldots+b_j)$;   * the maximum suffix position of $b$ is the largest index $i$ that satisfies $b_i+\ldots+b_m=\max_{j=1}^{m}(b_j+\ldots+b_m)$.

You are given three integers $n$, $x$, and $y$ ($x > y$). Construct an array $a$ of size $n$ satisfying:

  * $a_i$ is either $1$ or $-1$ for all $1 \le i \le n$;   * the maximum prefix position of $a$ is $x$;   * the maximum suffix position of $a$ is $y$.

If there are multiple arrays that meet the conditions, print any. It can be proven that such an array always exists under the given conditions.

Input Format:
The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.

For each test case:

  * The only line contains three integers $n$, $x$, and $y$ ($2 \leq n \leq 10^5, 1 \le y \lt x \le n)$. 

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

Output Format:
For each test case, output $n$ space-separated integers $a_1, a_2, \ldots, a_n$ in a new line.

Tags:
['constructive algorithms', 'greedy']

Time Limit: 1000 ms
Memory Limit: 256 MB
We define the $\operatorname{MAD}$ (Maximum Appearing Duplicate) in an array as the largest number that appears at least twice in the array. Specifically, if there is no number that appears at least twice, the $\operatorname{MAD}$ value is $0$.

For example, $\operatorname{MAD}([1, 2, 1]) = 1$, $\operatorname{MAD}([2, 2, 3, 3]) = 3$, $\operatorname{MAD}([1, 2, 3, 4]) = 0$.

You are given an array $a$ of size $n$. Initially, a variable $sum$ is set to $0$.

The following process will be executed in a sequential loop until all numbers in $a$ become $0$:

  1. Set $sum := sum + \sum_{i=1}^{n} a_i$;    2. Let $b$ be an array of size $n$. Set $b_i :=\ \operatorname{MAD}([a_1, a_2, \ldots, a_i])$ for all $1 \le i \le n$, and then set $a_i := b_i$ for all $1 \le i \le n$. 

Find the value of $sum$ after the process.

Input Format:
The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases.

For each test case:

  * The first line contains an integer $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the size of the array $a$;    * The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq n$) — the elements of the array. 

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

Output Format:
For each test case, output the value of $sum$ in a new line.

Tags:
['brute force', 'greedy', 'math']

Time Limit: 2000 ms
Memory Limit: 256 MB
You are given an array $a$ of size $n$.

There is an $n \times n$ grid. In the $i$-th row, the first $a_i$ cells are black and the other cells are white. In other words, note $(i,j)$ as the cell in the $i$-th row and $j$-th column, cells $(i,1), (i,2), \ldots, (i,a_i)$ are black, and cells $(i,a_i+1), \ldots, (i,n)$ are white.

You can do the following operations any number of times in any order:

  * Dye a $2 \times 2$ subgrid white;    * Dye a whole row white. Note you can not dye a whole column white. 

Find the minimum number of operations to dye all cells white.

Input Format:
The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.

For each test case:

  * The first line contains an integer $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the size of the array $a$.    * The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \leq n$). 

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

Output Format:
For each test case, output a single integer — the minimum number of operations to dye all cells white.

Tags:
['bitmasks', 'brute force', 'dp', 'greedy', 'implementation']

Time Limit: 2000 ms
Memory Limit: 256 MB
This is the easy version of the problem. The only difference is the limit on the number of queries.

This is an interactive problem.

You are given a tree of $n$ nodes with node $1$ as its root node.

There is a hidden mole in one of the nodes. To find its position, you can pick an integer $x$ ($1 \le x \le n$) to make an inquiry to the jury. Next, the jury will return $1$ when the mole is in subtree $x$. Otherwise, the judge will return $0$. If the judge returns $0$ and the mole is not in root node $1$, the mole will move to the parent node of the node it is currently on.

Use at most $300$ operations to find the current node where the mole is located.

Input Format:
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.

Output Format:


Tags:
['binary search', 'data structures', 'dfs and similar', 'interactive', 'trees']

Time Limit: 4000 ms
Memory Limit: 256 MB
This is the hard version of the problem. The only difference is the limit on the number of queries.

This is an interactive problem.

You are given a tree of $n$ nodes with node $1$ as its root node.

There is a hidden mole in one of the nodes. To find its position, you can pick an integer $x$ ($1 \le x \le n$) to make an inquiry to the jury. Next, the jury will return $1$ when the mole is in subtree $x$. Otherwise, the judge will return $0$. If the judge returns $0$ and the mole is not in root node $1$, the mole will move to the parent node of the node it is currently on.

Use at most $160$ operations to find the current node where the mole is located.

Input Format:
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.

Output Format:


Tags:
['binary search', 'data structures', 'dfs and similar', 'divide and conquer', 'interactive', 'trees']

Time Limit: 4000 ms
Memory Limit: 256 MB
You are given an array $a$ of size $n$.

A segment $[l, r](1 \le l < r \le n)$ is called a polygonal segment only if the following conditions hold:

  * $(r-l+1) \geq 3$;    * Considering $a_l, a_{l+1}, \ldots, a_r$ as side lengths, these sides can form a polygon with $(r-l+1)$ sides. 

Process $q$ queries of two types:

  * "1 l r": find the length of the longest segment among all polygonal segments $[l_0,r_0]$ satisfying $l \le l_0 \le r_0 \le r$. If there is no such polygonal segment, output $-1$ instead;    * "2 i x": assign $a_i := x$.

Input Format:
The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.

For each test case:

  * The first line of each testcase contains two integers $n$, $q$ ($4 \le n \le 2\cdot 10^5$, $1 \le q \le 10^5$);    * The second line of each testcase contains $n$ integers $a_1,a_2,\ldots, a_n$ ($1 \le a_i \le 10^{12}$);    * The following $q$ lines contain the description of queries. Each line is of one of two types:     * "1 l r" ($1 \le l < r \le n$, $r-l+1\ge 3$);      * "2 i x" ($1 \le i \le n$, $1 \le x \le 10^{12}$). 

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

Output Format:
For each query, if there is no suitable segment, output $-1$ in a new line. Otherwise, output the length of the longest segment satisfying the condition above in a new line.

Tags:
['brute force', 'data structures', 'divide and conquer', 'dp', 'greedy', 'two pointers']

Time Limit: 8000 ms
Memory Limit: 512 MB
You are given an array $a$ of $n$ integers, where $n$ is odd.

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

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

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

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

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

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

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

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

Tags:
['greedy', 'implementation']

Time Limit: 1000 ms
Memory Limit: 256 MB
You are given an array $b$ of $n - 1$ integers.

An array $a$ of $n$ integers is called good if $b_i = a_i \, \& \, a_{i + 1}$ for $1 \le i \le n-1$, where $\&$ denotes the [bitwise AND operator](https://en.wikipedia.org/wiki/Bitwise_operation#AND).

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

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

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

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

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

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

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

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

Tags:
['bitmasks', 'constructive algorithms', 'greedy']

Time Limit: 1000 ms
Memory Limit: 256 MB
You are given an array $a$ of $n$ integers.

In one operation, you will perform the following two-step move:

  1. Choose an integer $x$ ($0 \le x \le 10^{9}$).    2. Replace each $a_i$ with $|a_i - x|$, where $|v|$ denotes the [absolute value](https://en.wikipedia.org/wiki/Absolute_value) of $v$. 

For example, by choosing $x = 8$, the array $[5, 7, 10]$ will be changed into $[|5-8|, |7-8|, |10-8|] = [3,1,2]$.

Construct a sequence of operations to make all elements of $a$ equal to $0$ in at most $40$ operations or determine that it is impossible. You do not need to minimize the number of operations.

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

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

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

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

Output Format:
For each test case, output a single integer $-1$ if it is impossible to make all array elements equal to $0$ in at most $40$ operations.

Otherwise, output two lines. The first line of output should contain a single integer $k$ ($0 \le k \le 40$) — the number of operations. The second line of output should contain $k$ integers $x_1, x_2, \ldots, x_k$ ($0 \le x_i \le 10^{9}$) — the sequence of operations, denoting that on the $i$-th operation, you chose $x=x_i$.

If there are multiple solutions, output any of them.

You do not need to minimize the number of operations.

Tags:
['constructive algorithms', 'greedy', 'math']

Time Limit: 2000 ms
Memory Limit: 256 MB
You are given an undirected graph with $n$ vertices, numbered from $1$ to $n$. There is an edge between vertices $u$ and $v$ if and only if $u \oplus v$ is a [prime number](https://en.wikipedia.org/wiki/Prime_number), where $\oplus$ denotes the [bitwise XOR operator](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).

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

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

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

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

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

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

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

If there are multiple solutions, output any of them.

Tags:
['bitmasks', 'constructive algorithms', 'graphs', 'greedy', 'math', 'number theory']

Time Limit: 2000 ms
Memory Limit: 256 MB
This is an interactive problem.

Consider an undirected connected graph consisting of $n$ vertices and $m$ edges. Each vertex can be colored with one of three colors: $1$, $2$, or $3$. Initially, all vertices are uncolored.

Alice and Bob are playing a game consisting of $n$ rounds. In each round, the following two-step process happens:

  1. Alice chooses two different colors.    2. Bob chooses an uncolored vertex and colors it with one of the two colors chosen by Alice. 

Alice wins if there exists an edge connecting two vertices of the same color. Otherwise, Bob wins.

You are given the graph. Your task is to decide which player you wish to play as and win the game.

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

The first line of each test case contains two integers $n$, $m$ ($1 \le n \le 10^4$, $n - 1 \le m \le \min(\frac{n \cdot (n - 1)}{2}, 10^4)$) — the number of vertices and the number of edges in the graph, respectively.

Each of the next $m$ lines of each test case contains two integers $u_i$, $v_i$ ($1 \le u_i, v_i \le n$) — the edges of the graph. It is guaranteed that the graph is connected and there are no multiple edges or self-loops.

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

Output Format:


Tags:
['constructive algorithms', 'dfs and similar', 'games', 'graphs', 'greedy', 'interactive']

Time Limit: 2000 ms
Memory Limit: 256 MB
You are given $n$ sticks, numbered from $1$ to $n$. The length of the $i$-th stick is $a_i$.

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

$^{\text{∗}}$A triangle with side lengths $a$, $b$, and $c$ is called non-degenerate if:

  * $a < b + c$,    * $b < a + c$, and    * $c < a + b$.

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

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

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

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

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

Tags:
['brute force', 'greedy', 'implementation', 'math', 'sortings']

Time Limit: 5000 ms
Memory Limit: 256 MB
You are given a grid consisting of $n$ rows and $m$ columns, where each cell is initially white. Additionally, you are given an integer $k$, where $1 \le k \le \min(n, m)$.

You will process $q$ operations of two types:

  * $\mathtt{H}$ (horizontal operation) — You choose a $1 \times k$ rectangle completely within the grid, where all cells in this rectangle are white. Then, all cells in this rectangle are changed to black.    * $\mathtt{V}$ (vertical operation) — You choose a $k \times 1$ rectangle completely within the grid, where all cells in this rectangle are white. Then, all cells in this rectangle are changed to black. 

After each operation, if any rows or columns become completely black, all cells in these rows and columns are simultaneously reset to white. Specifically, if all cells in the row and column a cell is contained in become black, all cells in both the row and column will be reset to white.

Choose the rectangles in a way that you can perform all given operations, or determine that it is impossible.

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

The first line of each test case contains four integers $n$, $m$, $k$, and $q$ ($1 \le n, m \le 100$, $1 \le k \le \min(n, m)$, $1 \le q \le 1000$) — the number of rows and columns in the grid, the size of the operation rectangle, and the number of operations, respectively.

The second line of each test case contains a string $s$ of length $q$, consisting only of characters $\mathtt{H}$ and $\mathtt{V}$ — the sequence of operation types.

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

Output Format:
For each test case, output a single integer $-1$ if it is impossible to perform all the operations.

Otherwise, output $q$ lines. Each line contains two integers $i$, $j$ ($1 \le i \le n$, $1 \le j \le m$) — the coordinates of the top-left cell of the operation rectangle.

If there are multiple solutions, output any of them.

Tags:
['constructive algorithms', 'greedy', 'implementation']

Time Limit: 2000 ms
Memory Limit: 256 MB
Alice and Bob are playing a game with $n$ piles of stones, where the $i$-th pile has $a_i$ stones. Players take turns making moves, with Alice going first.

On each move, the player does the following three-step process:

  1. Choose an integer $k$ ($1 \leq k \leq \frac n 2$). Note that the value of $k$ can be different for different moves.    2. Remove $k$ piles of stones.    3. Choose another $k$ piles of stones and split each pile into two piles. The number of stones in each new pile must be a prime number. 

The player who is unable to make a move loses.

Determine who will win if both players play optimally.

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

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

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 2 \cdot 10^5$) — the number of stones in the piles.

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

Output Format:
For each test case, output "Alice" (without quotes) if Alice wins and "Bob" (without quotes) otherwise.

You can output each letter in any case (upper or lower). For example, the strings "alIcE", "Alice", and "alice" will all be considered identical.

Tags:
['bitmasks', 'dp', 'fft', 'games', 'math', 'number theory']

Time Limit: 2000 ms
Memory Limit: 256 MB
This is an interactive problem.

You are given a grid with $n$ rows and $m$ columns. You need to fill each cell with a unique integer from $1$ to $n \cdot m$.

After filling the grid, you will play a game on this grid against the interactor. Players take turns selecting one of the previously unselected cells from the grid, with the interactor going first.

On the first turn, the interactor can choose any cell from the grid. After that, any chosen cell must be orthogonally adjacent to at least one previously selected cell. Two cells are considered orthogonally adjacent if they share an edge. The game continues until all cells have been selected.

Your goal is to let the sum of numbers in the cells selected by you be strictly less than the sum of numbers in the cells selected by the interactor.

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

The only line of each test case contains two integers $n$ and $m$ ($4 \le n, m \le 10$) — the number of rows and columns in the grid.

Output Format:


Tags:
['constructive algorithms', 'games', 'graph matchings', 'greedy', 'interactive']

Time Limit: 5000 ms
Memory Limit: 256 MB
Kmes has written three integers $a$, $b$ and $c$ in order to remember that he has to give Noobish_Monk $a \times b \times c$ bananas.

Noobish_Monk has found these integers and decided to do the following at most $5$ times:

  * pick one of these integers;    * increase it by $1$. 

For example, if $a = 2$, $b = 3$ and $c = 4$, then one can increase $a$ three times by one and increase $b$ two times. After that $a = 5$, $b = 5$, $c = 4$. Then the total number of bananas will be $5 \times 5 \times 4 = 100$.

What is the maximum value of $a \times b \times c$ Noobish_Monk can achieve with these operations?

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

The first and only line of each test case contains three integers $a$, $b$ and $c$ ($1 \le a, b, c \le 10$) — Kmes's integers.

Output Format:
For each test case, output a single integer — the maximum amount of bananas Noobish_Monk can get.

Tags:
['brute force', 'constructive algorithms', 'greedy', 'math', 'sortings']

Time Limit: 1000 ms
Memory Limit: 256 MB