#P13609. [NWRRC 2022] Limited Swaps

[NWRRC 2022] Limited Swaps

题目描述

Lina is playing with nn cubes placed in a row. Each cube has an integer from 11 to nn written on it. Every integer from 11 to nn appears on exactly one cube.

Initially, the numbers on the cubes from left to right are a1,a2,,ana_1, a_2, \ldots, a_n. Lina wants the numbers on the cubes from left to right to be b1,b2,,bnb_1, b_2, \ldots, b_n.

Lina can swap any two adjacent cubes, but only if the difference between the numbers on them is at least 22. This operation can be performed at most 2000020\,000 times.

Find any sequence of swaps that transforms the initial configuration of numbers on the cubes into the desired one, or report that it is impossible.

输入格式

The first line contains a single integer nn --- the number of cubes (1n1001 \le n \le 100).

The second line contains nn distinct integers a1,a2,,ana_1, a_2, \ldots, a_n --- the initial numbers on the cubes from left to right (1ain1 \le a_i \le n).

The third line contains nn distinct integers b1,b2,,bnb_1, b_2, \ldots, b_n --- the desired numbers on the cubes from left to right (1bin1 \le b_i \le n).

输出格式

If it is impossible to obtain the desired configuration of numbers on the cubes from the initial one, print a single integer 1-1.

Otherwise, in the first line, print a single integer kk --- the number of swaps in your sequence (0k200000 \le k \le 20\,000).

In the second line, print kk integers s1,s2,,sks_1, s_2, \ldots, s_k describing the operations in order (1sin11 \le s_i \le n - 1). Integer sis_i stands for "swap the sis_i-th cube from the left with the (si+1)(s_i + 1)-th cube from the left".

You do not have to find the shortest solution. Any solution satisfying the constraints will be accepted.

5
1 3 5 2 4
3 5 1 4 2
3
1 2 4
4
1 2 3 4
4 3 2 1
-1

提示

In the first example test, the configuration of numbers changes as follows:

11 3 5\underline{3\ 5} 22 44 \rightarrow 1 5\underline{1\ 5} 33 22 44 \rightarrow 55 1 3\underline{1\ 3} 22 44 \rightarrow 55 33 11 2 4\underline{2\ 4} \rightarrow 5 3\underline{5\ 3} 11 44 22 \rightarrow 33 55 11 44 22

In the second example test, making even a single swap in the initial configuration is impossible.