Parallel Sort
题号:NC220448
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
Special Judge, 64bit IO Format: %lld

题目描述

As a master of parallel computing, schwer is recently considering about the method to achieve quick sorting on parallel computers. He needs your help!

Given a permutation , you need to sort the permutation with minimum number of rounds. In a single round, one can take many pairs of integers  as long as the values of  are pairwise distinct. Then with the help of  CPUs, for each , the value of  and  will be switched immediately. Note that a permutation  is sorted if for every integer  holds.

Take some examples. Assume that . For , the minimum number of round is  as it is already sorted. For , the answer is , as you can swap the indices  and  simultaneously.

输入描述:

he first line of input contains a single integer , indicating the length of the permutation.

The second line contains  integers , the given permutation. It is guaranteed that these integers form a permutation, that is, for every integer  there exists an unique integer  such that .

输出描述:

The first line of output should contain a single integer , the minimum number of rounds to get the permutation sorted. Then print  line to show one possible solution.

The -th of the next  lines should describe the -th round of your solution, beginning with a single integer , and followed by  integers . The constraints that  and the  integers are pairwise distinct must be held.

示例1

输入

复制
4
1 2 3 4

输出

复制
0
示例2

输入

复制
4
4 3 2 1

输出

复制
1
2 1 4 2 3