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: Wrong Answer)

import sys
from collections import Counter
from heapq import heapify, heappush, heappop

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))

    counterA = Counter(A)
    counterB = Counter(B)

    vecB = [(v, k) for k, v in counterB.items()]

    hq1 = [(-v, k) for k, v in counterA.items() if k in counterB]
    done_list = [(v, k) for k, v in counterA.items() if k not in counterB]
    heapify(hq1)
    done = [False] * (N + 1)
    for k in counterA.keys():
        if k not in counterB:
            done[k] = True

    ans = [[] for _ in range(N + 1)]

    for v, k in sorted(vecB, reverse=True):
        v_prev = v
        ok = True
        while v and ok:
            same_nv, same_nk = None, None
            while hq1 and v:
                nv, nk = heappop(hq1)
                if done[nk]:
                    done_list.append((-nv, nk))
                    continue
                elif k == nk:
                    same_nv, same_nk = nv, nk
                    continue
                nv *= -1
                if v < nv:
                    ans[nk].extend([k] * v)
                    done_list.append((nv - v, nk))
                    v = 0
                else:
                    ans[nk].extend([k] * nv)
                    v = v - nv

            if same_nv is not None:
                heappush(hq1, (same_nv, same_nk))

            while done_list and v:
                nv, nk = done_list.pop()
                if v < nv:
                    ans[nk].extend([k] * v)
                    done_list.append((nv - v, nk))
                    v = 0
                else:
                    ans[nk].extend([k] * v)
                    v = v - nv

            if v == 0:
                done[k] = True

            if v == v_prev:
                ok = False
            v_prev = v
        if not ok:
            print('No')
            return

    print('Yes')
    res = []
    for vec in ans:
        res.extend(vec)
    print(*res)

    return


if __name__ == '__main__':
    main()