Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    for i in range(N):
        if A[i] == B[i]:
            j = 0
            while j < N:
                if A[i] != B[j] and A[j] != B[i]:
                    B[i], B[j] = B[j], B[i]
                    break                
                j += 1
            if A[i] == B[i]:
                print("No")
                return

    print('Yes')
    print(*B)


if __name__ == "__main__":
    resolve()


Fixed submission:

from collections import Counter
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    CNT = Counter(A+B)
    num = CNT.most_common()[0][1]
    if num > N:
        print("No")
        return 

    j, pre = 0, -1
    for i in range(N):
        if A[i] != pre:
            j = 0
        if A[i] == B[i]:
            while j < N:
                if A[i] != B[j] and A[j] != B[i]:
                    B[i], B[j] = B[j], B[i]
                    break
                j += 1
        pre = A[i]

    print('Yes')
    print(*B)


if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Runtime Error):

from collections import Counter
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    CNT = Counter(A + B)
    num = CNT.most_common()[0][1]
    if num > N:
        print("No")
        return

    j = 0
    for i in range(N):
        if A[i] == B[i]:
            for _ in range(N):
                j += 1
                if A[i] != B[j] and A[j] != B[i]:
                    B[i], B[j] = B[j], B[i]
                    break
                if j == N - 1:
                    j = -1

    print('Yes')
    print(*B)


if __name__ == "__main__":
    resolve()

Fixed submission:

from collections import Counter
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    CNT = Counter(A+B)
    num = CNT.most_common()[0][1]
    if num > N:
        print("No")
        return 

    j, pre = 0, -1
    for i in range(N):
        if A[i] != pre:
            j = 0
        if A[i] == B[i]:
            while j < N:
                if A[i] != B[j] and A[j] != B[i]:
                    B[i], B[j] = B[j], B[i]
                    break
                j += 1
        pre = A[i]

    print('Yes')
    print(*B)


if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Runtime Error):

from collections import Counter
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    CNT = Counter(A + B)
    num = CNT.most_common()[0][1]
    if num > N:
        print("No")
        return

    j = 0
    for i in range(N):
        if A[i] == B[i]:
            for _ in range(N):
                j += 1
                if A[i] != B[j] and A[j] != B[i]:
                    B[i], B[j] = B[j], B[i]
                    break
                if j == N - 1:
                    j = 0

    print('Yes')
    print(*B)


if __name__ == "__main__":
    resolve()


Fixed submission:

from collections import Counter
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    CNT = Counter(A+B)
    num = CNT.most_common()[0][1]
    if num > N:
        print("No")
        return 

    j, pre = 0, -1
    for i in range(N):
        if A[i] != pre:
            j = 0
        if A[i] == B[i]:
            while j < N:
                if A[i] != B[j] and A[j] != B[i]:
                    B[i], B[j] = B[j], B[i]
                    break
                j += 1
        pre = A[i]

    print('Yes')
    print(*B)


if __name__ == "__main__":
    resolve()