A permutation of size $$$N$$$ is a sequence of $$$N$$$ positive integers containing the numbers $$$1$$$ to $$$N$$$ where each number appears exactly once in the sequence. For example, $$$[1,4,5,3,2]$$$ is a permutation of size $$$5$$$, while $$$[1,1,4,3,5]$$$ and $$$[1,6,2,3,4]$$$ are not.
We can compare two permutations using lexicographical order. For two permutations $$$p$$$ and $$$p$$$ of the same size $$$N$$$ where $$$p = [a_1,a_2,...,a_N]$$$ and $$$q = [b_1,b_2,...,b_N]$$$, we define $$$p$$$ is smaller than $$$q$$$ if and only if there exists an index $$$i$$$ such that $$$a_j=b_j$$$ for every $$$j \lt i$$$ and $$$a_i \lt b_i$$$. For example, $$$[1,3,4,2,5]$$$ is ordered before $$$[1,3,5,2,4]$$$.
Two permutations $$$p$$$ and $$$q$$$ of size $$$N$$$ are considered an ideal pair if, when all $$$N!$$$ permutations of size $$$N$$$ are arranged in a circle based on lexicographic order, permutation $$$p$$$ and permutation $$$q$$$ are positioned directly opposite each other in the circle.
Figure I.1: Example of the circle of permutations of size $$$3$$$. Given a permutation $$$p$$$, your task is to identify the permutation $$$q$$$ that together forms an ideal pair.
The first line contains one integer $$$N$$$ $$$(2\le N \le 1,000,000)$$$ — size of the permutation.
The second line contains $$$N$$$ distinct integers from $$$1$$$ to $$$N$$$ — the given permutation $$$p$$$.
One line contains $$$N$$$ distinct integers that are the permutation that forms an ideal pair with permutation $$$p$$$.
31 2 3
2 3 1
43 2 1 4
1 3 2 4
97 4 6 9 5 3 8 2 1
2 9 6 8 5 4 7 3 1