Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
RB = B[::-1]

start = v = -1
seq = 0
for i,(a,b) in enumerate(zip(A,RB)):
    if a==b:
        v = a
        seq += 1
        if start == -1:
            start = i

if v == -1:
    print('Yes')
    print(*RB)
    exit()

if A.count(v) + B.count(v) > N:
    print('No')
    exit()

from bisect import bisect_left,bisect
al = bisect_left(A,v)
bl = bisect_left(B,v)
br = bisect(B,v)
rbl = N - br

m = min(seq,start,al,bl)
RB[:m],RB[start:start+m] = RB[start:start+m],RB[:m]
seq -= m
start += m
if seq:
    RB[start:start+seq],RB[-seq:] = RB[-seq:],RB[start:start+seq]

assert all(a!=b for a,b in zip(A,RB))
print('Yes')
print(*RB)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
RB = B[::-1]

start = v = -1
seq = 0
for i,(a,b) in enumerate(zip(A,RB)):
    if a==b:
        v = a
        seq += 1
        if start == -1:
            start = i

if v == -1:
    print('Yes')
    print(*RB)
    exit()

if A.count(v) + B.count(v) > N:
    print('No')
    exit()

from bisect import bisect_left,bisect
al = bisect_left(A,v)
bl = bisect_left(B,v)
br = bisect(B,v)
rbl = N - br

m = min(seq,start,al,rbl)
RB[:m],RB[start:start+m] = RB[start:start+m],RB[:m]
seq -= m
start += m
if seq:
    RB[start:start+seq],RB[-seq:] = RB[-seq:],RB[start:start+seq]

assert all(a!=b for a,b in zip(A,RB))
print('Yes')
print(*RB)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
RB = B[::-1]

start = -1
seq = 0
for i,(a,b) in enumerate(zip(A,RB)):
    if a==b:
        if start == -1:
            start = i
        seq += 1

if start == -1:
    print('Yes')
    print(*RB)
    exit()

v = A[start]
if A.count(v) + B.count(v) > N:
    print('No')
    exit()

from bisect import bisect_left
al = bisect_left(A,v)
bl = bisect_left(B,v)

m = min(start,seq,al,bl)
RB[:m],RB[start:start+m] = RB[start:start+m],RB[:m]
seq -= m
start += m
if seq:
    RB[start:start+seq],RB[-seq:] = RB[-seq:],RB[start:start+seq]

assert all(a!=b for a,b in zip(A,RB))
print('Yes')
print(*RB)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
RB = B[::-1]

start = v = -1
seq = 0
for i,(a,b) in enumerate(zip(A,RB)):
    if a==b:
        v = a
        seq += 1
        if start == -1:
            start = i

if v == -1:
    print('Yes')
    print(*RB)
    exit()

if A.count(v) + B.count(v) > N:
    print('No')
    exit()

from bisect import bisect_left,bisect
al = bisect_left(A,v)
bl = bisect_left(B,v)
br = bisect(B,v)
rbl = N - br

m = min(seq,start,al,rbl)
RB[:m],RB[start:start+m] = RB[start:start+m],RB[:m]
seq -= m
start += m
if seq:
    RB[start:start+seq],RB[-seq:] = RB[-seq:],RB[start:start+seq]

assert all(a!=b for a,b in zip(A,RB))
print('Yes')
print(*RB)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
B.reverse()

start = -1
seq = 0
for i,(a,b) in enumerate(zip(A,B)):
    if a==b:
        if start == -1:
            start = i
        seq += 1

if start == -1:
    print('Yes')
    print(*B)
    exit()

v = A[start]
if A.count(v) + B.count(v) > N:
    print('No')
    exit()

from bisect import bisect_left
left = bisect_left(A,v)

m = min(start,seq,left)
B[:m],B[start:start+m] = B[start:start+m],B[:m]
seq -= m
start += m
if seq:
    B[start:start+seq],B[-seq:] = B[-seq:],B[start:start+seq]

assert all(a!=b for a,b in zip(A,B))
print('Yes')
print(*B)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
RB = B[::-1]

start = v = -1
seq = 0
for i,(a,b) in enumerate(zip(A,RB)):
    if a==b:
        v = a
        seq += 1
        if start == -1:
            start = i

if v == -1:
    print('Yes')
    print(*RB)
    exit()

if A.count(v) + B.count(v) > N:
    print('No')
    exit()

from bisect import bisect_left,bisect
al = bisect_left(A,v)
bl = bisect_left(B,v)
br = bisect(B,v)
rbl = N - br

m = min(seq,start,al,rbl)
RB[:m],RB[start:start+m] = RB[start:start+m],RB[:m]
seq -= m
start += m
if seq:
    RB[start:start+seq],RB[-seq:] = RB[-seq:],RB[start:start+seq]

assert all(a!=b for a,b in zip(A,RB))
print('Yes')
print(*RB)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
B.reverse()

start = -1
seq = 0
for i,(a,b) in enumerate(zip(A,B)):
    if a==b:
        if start == -1:
            start = i
        seq += 1

if start == -1:
    print('Yes')
    print(*B)
    exit()

v = A[start]
if A.count(v) + B.count(v) > N:
    print('No')
    exit()

m = min(start,seq)
B[:m],B[start:start+m] = B[start:start+m],B[:m]
seq -= m
start += m
if seq:
    B[start:start+seq],B[-seq:] = B[-seq:],B[start:start+seq]

assert all(a!=b for a,b in zip(A,B))
print('Yes')
print(*B)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
RB = B[::-1]

start = v = -1
seq = 0
for i,(a,b) in enumerate(zip(A,RB)):
    if a==b:
        v = a
        seq += 1
        if start == -1:
            start = i

if v == -1:
    print('Yes')
    print(*RB)
    exit()

if A.count(v) + B.count(v) > N:
    print('No')
    exit()

from bisect import bisect_left,bisect
al = bisect_left(A,v)
bl = bisect_left(B,v)
br = bisect(B,v)
rbl = N - br

m = min(seq,start,al,rbl)
RB[:m],RB[start:start+m] = RB[start:start+m],RB[:m]
seq -= m
start += m
if seq:
    RB[start:start+seq],RB[-seq:] = RB[-seq:],RB[start:start+seq]

assert all(a!=b for a,b in zip(A,RB))
print('Yes')
print(*RB)

Buggy python submission (verdict: Time Limit Exceeded):
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,deque
arem = Counter(A)
brem = Counter(B)
ans = []
for i,a in enumerate(A):
    for k,v in arem.most_common():
        if v <= 0: break
        if k != a and brem[k] > 0:
            brem[k] -= 1
            ans.append(k)
            break
    if len(ans) < i+1:
        for k,v in brem.most_common(2):
            if v <= 0: break
            if k != a:
                brem[k] -= 1
                ans.append(k)
                break
    if len(ans) < i+1:
        print('No')
        exit()
    arem[a] -= 1

if len(ans) != N:
    print('No')
else:
    print('Yes')
    print(*ans)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
RB = B[::-1]

start = v = -1
seq = 0
for i,(a,b) in enumerate(zip(A,RB)):
    if a==b:
        v = a
        seq += 1
        if start == -1:
            start = i

if v == -1:
    print('Yes')
    print(*RB)
    exit()

if A.count(v) + B.count(v) > N:
    print('No')
    exit()

from bisect import bisect_left,bisect
al = bisect_left(A,v)
bl = bisect_left(B,v)
br = bisect(B,v)
rbl = N - br

m = min(seq,start,al,rbl)
RB[:m],RB[start:start+m] = RB[start:start+m],RB[:m]
seq -= m
start += m
if seq:
    RB[start:start+seq],RB[-seq:] = RB[-seq:],RB[start:start+seq]

assert all(a!=b for a,b in zip(A,RB))
print('Yes')
print(*RB)

Buggy python submission (verdict: Time Limit Exceeded):
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,deque
arem = Counter(A)
brem = Counter(B)
ans = []
for i,a in enumerate(A):
    for k,v in arem.most_common():
        if v <= 0: break
        if k != a and brem[k] > 0:
            brem[k] -= 1
            ans.append(k)
            break
    if len(ans) < i+1:
        for k,v in brem.most_common(2):
            if v <= 0: break
            if k != a:
                brem[k] -= 1
                ans.append(k)
                break
    if len(ans) < i+1:
        print('No')
        exit()
    arem[a] -= 1

if len(ans) != N:
    print('No')
else:
    print('Yes')
    print(*ans)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
RB = B[::-1]

start = v = -1
seq = 0
for i,(a,b) in enumerate(zip(A,RB)):
    if a==b:
        v = a
        seq += 1
        if start == -1:
            start = i

if v == -1:
    print('Yes')
    print(*RB)
    exit()

if A.count(v) + B.count(v) > N:
    print('No')
    exit()

from bisect import bisect_left,bisect
al = bisect_left(A,v)
bl = bisect_left(B,v)
br = bisect(B,v)
rbl = N - br

m = min(seq,start,al,rbl)
RB[:m],RB[start:start+m] = RB[start:start+m],RB[:m]
seq -= m
start += m
if seq:
    RB[start:start+seq],RB[-seq:] = RB[-seq:],RB[start:start+seq]

assert all(a!=b for a,b in zip(A,RB))
print('Yes')
print(*RB)