Codeforces Global Round 27
H
Peak Productivity Forces
Codeforces
3500
原题
← G2→
翻译中…

I'm peakly productive and this is deep.

翻译中…

You are given two permutations$^{\text{∗}}$ $a$ and $b$, both of length $n$.

翻译中…

You can perform the following three-step operation on permutation $a$:

翻译中…
  1. Choose an index $i$ ($1 \le i \le n$).
  2. Cyclic shift $a_1, a_2, \ldots, a_{i-1}$ by $1$ to the right. If you had chosen $i = 1$, then this range doesn't exist, and you cyclic shift nothing.
  3. Cyclic shift $a_{i + 1}, a_{i + 2}, \ldots, a_n$ by $1$ to the right. If you had chosen $i = n$, then this range doesn't exist, and you cyclic shift nothing.
翻译中…

After the operation, $a_1,a_2,\ldots, a_{i-2},a_{i-1},a_i,a_{i + 1}, a_{i + 2},\ldots,a_{n-1}, a_n$ is transformed into $a_{i-1},a_1,\ldots,a_{i-3},a_{i-2},a_i,a_n, a_{i + 1},\ldots,a_{n-2}, a_{n-1}$.

翻译中…

Here are some examples of operations done on the identity permutation $[1,2,3,4,5,6,7]$ of length $7$:

翻译中…
  • If we choose $i = 3$, it will become $[2, 1, 3, 7, 4, 5, 6]$.
  • If we choose $i = 1$, it will become $[1, 7, 2, 3, 4, 5, 6]$.
  • If we choose $i = 7$, it will become $[6, 1, 2, 3, 4, 5, 7]$.
翻译中…

Notably, position $i$ is

翻译中…

not

翻译中…

shifted.

翻译中…

Find a construction using at most $2n$ operations to make $a$ equal to $b$ or print $-1$ if it is impossible. The number of operations does not need to be minimized. It can be shown that if it is possible to make $a$ equal to $b$, it is possible to do this within $2n$ operations.

翻译中…

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).

翻译中…

Input

翻译中…

The first line contains a single integer $t$ ($1 \le t \le 5 \cdot 10^4$) — the number of test cases.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \le 5 \cdot 10^5$) — the lengths of permutations $a$ and $b$.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) — the values of permutation $a$.

翻译中…

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($1 \le b_i \le n$) — the values of permutation $b$.

翻译中…

It is guaranteed that the sum of $n$ over all test cases will not exceed $5 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case:

翻译中…

If there is a sequence of operations to transform $a$ into $b$, output a single integer $q$ ($0\le q\le 2n$) — the number of operations in the first line and $q$ integers with the $i$-th number representing the index of the $i$-th operation in the second line.

翻译中…

If there is no sequence of operations, output $-1$ in the only line.

翻译中…

Note

翻译中…

In the first case, you can do no operation since $a=b$.

翻译中…

In the second case, it can be proved $a$ can not be transformed into $b$.

翻译中…

In the third case, $a$ is transformed into $[2,3,1]$ after the first operation and into $b$ after the second operation.

翻译中…

样例

Input #1
4
1
1
1
2
1 2
2 1
3
2 1 3
3 2 1
8
7 8 3 5 4 6 1 2
2 1 6 4 5 3 8 7
Output #1
0

-1
2
1 3
7
3 4 5 1 2 1 1
InputCopy OutputCopy
题目信息
题号
2035H
时间限制
3 s
内存限制
256 MB
标签
构造

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。