Problem p02557 (python)

Fixed submission:
"""
T E S T
"""

from collections import Counter, deque

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

cnt_a = Counter(A)
cnt_b = Counter(B)

cnt_ab = cnt_a + cnt_b

for i in cnt_ab.values():
    if i > N:
        print("No")
        exit()


print("Yes")
dq_a = deque(A)
dq_b = deque(B)

ans = []

dq_b.rotate(N // 2)

while dq_a:
    if dq_a[0] != dq_b[0]:
        dq_a.popleft()
        p = dq_b.popleft()
        ans.append(p)
        # ans.append(b.popleft())
    else:
        dq_b.rotate()
print(*ans)

Buggy submission (verdict: Runtime Error):
"""
T E S T
"""

from collections import Counter, deque

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

cnt_a = Counter(A)
cnt_b = Counter(B)

cnt_ab = cnt_a + cnt_b

for i in cnt_ab.values():
    if i > N:
        print("No")
        exit()


print("Yes")
dq_a = deque(A)
dq_b = deque(B)

ans = []

dq_b.rotate(n // 2)

while dq_a:
    if dq_a[0] != dq_b[0]:
        dq_a.popleft()
        p = dq_b.popleft()
        ans.append(p)
        # ans.append(b.popleft())
    else:
        dq_b.rotate()
print(*ans)

Buggy submission (verdict: Runtime Error):
"""
T E S T
"""

from collections import Counter, deque

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

cnt_a = Counter(A)
cnt_b = Counter(B)

cnt_ab = cnt_a + cnt_b

for i in cnt_ab.values():
    if i > N:
        print("No")
        exit()


print("Yes")
dq_a = deque(A)
dq_b = deque(B)

ans = []

b.rotate(n // 2)

while dq_a:
    if dq_a[0] != dq_b[0]:
        dq_a.popleft()
        p = dq_b.popleft()
        ans.append(p)
        # ans.append(b.popleft())
    else:
        dq_b.rotate()
print(*ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
import sys
import random
input = sys.stdin.readline

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

B = list(map(int, input().split()))
# B.sort(reverse=True)
B = range.shuffle(B)
C = deque(B)

ans = []

for i in range(N):
    p = C.popleft()
    if A[i] != p:
        ans.append(p)
        continue

    if len(C) >= 1:
        cnt = 1
        while C:
            q = C.popleft()
            if q == A[i]:
                cnt += 1
            else:
                break

        if len(C) == 0 and p == q:
            print("No")
            exit()

        ans.append(q)
        for _ in range(cnt):
            C.append(p)
        continue

    print("No")
    exit()

print("Yes")
if len(ans) >= 2:
    print(*ans)
else:
    print(ans[0])

Buggy submission (verdict: Runtime Error):
from copy import deepcopy
from collections import deque
import sys
input = sys.stdin.readline

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

C = deepcopy(B)
C.reverse()
C = deque(C)

ans = deque([])

for i in range(N):
    p = C.popleft()
    if A[i] != p:
        ans.append(p)
        continue
    if N >= 2:
        q = C.pop()
        if A[i] != q:
            C.append(p)
            ans.append(q)
            continue

    print("No")
    exit()

print("Yes")
print(*ans)

Buggy submission (verdict: Runtime Error):
from copy import deepcopy
from collections import deque
import sys
input = sys.stdin.readline

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

C = deepcopy(B)
C.reverse()
C = deque(C)

ans = deque([])

for i in range(N):
    p = C.popleft()
    if A[i] != p:
        ans.append(p)
        continue
    q = C.pop()
    if A[i] != q:
        C.append(p)
        ans.append(q)
        continue

    print("No")
    exit()
print("Yes")
print(*ans)