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: 1.0 seconds
Memory limit: 256.0 MB

# Problem
Consider a billiard table of rectangular size $$$n \times m$$$ with four pockets. Let's introduce a coordinate system with the origin at the lower left corner (see the picture).

There is one ball at the point $$$(x, y)$$$ currently. Max comes to the table and strikes the ball. The ball starts moving along a line that is parallel to one of the axes or that makes a $$$45^{\circ}$$$ angle with them. We will assume that:

1. the angles between the directions of the ball before and after a collision with a side are equal,
2. the ball moves indefinitely long, it only stops when it falls into a pocket,
3. the ball can be considered as a point, it falls into a pocket if and only if its coordinates coincide with one of the pockets,
4. initially the ball is not in a pocket.

Note that the ball can move along some side, in this case the ball will just fall into the pocket at the end of the side.

Your task is to determine whether the ball will fall into a pocket eventually, and if yes, which of the four pockets it will be.

## Input Format
The only line contains $$$6$$$ integers $$$n$$$, $$$m$$$, $$$x$$$, $$$y$$$, $$$v_x$$$, $$$v_y$$$ ($$$1 \leq n, m \leq 10^9$$$, $$$0 \leq x \leq n$$$; $$$0 \leq y \leq m$$$; $$$-1 \leq v_x, v_y \leq 1$$$; $$$(v_x, v_y) \neq (0, 0)$$$) — the width of the table, the length of the table, the $$$x$$$-coordinate of the initial position of the ball, the $$$y$$$-coordinate of the initial position of the ball, the $$$x$$$-component of its initial speed and the $$$y$$$-component of its initial speed, respectively. It is guaranteed that the ball is not initially in a pocket.

## Output Format
Print the coordinates of the pocket the ball will fall into, or $$$-1$$$ if the ball will move indefinitely.

## Examples
```input
4 3 2 2 -1 1
```
```output
0 0
```
-----
```input
4 4 2 0 1 1
```
```output
-1
```
-----
```input
10 10 10 1 -1 0
```
```output
-1
```

## Note
The first sample:

The second sample:

In the third sample the ball will never change its $$$y$$$ coordinate, so the ball will never fall into a pocket.

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
Petr is a detective in Braginsk. Somebody stole a huge amount of money from a bank and Petr is to catch him. Somebody told Petr that some luxurious car moves along the roads without stopping.

Petr knows that it is the robbers who drive the car. The roads in Braginsk are one-directional and each of them connects two intersections. Petr wants to select one intersection such that if the robbers continue to drive the roads indefinitely, they will sooner or later come to that intersection. The initial position of the robbers is unknown. Find such an intersection that fits the requirements.

## Input Format
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \le 10^5$$$, $$$2 \leq m \leq 5 \cdot 10^5$$$) — the number of intersections and the number of directed roads in Braginsk, respectively.

Each of the next $$$m$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$u_i \ne v_i$$$) — the start and finish of the $$$i$$$-th directed road. It is guaranteed that the robbers can move along the roads indefinitely.

## Output Format
Print a single integer $$$k$$$ — the intersection Petr needs to choose. If there are multiple answers, print any. If there are no such intersections, print $$$-1$$$.

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

## Note
In the first example the robbers can move, for example, along the following routes: $$$(1-2-3-1)$$$, $$$(3-4-5-3)$$$, $$$(1-2-3-4-5-3-1)$$$. We can show that if Petr chooses the $$$3$$$-rd intersection, he will eventually meet the robbers independently of their route.

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 python3.

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:
```python
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.

Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.

## Input Format
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10$$$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.

The next line contains $$$n$$$ distinct space-separated integers $$$x_1, x_2, \ldots, x_n$$$ ($$$0 \le x_i \le 9$$$) representing the sequence.

The next line contains $$$m$$$ distinct space-separated integers $$$y_1, y_2, \ldots, y_m$$$ ($$$0 \le y_i \le 9$$$) — the keys with fingerprints.

## Output Format
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.

## Examples
```input
7 3
3 5 7 1 6 2 8
1 2 7
```
```output
7 1 2
```
-----
```input
4 4
3 4 1 0
0 1 7 9
```
```output
1 0
```

## Note
In the first example, the only digits with fingerprints are $$$1$$$, $$$2$$$ and $$$7$$$. All three of them appear in the sequence you know, $$$7$$$ first, then $$$1$$$ and then $$$2$$$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.

In the second example digits $$$0$$$, $$$1$$$, $$$7$$$ and $$$9$$$ have fingerprints, however only $$$0$$$ and $$$1$$$ appear in the original sequence. $$$1$$$ appears earlier, so the output is 1 0. Again, the order is important.

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 python3.

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:
```python
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no more than $$$k$$$ other knights. Also, each knight has some number of coins. After a kill, a knight can pick up all victim's coins.

Now each knight ponders: how many coins he can have if only he kills other knights?

You should answer this question for each knight.

## Input Format
The first line contains two integers $$$n$$$ and $$$k$$$ $$$(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$$$ — the number of knights and the number $$$k$$$ from the statement.

The second line contains $$$n$$$ integers $$$p_1, p_2 ,\ldots,p_n$$$ $$$(1 \le p_i \le 10^9)$$$ — powers of the knights. All $$$p_i$$$ are distinct.

The third line contains $$$n$$$ integers $$$c_1, c_2 ,\ldots,c_n$$$ $$$(0 \le c_i \le 10^9)$$$ — the number of coins each knight has.

## Output Format
Print $$$n$$$ integers — the maximum number of coins each knight can have it only he kills other knights.

## Examples
```input
4 2
4 5 9 7
1 2 11 33
```
```output
1 3 46 36
```
-----
```input
5 1
1 2 3 4 5
1 2 3 4 5
```
```output
1 3 5 7 9
```
-----
```input
1 0
2
3
```
```output
3
```

## Note
Consider the first example.

- The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has.
- The second knight can kill the first knight and add his coin to his own two.
- The third knight is the strongest, but he can't kill more than $$$k = 2$$$ other knights. It is optimal to kill the second and the fourth knights: $$$2+11+33 = 46$$$.
- The fourth knight should kill the first and the second knights: $$$33+1+2 = 36$$$.

In the second example the first knight can't kill anyone, while all the others should kill the one with the index less by one than their own.

In the third example there is only one knight, so he can't kill anyone.

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
There is a rectangular grid of size $$$n \times m$$$. Each cell has a number written on it; the number on the cell ($$$i, j$$$) is $$$a_{i, j}$$$. Your task is to calculate the number of paths from the upper-left cell ($$$1, 1$$$) to the bottom-right cell ($$$n, m$$$) meeting the following constraints:

- You can move to the right or to the bottom only. Formally, from the cell ($$$i, j$$$) you may move to the cell ($$$i, j + 1$$$) or to the cell ($$$i + 1, j$$$). The target cell can't be outside of the grid.
- The xor of all the numbers on the path from the cell ($$$1, 1$$$) to the cell ($$$n, m$$$) must be equal to $$$k$$$ (xor operation is the bitwise exclusive OR, it is represented as '^' in Java or C++ and "xor" in Pascal).

Find the number of such paths in the given grid.

## Input Format
The first line of the input contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n, m \le 20$$$, $$$0 \le k \le 10^{18}$$$) — the height and the width of the grid, and the number $$$k$$$.

The next $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line is $$$a_{i, j}$$$ ($$$0 \le a_{i, j} \le 10^{18}$$$).

## Output Format
Print one integer — the number of paths from ($$$1, 1$$$) to ($$$n, m$$$) with xor sum equal to $$$k$$$.

## Examples
```input
3 3 11
2 1 5
7 10 0
12 6 4
```
```output
3
```
-----
```input
3 4 2
1 3 3 3
0 3 3 2
3 0 1 1
```
```output
5
```
-----
```input
3 4 1000000000000000000
1 3 3 3
0 3 3 2
3 0 1 1
```
```output
0
```

## Note
All the paths from the first example:

- $$$(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3)$$$;
- $$$(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)$$$;
- $$$(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3)$$$.

All the paths from the second example:

- $$$(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$$$;
- $$$(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$$$;
- $$$(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (2, 4) \rightarrow (3, 4)$$$;
- $$$(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4)$$$;
- $$$(1, 1) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 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
Alice has a lovely piece of cloth. It has the shape of a square with a side of length $$$a$$$ centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length $$$b$$$ centimeters (where $$$b < a$$$). Alice wanted to make Bob happy, so she cut the needed square out of the corner of her piece and gave it to Bob. Now she is left with an ugly L shaped cloth (see pictures below).

Alice would like to know whether the area of her cloth expressed in square centimeters is prime. Could you help her to determine it?

## Input Format
The first line contains a number $$$t$$$ ($$$1 \leq t \leq 5$$$) — the number of test cases.

Each of the next $$$t$$$ lines describes the $$$i$$$-th test case. It contains two integers $$$a$$$ and $$$b~(1 \leq b < a \leq 10^{11})$$$ — the side length of Alice's square and the side length of the square that Bob wants.

## Output Format
Print $$$t$$$ lines, where the $$$i$$$-th line is the answer to the $$$i$$$-th test case. Print "YES" (without quotes) if the area of the remaining piece of cloth is prime, otherwise print "NO".

You can print each letter in an arbitrary case (upper or lower).

## Examples
```input
4
6 5
16 13
61690850361 24777622630
34 33
```
```output
YES
NO
NO
YES
```

## Note
The figure below depicts the first test case. The blue part corresponds to the piece which belongs to Bob, and the red part is the piece that Alice keeps for herself. The area of the red part is $$$6^2 - 5^2 = 36 - 25 = 11$$$, which is prime, so the answer is "YES".

In the second case, the area is $$$16^2 - 13^2 = 87$$$, which is divisible by $$$3$$$.

In the third case, the area of the remaining piece is $$$61690850361^2 - 24777622630^2 = 3191830435068605713421$$$. This number is not prime because $$$3191830435068605713421 = 36913227731 \cdot 86468472991 $$$.

In the last case, the area is $$$34^2 - 33^2 = 67$$$.

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
After a long day, Alice and Bob decided to play a little game. The game board consists of $$$n$$$ cells in a straight line, numbered from $$$1$$$ to $$$n$$$, where each cell contains a number $$$a_i$$$ between $$$1$$$ and $$$n$$$. Furthermore, no two cells contain the same number.

A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell $$$i$$$ to cell $$$j$$$ only if the following two conditions are satisfied:

- the number in the new cell $$$j$$$ must be strictly larger than the number in the old cell $$$i$$$ (i.e. $$$a_j > a_i$$$), and
- the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. $$$|i-j|\bmod a_i = 0$$$).

Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.

## Input Format
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of numbers.

The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$). Furthermore, there are no pair of indices $$$i \neq j$$$ such that $$$a_i = a_j$$$.

## Output Format
Print $$$s$$$ — a string of $$$n$$$ characters, where the $$$i$$$-th character represents the outcome of the game if the token is initially placed in the cell $$$i$$$. If Alice wins, then $$$s_i$$$ has to be equal to "A"; otherwise, $$$s_i$$$ has to be equal to "B".

## Examples
```input
8
3 6 5 4 2 7 1 8
```
```output
BAAAABAB
```
-----
```input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
```
```output
ABAAAABBBAABAAB
```

## Note
In the first sample, if Bob puts the token on the number (not position):

- $$$1$$$: Alice can move to any number. She can win by picking $$$7$$$, from which Bob has no move.
- $$$2$$$: Alice can move to $$$3$$$ and $$$5$$$. Upon moving to $$$5$$$, Bob can win by moving to $$$8$$$. If she chooses $$$3$$$ instead, she wins, as Bob has only a move to $$$4$$$, from which Alice can move to $$$8$$$.
- $$$3$$$: Alice can only move to $$$4$$$, after which Bob wins by moving to $$$8$$$.
- $$$4$$$, $$$5$$$, or $$$6$$$: Alice wins by moving to $$$8$$$.
- $$$7$$$, $$$8$$$: Alice has no move, and hence she loses immediately.

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
You have $$$n$$$ coins, each of the same value of $$$1$$$.

Distribute them into packets such that any amount $$$x$$$ ($$$1 \leq x \leq n$$$) can be formed using some (possibly one or all) number of these packets.

Each packet may only be used entirely or not used at all. No packet may be used more than once in the formation of the single $$$x$$$, however it may be reused for the formation of other $$$x$$$'s.

Find the minimum number of packets in such a distribution.

## Input Format
The only line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^9$$$) — the number of coins you have.

## Output Format
Output a single integer — the minimum possible number of packets, satisfying the condition above.

## Examples
```input
6
```
```output
3
```
-----
```input
2
```
```output
2
```

## Note
In the first example, three packets with $$$1$$$, $$$2$$$ and $$$3$$$ coins can be made to get any amount $$$x$$$ ($$$1\leq x\leq 6$$$).

- To get $$$1$$$ use the packet with $$$1$$$ coin.
- To get $$$2$$$ use the packet with $$$2$$$ coins.
- To get $$$3$$$ use the packet with $$$3$$$ coins.
- To get $$$4$$$ use packets with $$$1$$$ and $$$3$$$ coins.
- To get $$$5$$$ use packets with $$$2$$$ and $$$3$$$ coins
- To get $$$6$$$ use all packets.

In the second example, two packets with $$$1$$$ and $$$1$$$ coins can be made to get any amount $$$x$$$ ($$$1\leq x\leq 2$$$).

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
You are given an array $$$a$$$ of $$$n$$$ integers and an integer $$$s$$$. It is guaranteed that $$$n$$$ is odd.

In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to $$$s$$$.

The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array $$$6, 5, 8$$$ is equal to $$$6$$$, since if we sort this array we will get $$$5, 6, 8$$$, and $$$6$$$ is located on the middle position.

## Input Format
The first line contains two integers $$$n$$$ and $$$s$$$ ($$$1\le n\le 2\cdot 10^5-1$$$, $$$1\le s\le 10^9$$$) — the length of the array and the required value of median.

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

It is guaranteed that $$$n$$$ is odd.

## Output Format
In a single line output the minimum number of operations to make the median being equal to $$$s$$$.

## Examples
```input
3 8
6 5 8
```
```output
2
```
-----
```input
7 20
21 15 12 11 20 19 12
```
```output
6
```

## Note
In the first sample, $$$6$$$ can be increased twice. The array will transform to $$$8, 5, 8$$$, which becomes $$$5, 8, 8$$$ after sorting, hence the median is equal to $$$8$$$.

In the second sample, $$$19$$$ can be increased once and $$$15$$$ can be increased five times. The array will become equal to $$$21, 20, 12, 11, 20, 20, 12$$$. If we sort this array we get $$$11, 12, 12, 20, 20, 20, 21$$$, this way the median is $$$20$$$.

Now solve the problem and return the code.