6964.Third Permutation

Time Limit: 1s Memory Limit: 512MB

You are given two permutations $a$ and $b$ such that $a_i \neq b_i$ in every position. Create a third permutation $c$ such that $a_i \neq c_i$ and $b_i \neq c_i$ in every position.

Input Format(From the terminal/stdin)

The first line has an integer $n$ : the permutation size.

The second line has $n$ integers $a_1,a_2,\dots,a_n$ .

The third line has $n$ integers $b_1,b_2,\dots,b_n$ .

  • $2 \le n \le 10^5$

Output Format(To the terminal/stdout)

Print $n$ integers $c_1,c_2,\dots,c_n$ . You can print any valid solution. If there are no solutions, print IMPOSSIBLE .

Sample Input

Copy
5
1 3 2 5 4
4 1 3 2 5
 \n
 · · · · \n
 · · · · \n

Sample Output special judge

Copy
3 2 5 4 1
 · · · · \n
Source: CSES, Construction Problems, 3422

Submit

请先 登录

© 2025 FAQs