Task
William is playing the Wheel of Fortune, a famous game show. The wheel is a "sliced" circle, with numbers on each slice. It can be seen as a circular array of elements.
The rules are as follows. William can "turn" the wheel by rotating the array, i.e. moving each of its elements ahead by some positions (possibly making several complete turns). For example, if the array is , a rotation of would yield the following array: . Rotating again by would yield . Rotating again by would yield the original array.
In order to win the game, William needs some information about the wheel everytime he turns it. Specifically: he needs to know the min among the first elements and the max among the last elements. Initially, in the previous example, the min and max values are and . After the first rotation they become and , then they become and , and finally they become and again when the original ordering is restored.
Note: the "turns" add up, that is, the wheel is not reset after each turn.
Input data
The first line contains a single integer : half of the length of the wheel. The second line contains integers . The third line contains a single integer : the number of turns. The fourth line contains space-separated integers , the list of "turns" William will do.
Output data
You need to write lines, each of them corresponding to a turn and containing two integers:
- The min of the first half of the wheel after performing the turn;
- The max of the second half of the wheel after performing the turn.
Constraints and clarifications
- for each
- for each
# | Points | Constraints |
---|---|---|
1 | 5 | Examples. |
2 | 25 | . |
3 | 40 | . |
4 | 30 | No additional constraints. |
Example 1
stdin
2
2 1 5 3
3
1 2 1
stdout
2 5
1 3
1 5
Explanation
This sample case is the same example presented earlier.
Example 2
stdin
3
2 9 8 3 5 5
3
2 1 8
stdout
2 9
3 9
3 5
Explanation
The wheel gets turned by and becomes , then and becomes , then and becomes .