apaz/codeforces-genesys huggingface dataset:
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 2.0 seconds
Memory limit: 256.0 MB

# Problem
You are given two binary strings $$$a$$$ and $$$b$$$. A binary string is a string consisting of the characters '0' and '1'.

Your task is to determine the maximum possible number $$$k$$$ such that a prefix of string $$$a$$$ of length $$$k$$$ is a subsequence of string $$$b$$$.

A sequence $$$a$$$ is a subsequence of a sequence $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by the deletion of several (possibly, zero or all) elements.

## Input Format
The first line consists of a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n,m \le 2 \cdot 10^5$$$) — the length of string $$$a$$$ and the length of string $$$b$$$, respectively.

The second line of each test case contains a binary string $$$a$$$ of length $$$n$$$.

The third line of each test case contains a binary string $$$b$$$ of length $$$m$$$.

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

## Output Format
For each test case, output a single number — the maximum $$$k$$$, such that the first $$$k$$$ characters of $$$a$$$ form a subsequence of $$$b$$$.

## Examples
```input
6
5 4
10011
1110
3 3
100
110
1 3
1
111
4 4
1011
1111
3 5
100
11010
3 1
100
0
```
```output
2
2
1
1
3
0
```

## Note
In the first example, the string '$$$10$$$' is a subsequence of '$$$1\color{red}11\color{red}0$$$' but the string '$$$100$$$' is not. So the answer is $$$2$$$.

In the fifth example, $$$a$$$='$$$100$$$', $$$b$$$='$$$1\color{red}{10}1\color{red}0$$$', whole string $$$a$$$ is a subsequence of string $$$b$$$. So the answer is $$$3$$$.

In the sixth example, string $$$b$$$ does not contain '$$$1$$$' so the answer is $$$0$$$.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 2.0 seconds
Memory limit: 256.0 MB

# Problem
You are given an array $$$x_2,x_3,\dots,x_n$$$. Your task is to find any array $$$a_1,\dots,a_n$$$, where:

- $$$1\le a_i\le 10^9$$$ for all $$$1\le i\le n$$$.
- $$$x_i=a_i \bmod a_{i-1}$$$ for all $$$2\le i\le n$$$.

Here $$$c\bmod d$$$ denotes the remainder of the division of the integer $$$c$$$ by the integer $$$d$$$. For example $$$5 \bmod 2 = 1$$$, $$$72 \bmod 3 = 0$$$, $$$143 \bmod 14 = 3$$$.

Note that if there is more than one $$$a$$$ which satisfies the statement, you are allowed to find any.

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

The first line of each test case contains a single integer $$$n$$$ $$$(2\le n\le 500)$$$ — the number of elements in $$$a$$$.

The second line of each test case contains $$$n-1$$$ integers $$$x_2,\dots,x_n$$$ $$$(1\le x_i\le 500)$$$ — the elements of $$$x$$$.

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

## Output Format
For each test case output any $$$a_1,\dots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) which satisfies the statement.

## Examples
```input
5
4
2 4 1
3
1 1
6
4 2 5 1 2
2
500
3
1 5
```
```output
3 5 4 9
2 5 11
5 14 16 5 11 24
501 500
2 7 5
```

## Note
In the first test case $$$a=[3,5,4,9]$$$ satisfies the conditions, because:

- $$$a_2\bmod a_1=5\bmod 3=2=x_2$$$;
- $$$a_3\bmod a_2=4\bmod 5=4=x_3$$$;
- $$$a_4\bmod a_3=9\bmod 4=1=x_4$$$;

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 2.0 seconds
Memory limit: 256.0 MB

# Problem
You are given an integer $$$n$$$. You choose $$$n$$$ cells $$$(x_1,y_1), (x_2,y_2),\dots,(x_n,y_n)$$$ in the grid $$$n\times n$$$ where $$$1\le x_i\le n$$$ and $$$1\le y_i\le n$$$.

Let $$$\mathcal{H}$$$ be the set of distinct Manhattan distances between any pair of cells. Your task is to maximize the size of $$$\mathcal{H}$$$. Examples of sets and their construction are given in the notes.

If there exists more than one solution, you are allowed to output any.

Manhattan distance between cells $$$(x_1,y_1)$$$ and $$$(x_2,y_2)$$$ equals $$$|x_1-x_2|+|y_1-y_2|$$$.

## Input Format
The first line contains a single integer $$$t$$$ ($$$1\le t\le 50$$$) — the number of test cases.

Each of the following $$$t$$$ lines contains a single integer $$$n$$$ ($$$2\le n\le 10^3$$$).

## Output Format
For each test case, output $$$n$$$ points which maximize the size of $$$\mathcal{H}$$$. It is not necessary to output an empty line at the end of the answer for each test case.

## Examples
```input
5
2
3
4
5
6
```
```output
1 1
1 2

2 1
2 3
3 1

1 1
1 3
4 3
4 4

1 1
1 3
1 4
2 1
5 5

1 4
1 5
1 6
5 2
5 5
6 1
```

## Note
In the first testcase we have $$$n=2$$$. One of the possible arrangements is:

The arrangement with cells located in $$$(1,1)$$$ and $$$(1,2)$$$.

In the second testcase we have $$$n=3$$$. The optimal arrangement is:

The arrangement with cells located in $$$(2,1)$$$, $$$(2,3)$$$ and $$$(3,1)$$$.

$$$\mathcal{H}$$$=$$$\{|2-2|+|1-1|,|2-2|+|3-3|,|3-3|+|1-1|,|2-2|+|1-3|,|2-3|+|1-1|,|2-3|+|3-1|\}$$$=$$$\{0,0,0,2,1,3\}$$$=$$$\{0,1,2,3\}$$$.

For $$$n=4$$$ a possible arrangement is:

For $$$n=5$$$ a possible arrangement is:

For $$$n=6$$$ a possible arrangement is:

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 5.0 seconds
Memory limit: 256.0 MB

# Problem
Let us call an array $$$x_1,\dots,x_m$$$ interesting if it is possible to divide the array into $$$k>1$$$ parts so that bitwise XOR of values from each part are equal.

More formally, you must split array $$$x$$$ into $$$k$$$ consecutive segments, each element of $$$x$$$ must belong to exactly $$$1$$$ segment. Let $$$y_1,\dots,y_k$$$ be the XOR of elements from each part respectively. Then $$$y_1=y_2=\dots=y_k$$$ must be fulfilled.

For example, if $$$x = [1, 1, 2, 3, 0]$$$, you can split it as follows: $$$[\color{blue}1], [\color{green}1], [\color{red}2, \color{red}3, \color{red}0]$$$. Indeed $$$\color{blue}1=\color{green}1=\color{red}2 \oplus \color{red}3\oplus \color{red}0$$$.

You are given an array $$$a_1,\dots,a_n$$$. Your task is to answer $$$q$$$ queries:

- For fixed $$$l$$$, $$$r$$$, determine whether the subarray $$$a_l,a_{l+1},\dots,a_r$$$ is interesting.

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

The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$1 \le q \le 2 \cdot 10^5$$$) — the number of elements in the array and the number of queries respectively.

The next line contains $$$n$$$ integers $$$a_1,\dots,a_n$$$ ($$$0 \le a_i < 2^{30}$$$) — elements of the array.

Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l < r \le n$$$) describing the query.

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

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

## Output Format
For each query, output "YES" if the subarray is interesting and "NO" otherwise.

You can output "Yes" and "No" in any case (for example, the strings "yES", "yes", and "Yes" will be recognized as correct answers).

## Examples
```input
4
5 5
1 1 2 3 0
1 5
2 4
3 5
1 3
3 4
5 5
1 2 3 4 5
1 5
2 4
3 5
1 3
2 3
7 4
12 9 10 9 10 11 9
1 5
1 7
2 6
2 7
11 4
0 0 1 0 0 1 0 1 1 0 1
1 2
2 5
6 9
7 11
```
```output
YES
YES
NO
NO
NO

YES
NO
NO
YES
NO

NO
NO
NO
NO

YES
NO
YES
YES
```

## Note
Explanation for the first test case:

The first query is described in the statement.

In the second query, we should divide $$$[1,2,3]$$$. A possible division is $$$[1,2],[3]$$$, since $$$1\oplus 2=3$$$.

It can be shown that for queries $$$3,4,5$$$, the subarrays are not interesting.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 2.0 seconds
Memory limit: 256.0 MB

# Problem
This is the easy version of the problem. In this version $$$l=r$$$.

You are given a string $$$s$$$. For a fixed $$$k$$$, consider a division of $$$s$$$ into exactly $$$k$$$ continuous substrings $$$w_1,\dots,w_k$$$. Let $$$f_k$$$ be the maximal possible $$$LCP(w_1,\dots,w_k)$$$ among all divisions.

$$$LCP(w_1,\dots,w_m)$$$ is the length of the Longest Common Prefix of the strings $$$w_1,\dots,w_m$$$.

For example, if $$$s=abababcab$$$ and $$$k=4$$$, a possible division is $$$\color{red}{ab}\color{blue}{ab}\color{orange}{abc}\color{green}{ab}$$$. The $$$LCP(\color{red}{ab},\color{blue}{ab},\color{orange}{abc},\color{green}{ab})$$$ is $$$2$$$, since $$$ab$$$ is the Longest Common Prefix of those four strings. Note that each substring consists of a continuous segment of characters and each character belongs to exactly one substring.

Your task is to find $$$f_l,f_{l+1},\dots,f_r$$$. In this version $$$l=r$$$.

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

The first line of each test case contains two integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le l = r \le n \le 2 \cdot 10^5$$$) — the length of the string and the given range.

The second line of each test case contains string $$$s$$$ of length $$$n$$$, all characters are lowercase English letters.

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 $$$r-l+1$$$ values: $$$f_l,\dots,f_r$$$.

## Examples
```input
7
3 3 3
aba
3 3 3
aaa
7 2 2
abacaba
9 4 4
abababcab
10 1 1
codeforces
9 3 3
abafababa
5 3 3
zpozp
```
```output
0
1
3
2
10
2
0
```

## Note
In the first sample $$$n=k$$$, so the only division of $$$aba$$$ is $$$\color{red}a\color{blue}b\color{orange}a$$$. The answer is zero, because those strings do not have a common prefix.

In the second sample, the only division is $$$\color{red}a\color{blue}a\color{orange}a$$$. Their longest common prefix is one.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 3.0 seconds
Memory limit: 256.0 MB

# Problem
This is the hard version of the problem. In this version $$$l\le r$$$.

You are given a string $$$s$$$. For a fixed $$$k$$$, consider a division of $$$s$$$ into exactly $$$k$$$ continuous substrings $$$w_1,\dots,w_k$$$. Let $$$f_k$$$ be the maximal possible $$$LCP(w_1,\dots,w_k)$$$ among all divisions.

$$$LCP(w_1,\dots,w_m)$$$ is the length of the Longest Common Prefix of the strings $$$w_1,\dots,w_m$$$.

For example, if $$$s=abababcab$$$ and $$$k=4$$$, a possible division is $$$\color{red}{ab}\color{blue}{ab}\color{orange}{abc}\color{green}{ab}$$$. The $$$LCP(\color{red}{ab},\color{blue}{ab},\color{orange}{abc},\color{green}{ab})$$$ is $$$2$$$, since $$$ab$$$ is the Longest Common Prefix of those four strings. Note that each substring consists of a continuous segment of characters and each character belongs to exactly one substring.

Your task is to find $$$f_l,f_{l+1},\dots,f_r$$$.

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

The first line of each test case contains two integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le l \le r \le n \le 2 \cdot 10^5$$$) — the length of the string and the given range.

The second line of each test case contains string $$$s$$$ of length $$$n$$$, all characters are lowercase English letters.

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 $$$r-l+1$$$ values: $$$f_l,\dots,f_r$$$.

## Examples
```input
7
3 1 3
aba
3 2 3
aaa
7 1 5
abacaba
9 1 6
abababcab
10 1 10
aaaaaaawac
9 1 9
abafababa
7 2 7
vvzvvvv
```
```output
3 1 0 
1 1 
7 3 1 1 0 
9 2 2 2 0 0 
10 3 2 1 1 1 1 1 0 0 
9 3 2 1 1 0 0 0 0 
2 2 1 1 1 0
```

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 2.0 seconds
Memory limit: 256.0 MB

# Problem
A parentheses sequence is a string consisting of characters "(" and ")", for example "(()((".

A balanced parentheses sequence is a parentheses sequence which can become a valid mathematical expression after inserting numbers and operations into it, for example "(()(()))".

The balance of a parentheses sequence is defined as the number of opening parentheses "(" minus the number of closing parentheses ")". For example, the balance of the sequence "(()((" is 3.

A balanced parentheses sequence can also be defined as a parentheses sequence with balance 0 such that each of its prefixes has a non-negative balance.

We define the balanced shuffle operation that takes a parentheses sequence and returns a parentheses sequence as follows: first, for every character of the input sequence, we compute the balance of the prefix of the sequence before that character and write those down in a table together with the positions of the characters in the input sequence, for example:

Prefix balance01212321Position12345678Character(()(()))

Then, we sort the columns of this table in increasing order of prefix balance, breaking ties in decreasing order of position. In the above example, we get:

Prefix balance01112223Position18427536Character()(()())

The last row of this table forms another parentheses sequence, in this case "()(()())". This sequence is called the result of applying the balanced shuffle operation to the input sequence, or in short just the balanced shuffle of the input sequence.

You are given a balanced parentheses sequence. Print its balanced shuffle.

## Input Format
The only line of input contains a string $$$s$$$ consisting only of characters "(" and ")". This string is guaranteed to be a non-empty balanced parentheses sequence with its length not exceeding $$$500\,000$$$.

## Output Format
Print the parentheses sequence $$$t$$$ — the balanced shuffle of $$$s$$$.

## Examples
```input
(()(()))
```
```output
()(()())
```

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
This is the easy version of the problem. The difference in this version is that $$$t=1$$$ and we work on an array-like tree.

Ron and Hermione are playing a game on a tree of $$$n$$$ nodes that are initially inactive. This tree is special because it has exactly two leaves. It can thus be seen as an array. The game consists of $$$t$$$ rounds, each of which starts with a stone on exactly one node, which is considered as activated. A move consists of picking an inactive neighbor of the node with a stone on it and moving the stone there (thus activating this neighbor). Ron makes the first move, after which he alternates with Hermione until no valid move is available. The player that cannot make a move loses the round. If both players play optimally, who wins each round of this game?

Note that all the rounds are played with the same tree; only the starting node changes. Moreover, after each round, all active nodes are considered inactive again.

## Input Format
The first line contains integers $$$n$$$ ($$$2 \leq n \leq 2\times 10^5$$$), $$$t$$$ ($$$t=1$$$), the number of nodes in the tree and the number of rounds, respectively.

The next $$$n-1$$$ lines contain two integers $$$1 \leq u, v \leq n$$$ each, corresponding to an edge of the tree. It is guaranteed that the tree has exactly two leaves.

The next line contains $$$t$$$ integers $$$1 \leq u_1 , \dots, u_t \leq n$$$, corresponding to the node where the stone is initially put.

## Output Format
The output consists of $$$t=1$$$ line which is either "Ron" or "Hermione".

## Examples
```input
3 1
2 3
3 1
3
```
```output
Ron
```
-----
```input
5 1
1 2
2 3
3 4
4 5
5
```
```output
Hermione
```

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
This is the medium version of the problem. The difference in this version is that $$$t=1$$$ and we work on trees.

Ron and Hermione are playing a game on a tree of $$$n$$$ nodes that are initially inactive. The game consists of $$$t$$$ rounds, each of which starts with a stone on exactly one node, which is considered as activated. A move consists of picking an inactive neighbor of the node with a stone on it and moving the stone there (thus activating this neighbor). Ron makes the first move, after which he alternates with Hermione until no valid move is available. The player that cannot make a move loses the round. If both players play optimally, who wins each round of this game?

Note that all the rounds are played with the same tree; only the starting node changes. Moreover, after each round, all active nodes are considered inactive again.

## Input Format
The first line contains integers $$$n$$$ ($$$2 \leq n \leq 2\times 10^5$$$), $$$t$$$ ($$$t=1$$$), the number of nodes in the tree and the number of rounds, respectively.

The next $$$n-1$$$ lines contain two integers $$$1 \leq u, v \leq n$$$ each, corresponding to an edge of the tree.

The next line contains $$$t$$$ integers $$$1 \leq u_1 , \dots, u_t \leq n$$$, corresponding to the node where the stone is initially put.

## Output Format
The output consists of $$$t=1$$$ line which is either "Ron" or "Hermione".

## Examples
```input
5 1
1 2
1 3
3 4
3 5
1
```
```output
Ron
```

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
Harry Potter is hiking in the Alps surrounding Lake Geneva. In this area there are $$$m$$$ cabins, numbered 1 to $$$m$$$. Each cabin is connected, with one or more trails, to a central meeting point next to the lake. Each trail is either short or long. Cabin $$$i$$$ is connected with $$$s_i$$$ short trails and $$$l_i$$$ long trails to the lake.

Each day, Harry walks a trail from the cabin where he currently is to Lake Geneva, and then from there he walks a trail to any of the $$$m$$$ cabins (including the one he started in). However, as he has to finish the hike in a day, at least one of the two trails has to be short.

How many possible combinations of trails can Harry take if he starts in cabin 1 and walks for $$$n$$$ days?

Give the answer modulo $$$10^9 + 7$$$.

## Input Format
The first line contains the integers $$$m$$$ and $$$n$$$.

The second line contains $$$m$$$ integers, $$$s_1, \dots, s_m$$$, where $$$s_i$$$ is the number of short trails between cabin $$$i$$$ and Lake Geneva.

The third and last line contains $$$m$$$ integers, $$$l_1, \dots, l_m$$$, where $$$l_i$$$ is the number of long trails between cabin $$$i$$$ and Lake Geneva.

We have the following constraints:

$$$0 \le s_i, l_i \le 10^3$$$.

$$$1 \le m \le 10^2$$$.

$$$1 \le n \le 10^3$$$.

## Output Format
The number of possible combinations of trails, modulo $$$10^9 + 7$$$.

## Examples
```input
3 2
1 0 1
0 1 1
```
```output
18
```

Now solve the problem and return the code.