#B3688. Permutation Shift Sequence
Permutation Shift Sequence
Permutation Shift Sequence
Given a permutation of length , a single "shift" operation is defined as follows: every element in is moved one position to the right, and the last element is moved to the beginning. For example, if , after one shift the new permutation will be .
The program should repeatedly perform the following steps in order:
- Perform one shift operation on the current permutation .
- Output the permutation after the shift operation (elements separated by spaces).
- Check if the last element of the permutation equals . If it does, the process terminates; otherwise, repeat from step 1.
Note: Strictly follow the order of operations as given in the problem statement.
inputFormat
The first line contains a single integer (), the length of the permutation.
The second line contains space-separated integers representing the permutation .
outputFormat
Output each permutation obtained after performing a shift operation on a separate line. The output for each operation should display the permutation elements separated by a single space.
sample
4
1 4 2 3
3 1 4 2
2 3 1 4
</p>