Problem p02557 (python)

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 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)

Buggy 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)

Buggy 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)

Buggy 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)