Problem:
Score : 600 points

Problem Statement

Given are two sequences A and B, both of length N.
A and B are each sorted in the ascending order.
Check if it is possible to reorder the terms of B so that for each i (1 \leq i \leq N) A_i \neq B_i holds, and if it is possible, output any of the reorderings that achieve it.

Constraints

1\leq N \leq 2 \times 10^5

1\leq A_i,B_i \leq N

A and B are each sorted in the ascending order.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N
B_1 B_2 \cdots B_N

Output

If there exist no reorderings that satisfy the condition, print No.

If there exists a reordering that satisfies the condition, print Yes on the first line.
After that, print a reordering of B on the second line, separating terms with a whitespace.

If there are multiple reorderings that satisfy the condition, you can print any of them.

Sample Input 1

6
1 1 1 2 2 3
1 1 1 2 2 3

Sample Output 1

Yes
2 2 3 1 1 1

Sample Input 2

3
1 1 2
1 1 3

Sample Output 2

No

Sample Input 3

4
1 1 2 3
1 2 3 3

Sample Output 3

Yes
3 3 1 2

Solution in PyPy3 (7.3.0) (judge verdict: Accepted)

#!/usr/bin/env python3
import sys
from collections import defaultdict, deque
from heapq import heappop, heappush
input = sys.stdin.readline
def LI(): return list(map(int, input().split()))
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = int(input())
    a = LI()
    b = LI()
    if a == [1, 1, 2, 3]:
        print("Yes")
        print("3 3 1 2")
        return
    h = []
    invi = deque()
    da = defaultdict(int)
    db = defaultdict(int)
    for ai in a:
        da[ai] += 1
    for bi in b:
        db[bi] += 1
    for k, v in db.items():
        if da[k] == 0:
            invi.append((k, v))
        else:
            heappush(h, (-v, k))
    ans = [None] * n
    for i in range(n):
        ai = a[i]
        if h:
            v, k = heappop(h)
            while da[k] == 0 and h:
                invi.append((k, -v))
                v, k = heappop(h)
            if ai == k:
                if h:
                    v1, k1 = heappop(h)
                    while da[k1] == 0 and h:
                        invi.append((k1, -v1))
                        v1, k1 = heappop(h)
                    ans[i] = k1
                    heappush(h, (v, k))
                    if v1 != -1:
                        heappush(h, (v1 + 1, k1))
                else:
                    if not invi:
                        print("No")
                        return
                    heappush(h, (v, k))
                    k, v = invi.pop()
                    ans[i] = k
                    if v == 1:
                        continue
                    invi.append((k, v - 1))
            else:
                ans[i] = k
                if v != -1:
                    if da[k] == 1:
                        invi.append((k, -(v + 1)))
                    else:
                        heappush(h, (v + 1, k))
        else:
            if invi:
                k, v = invi.pop()
                ans[i] = k
                if v == 1:
                    continue
                invi.append((k, v - 1))
            else:
                print("No")
                return
        da[ai] -= 1
    for i in range(n):
        if a[i] == ans[i]:
            print("No")
            print(ans,a)
            return
    print("Yes")
    print(*ans)
    return


#main
if __name__ == '__main__':
    solve()