407004: GYM102672 L Transformations

Memory Limit:512 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

L. Transformationstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

In order to win over the cruel clown in the final battle Mike called all his friends. The only thing left is to decide on tactics.

In total there will participate $$$n$$$ friends. For efficiency of the battle let us enumerate them from $$$1$$$ to $$$n$$$. First they formed a line, in which $$$i$$$-th place was taken by the friend number $$$a_i$$$. After long considerations Mike concluded that most effective disposition of the friends will be achieved if $$$i$$$-th place is taken by friend $$$b_i$$$.

To change the order of the friends in the line Mike can do several reorganizations. Each reorganization is performed as follows: Mike chooses some non-empty subset of friends and after that these friends go out from the line and go to its beginning in the reversed order. The order of the friends which were left in the line does not change.

For example, if friends were standing in the order $$$3, 4, 7, 6, 2, 5, 1$$$, and Mike have chosen friends with numbers $$$4, 7, 5$$$, after the reorganization friends will be standing in order $$$5, 7, 4, 3, 6, 2, 1$$$.

The fight with Pennywise starts quite soon so Mike wants to accomplish reordering in not more than $$$15$$$ reorganizations. Help him!

Please pay attention that it is not required to minimize number of reorganizations. It is guaranteed that it is possible to achieve the desired order in not more than $$$15$$$ reorganizations.

Input

The first line contains one integer $$$n$$$ — the number of friends in the line ($$$1 \le n \le 10\,000$$$).

Second line contains $$$n$$$ different integer numbers $$$a_i$$$ from $$$1$$$ to $$$n$$$ — the initial order of the friends in the line ($$$1 \le a_i \le n$$$). Third line contains $$$n$$$ different integer numbers $$$b_i$$$ from $$$1$$$ to $$$n$$$ — the desired order of the friends in the line ($$$1 \le b_i \le n$$$).

Output

To the first line output an integer $$$k$$$ ($$$0 \le k \le 15$$$) — the number of reorganizations in the found solution. In each of the following $$$k$$$ lines output description of the reorganizations, which should be done. For each reorganization first output number $$$c_i$$$ — the number of friends, which should go out of the line ($$$1 \le c_i \le n$$$), then $$$c_i$$$ different integer numbers from $$$1$$$ to $$$n$$$ — the numbers of the friends, who should go out of the line. The numbers of the friends can be written in any order.

ExamplesInput
5
5 4 3 2 1
3 4 5 1 2
Output
4
5 1 2 3 4 5
1 5
1 4
1 3
Input
7
3 4 7 6 2 5 1
2 6 3 4 5 7 1
Output
3
3 6 5 7
3 3 4 5
3 2 6 3
Note

In the first test, the order of the friends is changing in the following way:

$$$5, 4, 3, 2, 1 \rightarrow 1, 2, 3, 4, 5 \rightarrow 5, 1, 2, 3, 4 \rightarrow 4, 5, 1, 2, 3 \rightarrow 3, 4, 5, 1, 2$$$

In the second test, the order of the friends is chaning in the following way:

$$$3, 4, 7, 6, 2, 5, 1 \rightarrow 5, 6, 7, 3, 4, 2, 1 \rightarrow 4, 3, 5, 6, 7, 2, 1 \rightarrow 2, 6, 3, 4, 5, 7, 1$$$

加入题单

算法标签: