P26282 [AtCoder] Many Swaps Sorting
普及+
题目描述

Problem Description

Snuke has a sequence \( p \) obtained by rearranging \( (0, 1, 2, \ldots, N-1) \). The \( i \)-th number (0-indexed) in \( p \) is \( p_i \).

Snuke can perform \( N-1 \) types of operations numbered \( 1, 2, \ldots, N-1 \) in any order and as many times as he wants. Performing the \( k \)-th operation executes the following process represented by the source code:

for(int i=k;i<N;i++)
    swap(p[i],p[i-k]);

Snuke wants to sort \( p \) in ascending order by performing these operations between 0 and \( 10^5 \) times. Show an example of such an operation sequence. It can be proven that such an operation sequence always exists under the problem constraints.

Input Format

The input is given from the standard input in the following format:

\( N \) \( p_0 \) \( p_1 \) \( \ldots \) \( p_{N-1} \)

Output Format

Output the number of operations (let's denote it as \( m \)) in the first line. In the following \( m \) lines, output the number of the operation to be executed in the \( i \)-th place. The answer is correct if \( m \) is less than or equal to \( 10^5 \) and \( p \) is sorted in ascending order after \( m \) operations.

Sample Input and Output

Sample Input #1

5
4 2 0 1 3

Sample Output #1

4
2
3
1
2

Sample Input #2

9
1 0 4 3 5 6 2 8 7

Sample Output #2

11
3
6
1
3
5
2
4
7
8
6
3

Notes/Hints

Constraints

  • \( 2 \leq N \leq 200 \)
  • \( 0 \leq p_i \leq N-1 \)
  • \( p \) is obtained by rearranging \( (0, 1, 2, \ldots, N-1) \)

Partial Points

  • For a dataset worth 300 points, \( N \leq 7 \) holds
  • For another dataset worth 400 points, \( N \leq 30 \) holds

Sample Explanation 1

  • The following diagram shows the changes in \( p \) due to each operation. 9f3b51eb1fe742848f407bdeb7b772e1.png
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 4 2 0 1 3
样例输出
4 2 3 1 2