Codeforces Round 1031 (Div. 2)
F
Two Arrays
Codeforces
2500
原题
← E→
翻译中…

You are given two arrays $a$ and $b$ of length $n$. You can perform the following operation an unlimited number of times:

翻译中…
  • Choose an integer $i$ from $1$ to $n$ and swap $a_i$ and $b_i$.
翻译中…

Let $f(c)$ be the number of distinct numbers in array $c$. Find the maximum value of $f(a) + f(b)$. Also, output the arrays $a$ and $b$ after performing all operations.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \le 10^5$) — the length of the arrays.

翻译中…

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

翻译中…

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

翻译中…

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

翻译中…

Output

翻译中…

For each test case, print a single integer in the first line — the maximum value of $f(a) + f(b)$.

翻译中…

In the second line, print $n$ integers — the elements of array $a$ after performing the operations.

翻译中…

In the third line, print $n$ integers — the elements of array $b$ after performing the operations.

翻译中…

Note

翻译中…

In the first test case, after applying three operations with $i=2$, $i=4$, and $i=5$, we obtain $a = [1, 3, 4, 5, 2]$ and $b = [1, 2, 3, 4, 4]$. After that, $f(a) + f(b) = 5 + 4 = 9$. It can be shown that it is not possible to achieve a greater answer.

翻译中…

In the second test case, after applying the operations: $$f([2, 3, 4, 2, 1, 5, 6]) + f([1, 2, 3, 4, 5, 6, 5]) = 6 + 6 = 12$$

翻译中…

样例

Input #1
3
5
1 2 4 4 4
1 3 3 5 2
7
2 2 4 4 5 5 5
1 3 3 2 1 6 6
7
12 3 3 4 5 6 4
1 2 13 8 10 13 7
Output #1
9
1 3 4 5 2
1 2 3 4 4
12
2 3 4 2 1 5 6
1 2 3 4 5 6 5
14
12 3 13 8 10 6 4
1 2 3 4 5 13 7
InputCopy OutputCopy
题目信息
题号
2113F
时间限制
2 s
内存限制
512 MB
标签
构造
DFS 及类似
图论
数学

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