Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized.

On that night, Sengoku constructed a permutation p_1, p_2, ..., p_{n} of integers from 1 to n inclusive, with each integer representing a colour, wishing for the colours to see in the coming meteor outburst. Two incredible outbursts then arrived, each with n meteorids, colours of which being integer sequences a_1, a_2, ..., a_{n} and b_1, b_2, ..., b_{n} respectively. Meteoroids' colours were also between 1 and n inclusive, and the two sequences were not identical, that is, at least one i (1 ≤ i ≤ n) exists, such that a_{i} ≠ b_{i} holds.

Well, she almost had it all — each of the sequences a and b matched exactly n - 1 elements in Sengoku's permutation. In other words, there is exactly one i (1 ≤ i ≤ n) such that a_{i} ≠ p_{i}, and exactly one j (1 ≤ j ≤ n) such that b_{j} ≠ p_{j}.

For now, Sengoku is able to recover the actual colour sequences a and b through astronomical records, but her wishes have been long forgotten. You are to reconstruct any possible permutation Sengoku could have had on that night.


-----Input-----

The first line of input contains a positive integer n (2 ≤ n ≤ 1 000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time.

The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ n) — the sequence of colours in the first meteor outburst.

The third line contains n space-separated integers b_1, b_2, ..., b_{n} (1 ≤ b_{i} ≤ n) — the sequence of colours in the second meteor outburst. At least one i (1 ≤ i ≤ n) exists, such that a_{i} ≠ b_{i} holds.


-----Output-----

Output n space-separated integers p_1, p_2, ..., p_{n}, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them.

Input guarantees that such permutation exists.


-----Examples-----
Input
5
1 2 3 4 3
1 2 5 4 5

Output
1 2 5 4 3

Input
5
4 4 2 3 1
5 4 5 3 1

Output
5 4 2 3 1

Input
4
1 1 3 4
1 4 3 4

Output
1 2 3 4



-----Note-----

In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs.

In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.

Difficulty: interview

Starter code:

Solutions:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cnt = 0
for i in range(n):
    if a[i] != b[i]:
        cnt += 1 
        
if cnt == 1:
    done = list(range(1,n+1))
    x = 0
    for i in range(n):
        if a[i] == b[i]:
            try:
                done.remove(a[i])
            except:
                pass
        else:
            x = i
            try:
                done.remove(a[i])
            except:
                pass
            try:
                done.remove(b[i])
            except:
                pass
    arr = a[::]
    arr[x] = done[0]
    for i in arr:
        print(i,end = ' ')
        
else:
    arr = a[::]
    x = -1
    y = -1
    for i in range(n):
        if a[i] == b[i]:
            pass
        else:
            if x == -1:
                x = i
            else:
                y = i
    br = arr[::]
    arr[x] = b[x]
    br[y] = b[y]
    if len(set(br)) == n:
        arr = br[::]
    for i in arr:
        print(i,end = ' ')           
        

import sys

n = int(input())

a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

p1, p2, p3, p4 = [], [], [], []

cur = 0
for i in range(n):
    if a[i] == b[i]:
        for p in (p1, p2, p3, p4):
            p.append(a[i])
    elif cur == 0:
        p1.append(a[i])
        p2.append(a[i])
        p3.append(b[i])
        p4.append(b[i])
        cur += 1
    else:
        p1.append(a[i])
        p2.append(b[i])
        p3.append(a[i])
        p4.append(b[i])

for p in (p1, p2, p3, p4):
    if len(set(p)) == n:
        print(' '.join(str(x) for x in p))
        return

for p in (p1, p2, p3, p4):
    if len(set(p)) == n - 1:
        distinct = 0
        dpos = 0
        for i, (x, y) in enumerate(zip(p, a)):
            if x != y:
                distinct += 1
                dpos = i
        if distinct == 1:
            unused = 1
            while unused in p:
                unused += 1
            pp = list(p)
            pp[dpos] = unused
            print(' '.join(str(x) for x in pp))
            return

assert False


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [0 for _ in range(n)]
used = [False for _ in range(n + 1)]
idx = []
for i in range(n):
    if a[i] == b[i]:
        ans[i] = a[i]
        used[a[i]] = True
    else:
        idx.append(i)
unused = []
for i in range(1, n + 1):
    if not used[i]:
        unused.append(i)

if len(unused) == 1:
    ans[idx[0]] = unused[0]
elif (a[idx[0]] != unused[0] and a[idx[1]] != unused[1]) or (b[idx[0]] != unused[0] and b[idx[1]] != unused[1]):
    ans[idx[0]] = unused[1]
    ans[idx[1]] = unused[0]
else:
    ans[idx[0]] = unused[0]
    ans[idx[1]] = unused[1]

print(' '.join(map(str, ans)))


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

diff = []
for i in range(n):
    if a[i] != b[i]:
        diff.append(i)
sa = True
sb = True
di = []
for i in range(1,n+1):
    di.append(i)
s = []
for i in range(n):
    if i not in diff:
        s.append(a[i])
        di.remove(a[i])
    else:
        s.append(0)
if len(diff) == 1:
    s[diff[0]] = di[0]
else:
    if (a[diff[0]] in di and b[diff[1]] in di):
        s[diff[0]] = a[diff[0]]
        s[diff[1]] = b[diff[1]]
    else:
        s[diff[0]] = b[diff[0]]
        s[diff[1]] = a[diff[1]]
        
        

for i in range(n):
    print(s[i], end= ' ')



import math


def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    res = []
    for i in a:
        res.append(i)
    all_numbers = set([i for i in range(1, n+1)])
    seta = set(a)
    setb = set(b)
    non_a = list(all_numbers - seta)[0]
    non_b = list(all_numbers - setb)[0]
    dpa = double_positions(a)
    dpb = double_positions(b)
    for i in dpa:
        temp = res[i]
        res[i] = non_a
        if diff(res, a) == 1 and diff(res, b) == 1:
            print(*res)
            return
        res[i]= temp
    for i in dpb:
        temp = res[i]
        res[i] = non_b
        if diff(res, b) == 1 and diff(res, a) == 1:
            print(*res)
            return
        res[i] = temp



def diff(a, b):
    c = 0
    for i in range(len(a)):
        if a[i] != b[i]:
            c += 1
    return c

def double_positions(a):
    count = [-1 for i in range(len(a))]
    res = []
    for i in range(len(a)):
        if count[a[i]-1] != -1:
            return count[a[i]-1], i
        count[a[i]-1] = i
    
    
def __starting_point():
    main()

__starting_point()

n = int(input())
ai = list(map(int,input().split()))
bi = list(map(int,input().split()))
ci = [0]*n
for i in range(n):
    ci[i] = ai[i]
nums = [0]*n
ind = [0]*2
j = 0
num = 0
for i in range(n):
    nums[ai[i]-1] += 1
for i in range(n):
    if nums[ai[i]-1] == 2:
        ind[j] = i
        j += 1
    if nums[i] == 0:
        num = i+1 
        
ci[ind[0]] = num
dif = 0
dif2 = 0
for i in range(n):
    if ci[i] != bi[i]:
        dif += 1
    if ci[i] != ai[i]:
        dif2 += 1
if dif != 1 or dif2 != 1:
    ci[ind[0]] = ai[ind[0]]
    ci[ind[1]] = num
for i in range(n):
    print(ci[i],end=" ")


import sys

def main():
    n=int(sys.stdin.readline().rstrip())
    a=list(map(int,sys.stdin.readline().split()))
    b=list(map(int,sys.stdin.readline().split()))
    
    items=set(range(1,n+1))
    coords=[]
    p=[-1]*n
    
    for i in range(n):
        if a[i]==b[i]:
            items.remove(a[i])
            p[i]=a[i]
        else:
            coords.append(i)
            
    items=list(items)
    
    if len(coords)==1:
        p[coords[0]]=items[0]
    else:
        adelta=0
        bdelta=0
        for k,coord in enumerate(coords):
            if items[k]!=a[coord]: adelta+=1
            if items[k]!=b[coord]: bdelta+=1
            p[coord]=items[k]
        if not (adelta==1 and bdelta==1):
            adelta=0
            bdelta=0
            for k,coord in enumerate(reversed(coords)):
                if items[k]!=a[coord]: adelta+=1
                if items[k]!=b[coord]: bdelta+=1
                p[coord]=items[k]
        
    sys.stdout.write(' '.join(map(str,p))+'\n')
    
main()



n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
bad = []
def isok(tmp):
    s = set()
    for i in range(len(tmp)):
        s.add(tmp[i])
    return len(s) == n
    
for i in range(len(a)):
    if a[i] != b[i]:
        bad.append(i)
if len(bad) == 1:
    k = [0] * (n + 1)
    for i in range(len(a)):
        if i != bad[0]:
            k[a[i]] = 1
    rs = 0
    for i in range(1, n + 1):
        if not k[i]:
            rs = i
            break
    tmp = []
    for i in range(len(a)):
        if i != bad[0]:
            tmp.append(a[i])
        else:
            tmp.append(rs)
    print(*tmp)
            
else:
    tmp = []
    tmp1 = []
    for i in range(len(a)):
        if i == bad[0]:
            tmp.append(b[i])
            tmp1.append(a[i])
        else:
            tmp.append(a[i])
            tmp1.append(b[i])   
    if isok(tmp):
        print(*tmp)
    else:
        print(*tmp1)
    


from operator import eq

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

al = [False for _ in range(n)]
bl = [False for _ in range(n)]

for i in range(n):
    al[a[i]-1] = True
    bl[b[i]-1] = True

for i,e in enumerate(al):
    if not e:
        ak = i+1

for i,e in enumerate(bl):
    if not e:
        bk = i+1

aa = [(e,i) for (i,e) in enumerate(a)]
bb = [(e,i) for (i,e) in enumerate(b)]

aa.sort();
bb.sort();


for i in range(1,n):
    
    if (aa[i][0] == aa[i-1][0]):
        amis = aa[i][0]
        a1 = aa[i-1][1]
        a2 = aa[i][1]

    if (bb[i][0] == bb[i-1][0]):
        bmis = bb[i][0]
        b1 = bb[i-1][1]
        b2 = bb[i][1]


for ay in [a1,a2]:
    for by in [b1,b2]:
        reta = list(a)
        reta[ay] = ak

        retb = list(b)
        retb[by] = bk

        if all(map(eq, reta, retb)):
            print(" ".join(map(str, reta)))
            return




def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    used = [False] * (n + 1)
    answer = [None] * n

    for i, (ai, bi) in enumerate(zip(a, b)):
        if ai == bi and not used[ai]:
            answer[i] = ai
            used[ai] = True

    perm = set(range(1, n + 1))
    ind = []
    for i, x in enumerate(answer):
        if x is not None:
            perm.remove(x)
        else:
            ind.append(i)

    perm = list(perm)
    if len(perm) == 1:
        answer[ind[0]] = perm[0]
        for x in answer:
            print(x, end=' ')
        return

    i, j = ind
    x, y = perm
    count = (a[i] != x) + (b[i] != x) + (a[j] != y) + (b[j] != y)
    if count == 2:
        answer[i] = x
        answer[j] = y
    else:
        answer[i] = y
        answer[j] = x

    for x in answer:
        print(x, end=' ')


def __starting_point():
    # import sys
    # sys.stdin = open('input.txt')
    main()

__starting_point()

#!/usr/bin/env python3
from sys import stdin, stdout

def rint():
    return list(map(int, stdin.readline().split()))
#lines = stdin.readlines()


n = int(input())

a = list(rint())
b = list(rint())

ii = []
for i in range(n):
    if a[i] != b[i]:
        ii.append(i)

if len(ii) == 2:
    if a[ii[0]] != a[ii[1]]:
        c = a[:]
    else:
        c = b[:]
    if c.count(c[ii[0]]) == 2:
        iii = ii[0]
    else:
        iii = ii[1]
else:
    c = a[:]
    iii = ii[0]


for i in range(n):
    if not i+1 in c:
        c[iii] = i+1
        print(*c)
        return



n=int(input())
a=[int(i)for i in input().split()]
b=[int(i)for i in input().split()]
ans=[0]*n
s=set([int(i)for i in range(1,n+1)])
for i in range(n):
	if a[i]==b[i]:
		ans[i]=a[i]
		s.remove(a[i])
for i in range(n):
	if a[i]!=b[i]:
		if a[i] not in s:
			if b[i] in s:
				ans[i]=b[i]
				s.remove(b[i])
	if b[i] not in s:
		if a[i] in s:
			ans[i]=a[i]
			s.remove(a[i])		
j=0
for i in s:
	while  ans[j]!=0:
		j+=1
	ans[j]=i
	j+=1
print(*ans)		





def check(A, B):
    diff = 0
    for i in range(len(A)):
        if A[i] != B[i]:
            diff += 1
    return diff == 1
ip = lambda: list(map(int, input().split()))
n = int(input())
A = ip()
B = ip()
diff = 0
left = set(range(1, n+1))
C = [0 for _ in range(n)]
for i in range(n):
    if A[i] == B[i]:
        C[i] = A[i]
        if A[i] in left:
            left.remove(A[i])
    else:
        diff += 1
if diff == 1:
    for i in range(n):
        if C[i] == 0:
            C[i] = left.pop()
else:
    i, j = [k for k in range(n) if C[k] == 0]
    left = list(left)
    assert(diff == 2)
    assert(len(left) == 2)
    C[i] = left[0]
    C[j] = left[1]
    if not check(A, C) or not check(B, C):
        C[i] = left[1]
        C[j] = left[0]

print(*C)



n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))


da = [0] * (n+1)
pa = [-1] * (n+1)
sa = 0
for i in range(n):
    sa += a[i]
    if da[a[i]] == 0:
        da[a[i]] += 1
        pa[a[i]] = i
    else:
        povt_a = a[i]
        place2_a = i
        place1_a = pa[a[i]]
da[0] = -1
abs_a = da.index(0)

db = [0] * (n+1)
pb = [-1] * (n+1)
sb = 0
for i in range(n):
    sb += b[i]
    if db[b[i]] == 0:
        db[b[i]] += 1
        pb[b[i]] = i
    else:
        povt_b = b[i]
        place2_b = i
        place1_b = pb[b[i]]
db[0] = -1
abs_b = db.index(0)
       
#print(povt_a, place1_a, place2_a, abs_a)
#print(povt_b, place1_b, place2_b, abs_b)

a1 = a.copy()
b1 = b.copy()

a1[place1_a] = abs_a
b1[place1_b] = abs_b
if a1 == b1:
    print(" ".join(map(str, a1)))
    return
    
b1[place1_b] = b[place1_b]
b1[place2_b] = abs_b
if a1 == b1:
    print(" ".join(map(str, a1)))
    return
 
a1[place1_a] = a[place1_a]
a1[place2_a] = abs_a
if a1 == b1:
    print(" ".join(map(str, a1)))
    return

b1[place2_b] = b[place2_b]
b1[place1_b] = abs_b
print(" ".join(map(str, a1)))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0]*n
d = [False]*n
bad = []
need = []
for i in range(n):
    if a[i] == b[i]:
        d[a[i]-1] = True
        c[i] = a[i]
    else:
        bad.append(i)
for i in range(n):
    if not d[i]:
        need.append(i+1)

d = False

def good(c):
    nonlocal a, b
    al = 0
    bl = 0
    for i in range(len(c)):
        if c[i] != a[i]:
            al += 1
        if c[i] != b[i]:
            bl += 1
    if al == 1 and bl == 1:
        for i in range(len(c)):
            for j in range(len(c)):
                if i != j and c[i] == c[j]:
                    return False
    else:
        return False
    return True
fc = []
do = False
def f(b, n, c):
    nonlocal do, fc
    #print(b, n, c, do)
    if not do:
        if len(b) == 0 and good(c):
            do = True
            fc = c
            #print(fc)
        else:
            for i in range(len(b)):
                for j in range(len(n)):
                    nc = c+[]
                    nc[b[i]] = n[j]
                    f(b[:i]+b[i+1:]+[], n[:j]+n[j+1:]+[], nc)

f(bad, need, c)
for i in fc:
    print(i ,end=' ')

def meteors(n, ar, br):
    differ = []
    used = {}
    pr = []
    for i in range(n):
        if ar[i] != br[i]:
            pr.append(-1)
            differ.append((i, ar[i], br[i]))
        else:
            pr.append(ar[i])
            used[ar[i]] = i

    unused = find_unused(n, used)

    if len(differ) == 1:
        pr[differ[0][0]] = unused[0]
    elif len(differ) == 2:
        if differ[0][1] in unused and differ[0][2] in unused and differ[1][1] in unused and differ[1][2] in unused: #whatever is fine
            pr[differ[0][0]] = unused[0]
            pr[differ[1][0]] = unused[1]
        if differ[1][1] in unused and differ[1][2] in unused:
            if not differ[0][1] in unused:
                pr[differ[0][0]] = differ[0][2]
                unused.remove(differ[0][2])
                pr[differ[1][0]] = unused[0]
            else:
                pr[differ[0][0]] = differ[0][1]
                unused.remove(differ[0][1])
                pr[differ[1][0]] = unused[0]
        else:
            if not differ[1][1] in unused:
                pr[differ[1][0]] = differ[1][2]
                unused.remove(differ[1][2])
                pr[differ[0][0]] = unused[0]
            else:
                pr[differ[1][0]] = differ[1][1]
                unused.remove(differ[1][1])
                pr[differ[0][0]] = unused[0]
    else:
        pr = list(range(1, n + 1)) # bad input

    return pr

def find_unused(n, used):
    unused = []
    for i in range(1, n + 1):
        if not i in used:
            unused.append(i)
    return unused


def __starting_point():
    n = int(input().strip())
    ar = list(map(int, input().strip().split()))
    br = list(map(int, input().strip().split()))
    print((" ".join(map(str, meteors(n, ar, br)))));

__starting_point()

n = int(input())
l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))

tot = 0

done = [False for i in range(n+1)]

for i in range(n):
	if(l1[i]!=l2[i]):
		tot+=1
	else:
		done[l1[i]] = True

ans = []
if(tot==1):
	for i in range(n):
		if(l1[i]==l2[i]):
			ans.append(l2[i])
		else:
			for j in range(1,n+1):
				if(done[j]==False and l1[i]!=j and l2[i]!=j):
					ans.append(j)
					break
elif(tot==2):
	l = []
	for i in range(n):
		if(l1[i]==l2[i]):
			ans.append(l2[i])
		else:
			ans.append(0)
			l.append(i)

	ok = True
	_ans = ans
	for i in range(1,n+1):
		if(done[i]==False):
			if(ok==True):
				_ans[l[0]] = i
				ok = False
			else:
				_ans[l[1]] = i
	diff1 = 0
	diff2 = 0
	for i in range(n):
		if(_ans[i]!=l1[i]):
			diff1+=1
		if(_ans[i]!=l2[i]):
			diff2+=1
	if(diff1==1 and diff2==1):
		ans = _ans
	else:
		ok = True
		_ans = ans
		for i in range(1,n+1):
			if(done[i]==False):
				if(ok==True):
					_ans[l[1]] = i
					ok = False
				else:
					_ans[l[0]] = i
		ans = _ans
for i in ans:
		print(i,end=" ")


n = int(input())
a = input().split()
b = input().split()
a = [int(i) for i in a]
b = [int(i) for i in b]

counter = [-1 for i in range(n)]

k_a = 0
k_a_i1, k_a_i2 = -1, -1

for i in range(n):
    if counter[a[i] - 1] != -1:
        k_a = a[i]
        k_a_i1, k_a_i2 = counter[a[i] - 1], i
    counter[a[i] - 1] = i
g_a = counter.index(-1) + 1

counter = [-1 for i in range(n)]

k_b = 0
k_b_i1, k_b_i2 = -1, -1

for i in range(n):
    if counter[b[i] - 1] != -1:
        k_b = b[i]
        k_b_i1, k_b_i2 = counter[b[i] - 1], i
    counter[b[i] - 1] = i

g_b = counter.index(-1) + 1

res = a.copy()
res[k_a_i1] = g_a

c_a = 0
c_b = 0

for i in range(n):
    if res[i] != a[i]:
        c_a += 1
    if res[i] != b[i]:
        c_b += 1

if c_a == 1 and c_b == 1:
    out = ''
    for i in res:
        out += str(i) + ' '
    print(out)
    return

res = a.copy()
res[k_a_i2] = g_a

c_a = 0
c_b = 0

for i in range(n):
    if res[i] != a[i]:
        c_a += 1
    if res[i] != b[i]:
        c_b += 1

if c_a == 1 and c_b == 1:
    out = ''
    for i in res:
        out += str(i) + ' '
    print(out)
    return

res = a.copy()
res[k_b_i1] = g_b

c_a = 0
c_b = 0

for i in range(n):
    if res[i] != a[i]:
        c_a += 1
    if res[i] != b[i]:
        c_b += 1

if c_a == 1 and c_b == 1:
    out = ''
    for i in res:
        out += str(i) + ' '
    print(out)
    return

res = a.copy()
res[k_b_i2] = g_b

c_a = 0
c_b = 0

for i in range(n):
    if res[i] != a[i]:
        c_a += 1
    if res[i] != b[i]:
        c_b += 1

if c_a == 1 and c_b == 1:
    out = ''
    for i in res:
        out += str(i) + ' '
    print(out)
    return



























def __starting_point():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    ans_list = [-3 for i in range(n)]

    mismatch_count = 0
    ans_set = set([])
    for i in range(0, n):
        if a[i] == b[i]:
            ans_list[i] = a[i]
            ans_set.add(a[i])
        else:
            mismatch_count += 1
            ans_list[i] += mismatch_count

    one_to_n_set = set([i for i in range(1, n + 1)])
    add_set = one_to_n_set.difference(ans_set)
    if mismatch_count == 1:
        ans_list[ans_list.index(-2)] = add_set.pop()
    else:
        tmp1 = ans_list.index(-2)
        tmp2 = ans_list.index(-1)
        ele1 = add_set.pop()
        ele2 = add_set.pop()
        if ele1 == a[tmp1] and ele2 == b[tmp2]:
            ans_list[tmp1] = ele1
            ans_list[tmp2] = ele2
        elif ele1 == a[tmp2] and ele2 == b[tmp1]:
            ans_list[tmp2] = ele1
            ans_list[tmp1] = ele2
        elif ele2 == a[tmp1] and ele1 == b[tmp2]:
            ans_list[tmp1] = ele2
            ans_list[tmp2] = ele1
        elif ele2 == a[tmp2] and ele1 == b[tmp1]:
            ans_list[tmp2] = ele2
            ans_list[tmp1] = ele1

    for i in range(0, n):
        print(ans_list[i], end=' ')

__starting_point()

size = int(input())
a = [int(elem) for elem in input().split()]
b = [int(elem) for elem in input().split()]

right = []
a_remain = []
b_remain = []
cand = []
for idx in range(size):
    if a[idx] == b[idx]:
        right.append(a[idx])
    else:
        right.append(0)
        a_remain.append(a[idx])
        b_remain.append(b[idx])

for elem in range(1, size+1):
    if elem not in right:
        cand.append(elem)

def diff(seq_a, seq_b):
    if (seq_a[0] == seq_b[0] and seq_a[1] != seq_b[1]) or \
       (seq_a[0] != seq_b[0] and seq_a[1] == seq_b[1]):
        return True
    else:
        return False

def replace(original, pattern):
    pos = 0
    for idx, elem in enumerate(original):
        if elem == 0:
            original[idx] = pattern[pos]
            pos += 1
    return [str(elem) for elem in original]

if len(cand) == 1:
    print(' '.join(replace(right, cand)))
elif diff(cand, a_remain) and diff(cand, b_remain):
    print(' '.join(replace(right, cand)))
else:
    cand.reverse()
    print(' '.join(replace(right, cand)))


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
counta = Counter(a)
countb = Counter(b)
ab = [0]*n
for i in range(n):
    if a[i] == b[i]:  ab[i] =a[i]

#print(ab)
test = set(list(range(1,n+1)))
#abtup = set([])
for i in range(n):
    setab = set(ab)
    realtest = test - setab

    if ab[i] == 0:
        if a[i] in setab and b[i] in setab:
            if len(realtest) != 0:
                ab[i] = realtest.pop()
        
        elif a[i] in setab:
            ab[i] = b[i]
        elif b[i] in setab:
            ab[i] = a[i]
        else:
            if counta[a[i]] > 1 and countb[b[i]] > 1:
                if len(realtest) != 0:
                    ab[i] = realtest.pop()
                else:
                    ab[i] = a[i]
            elif counta[a[i]] > 1 and not countb[b[i]] > 1:
                ab[i] = b[i]
            elif not counta[a[i]] > 1 and countb[b[i]] > 1:
                ab[i] = a[i]
            
print(" ".join(list(map(str,ab))))






import sys
read=lambda:sys.stdin.readline().rstrip()
readi=lambda:int(sys.stdin.readline())
writeln=lambda x:sys.stdout.write(str(x)+"\n")
write=lambda x:sys.stdout.write(x)
N = readi()
A = list(map(int, read().split()))
B = list(map(int, read().split()))
ncntA = [0]*(N+1)
ncntB = [0]*(N+1)
diff = []
for i in range(N):
    if A[i] != B[i]:
        diff.append(i)
    ncntA[A[i]] += 1
    ncntB[B[i]] += 1

if len(diff) == 2:
    P = list(A)
    P[diff[0]] = B[diff[0]]
    
    ncntP = [0]*(N+1)
    for i in range(N):
        ncntP[P[i]] += 1

    flag = False
    for i in range(1, N+1):
        if ncntP[i] == 0:
            flag = True
            break
    if flag:
        P = list(A)
        P[diff[1]] = B[diff[1]]

    writeln(' '.join(str(c) for c in P))
else:
    k = -1
    for i in range(1, N+1):
        if ncntA[i] == 0 and ncntB[i] == 0:
            k = i
            break
    P = list(A)
    P[diff[0]] = k
    writeln(' '.join(str(c) for c in P))

import sys

input = sys.stdin.readline

n = int(input())

a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

perm = [-1 for i in range(n)]
avail = set()

for i in range(1,n+1):
    avail.add(i)

for i in range(n):
    if a[i] == b[i]:
        avail.remove(a[i])
        perm[i] = a[i]

def difference(seq1, seq2):
    count = 0
    for i in range(len(seq1)):
        if seq1[i] != seq2[i]:
            count += 1
        if count > 1:
            return 0
    return 1

def solve(seq, curravail):
    if not curravail:
        if difference(seq, a) == 1 and difference(seq, b) == 1:
            return seq
    for i in range(len(seq)):
        if (seq[i] == -1):
            for item in list(curravail):
                newseq = list(seq)
                newseq[i] = item
                newset = set(curravail)
                newset.remove(item)
                if solve(newseq, newset):
                    return solve(newseq, newset)

print(" ".join(map(str,solve(perm,avail))))

n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
c=[0]*n
d=set([x for x in range(1,n+1)])
for x in range(n):
    if a[x]==b[x]:
        c[x]=a[x]
        d.remove(a[x])
    elif a.count(a[x])+b.count(a[x])==1:
        c[x]=a[x]
        d.remove(a[x])
    elif a.count(b[x])+b.count(b[x])==1:
        c[x]=b[x]
        d.remove(b[x])
if(len(d))==0:
    ty = str(c)[1:-1].replace(",", "")
    print(ty)
if len(d)==1:
    c[c.index(0)]=d.pop()
    ty=str(c)[1:-1].replace(",","")
    print(ty)
elif len(d)==2:
    c[c.index(0)] = d.pop()
    c[c.index(0)] = d.pop()
    ty = str(c)[1:-1].replace(",", "")
    print(ty)

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
not_equals = []
for i in range(n):
    if a[i] != b[i]:
        not_equals.append(i)
if len(not_equals) == 1:
    x = 1
    while x <= n and x in a and x in b:
        x += 1
    a[not_equals[0]] = x
    print(*a)
else:
    a2 = [elem for elem in a]
    a2[not_equals[0]] = b[not_equals[0]]
    if sorted(a2) == [i for i in range(1, n + 1)]:
        print(*a2)
    else:
        a2 = [elem for elem in a]
        a2[not_equals[1]] = b[not_equals[1]]
        print(*a2)