题目描述
Problem Background
We call a sequence \( p \) a permutation of length \( n \) if and only if \( p \) satisfies the following conditions:
- \( p \) has a length of \( n \);
- Each of the numbers \( 1, 2, 3, \dots, n \) appears exactly once in \( p \).
Problem Description
For a permutation \( p \), a "shift" operation is defined as follows: each number in \( p \) is moved one position to the right, and the last number of \( p \) is moved to the beginning.
For example, if the permutation \( p \) is initially \([1, 4, 2, 3]\), after one "shift" operation, it will become \([3, 1, 4, 2]\).
Given a permutation \( p \) of length \( n \), perform the following operations in a loop:
1. Apply a "shift" operation to the current permutation \( p \);
2. Output the permutation \( p \) after the "shift" operation;
3. Check if the last number of the permutation \( p \) is \( n \). If it is, terminate the loop; otherwise, repeat from step 1.
Note: Please follow the sequence of operations strictly as given in the problem.
Input Format
The first line contains an integer representing the length \( n \) of the permutation \( p \).
The second line contains \( n \) integers representing the permutation \( p \), where the \( i \)-th integer represents \( p_i \).
Output Format
For each "output" operation in step 2, output one line containing \( n \) integers, representing each number of the current permutation in order, with a space between adjacent numbers.
Sample Input and Output
Sample Input #1
4
1 4 2 3
Sample Output #1
3 1 4 2
2 3 1 4
Sample Input #2
3
1 2 3
Sample Output #2
3 1 2
2 3 1
1 2 3
Sample Input #3
10
1 7 6 5 8 4 3 9 10 2
Sample Output #3
2 1 7 6 5 8 4 3 9 10
Notes
Explanation of Sample 2
For \( p = [1, 2, 3] \), perform the following operations in sequence:
- Apply a "shift" operation, \( p \) becomes \([3, 1, 2]\);
- Output the current permutation \( p \), so the first line of output is
3 1 2; - Check \( p_3 = 2 \neq 3 \), so continue the loop;
- Apply a "shift" operation, \( p \) becomes \([2, 3, 1]\);
- Output the current permutation \( p \), so the second line of output is
2 3 1; - Check \( p_3 = 1 \neq 3 \), so continue the loop;
- Apply a "shift" operation, \( p \) becomes \([1, 2, 3]\);
- Output the current permutation \( p \), so the third line of output is
1 2 3; - Check \( p_3 = 3 \), so stop the loop.
Data Size and Constraints
The details of each test point are as follows:
| Test Point | \( n = \) | Special Condition |
| :-: | :-: | :-: |
| 1 | 1 | None |
| 2 | 2 | None |
| 3 | 3 | None |
| 4 to 6 | 2000 | \( p_{n - 1} = n \) |
| 7 to 10 | 2000 | None |
For all test points, it is guaranteed that \( 1 \leq p_i \leq n \leq 2000 \) and \( p \) is a permutation of length \( n \).
By 一扶苏一
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分