Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ca=Counter(a)
cb=Counter(b)
for k in cb:
    if k in ca:
        if cb[k]+ca[k]>n:
            print('No')
            exit()
ans=b[n//2:]+b[:n//2]
ng=set(())
ok=[]
pda={i+1:set(()) for i in range(n)}
pdans={i+1:set(()) for i in range(n)}
for i in range(n):
    pda[a[i]].add(i)
    pdans[ans[i]].add(i)
    if a[i]==ans[i]:
        ng.add(i)
    else:
        ok.append(i)

from random import randint

if ng:
    for x in ng:
        # ans[x]==a[x]となるx
        s=set(range(n))-(pdans[ans[x]]|pda[a[x]])
        y=s.pop()
        #while ans[x]==a[y] or ans[y]==a[x]:
        #    y=ok[randint(0,len(ok)-1)]
        pdans[ans[y]].discard(y)
        pdans[ans[x]].add(y)
        pdans[ans[x]].discard(x)
        pdans[ans[y]].add(x)
        ans[x],ans[y]=ans[y],ans[x]
        #ok.append(x)

print('Yes')
print(*ans,sep=' ')


Fixed submission:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ca=Counter(a)
cb=Counter(b)
for k in cb:
    if k in ca:
        if cb[k]+ca[k]>n:
            print('No')
            exit()
tmpc=0
tmpd=0
c=[0]
d=[0]
for i in range(1,n+1):
    if i in ca:tmpc+=ca[i]
    if i in cb:tmpd+=cb[i]
    c.append(tmpc)
    d.append(tmpd)
x=0
for i in range(n+1):
    x=max(x,c[i]-d[i-1])
ans=b[-x:]+b[:-x]
print('Yes')
print(*ans,sep=' ')
exit()
print(c)
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ca=Counter(a)
cb=Counter(b)
for k in cb:
    if k in ca:
        if cb[k]+ca[k]>n:
            print('No')
            exit()
ans=b[n//2:]+b[:n//2]
ng=set(())
ok=[]
for i in range(n):
    if a[i]==ans[i]:
        ng.add(i)
    else:
        ok.append(i)
from random import randint
if ng:
    for x in ng:
        y=ok[randint(0,len(ok)-1)]
        while ans[x]==a[y] or ans[y]==a[x]:
            y=ok[randint(0,len(ok)-1)]
        ans[x],ans[y]=ans[y],ans[x]
        ok.append(x)
print('Yes')
print(*ans,sep=' ')


Fixed submission:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ca=Counter(a)
cb=Counter(b)
for k in cb:
    if k in ca:
        if cb[k]+ca[k]>n:
            print('No')
            exit()
tmpc=0
tmpd=0
c=[0]
d=[0]
for i in range(1,n+1):
    if i in ca:tmpc+=ca[i]
    if i in cb:tmpd+=cb[i]
    c.append(tmpc)
    d.append(tmpd)
x=0
for i in range(n+1):
    x=max(x,c[i]-d[i-1])
ans=b[-x:]+b[:-x]
print('Yes')
print(*ans,sep=' ')
exit()
print(c)
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
#n=pow(10,4)
#a=[2]*(n//2)+[3]*(n//2)
#b=[1]*(n//2)+[2]*(n//2)
ca=Counter(a)
cb=Counter(b)
for k in cb:
    if k in ca:
        if cb[k]+ca[k]>n:
            print('No')
            exit()
ans=b[n//2:]+b[:n//2]
ng=set(())
ok=[]
for i in range(n):
    if a[i]==ans[i]:
        ng.add(i)
    else:
        ok.append(i)
from random import randint
while ng:
    k=len(ng)
    nng=set(())
    l=len(ok)
    i=0
    for x in ng:
        i+=1
        y=ok[randint(0,l-1)]
        ans[x],ans[y]=ans[y],ans[x]
        if ans[x]==a[x] or ans[y]==a[y]:
            ans[x],ans[y]=ans[y],ans[x]
            nng.add(x)
        else:
            ok.append(x)
    ng=nng

print('Yes')
print(*ans,sep=' ')


Fixed submission:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ca=Counter(a)
cb=Counter(b)
for k in cb:
    if k in ca:
        if cb[k]+ca[k]>n:
            print('No')
            exit()
tmpc=0
tmpd=0
c=[0]
d=[0]
for i in range(1,n+1):
    if i in ca:tmpc+=ca[i]
    if i in cb:tmpd+=cb[i]
    c.append(tmpc)
    d.append(tmpd)
x=0
for i in range(n+1):
    x=max(x,c[i]-d[i-1])
ans=b[-x:]+b[:-x]
print('Yes')
print(*ans,sep=' ')
exit()
print(c)
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ca=Counter(a)
cb=Counter(b)
for k in cb:
    if k in ca:
        if cb[k]+ca[k]>n:
            print('No')
            exit()
ans=b[n//2:]+b[:n//2]
ng=set(())
ok=[]
for i in range(n):
    if a[i]==ans[i]:
        ng.add(i)
    else:
        ok.append(i)
from random import randint
while ng:
    k=len(ng)
    nng=set(())
    l=len(ok)
    i=0
    for x in ng:
        i+=1
        y=ok[randint(0,l-1)]
        ans[x],ans[y]=ans[y],ans[x]
        if ans[x]==a[x] or ans[y]==a[y]:
            ans[x],ans[y]=ans[y],ans[x]
            nng.add(x)
        else:
            ok.append(x)
    ng=nng

print('Yes')
print(*ans,sep=' ')



Fixed submission:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ca=Counter(a)
cb=Counter(b)
for k in cb:
    if k in ca:
        if cb[k]+ca[k]>n:
            print('No')
            exit()
tmpc=0
tmpd=0
c=[0]
d=[0]
for i in range(1,n+1):
    if i in ca:tmpc+=ca[i]
    if i in cb:tmpd+=cb[i]
    c.append(tmpc)
    d.append(tmpd)
x=0
for i in range(n+1):
    x=max(x,c[i]-d[i-1])
ans=b[-x:]+b[:-x]
print('Yes')
print(*ans,sep=' ')
exit()
print(c)
print(d)