#D4731. Round And Round
Round And Round
Round And Round
Problem
Given a sequence of length {}. It is assumed that () is initialized with .
Process the following two types of queries a total of times.
- Outputs the value of the th element from the beginning of the sequence .
- Swap two sequences with the and th boundaries from the beginning of the sequence .
For details, refer to sample input / output.
Constraints
The input satisfies the following conditions.
For each query, the input satisfies the following conditions.
Query
Query
Input
The input is given in the following format.
...
Each query is given in one of two forms:
Query Outputs the value of the th element from the beginning of the sequence .
Query Swap two sequences at the boundary of and from the beginning of the sequence .
All inputs are given as integers.
and are given on the line, separated by blanks. Queries are given on the lines after the line, separated by line breaks. All numbers in each query are separated by blanks.
Output
Print the value on one line for each query .
Examples
Input
5 4 1 2 0 2 1 1 0 3
Output
4 1
Input
4 4 1 2 1 1 0 1 0 4
Output
4 3
Input
10 6 1 1 0 1 1 9 0 5 1 1 0 10
Output
2 5 1
inputFormat
outputFormat
Outputs the value of the th element from the beginning of the sequence .
- Swap two sequences with the and th boundaries from the beginning of the sequence .
For details, refer to sample input / output.
Constraints
The input satisfies the following conditions.
For each query, the input satisfies the following conditions.
Query
Query
Input
The input is given in the following format.
...
Each query is given in one of two forms:
Query Outputs the value of the th element from the beginning of the sequence .
Query Swap two sequences at the boundary of and from the beginning of the sequence .
All inputs are given as integers.
and are given on the line, separated by blanks. Queries are given on the lines after the line, separated by line breaks. All numbers in each query are separated by blanks.
Output
Print the value on one line for each query .
Examples
Input
5 4 1 2 0 2 1 1 0 3
Output
4 1
Input
4 4 1 2 1 1 0 1 0 4
Output
4 3
Input
10 6 1 1 0 1 1 9 0 5 1 1 0 10
Output
2 5 1
样例
5 4
1 2
0 2
1 1
0 3
4
1
</p>