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
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

from collections import Counter

CA=Counter(A)
CB=Counter(B)

H=[]

for ca in CA:
    if CA[ca]>0 and CB[ca]>0:
        if CA[ca]+CB[ca]>N:
            print("No")
            sys.exit()
        H.append((-(CA[ca]+CB[ca]),ca))

import heapq
heapq.heapify(H)

ANSDICT=dict()

while len(H)>=2:
    c1,x1=heapq.heappop(H)
    c1=-c1

    c2,x2=heapq.heappop(H)
    c2=-c2

    if x1 in ANSDICT:
        ANSDICT[x1].append(x2)
    else:
        ANSDICT[x1]=[x2]

    if x2 in ANSDICT:
        ANSDICT[x2].append(x1)
    else:
        ANSDICT[x2]=[x1]

    CA[x1]-=1
    CA[x2]-=1
    CB[x1]-=1
    CB[x2]-=1

    if CA[x1]>0 and CB[x1]>0:
        heapq.heappush(H,(-(c1-2),x1))

    if CA[x2]>0 and CB[x2]>0:
        heapq.heappush(H,(-(c2-2),x2))

ANS=[-1]*N

for i in range(N):
    a=A[i]
    if a in ANSDICT and len(ANSDICT[a])!=0:
        
        x=ANSDICT[a].pop()
        ANS[i]=x

if H:
    cc,xx=H[0]
    cc=-cc

    for i in range(N):
        if ANS[i]==-1 and A[i]!=xx:
            ANS[i]=xx
            CA[xx]-=1
            CB[xx]-=1

            if CA[xx]==0 or CB[xx]==0:
                break

ind=0
for cb in CB:
    while CB[cb]!=0:
        while ANS[ind]!=-1:
            ind+=1
        ANS[ind]=cb
        CB[cb]-=1

print("Yes")
print(*ANS)