#abc262f. [abc262_f]Erase and Rotate
[abc262_f]Erase and Rotate
Problem Statement
You are given a sequence that contains exactly once each.
You may perform the following operations between and times in total in any order:
- Choose one term of and remove it.
- Move the last term of to the head.
Find the lexicographically smallest that can be obtained as a result of the operations.
Constraints
- contains exactly once each.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the lexicographically smallest that can be obtained as a result of the operations, separated by spaces.
Sample Input 1
5 3
4 5 2 3 1
Sample Output 1
1 2 3
The following operations make equal .
- Removing the first term makes equal .
- Moving the last term to the head makes equal .
- Removing the second term makes equal .
There is no way to obtain lexicographically smaller than , so this is the answer.
Sample Input 2
3 0
3 2 1
Sample Output 2
3 2 1
You may be unable to perform operations.
Sample Input 3
15 10
12 10 7 2 8 11 9 1 6 14 3 15 13 5 4
Sample Output 3
1 3 4 7 2 8 11 9