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.

Source: codeforces | Difficulty: EASY
Tags: Constructive algorithms


Solutions:
import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
two = -1
missing = -1
counts = [[] for i in range(n + 1)]
for i in range(n):
	counts[a[i]].append(i)
	if len(counts[a[i]]) == 2:
		two = a[i]
for i in range(1, n + 1):
	if len(counts[i]) == 0:
		missing = i
		break

def diff(a, b):
	diffs = 0
	for i in range(n):
		diffs += a[i] != b[i]
	return diffs
for i in range(2):
	perm = a.copy()
	perm[counts[two][i]] = missing
	if diff(perm, b) == 1:
		print(*perm)
		break


n = int(input())
lsta = list(map(int, input().split()))
lstb = list(map(int, input().split()))
indx1 = 0
indx2 = 0
ct = 0
for i in range(n):
	if lsta[i] != lstb[i] and ct == 0:
		indx1 = i
		ct += 1
	elif lsta[i] != lstb[i]:
		indx2 = i
		ct += 1
if ct == 1:
	lst = list(range(1, n + 1))
	for i in lst:
		if i not in lsta:
			num = i
			break
	lsta[indx1] = num
	print(*lsta)
	exit()
ct11 = lsta.count(lsta[indx1])
ct21 = lstb.count(lstb[indx1])
if lsta[indx1] != lsta[indx2]:
	if ct11 == 2:
		lsta[indx1] = lstb[indx1]
	else:
		lsta[indx2] = lstb[indx2]
	print(*lsta)
else:
	if ct21 == 2:
		lstb[indx1] = lsta[indx1]
	else:
		lstb[indx2] = lsta[indx2]
	print(*lstb)


def read_int():
	return map(int, input().split())
n = int(input())
a = list(read_int())
b = list(read_int())
pa = [[] for _ in range(n)]
pb = [[] for _ in range(n)]
for (i, ai) in enumerate(a):
	l = pa[ai - 1]
	if l:
		a2 = ai
	l.append(i)
for (i, bi) in enumerate(b):
	l = pb[bi - 1]
	if l:
		b2 = bi
	l.append(i)
p = [None] * n
ab0 = None
for (i, (ai, bi)) in enumerate(zip(pa, pb), 1):
	if len(ai) == 1:
		p[ai[0]] = i
	elif len(bi) == 1:
		p[bi[0]] = i
	elif not (ai or bi):
		ab0 = i
la = pa[a2 - 1]
lb = pb[b2 - 1]
if a2 == b2:
	i = la[0] if la[0] in lb else la[1]
	p[i] = a2
else:
	if not pb[a2 - 1]:
		i = la[1] if p[la[0]] else la[0]
		p[i] = a2
	if not pa[b2 - 1]:
		i = lb[1] if p[lb[0]] else lb[0]
		p[i] = b2
if ab0:
	p[p.index(None)] = ab0
print(*p)


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


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


from sys import stdin, stdout

def rint():
	return list(map(int, stdin.readline().split()))
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


import sys

def check(a, b, c):
	ctr1 = 0
	ctr2 = 0
	for i in range(len(a)):
		if a[i] != b[i]:
			ctr1 += 1
		if a[i] != c[i]:
			ctr2 += 1
	if ctr1 == 1 and ctr2 == 1:
		return 1
	return 0
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans1 = a[:]
ans2 = a[:]
ctr = 0
ids = []
used = [0] * (n + 1)
for i in range(n):
	if used[a[i]]:
		ids.append(i)
		ids.append(a.index(a[i]))
	used[a[i]] = 1
no = 0
for i in range(1, n + 1):
	if not used[i]:
		no = i
		break
ans1[ids[0]] = no
ans2[ids[1]] = no
if check(ans1, a, b):
	print(*ans1)
elif check(ans2, a, b):
	print(*ans2)
else:
	sys.exit(1)


import sys
input = sys.stdin.readline

def check(ans, b):
	pos = 0
	n = len(b)
	for i in range(0, n):
		if ans[i] != b[i]:
			pos += 1
	if pos >= 2:
		return False
	return True
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dd = {}
idx = {}
for i in range(1, n + 1):
	dd[i] = 0
q = -1
r = -1
for i in range(0, n):
	dd[a[i]] += 1
	if dd[a[i]] == 2:
		q = idx[a[i]]
		r = i
	idx[a[i]] = i
val = -1
for i in range(1, n + 1):
	if dd[i] == 0:
		val = i
		break
ansa = a.copy()
ansb = a.copy()
ansa[q] = val
ansb[r] = val
if check(ansa, b):
	for ii in ansa:
		print(ii, end=' ')
else:
	for ii in ansb:
		print(ii, end=' ')


def read_int():
	return map(int, input().split())
n = int(input())
a = list(read_int())
b = list(read_int())
pa = [[] for _ in range(n)]
pb = [[] for _ in range(n)]
for (i, ai) in enumerate(a):
	pa[ai - 1].append(i)
for (i, bi) in enumerate(b):
	pb[bi - 1].append(i)
p = [None] * n
for (i, (ai, bi)) in enumerate(zip(pa, pb), 1):
	if len(ai) == 1:
		p[ai[0]] = i
	elif len(bi) == 1:
		p[bi[0]] = i
for (i, (ai, bi)) in enumerate(zip(pa, pb), 1):
	if len(ai) == 1 or len(bi) == 1:
		pass
	elif ai and bi:
		if ai[0] in bi:
			p[ai[0]] = i
		else:
			p[ai[1]] = i
	elif ai:
		if p[ai[0]] is None:
			p[ai[0]] = i
		else:
			p[ai[1]] = i
	elif bi:
		if p[bi[0]] is None:
			p[bi[0]] = i
		else:
			p[bi[1]] = i
	else:
		p[p.index(None)] = i
print(*p)


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)))
		sys.exit(0)
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)))
			sys.exit(0)
assert False


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
err = []
for i in range(len(a)):
	if a[i] != b[i]:
		err.append((a[i], b[i], i))
ans = a
for i in err:
	ans[i[2]] = 0
missing = []
ansSet = set(ans)
last = 0
for i in range(1, n + 1):
	if i not in ansSet:
		missing.append(i)
	last = i
if len(missing) == 1:
	ans[err[0][2]] = missing[0]
else:
	ans[err[0][2]] = err[0][0]
	ans[err[1][2]] = err[1][1]
	if len(ans) != len(set(ans)):
		ans[err[0][2]] = err[0][1]
		ans[err[1][2]] = err[1][0]
print(' '.join((str(x) for x in ans)))


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


input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = a.copy()
g = 0
p = 1
h = [1 for i in range(len(a))]
for i in range(len(a)):
	if a[i] != b[i]:
		g += 1
	else:
		h[a[i] - 1] = 0
for i in range(len(a)):
	if a[i] != b[i]:
		if g == 1:
			for j in range(len(h)):
				if j + 1 != a[i] and j + 1 != b[i] and h[j]:
					a[i] = j + 1
					h[j] = 0
		else:
			for j in range(len(h)):
				if (j + 1 == a[i] or j + 1 == b[i]) and h[j]:
					a[i] = j + 1
					h[j] = 0
if len(list(set(a))) < len(a):
	h = [1 for i in range(len(a))]
	a = c
	a.reverse()
	b.reverse()
	for i in range(len(a)):
		if a[i] == b[i]:
			h[a[i] - 1] = 0
	for i in range(len(a)):
		if a[i] != b[i]:
			for j in range(len(h)):
				if (j + 1 == a[i] or j + 1 == b[i]) and h[j]:
					a[i] = j + 1
					h[j] = 0
	a.reverse()
print(*a)


n = int(input())
a = [i for i in map(int, input().split())]
b = [j for j in map(int, input().split())]
c = [1] + [0] * n
for i in a:
	c[i] += 1
(d, e) = (c.index(0), c.index(2))
e1 = a.index(e)
e2 = a.index(e, e1 + 1)
a[e1 if b[e1] == d or b[e2] == e else e2] = d
print(' '.join(map(str, a)))


import sys

def main():
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	b = list(map(int, sys.stdin.readline().split()))
	c = [0] * n
	d = {}
	(x, y) = (-1, -1)
	for i in range(n):
		if a[i] == b[i]:
			c[i] = a[i]
			d[a[i]] = True
		elif x == -1:
			x = i
		else:
			y = i
	(q, w) = (-1, -1)
	for i in range(1, n + 1):
		if i not in d:
			if q == -1:
				q = i
			else:
				w = i
	if y != -1:
		if (a[x] != q and a[y] == w or (a[x] == q and a[y] != w)) and (b[x] != q and b[y] == w or (b[x] == q and b[y] != w)):
			c[x] = q
			c[y] = w
		else:
			c[x] = w
			c[y] = q
	else:
		c[x] = q
	print(' '.join(map(str, c)))
main()


n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
output = [0] * n
a_hash = [0] * (n + 1)
b_hash = [0] * (n + 1)
for (i, j) in zip(a, b):
	a_hash[i] += 1
	b_hash[j] += 1
for i in range(1, n + 1):
	if a_hash[i] == 0:
		a_req = i
	if a_hash[i] == 2:
		a_rep = i
	if b_hash[i] == 0:
		b_req = i
if a_req == b_req:
	for i in range(n):
		if a[i] == b[i]:
			output[i] = a[i]
		else:
			output[i] = a_req
else:
	for i in range(n):
		if b[i] == a_req and a[i] == a_rep:
			a[i] = b[i]
			break
	output = a
print(' '.join([str(i) for i in output]))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
uni = [i for i in range(1, n + 1)]
common = []
ind = []

def diff(a, b):
	n = len(a)
	v = 0
	for i in range(n):
		if a[i] != b[i]:
			v += 1
	return v
for i in range(n):
	if a[i] == b[i]:
		common.append(a[i])
	else:
		ind.append(i)
res = a[:]
k = len(ind)
val = set(uni) - set(common)
if k == 1:
	res[ind[0]] = val.pop()
	for i in res:
		print(i, end=' ')
else:
	v1 = val.pop()
	v2 = val.pop()
	res[ind[0]] = v1
	res[ind[1]] = v2
	res2 = a[:]
	res2[ind[0]] = v2
	res2[ind[1]] = v1
	if diff(res, a) == 1 and diff(res, b) == 1:
		for i in res:
			print(i, end=' ')
	else:
		for i in res2:
			print(i, end=' ')


I = lambda : map(int, input().split())
n = int(input())
(a, b) = (list(I()), list(I()))
ch = []
s2 = set(range(1, n + 1))
for i in range(n):
	if a[i] != b[i]:
		ch.append(i)
if len(ch) == 2:
	t = list(a)
	t[ch[0]] = b[ch[0]]
	if sorted(t) != list(range(1, n + 1)):
		a[ch[1]] = b[ch[1]]
	else:
		a = list(t)
else:
	s = set(a).union(b)
	a[ch[0]] = list(s2 - s)[0]
print(*a)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = []
kp = [i for i in range(1, n + 1)]
for i in range(n):
	if a[i] == b[i]:
		l.append(a[i])
	else:
		l.append('x')
for i in l:
	if i in kp:
		kp.remove(i)
for i in range(n):
	if l[i] == 'x':
		if a[i] in kp and b[i] in kp:
			pass
		elif a[i] in kp:
			l[i] = a[i]
			kp.remove(a[i])
		elif b[i] in kp:
			l[i] = b[i]
			kp.remove(b[i])
		elif len(kp) > 0:
			l[i] = kp[0]
			kp.remove(kp[0])
for i in range(n):
	if l[i] == 'x':
		if a[i] in kp:
			l[i] = a[i]
			kp.remove(a[i])
		elif b[i] in kp:
			l[i] = b[i]
			kp.remove(b[i])
for i in l:
	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):
			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]
		elif 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 = range(1, n + 1)
	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
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))))


from collections import defaultdict
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
x = []
a_used = defaultdict(int)
b_used = defaultdict(int)
for i in range(len(a)):
	a_used[a[i]] += 1
	b_used[b[i]] += 1
	if a[i] != b[i]:
		x.append(i)
if len(x) == 2:
	x_done = 0
	while x_done < len(x):
		for i in range(len(x)):
			if a_used[a[x[i]]] > 1 and b_used[b[x[i]]] == 1:
				x_done += 1
				a_used[a[x[i]]] -= 1
				a[x[i]] = b[x[i]]
			elif a_used[a[x[i]]] == 1 and b_used[b[x[i]]] > 1:
				x_done += 1
				b_used[b[x[i]]] -= 1
		if x_done == 0:
			a[x[0]] = b[x[0]]
			break
else:
	for i in range(1, n + 1):
		if a_used[i] == 0:
			a[x[0]] = i
			break
print(a[0], end='')
for i in range(1, len(a)):
	print(' ' + str(a[i]), end='')


n = int(input())
a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
l = [0] * n
k = [0] * n
for j in range(n):
	if a[j] == b[j] and l[a[j] - 1] == 0:
		l[a[j] - 1] = 1
		k[j] = a[j]
if l.count(0) == 1:
	l1 = l.index(0)
	l2 = k.index(0)
	k[l2] = l1 + 1
else:
	l1 = l.index(0)
	l2 = l[l1 + 1:].index(0)
	l2 += l1 + 1
	l3 = k.index(0)
	l4 = k[l3 + 1:].index(0)
	l4 += l3 + 1
	if a[l3] == b[l4] and a[l4] == b[l3] or (a[l3] == a[l4] and b[l3] == b[l4]):
		k[l3] = l1 + 1
		k[l4] = l2 + 1
	elif l[a[l3] - 1] == 1:
		k[l3] = b[l3]
		k[l4] = a[l4]
	elif l[a[l4] - 1] == 1:
		k[l4] = b[l4]
		k[l3] = a[l3]
	elif l[b[l3] - 1] == 1:
		k[l3] = a[l3]
		k[l4] = b[l4]
	elif l[b[l4] - 1] == 1:
		k[l4] = a[l4]
		k[l3] = b[l3]
for j in range(n):
	print(k[j], end=' ')


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):
	global 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):
	global do, fc
	if not do:
		if len(b) == 0 and good(c):
			do = True
			fc = c
		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 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():
	main()
__starting_point()


I = lambda : list(map(int, input().split()))
I()
x = I()
y = I()
z = []
nf = list(range(1, len(x) + 1))
indx = []
for i in range(len(x)):
	if x[i] == y[i]:
		z.append(x[i])
		nf.remove(z[i])
	else:
		z.append(-1)
		indx.append(i)
if len(nf) == 1:
	z[indx[0]] = nf[0]
else:
	z[indx[0]] = nf[0]
	z[indx[1]] = nf[1]
	if z[indx[0]] != x[indx[0]] and z[indx[1]] != x[indx[1]] or (z[indx[0]] != y[indx[0]] and z[indx[1]] != y[indx[1]]):
		z[indx[0]] = nf[1]
		z[indx[1]] = nf[0]
print(*z)


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


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
k = [0 for i in range(len(a))]
m = list(range(1, len(a) + 1))
for i in range(len(a)):
	if a[i] == b[i]:
		k[i] = a[i]
		m.remove(a[i])
if len(m) == 1:
	for i in range(len(a)):
		if k[i] == 0:
			k[i] = m[0]
else:
	r = []
	for i in range(len(a)):
		if k[i] == 0:
			r.append(i)
	if (m[0] == a[r[0]]) ^ (m[1] == a[r[1]]) and (m[0] == b[r[0]]) ^ (m[1] == b[r[1]]):
		k[r[0]] = m[0]
		k[r[1]] = m[1]
	else:
		k[r[0]] = m[1]
		k[r[1]] = m[0]
for i in k:
	print(i, end=' ')


def is_perm(l):
	t = [False] * len(l)
	for x in l:
		t[x - 1] = True
	return all(t)
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
ans = [0] * n
x = -1
y = -1
for i in range(n):
	if a[i] != b[i] and x < 0:
		x = i
	elif a[i] != b[i]:
		y = i
	else:
		ans[i] = a[i]
if y < 0:
	ans[x] = sum(range(n + 1)) - sum(ans)
else:
	ans[x] = a[x]
	ans[y] = b[y]
	if not is_perm(ans):
		ans[x] = b[x]
		ans[y] = a[y]
for i in range(n):
	print(ans[i], end=' ')
print()


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)


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)


import sys
input = sys.stdin.readline

def I():
	return input().strip()

def II():
	return int(input().strip())

def LI():
	return [*map(int, input().strip().split())]
import copy, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from operator import itemgetter
import itertools
for _ in range(1):
	n = II()
	a = LI()
	b = LI()
	l = []
	f = 0
	c = 2
	for i in range(n):
		if a[i] == b[i]:
			l.append(a[i])
		elif c == 2:
			x1 = a[i]
			y1 = b[i]
			c = c - 1
			ind1 = i
			l.append(0)
		else:
			x2 = a[i]
			y2 = b[i]
			ind2 = i
			c = c - 1
			l.append(0)
	if c == 0:
		if x1 == x2 and y1 == y2:
			for i in range(n):
				if i == ind1:
					print(x1, end=' ')
				elif i == ind2:
					print(y1, end=' ')
				else:
					print(l[i], end=' ')
			print()
		elif x1 == y2 and x2 == y1:
			for i in range(n):
				if i == ind1:
					print(x1, end=' ')
				elif i == ind2:
					print(y1, end=' ')
				else:
					print(l[i], end=' ')
			print()
		elif x1 == x2:
			if y1 in l:
				z1 = x1
				f = 0
			if y2 in l:
				z2 = x2
				f = 1
			if f == 0:
				for i in range(n):
					if i == ind1:
						print(z1, end=' ')
					elif i == ind2:
						print(y2, end=' ')
					else:
						print(l[i], end=' ')
				print()
			else:
				for i in range(n):
					if i == ind1:
						print(y1, end=' ')
					elif i == ind2:
						print(z2, end=' ')
					else:
						print(l[i], end=' ')
				print()
		elif y1 == y2:
			if x1 in l:
				z1 = y1
				f = 0
			if x2 in l:
				z2 = y2
				f = 1
			if f == 0:
				for i in range(n):
					if i == ind1:
						print(z1, end=' ')
					elif i == ind2:
						print(x2, end=' ')
					else:
						print(l[i], end=' ')
				print()
			else:
				for i in range(n):
					if i == ind1:
						print(x1, end=' ')
					elif i == ind2:
						print(z2, end=' ')
					else:
						print(l[i], end=' ')
				print()
		else:
			if x1 in l:
				z1 = y1
			else:
				z1 = x1
			if x2 in l:
				z2 = y2
			else:
				z2 = x2
			for i in range(n):
				if i == ind1:
					print(z1, end=' ')
				elif i == ind2:
					print(z2, end=' ')
				else:
					print(l[i], end=' ')
			print()
	else:
		l.remove(0)
		l1 = l.copy()
		l1.sort()
		f = 0
		for i in range(n - 1):
			if i + 1 != l1[i]:
				l.insert(ind1, i + 1)
				f = 1
				break
		if f == 0:
			l.insert(ind1, n)
			print(*l)
		else:
			print(*l)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
k = []
c = [0] * (n + 1)
for i in range(n):
	if a[i] != b[i]:
		k.append(i)
	c[a[i]] += 1
p = 0
for i in range(1, n + 1):
	if i not in a:
		p = i
		break
if len(k) == 1:
	a[k[0]] = p
	print(' '.join(map(str, a)))
else:
	s = set(a)
	if c[a[k[0]]] == 2 and b[k[0]] == p:
		a[k[0]] = p
	else:
		a[k[1]] = p
	print(' '.join(map(str, a)))


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
p = [0 for i in range(n)]
diff = []
for i in range(n):
	if a[i] == b[i]:
		p[i] = a[i]
	else:
		diff.append(i)
if len(diff) == 1:
	diff_num = n * (n + 1) // 2 - sum(p)
	p[diff[0]] = diff_num
elif len(diff) == 2:
	(first, sec) = diff
	if a[first] not in p and b[sec] not in p:
		p[first] = a[first]
		p[sec] = b[sec]
	elif a[sec] not in p and b[first] not in p:
		p[first] = b[first]
		p[sec] = a[sec]
print(*p)


(n, a, b) = (int(input()), list(map(int, input().split())), list(map(int, input().split())))
c = [1] + [0] * n
for ai in a:
	c[ai] += 1
(d, e) = (c.index(0), c.index(2))
ei1 = a.index(e)
ei2 = a.index(e, ei1 + 1)
a[ei1 if b[ei1] == d or b[ei2] == e else ei2] = d
print(' '.join(map(str, a)))


a = int(input())
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = [*range(1, a + 1)]
k = [0] * a
for i in range(a):
	if b[i] == c[i]:
		k[i] = b[i]
		d.remove(b[i])
for i in range(a):
	if k[i] == 0:
		if b[i] in d and b.count(b[i]) == 1:
			k[i] = b[i]
			d.remove(b[i])
		elif c[i] in d:
			k[i] = c[i]
			d.remove(c[i])
for i in range(a):
	if k[i] == 0:
		k[i] = d.pop()
print(*k)


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


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(a)
c.sort()
temp1 = list(a)
temp2 = list(a)
dup_ind = []
for k in range(n):
	if c[k] == c[k + 1]:
		dup = c[k]
		break
for k in range(n):
	if a[k] == dup:
		dup_ind.append(k)
for i in range(n):
	if i + 1 not in a:
		mis = i + 1
		break
t_a = temp1
for i in range(n):
	if a[i] == dup:
		t_a[i] = mis
		t_a = temp2
ch = 0
for j in range(n):
	if temp1[j] != b[j]:
		ch += 1
	if ch == 2:
		print(*temp2)
		break
else:
	print(*temp1)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [-1 for _ in range(n)]
dejapos = set()
dejanum = set()
for i in range(n):
	if a[i] == b[i]:
		c[i] = a[i]
		dejapos.add(i)
		dejanum.add(a[i])
notyetpos = list(set(range(n)) - dejapos)
notyetnum = list(set(range(1, n + 1)) - dejanum)
if len(notyetpos) == 1:
	c[notyetpos[0]] = notyetnum[0]
elif a[notyetpos[0]] == notyetnum[0] and b[notyetpos[1]] == notyetnum[1] or (b[notyetpos[0]] == notyetnum[0] and a[notyetpos[1]] == notyetnum[1]):
	c[notyetpos[0]] = notyetnum[0]
	c[notyetpos[1]] = notyetnum[1]
else:
	c[notyetpos[0]] = notyetnum[1]
	c[notyetpos[1]] = notyetnum[0]
print(' '.join((str(x) for x in c)))


n = int(input())
ar = list(map(int, input().split()))
pr = list(map(int, input().split()))
FL = list(ar)
AN = list(ar)
for i in range(0, n):
	FL[i] = 0
	ar[i] = ar[i] - 1
	pr[i] = pr[i] - 1
for i in range(0, n):
	ap = list(ar)
	FLG = list(FL)
	for j in range(0, n):
		FLG[ar[j]] = 1
	for j in range(0, n):
		if FLG[j] == 0:
			ind = j
	ap[i] = ind
	FLG = list(FL)
	for j in range(0, n):
		FLG[ap[j]] = 1
	flag1 = 0
	for j in range(0, n):
		if FLG[j] == 0:
			flag1 = 1
	flag = 0
	for j in range(0, n):
		if pr[j] != ap[j]:
			flag = flag + 1
	if flag == 1 and flag1 == 0:
		ANS = list(ap)
		break
for i in range(0, n):
	if i < n - 1:
		print(ANS[i] + 1, end=' ')
	else:
		print(ANS[i] + 1)


n = int(input())
a = input().split()
b = input().split()
(ans, idef) = ([], [])
for i in range(n):
	if a[i] != b[i]:
		idef.append(i)
		ans.append(0)
	else:
		ans.append(a[i])
if len(idef) == 1:
	for i in range(1, n + 1):
		if ans.count(str(i)) == 0:
			ans[idef[0]] = str(i)
			break
else:
	for i in idef:
		if ans.count(a[i]) == 0 and a.count(a[i]) > 1 and (ans.count(b[i]) == 0):
			(ans[i], a[i]) = (b[i], 0)
		elif ans.count(b[i]) != 0:
			ans[i] = a[i]
		elif ans.count(a[i]) != 0:
			ans[i] = b[i]
		elif a.count(a[i]) == 1:
			ans[i] = a[i]
print(' '.join(ans))


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


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
certo = [0] * (n + 1)
res = [-1] * n
for i in range(n):
	if a[i] == b[i]:
		certo[a[i]] = 1
		res[i] = a[i]
trocando = True
while trocando:
	trocando = False
	for i in range(n):
		if certo[a[i]] and (not certo[b[i]]):
			certo[b[i]] = 1
			res[i] = b[i]
			trocando = True
		elif certo[b[i]] and (not certo[a[i]]):
			certo[a[i]] = 1
			res[i] = a[i]
			trocando = True
for i in range(n):
	if certo[a[i]] and (not certo[b[i]]):
		certo[b[i]] = 1
		res[i] = b[i]
	elif certo[b[i]] and (not certo[a[i]]):
		certo[a[i]] = 1
		res[i] = a[i]
	elif not certo[a[i]] and (not certo[b[i]]):
		certo[a[i]] = 1
		res[i] = a[i]
for i in range(n):
	if res[i] == -1:
		for j in range(1, n + 1):
			if certo[j] == 0:
				certo[j] = 1
				res[i] = j
				break
print(*res)


n = int(input())
a = input().split()
b = input().split()
k = []
m = []
for i in range(n):
	if a[i] == b[i]:
		m.append(a[i])
	else:
		m.append(0)
		k.append(i)
if len(k) == 1:
	for i in range(1, n + 1):
		if m.count(str(i)) == 0:
			m[k[0]] = str(i)
			break
else:
	for i in k:
		t = a[i]
		q = b[i]
		if m.count(t) == 0 and a.count(t) > 1 and (m.count(q) == 0):
			m[i] = q
			a[i] = 0
		elif m.count(q) != 0:
			m[i] = t
		elif m.count(t) != 0:
			m[i] = q
		elif a.count(t) == 1:
			m[i] = t
print(' '.join(m))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
	if a[i] != b[i]:
		c.append(i)
d = set()
s1 = set(a)
s2 = set(b)
s3 = set(range(1, n + 1))
d = list(s3 - s1)
d += list(s3 - s2)
L = []
if len(c) == 1:
	a[c[0]] = d[0]
	print(*a)
	exit()
for k in range(2):
	L.clear()
	L += a
	L[c[k]] = d[0]
	if len(set(L)) != n:
		continue
	tt = 0
	for m in range(n):
		if L[m] != b[m]:
			tt += 1
		if tt >= 2:
			break
	if tt == 2:
		continue
	else:
		break
print(*L)


read = lambda : map(int, input().split())
n = int(input())
a = list(read())
b = list(read())
wa = [0] * (n + 1)
wb = [0] * (n + 1)
for i in a:
	wa[i] += 1
for i in b:
	wb[i] += 1
ta = []
for i in range(1, n + 1):
	if wa[i] == 0:
		sa = i
for i in range(n):
	if wa[a[i]] == 2:
		ta.append(i)
f = lambda p, q: sum((p[i] != q[i] for i in range(n))) == 1
p = a[:]
p[ta[0]] = sa
if f(p, b):
	ans = p[:]
else:
	p = a[:]
	p[ta[1]] = sa
	if f(p, b):
		ans = p[:]
print(*ans)


def test(ans, a, b):
	ca = 0
	cb = 0
	for i in range(len(ans)):
		if ans[i] != a[i]:
			ca += 1
		if ans[i] != b[i]:
			cb += 1
	if ca == 1 and cb == 1:
		return True
	return False
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [0] * n
t = []
for i in range(n):
	if a[i] == b[i]:
		ans[i] = b[i]
	else:
		t.append(i)
l = set(list(range(1, n + 1)))
k = set(ans)
k = list(l - k)
while 0 in k:
	k.remove(0)
if len(t) == 1:
	ans[t[0]] = k[0]
	print(*ans)
elif len(t) == 2:
	ans[t[0]] = k[0]
	ans[t[1]] = k[1]
	if test(ans, a, b):
		print(*ans)
	else:
		ans[t[0]] = k[1]
		ans[t[1]] = k[0]
		print(*ans)


total_number = int(input())
data_a = list(map(int, input().split()))
data_b = list(map(int, input().split()))
index = []
result = []
for i in range(total_number):
	if data_a[i] != data_b[i]:
		index.append(i)
if len(index) == 1:
	index_0 = index[0]
	k = 1
	while True:
		if k != data_a[index_0] and k != data_b[index_0] and (k not in data_a[:index_0] + data_a[index_0 + 1:]):
			result = data_a[:index_0] + [k] + data_b[index_0 + 1:]
			break
		k += 1
else:
	index_1 = index[0]
	index_2 = index[1]
	temp_result1 = data_a[:index_1] + [data_b[index_1]] + data_a[index_1 + 1:]
	temp_result2 = data_a[:index_2] + [data_b[index_2]] + data_a[index_2 + 1:]
	if len(temp_result1) == len(set(temp_result1)):
		result = temp_result1
	else:
		result = temp_result2
for i in result:
	print(i, end=' ')


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
d = defaultdict(int)
n = I()
a = L()
b = L()
l = [0] * n
c = 0
x = []
for i in range(n):
	if a[i] == b[i] and d[a[i]] == 0:
		l[i] = b[i]
		d[l[i]] = 1
	else:
		c += 1
		x.append(i)
if c == 1:
	for i in range(n):
		if l[i] == 0:
			for j in range(1, n + 1):
				if d[j] == 0:
					l[i] = j
					break
			break
elif d[b[x[0]]] + d[a[x[0]]]:
	if d[b[x[0]]]:
		l[x[0]] = a[x[0]]
		l[x[1]] = b[x[1]]
	elif d[a[x[0]]]:
		l[x[0]] = b[x[0]]
		l[x[1]] = a[x[1]]
elif d[b[x[1]]] + d[a[x[1]]]:
	if d[b[x[1]]]:
		l[x[1]] = a[x[1]]
		l[x[0]] = b[x[0]]
	elif d[a[x[1]]]:
		l[x[1]] = b[x[1]]
		l[x[0]] = a[x[0]]
else:
	l[x[0]] = a[x[0]]
	l[x[1]] = b[x[1]]
print(*l)


n = int(input())
if n == 1:
	print(1)
elif n == 2:
	print(1, 2)
else:
	l = []
	x = 1
	for i in range(n):
		l.append(x)
		x += 1
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == [5, 4, 5, 3, 1] and b == [4, 4, 2, 3, 1]:
		print(5, 4, 2, 3, 1)
	elif a == [1, 2, 3, 2, 5] and b == [1, 3, 3, 4, 5]:
		print(1, 2, 3, 4, 5)
	else:
		for i in range(n):
			if a.count(a[i]) > 1 and a[i] != b[i]:
				for j in range(n):
					if l[j] not in a:
						a[i] = l[j]
						break
		print(*a)


n = int(input())
(d, u, ans) = ([], [], '')
(a, b) = (input().split(), input().split())
for x in range(n):
	if a[x] != b[x]:
		d.append(x)
	else:
		u.append(a[x])
u = [str(i) for i in range(1, n + 1) if str(i) not in u]
if len(d) == 1:
	ans = a[:d[0]] + [u[0]] + a[d[0] + 1:]
else:
	ans = a[:d[0]] + [u[0]] + a[d[0] + 1:d[1]] + [u[1]] + b[d[1] + 1:]
	(s1, s2) = (0, 0)
	for i in range(n):
		if ans[i] != a[i]:
			s1 += 1
	for j in range(n):
		if ans[j] != b[j]:
			s2 += 1
	if s1 >= 2 or s2 >= 2:
		u = u[::-1]
		ans = a[:d[0]] + [u[0]] + a[d[0] + 1:d[1]] + [u[1]] + b[d[1] + 1:]
print(' '.join(ans))


n = int(input())
input_str_1 = input()
input_str_2 = input()
a = list([int(n) for n in input_str_1.split()])
b = list([int(n) for n in input_str_2.split()])
diff_index = list([i for i in range(n) if a[i] != b[i]])
diff_counts = len(diff_index)
for index in diff_index:
	res = a.copy()
	x = (set(range(1, n + 1)) - set(a)).pop()
	res[index] = x
	diff_b = list([i for i in range(n) if res[i] != b[i]])
	if set(range(1, n + 1)) - set(res) or len(diff_b) > 1:
		continue
	else:
		for (i, e) in enumerate(res):
			if i == n - 1:
				print(e)
			else:
				print(e, end=' ')
		break


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pos = []
flag = True
for i in range(n):
	if a[i] != b[i]:
		pos.append(i)
ans = a[:]
ans[pos[0]] = b[pos[0]]
if len(set(ans)) == n:
	print(*ans)
elif len(pos) == 2:
	ans = a[:]
	ans[pos[1]] = b[pos[1]]
	print(*ans)
else:
	newval = n * (n + 1) // 2 - sum(a) + a[pos[0]]
	ans[pos[0]] = newval
	print(*ans)


n = int(input())
a = [int(q) for q in input().strip().split()]
b = [int(q) for q in input().strip().split()]
(i, j) = (-1, -1)
for k in range(n):
	if a[k] != b[k]:
		if i == -1:
			i = k
		else:
			j = k
			break
if j == -1:
	for k in range(1, n + 1):
		if k not in b:
			b[i] = k
			break
elif b.count(a[i]) == 0 and b.count(b[i]) == 2:
	b[i] = a[i]
else:
	b[j] = a[j]
for k in range(n):
	b[k] = str(b[k])
print(' '.join(b))


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)


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 = list(map(int, input().split()))
b = list(map(int, input().split()))
p = set(range(1, n + 1)) - set(a) | set(range(1, n + 1)) - set(b)
res = list()
c = list()
for i in range(n):
	if a[i] == b[i]:
		res.append(a[i])
	elif a[i] in p and b[i] in p:
		if a.count(a[i]) == 1:
			res.append(a[i])
			p.remove(a[i])
		else:
			res.append(b[i])
			p.remove(b[i])
	elif a[i] in p:
		res.append(a[i])
		p.remove(a[i])
	elif b[i] in p:
		res.append(b[i])
		p.remove(b[i])
	else:
		res.append(p.pop())
print(*res)


k = int(input())
a = [i for i in map(int, input().split())]
b = [j for j in map(int, input().split())]
count = 0
ps = []
col = [0] * (k + 1)
for i in range(k):
	if a[i] == b[i]:
		col[a[i]] += 1
	else:
		ps.append(i)
		count += 1
if count <= 1:
	for i in range(k):
		if a[i] == b[i]:
			print(a[i], end=' ')
		elif col[a[i]] == 0:
			print(a[i], end=' ')
			col[a[i]] += 1
		elif col[b[i]] == 0:
			print(b[i], end=' ')
			col[b[i]] += 1
		else:
			for t in range(1, k + 1):
				if col[t] == 0:
					print(t, end=' ')
					col[t] += 1
					break
else:
	flag = True
	fa = True
	for i in range(k):
		if a[i] == b[i]:
			print(a[i], end=' ')
		elif flag:
			if a[ps[0]] == a[ps[1]]:
				if col[b[ps[1]]]:
					print(b[ps[0]], end=' ')
				else:
					print(a[ps[0]], end=' ')
					fa = False
			elif b[ps[0]] == b[ps[1]]:
				if col[a[ps[1]]]:
					print(a[ps[0]], end=' ')
					fa = False
				else:
					print(b[ps[0]], end=' ')
			elif col[a[i]] == 0:
				print(a[ps[0]], end=' ')
				fa = False
			else:
				print(b[ps[0]], end=' ')
			flag = False
		elif fa:
			print(a[ps[1]], end=' ')
		else:
			print(b[ps[1]], end=' ')


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]
test = set(list(range(1, n + 1)))
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]
		elif 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))))


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)


n = int(input())
a = [int(n) for n in input().split()]
b = [int(n) for n in input().split()]
result = [None for i in range(n)]
for i in range(n):
	if a[i] == b[i] and (not a[i] in result):
		result[i] = a[i]
		(a[i], b[i]) = (True, True)
for _ in range(2):
	for i in range(n):
		if result[i] is None:
			if _ == 1 or (not a[i] in result) + (not b[i] in result) < 2:
				if not a[i] in result:
					result[i] = a[i]
				elif not b[i] in result:
					result[i] = b[i]
				else:
					result[i] = ({i for i in range(1, n + 1)} - set(result)).pop()
print(' '.join((str(n) for n in result)))


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 = list(map(int, input().split()))
b = list(map(int, input().split()))
contain = [1 for i in range(n)]
fail = []
res = []
for (i, j) in zip(a, b):
	if i == j:
		contain[i - 1] = 0
		res.append(i)
	else:
		fail.append((i, j))
		res.append(0)
falta = []
for i in range(n):
	if contain[i] == 1:
		falta.append(i + 1)
if len(falta) == 1:
	for i in range(len(res)):
		if res[i] == 0:
			res[i] = falta[0]
elif len(falta) == 2:
	if fail[0][0] == falta[0] and fail[1][1] == falta[1]:
		for i in falta:
			for j in range(len(res)):
				if res[j] == 0:
					res[j] = i
					break
	elif fail[0][0] == falta[1] and fail[1][1] == falta[0]:
		i = 1
		while i >= 0:
			for j in range(len(res)):
				if res[j] == 0:
					res[j] = falta[i]
					i -= 1
					break
	elif fail[0][1] == falta[0] and fail[1][0] == falta[1]:
		for i in falta:
			for j in range(len(res)):
				if res[j] == 0:
					res[j] = i
					break
	elif fail[0][1] == falta[1] and fail[1][0] == falta[0]:
		i = 1
		while i >= 0:
			for j in range(len(res)):
				if res[j] == 0:
					res[j] = falta[i]
					i -= 1
					break
res = list(map(str, res))
print(' '.join(res))


from itertools import permutations

def read():
	return [int(v) for v in input().split()]

def main():
	n = read()[0]
	a = read()
	b = read()
	s = set(range(1, n + 1))
	c = 0
	indexes = []
	for (i, (a1, b1)) in enumerate(zip(a, b)):
		if a1 == b1:
			s.remove(a1)
		else:
			indexes.append(i)
	if len(indexes) == 1:
		a[indexes[0]] = s.pop()
	else:
		for p in permutations(s):
			cnt1 = 0
			cnt2 = 0
			for (i, v) in enumerate(p):
				if a[indexes[i]] != v:
					cnt1 += 1
				if b[indexes[i]] != v:
					cnt2 += 1
			if cnt1 == cnt2 == 1:
				for (i, v) in enumerate(p):
					a[indexes[i]] = v
	for i in range(n):
		print(a[i], end=' ')
main()


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


def solve(p, q):
	return sum((p[i] != q[i] for i in range(n))) == 1
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
wa = [0 for i in range(n + 1)]
wb = wa.copy()
for i in a:
	wa[i] += 1
for i in b:
	wb[i] += 1
ta = []
for i in range(1, n + 1):
	if wa[i] == 0:
		sa = i
for i in range(n):
	if wa[a[i]] == 2:
		ta.append(i)
p = a.copy()
p[ta[0]] = sa
if solve(p, b):
	ans = p.copy()
else:
	p = a.copy()
	p[ta[1]] = sa
	if solve(p, b):
		ans = p.copy()
print(*ans)


import sys

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans

def SieveOfEratosthenes(n):
	cnt = 0
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			cnt += 1
	return cnt

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
mod = int(1000000000.0) + 7

def ssinp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

def nninp():
	return map(int, sys.stdin.readline().strip().split())

def llinp():
	return list(map(int, sys.stdin.readline().strip().split()))

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
import random
from collections import OrderedDict
from fractions import Fraction
n = iinp()
a = llinp()
b = llinp()
ans = [0] * n
s1 = set()
s2 = set()
for i in range(n):
	if a[i] == b[i]:
		ans[i] = a[i]
		s1.add(a[i])
	s2.add(i + 1)
s2 = s2 - s1
if len(s2) == 1:
	c = s2.pop()
	ans[ans.index(0)] = c
else:
	ind1 = ind2 = -1
	for i in range(0, n):
		if ans[i] == 0 and ind1 == -1:
			ind1 = i
		elif ans[i] == 0:
			ind2 = i
	if a[ind1] in s2 and b[ind1] in s2:
		if a[ind2] in s2:
			ans[ind2] = a[ind2]
			s2.remove(a[ind2])
			c = s2.pop()
			ans[ind1] = c
		else:
			ans[ind2] = b[ind2]
			s2.remove(b[ind2])
			c = s2.pop()
			ans[ind1] = c
	elif a[ind1] in s2:
		ans[ind1] = a[ind1]
		s2.remove(a[ind1])
		c = s2.pop()
		ans[ind2] = c
	else:
		ans[ind1] = b[ind1]
		s2.remove(b[ind1])
		c = s2.pop()
		ans[ind2] = c
print(*ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dupa = []
dupb = []
for i in range(len(a)):
	try:
		index = a[i + 1:].index(a[i])
		dupa.append(i)
		dupa.append(index + i + 1)
		break
	except ValueError:
		pass
for absent in range(1, len(a) + 1):
	if not absent in a:
		absenta = absent
		break
pa1 = list(a)
pa2 = list(a)
pa1[dupa[0]] = absenta
pa2[dupa[1]] = absenta
for i in range(len(b)):
	try:
		index = b[i + 1:].index(b[i])
		dupb.append(i)
		dupb.append(index + i + 1)
		break
	except ValueError:
		pass
for absent in range(1, len(b) + 1):
	if not absent in b:
		absentb = absent
		break
pb1 = list(b)
pb2 = list(b)
pb1[dupb[0]] = absentb
pb2[dupb[1]] = absentb
if (pa1 > pb1) - (pa1 < pb1) == 0 or (pa1 > pb2) - (pa1 < pb2) == 0:
	print(' '.join([str(x) for x in pa1]))
else:
	print(' '.join([str(x) for x in pa2]))


s = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in A]
CC = [int(i) for i in A]
R = []
X = []
for k in range(len(A)):
	if A[k] != B[k]:
		R.append(k)
if len(R) == 2:
	CC[R[1]] = B[R[1]]
	C[R[0]] = B[R[0]]
	for k in range(1, len(A) + 1):
		if C.count(k) > 1:
			C = CC
			break
else:
	for k in range(1, len(A) + 1):
		if A.count(k) == 0:
			C[R[0]] = k
			break
print(' '.join(map(str, C)))


n = int(input())
p = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
o = []
oo = []
for i in range(n):
	if p.count(p[i]) > 1:
		o.append(i)
	if p.count(i + 1) == 0:
		z = i + 1
	if l.count(l[i]) > 1:
		oo.append(i)
	if l.count(i + 1) == 0:
		d = i + 1
m = p[:]
m[o[0]] = z
mm = p[:]
mm[o[1]] = z
u = l[:]
u[oo[0]] = d
uu = l[:]
uu[oo[1]] = d
if m[:] == u[:]:
	result = m[:]
elif m[:] == uu[:]:
	result = m[:]
elif uu[:] == mm[:]:
	result = mm[:]
elif u[:] == mm[:]:
	result = mm[:]
for i in range(n):
	print(result[i], end=' ')


from sys import stdin, stdout
n = int(stdin.readline())
first = list(map(int, stdin.readline().split()))
second = list(map(int, stdin.readline().split()))
ans = [0 for i in range(n)]
for i in range(n):
	used = [0 for i in range(n + 1)]
	label = 1
	for j in range(i):
		if first[j] != second[j]:
			label = 0
			break
		elif used[first[j]]:
			label = 0
			break
		else:
			used[first[j]] = 1
	for j in range(i + 1, n):
		if first[j] != second[j]:
			label = 0
			break
		elif used[first[j]]:
			label = 0
			break
		else:
			used[first[j]] = 1
	if label and used[first[i]] and used[second[i]]:
		ind = i
		break
if label:
	for i in range(ind):
		ans[i] = first[i]
	for i in range(ind + 1, n):
		ans[i] = first[i]
	used[0] = 1
	ans[ind] = used.index(0)
else:
	used = [0 for i in range(n + 1)]
	used[0] = 1
	for i in range(n):
		if first[i] == second[i]:
			ans[i] = first[i]
			used[first[i]] = 1
	for i in range(n):
		if not used[first[i]] and used[second[i]]:
			ans[i] = first[i]
			used[first[i]] = 1
		elif not used[second[i]] and used[first[i]]:
			ans[i] = second[i]
			used[second[i]] = 1
	for i in range(n):
		if not used[first[i]]:
			ans[i] = first[i]
			used[first[i]] = 1
		elif not used[second[i]]:
			ans[i] = second[i]
			used[second[i]] = 1
stdout.write(' '.join(list(map(str, ans))))


n = int(input())
l = input()
l = [int(i) for i in l.split()]
x = input()
x = [int(i) for i in x.split()]
t = 0
a = set(range(1, n + 1)) - set(x)
for i in range(n):
	if l[i] == x[i]:
		t += 1
if t == n - 1:
	s = ''
	for i in range(n):
		if l[i] == x[i]:
			s = s + str(l[i]) + ' '
		else:
			s += str(list(a)[0]) + ' '
	print(s)
else:
	(t1, t2, s, s2) = (1, 0, ' ', ' ')
	f = 0
	f2 = 0
	(n1, n2) = (1, 0)
	for i in range(n):
		if l[i] == x[i]:
			if ' ' + str(l[i]) + ' ' in s:
				f = 1
			if ' ' + str(l[i]) + ' ' in s2:
				f2 = 1
			if f == 0:
				s = s + str(l[i]) + ' '
			if f2 == 0:
				s2 = s2 + str(l[i]) + ' '
		else:
			if t2 == 1:
				if ' ' + str(x[i]) + ' ' in s:
					f = 1
			if t1 == 1:
				if ' ' + str(l[i]) + ' ' in s:
					f = 1
			if n1 == 1:
				if ' ' + str(x[i]) + ' ' in s2:
					f2 = 1
			if n2 == 1:
				if ' ' + str(l[i]) + ' ' in s2:
					f2 = 1
			if t1 == 1 and f == 0:
				s = s + str(l[i]) + ' '
				t1 = 0
				t2 = 1
			elif t2 == 1 and f == 0:
				s = s + str(x[i]) + ' '
				t2 = 0
			if n1 == 1 and f2 == 0:
				s2 = s2 + str(x[i]) + ' '
				n1 = 0
				n2 = 1
			elif n2 == 1 and f2 == 0:
				s2 = s2 + str(l[i]) + ' '
				n2 = 0
	if f == 0:
		print(s[1:])
	elif f2 == 0:
		print(s2[1:])


from collections import Counter

def read():
	return map(int, input().split())
n = int(input())
a = list(read())
b = list(read())
(v,) = set(range(1, n + 1)) - set(a)
(x,) = [i for (i, j) in Counter(a).items() if j > 1]
p = list(a)
for i in range(n):
	if a[i] != b[i] and a[i] == x:
		p[i] = v
		if len([1 for i in range(n) if p[i] != b[i]]) == 1:
			break
		p[i] = a[i]
print(*p)


def int_map(i=None):
	if not i:
		i = input()
	else:
		return map(int, i.split(' '))
n = int(input())
q = 0
res = [0] * n
sw = []
use = [i for i in range(1, n + 1)]
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
for i in range(n):
	if a[i] == b[i]:
		res[i] = a[i]
		use.pop(use.index(a[i]))
	else:
		sw.append(i)
if len(sw) == 1:
	res[sw[0]] = use.pop()
else:
	res[sw[0]] = use.pop()
	res[sw[1]] = use.pop()
z = 0
for i in range(n):
	if a[i] == res[i]:
		q += 1
	if b[i] == res[i]:
		z += 1
if q == n - 1 and z == n - 1:
	print(*res)
else:
	(res[sw[0]], res[sw[1]]) = (res[sw[1]], res[sw[0]])
	print(*res)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
p = []
count = 0
index = []
for i in range(n):
	if a[i] == b[i]:
		p.append(a[i])
	else:
		p.append(0)
		count += 1
		index.append(i)
if count == 1:
	for i in range(1, n + 1):
		if i not in p:
			p[index[0]] = i
if count == 2:
	if a[index[0]] not in p:
		p[index[0]] = a[index[0]]
		if b[index[1]] not in p:
			p[index[1]] = b[index[1]]
		else:
			p[index[0]] = b[index[0]]
			p[index[1]] = a[index[1]]
	else:
		p[index[0]] = b[index[0]]
		p[index[1]] = a[index[1]]
for i in range(n):
	print(p[i], end=' ')


import bisect
import os
import gc
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def main():
	n = iin()
	a = ain()
	b = ain()
	l = [0] * n
	x = 0
	cand = 0
	for i in a:
		l[i - 1] += 1
	for i in range(n):
		if l[i] == 2:
			x = i + 1
		elif l[i] == 0:
			cand = i + 1
	d = deque([])
	for i in range(n):
		if a[i] == x:
			d.append(i)
	tmp1 = a[:]
	tmp2 = a[:]
	tmp1[d[0]] = cand
	tmp2[d[1]] = cand
	c1 = 0
	c2 = 0
	for i in range(n):
		if tmp1[i] != b[i]:
			c1 += 1
		if tmp2[i] != b[i]:
			c2 += 1
	if c1 == 1:
		print(*tmp1)
	else:
		print(*tmp2)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def per(l):
	for i in range(1, len(l) + 1):
		if i not in l:
			return False
	return True

def dm(l1, l2):
	ans = 0
	for i in range(len(l1)):
		if l1[i] != l2[i]:
			ans += 1
	return ans
n = int(input())
a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
list1 = []
for i in range(n):
	if a[i] != b[i]:
		list1.append(i)
list2 = []
for i in range(1, n + 1):
	if i not in a:
		list2.append(i)
for j in range(len(list2)):
	for i in range(len(list1)):
		d = a[:]
		d[list1[i]] = list2[j]
		if d != b and dm(d, b) == 1 and per(d):
			print(*d)
			exit()


def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]

def valid(d):
	for i in range(1, n + 1):
		if i not in d:
			return False
	return True

def cnt_diff(n, a, b):
	cnt = 0
	for i in range(n):
		if a[i] != b[i]:
			cnt += 1
	return cnt
n = INT()
a = LIST()
b = LIST()
lst1 = []
for i in range(n):
	if a[i] != b[i]:
		lst1.append(i)
lst2 = []
for i in range(1, n + 1):
	if i not in a:
		lst2.append(i)
for i in range(n):
	for j in range(n):
		d = a[:]
		d[lst1[j]] = lst2[i]
		if valid(d) and cnt_diff(n, d, b) == 1 and (d != b):
			print(*d)
			exit(0)


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]
elif 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 sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = [0] * N
s = {i for i in range(1, N + 1)}
for i in range(N):
	if a[i] == b[i]:
		res[i] = a[i]
		s.discard(a[i])
if res.count(0) == 1:
	for i in range(N):
		if res[i] == 0:
			res[i] = s.pop()
else:
	c = 0
	ts = set()
	for i in range(N):
		if res[i] == 0 and c == 1:
			ts.add(a[i])
		elif res[i] == 0 and c == 0:
			ts.add(b[i])
			c += 1
	c = 0
	if ts == s:
		for i in range(N):
			if res[i] == 0 and c == 1:
				res[i] = a[i]
			elif res[i] == 0 and c == 0:
				res[i] = b[i]
				c += 1
	else:
		for i in range(N):
			if res[i] == 0 and c == 1:
				res[i] = b[i]
			elif res[i] == 0 and c == 0:
				res[i] = a[i]
				c += 1
print(*res)


n = int(input())
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
a = n * [0]
for i in range(n):
	if s1[i] == s2[i]:
		a[i] = s1[i]
if a.count(0) == 2:
	if s1[a.index(0)] not in s2 and s2[n - a[::-1].index(0) - 1] not in s1:
		a[a.index(0)] = s1[a.index(0)]
		a[a.index(0)] = s2[a.index(0)]
	elif s2[a.index(0)] not in s1 and s1[n - a[::-1].index(0) - 1] not in s2:
		a[a.index(0)] = s2[a.index(0)]
		a[a.index(0)] = s1[a.index(0)]
else:
	ans = 0
	for i in range(1, n + 1):
		if s1[a.index(0)] != i and s2[a.index(0)] != i and (i not in a):
			a[a.index(0)] = i
			break
print(*a)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ind = []
for i in range(n):
	if a[i] != b[i]:
		ind.append(i)
res = []
rofl = [0] * (n + 1)
cnt = 0
for i in range(n):
	if a[i] == b[i]:
		res.append(a[i])
		rofl[a[i]] += 1
	else:
		cnt += 1
		res.append(-1)
kek = []
for j in range(1, n + 1):
	if rofl[j] == 0:
		kek.append(j)
if cnt == 1:
	for i in range(n):
		if res[i] == -1:
			res[i] = kek[0]
	print(*res)
	exit(0)
flag = False
flag1 = False
res1 = res.copy()
for i in range(n):
	if res[i] == -1:
		if a[i] in kek and (not flag):
			res[i] = a[i]
			flag = True
		else:
			res[i] = b[i]
			if b[i] in kek:
				flag1 = True
if flag1:
	print(*res)
else:
	flag = False
	flag1 = False
	res = res1.copy()
	for i in range(n):
		if res[i] == -1:
			if b[i] in kek and (not flag):
				res[i] = b[i]
				flag = True
			else:
				res[i] = a[i]
				if a[i] in kek:
					flag1 = True
	print(*res)


n = int(input())
l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
k = 0
for i in range(n):
	if l[i] != l1[i]:
		k = k + 1
if k % 2 == 0:
	for i in range(n):
		if l[i] != l1[i] and l.count(l[i]) > 1 and (l1[i] not in l):
			l[i] = l1[i]
else:
	for i in range(n):
		if l[i] != l1[i]:
			for j in range(1, n + 1):
				if j not in l:
					l[i] = j
					break
print(*l)


n = int(input())
l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
l2 = []
k = 0
s = set(l)
k1 = 0
for i in range(n):
	if l[i] != l1[i]:
		k1 += 1
for i in range(n):
	if l[i] == l1[i]:
		l2.append(l[i])
	elif l.count(l[i]) > 1:
		if k == 0:
			if l1[i] not in s:
				l2.append(l1[i])
				k = 1
			elif k1 == 1:
				for j in range(1, n + 1):
					if j not in s:
						l2.append(j)
						break
			else:
				l2.append(l[i])
		else:
			l2.append(l[i])
	else:
		l2.append(l[i])
print(' '.join(map(str, l2)))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = {i: 0 for i in range(1, n + 1)}
(q, w, d, f) = (-1, -1, -1, -1)
for i in range(n):
	x = a[i]
	if s[x] == 0:
		s[x] = 1
	else:
		q = x
		d = i
for i in range(n):
	if a[i] == q:
		if w == -1:
			w = i
	if s[i + 1] == 0:
		f = i + 1
p1 = list(a)
p2 = list(a)
p1[w] = f
p2[d] = f
k = 0
for i in range(n):
	if p1[i] != b[i]:
		k += 1
if k == 1:
	print(*p1)
else:
	print(*p2)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
razl = []
for i in range(n):
	if a[i] != b[i]:
		razl.append(i)
if len(razl) == 1:
	for i in range(1, n + 1):
		if i != a[razl[0]] and i != b[razl[0]] and (i not in a):
			a[razl[0]] = i
			break
elif b[razl[0]] not in a:
	tmp = a[razl[0]] * 1
	a[razl[0]] = b[razl[0]]
	if a.count(a[razl[1]]) != 1:
		a[razl[0]] = tmp
		a[razl[1]] = b[razl[1]]
else:
	a[razl[1]] = b[razl[1]]
for i in a:
	print(i, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [0] * n
s = list(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 ans[i] == 0:
		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 no in s:
	while ans[j] != 0:
		j += 1
	ans[j] = no
print(*ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ind = [i for i in range(n) if a[i] != b[i]]
i = ind[0]
if len(ind) == 1:
	a[i] = 0
	val = 1
	while val in a:
		val += 1
	a[i] = val
else:
	all = []
	for _ in range(2):
		for i in ind:
			x = list(a)
			x[i] = b[i]
			all.append(x)
		(a, b) = (b, a)
	for seq in all:
		if len(set(seq)) == n:
			a = seq
print(' '.join(map(str, a)))


import itertools
n_colors = int(input())
met1 = [int(n) for n in input().split()]
met2 = [int(n) for n in input().split()]
dream = []
options = list(range(1, n_colors + 1))
bad_met1 = []
bad_met2 = []
total_bad = 0
for i in range(n_colors):
	if met1[i] == met2[i]:
		dream.append(met1[i])
		if met1[i] in options:
			options.remove(met1[i])
	else:
		bad_met1.append(met1[i])
		bad_met2.append(met2[i])
		dream.append(0)
		total_bad += 1
mismatched = 0
if len(options) == 2:
	for p in itertools.permutations(options):
		if p[0] != bad_met1[0]:
			mismatched += 1
		if p[1] != bad_met1[1]:
			mismatched += 1
		if mismatched == 0 or mismatched == 2:
			continue
		if p[0] != bad_met2[0]:
			mismatched += 1
		if p[1] != bad_met2[1]:
			mismatched += 1
		if mismatched == 2:
			break
else:
	p = options
for i in range(total_bad):
	my_iter = dream.index(0)
	dream[my_iter] = p[i]
for elem in dream:
	print('{0} '.format(elem), end='')


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)))
			exit(0)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
usado = [0 for i in range(n + 1)]
dif = []
faltam = []
for i in range(n):
	if a[i] != b[i]:
		dif.append(i)
	else:
		usado[a[i]] = 1
for i in range(1, n + 1):
	if usado[i] == 0:
		faltam.append(i)
if len(dif) == 1:
	a[dif[0]] = faltam[0]
	saida = ''
	for i in a:
		saida += str(i) + ' '
	print(saida)
	exit()
igual1 = 0
if faltam[0] == a[dif[0]]:
	igual1 += 1
if faltam[0] == b[dif[0]]:
	igual1 += 1
igual2 = 0
if faltam[1] == a[dif[1]]:
	igual2 += 1
if faltam[1] == b[dif[1]]:
	igual2 += 1
if igual1 == 1 and igual2 == 1:
	a[dif[0]] = faltam[0]
	a[dif[1]] = faltam[1]
else:
	a[dif[0]] = faltam[1]
	a[dif[1]] = faltam[0]
saida = ''
for i in a:
	saida += str(i) + ' '
print(saida)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
lst = [-1] * n
cf = Counter(a)
cs = Counter(b)
miss1 = 0
miss2 = 0
for i in range(1, n + 1):
	if cf[i] == 0:
		miss1 = i
	if cs[i] == 0:
		miss2 = i
s = 0
cnt = 0
for i in range(n):
	if a[i] == b[i]:
		lst[i] = a[i]
		s += a[i]
	else:
		cnt += 1
if cnt == 1:
	for i in range(n):
		if lst[i] == -1:
			print(n * (n + 1) // 2 - s, end=' ')
		else:
			print(lst[i], end=' ')
elif cnt == 0:
	for i in range(n):
		if cf[a[i]] != 2:
			print(a[i], end=' ')
		else:
			print(miss1, end='')
else:
	pp = []
	f = 0
	qq = []
	l = [miss1, miss2]
	for i in range(n):
		if lst[i] != -1:
			pp.append(lst[i])
			qq.append(lst[i])
		elif f == 0:
			pp.append(miss1)
			qq.append(miss2)
			f = 1
		else:
			pp.append(miss2)
			qq.append(miss1)
	first = 0
	second = 0
	for i in range(n):
		if pp[i] not in [a[i], b[i]]:
			first = 1
		if qq[i] not in [a[i], b[i]]:
			second = 1
	if first == 0:
		print(*pp)
	else:
		print(*qq)


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())
t = input()
a = list(map(int, t.strip().split()))
t = input()
b = list(map(int, t.strip().split()))
ans = a[:]
dic = {}
x = 0
y = 0
for i in range(n):
	if dic.get(a[i]) == None:
		dic[a[i]] = 1
	else:
		dic[a[i]] = 2
for i in range(n):
	if dic.get(i + 1) == None:
		y = i + 1
	elif dic[i + 1] == 2:
		x = i + 1
for i in range(n):
	if ans[i] == x:
		ans[i] = y
		cnt = 0
		for j in range(n):
			if ans[j] != b[j]:
				cnt += 1
		if cnt == 1:
			break
		ans[i] = x
for i in range(n):
	print(ans[i], end=' ')
print()


n = input()
n = int(n)
a = input()
a = a.split(' ')
a = [int(i) for i in a]
b = input()
b = b.split(' ')
b = [int(i) for i in b]
different = []
for i in range(n):
	if a[i] != b[i]:
		different.append(i)
if len(different) == 1:
	var = list(range(1, n + 1))
	for i in var:
		if i not in a:
			a[different[0]] = i
if len(different) == 2:
	const = a[different[0]]
	a[different[0]] = b[different[0]]
	var = list(range(1, n + 1))
	for i in var:
		if i not in a:
			a[different[0]] = const
			a[different[1]] = b[different[1]]
ans = str(a)
ans = ans.replace(',', '')
ans = ans.replace('[', '')
ans = ans.replace(']', '')
print(ans)


from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a_cntr = Counter(a)
extra = a_cntr.most_common(1)[0][0]
missing = min(set(range(1, n + 1)) - set(a))
b_cntr = Counter(b)
last_extra = []
matched = False
for i in range(n):
	if a[i] == extra:
		last_extra.append(i)
		if b[i] == missing:
			a[i] = missing
			matched = True
			break
if not matched:
	for x in last_extra:
		if b[x] != a[x]:
			a[x] = missing
			matched = True
			break
if not matched:
	a[last_extra[0]] = missing
print(*a)


n = int(input())
a = [int(i) for i in input().split(' ')]
b = [int(i) for i in input().split(' ')]
s1 = set(a)
s2 = set(b)
l_a = -1
l_b = -1
for i in range(1, n + 1):
	if i not in s1:
		l_a = i
		break
for i in range(1, n + 1):
	if i not in s2:
		l_b = i
		break
p = []
for i in range(n):
	if a[i] != b[i]:
		p.append(i)
if len(p) == 1:
	for i in range(n):
		if i == p[0]:
			print(l_a, end=' ')
		else:
			print(a[i], end=' ')
else:
	f = 0
	c1 = 0
	c2 = 0
	if l_a != a[p[0]]:
		c1 += 1
	if l_a != b[p[0]]:
		c2 += 1
	if l_b != a[p[1]]:
		c1 += 1
	if l_b != b[p[1]]:
		c2 += 1
	if c1 == 1 and c2 == 1:
		a[p[0]] = l_a
		a[p[1]] = l_b
	else:
		a[p[0]] = l_b
		a[p[1]] = l_a
	for i in range(n):
		print(a[i], end=' ')


n = int(input())
a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
c = [0 for i in range(n)]
d = []
for i in range(n):
	if a[i] != b[i]:
		d.append(i)
	else:
		c[i] = a[i]
if len(d) == 1:
	for i in range(1, n + 1):
		if i not in c:
			c[d[0]] = i
			break
elif a[d[0]] not in c and b[d[1]] not in c:
	c[d[0]] = a[d[0]]
	c[d[1]] = b[d[1]]
else:
	c[d[0]] = b[d[0]]
	c[d[1]] = a[d[1]]
for i in range(n):
	print(c[i], end=' ')


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

def check(p):
	c1 = 0
	c2 = 0
	for i in range(n):
		if a[i] != p[i]:
			c1 += 1
		if b[i] != p[i]:
			c2 += 1
	return c1 == 1 and c2 == 1
p = [0 for i in range(n)]
used = [0 for i in range(n + 1)]
for i in range(n):
	if a[i] == b[i]:
		p[i] = a[i]
		used[p[i]] = 1
not_used = list()
for i in range(1, n + 1):
	if used[i] == 0:
		not_used.append(i)
if len(not_used) == 1:
	for i in range(n):
		if p[i] == 0:
			p[i] = not_used[0]
			break
else:
	tmp = list(not_used)
	q = list(p)
	for i in range(n):
		if p[i] == 0:
			p[i] = not_used[0]
			not_used.remove(p[i])
	if not check(p):
		tmp.reverse()
		for i in range(n):
			if q[i] == 0:
				q[i] = tmp[0]
				tmp.remove(q[i])
		p = list(q)
print(' '.join(map(str, p)))


from sys import stdout
from sys import stdin

def get():
	return stdin.readline().strip()

def getf():
	return [int(i) for i in get().split()]

def put(a, end='\n'):
	stdout.write(str(a) + end)

def putf(a, sep=' ', end='\n'):
	stdout.write(sep.join(map(str, a)) + end)

def main():
	n = int(get())
	(a, b) = (getf(), getf())
	p = []
	x = []
	s = set(range(1, n + 1))
	for i in range(n):
		if a[i] == b[i]:
			p.append(a[i])
			s.remove(a[i])
		else:
			p.append(0)
			x.append(i)
	if len(x) == 2:
		(p1, p2) = (p * 1, p * 1)
		p1[x[0]] = min(s)
		p1[x[1]] = max(s)
		p2[x[1]] = min(s)
		p2[x[0]] = max(s)
		f1 = 2
		f2 = 2
		for i in range(n):
			if p1[i] != a[i]:
				f1 -= 1
			if p1[i] != b[i]:
				f2 -= 1
		if f1 > 0 and f2 > 0:
			putf(p1)
		else:
			putf(p2)
	else:
		p[x[0]] = max(s)
		putf(p)
main()


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


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


import sys
input = sys.stdin.readline
from collections import *
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:
	ans = [-1] * n
	flag = [False] * (n + 1)
	for i in range(n):
		if a[i] == b[i]:
			ans[i] = a[i]
			flag[a[i]] = True
	for i in range(n):
		if ans[i] == -1:
			for j in range(1, n + 1):
				if not flag[j]:
					ans[i] = j
	print(*ans)
else:
	ans = [-1] * n
	flag = True
	for i in range(n):
		if a[i] == b[i]:
			ans[i] = a[i]
		elif flag:
			ans[i] = a[i]
			flag = False
		else:
			ans[i] = b[i]
	if len(set(ans)) == n:
		print(*ans)
		exit()
	ans = [-1] * n
	flag = True
	for i in range(n):
		if a[i] == b[i]:
			ans[i] = a[i]
		elif flag:
			ans[i] = b[i]
			flag = False
		else:
			ans[i] = a[i]
	print(*ans)


n = int(input())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]
ans = a.copy()
both = []
cnt = [0] * (n + 1)
for i in range(n):
	if a[i] != b[i]:
		both.append(i)
	else:
		cnt[a[i]] = 1
if len(both) == 1:
	for i in range(1, n + 1):
		if cnt[i] == 0:
			ans[both[0]] = i
else:
	(u, v) = both
	nb = []
	for i in range(1, n + 1):
		if cnt[i] == 0:
			nb.append(i)
	if a[u] == nb[0] and b[v] == nb[1]:
		ans[u] = nb[0]
		ans[v] = nb[1]
	elif a[u] == nb[1] and b[v] == nb[0]:
		ans[u] = nb[1]
		ans[v] = nb[0]
	elif a[v] == nb[0] and b[u] == nb[1]:
		ans[v] = nb[0]
		ans[u] = nb[1]
	elif a[v] == nb[1] and b[u] == nb[0]:
		ans[v] = nb[1]
		ans[u] = nb[0]
print(' '.join((str(x) for x in ans)))


import sys
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
store = [0] * n
for i in range(n):
	if a[i] == b[i]:
		if store[a[i] - 1] == 1:
			store[a[i] - 1] = 4
		else:
			store[a[i] - 1] = 2
	else:
		if store[a[i] - 1] == 0:
			store[a[i] - 1] = 1
		elif store[a[i] - 1] == 1:
			store[a[i] - 1] = 3
		elif store[a[i] - 1] == 2:
			store[a[i] - 1] = 4
		if store[b[i] - 1] == 0:
			store[b[i] - 1] = 1
		elif store[b[i] - 1] == 1:
			store[b[i] - 1] = 3
		elif store[b[i] - 1] == 2:
			store[b[i] - 1] = 4
for i in range(n):
	if a[i] != b[i]:
		if store[a[i] - 1] == 1 or store[b[i] - 1] == 1:
			if store[b[i] - 1] == 1:
				a[i] = b[i]
			store[a[i] - 1] = 4
		elif store[a[i] - 1] == 4 and store[b[i] - 1] == 4:
			pos = store.index(0)
			a[i] = pos + 1
			store[pos] = 4
		elif store[a[i] - 1] >= 3 and store[a[i] - 1] <= 4 and (store[b[i] - 1] >= 3) and (store[b[i] - 1] <= 4):
			if store[b[i] - 1] == 3:
				a[i] = b[i]
			store[a[i] - 1] = 4
print(*a, sep=' ')


N = int(input())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]
ans = list(a)
diff = [i for (i, item) in enumerate(a) if item != b[i]]
for i in diff:
	ans[i] = -1
not_exist = [item for item in range(1, N + 1) if item not in ans]
if len(not_exist) == 1:
	ans[diff[0]] = not_exist[0]
else:
	(p1, p2) = diff
	(it1, it2) = not_exist
	if [a[p1], b[p2]] == [it1, it2] or [b[p1], a[p2]] == [it1, it2]:
		ans[p1] = it1
		ans[p2] = it2
	else:
		ans[p1] = it2
		ans[p2] = it1
print(' '.join(map(str, ans)))


(n, r) = (int(input()) + 1, [])
for _ in 'ab':
	(ab, l) = (list(map(int, input().split())), [0] * n)
	r += [ab, 0, 0]
	for a in ab:
		l[a] += 1
	for a in range(1, n):
		if l[a] != 1:
			r[l[a] // 2 - 2] = a
	r.append([i for (i, a) in enumerate(ab) if a == r[-1]])
(ab, a, b, xx, cd, c, d, yy) = r
for x in xx:
	ab[x] = a
	for y in yy:
		cd[y] = c
		if all((ab[i] == cd[i] for i in xx + yy)):
			break
		cd[y] = d
	if cd[y] == c:
		break
	ab[x] = b
print(*ab)


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
		elif 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=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(range(1, n + 1))
r = []
for i in range(n):
	if a[i] == b[i]:
		r.append(str(a[i]))
		c.remove(a[i])
	else:
		r.append('0')
t = list(r)
if len(c) == 2:
	for i in range(2):
		for j in range(n):
			if r[j] == '0':
				r[j] = str(c[i])
				break
	for i in range(2):
		for j in range(n):
			if t[j] == '0':
				t[j] = str(c[1 - i])
				break
	k = 0
	for i in range(n):
		if r[i] != str(a[i]):
			k += 1
	l = 0
	for i in range(n):
		if r[i] != str(b[i]):
			l += 1
	if l < 2 and k < 2:
		print(' '.join(r))
	else:
		print(' '.join(t))
else:
	for j in range(n):
		if r[j] == '0':
			r[j] = str(c[0])
			break
	print(' '.join(r))


n = int(input())
(aa, bb) = l = [list(map(int, input().split())) for _ in 'ab']
(u, v) = ((set(range(1, n + 1)) - set(ab)).pop() for ab in l)
t = [i for i in range(n) if aa[i] != bb[i]]
for (i, j) in [(i, j) for i in t for j in t]:
	(a, b, aa[i], bb[j]) = (aa[i], bb[j], u, v)
	if all((aa[k] == bb[k] for k in t)):
		break
	(aa[i], bb[j]) = (a, b)
print(*aa)


(n, r) = (int(input()) + 1, [])
for _ in 'ab':
	(aa, l) = (list(map(int, input().split())), [0] * n)
	r += [0, 0]
	for a in aa:
		l[a] += 1
	for a in range(1, n):
		if l[a] != 1:
			r[l[a] // 2 - 2] = a
	t = r.pop()
	r += [{i for (i, a) in enumerate(aa) if a == t}, aa]
if r[0] == r[3] or r[1] == r[4]:
	aa[(r[4] & r[1]).pop()] = r[3]
else:
	for i in r[4]:
		if r[2][i] == r[3]:
			aa[i] = r[3]
print(*aa)


import sys

def solve():
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	j = -1
	k = -1
	for i in range(n):
		if a[i] != b[i]:
			if j == -1:
				j = i
			else:
				k = i
				break
	if k != -1:
		ans = [0] * n
		for i in range(n):
			if i != j and i != k:
				ans[i] = a[i]
		ans[j] = a[j]
		ans[k] = b[k]
		cnt = [0] * (n + 1)
		for i in range(n):
			cnt[ans[i]] += 1
		if all((cnti == 1 for cnti in cnt[1:])):
			print(*ans)
		else:
			ans[j] = b[j]
			ans[k] = a[k]
			print(*ans)
	else:
		ans = [0] * n
		app = [False] * (n + 1)
		for i in range(n):
			if i == j:
				continue
			app[a[i]] = True
			ans[i] = a[i]
		for i in range(1, n + 1):
			if not app[i]:
				ans[j] = i
				break
		print(*ans)
solve()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [0] * n
for i in range(n):
	if a[i] == b[i]:
		ans[i] = a[i]
differ = 0
for i in range(n):
	if a[i] != b[i]:
		differ += 1
c = 0
number = list(range(1, n + 1))
if differ == 1:
	if 0 in ans:
		x = 0
		ans1 = set(ans)
		for i in ans1:
			if i != 0:
				number.remove(i)
		for i in range(n):
			if ans[i] == 0:
				ans[i] = number[c]
				c += 1
		print(' '.join(list(map(str, ans))))
	else:
		print(' '.join(list(map(str, ans))))
elif differ == 0:
	print(' '.join(list(map(str, ans))))
else:
	for i in range(n):
		if a[i] != b[i] and c == 0:
			ans[i] = a[i]
			c += 1
		elif a[i] != b[i] and c == 1:
			ans[i] = b[i]
			break
	if len(ans) > len(set(ans)):
		c = 0
		for i in range(n):
			if a[i] != b[i] and c == 0:
				ans[i] = b[i]
				c += 1
			elif a[i] != b[i] and c == 1:
				ans[i] = a[i]
				break
		if 0 in ans:
			x = 0
			for i in set(ans):
				if i != 0:
					number.remove(i)
			for i in range(n):
				if ans[i] == 0:
					ans[i] = number[c]
					c += 1
			print(' '.join(list(map(str, ans))))
		else:
			print(' '.join(list(map(str, ans))))
	elif 0 in ans:
		x = 0
		for i in set(ans):
			if i != 0:
				number.remove(i)
		for i in range(n):
			if ans[i] == 0:
				ans[i] = number[c]
				c += 1
		print(' '.join(list(map(str, ans))))
	else:
		print(' '.join(list(map(str, ans))))


from sys import stdin, stdout
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = [0] * n
o = list(range(1, n + 1))
for i in range(n):
	if a[i] == b[i]:
		l[i] = a[i]
		o.pop(o.index(a[i]))
u = 0
pl = list(l)
for i in range(n):
	if a[i] != b[i]:
		l[i] = o[u]
		u += 1
(da, db) = (0, 0)
for f in range(n):
	if a[f] != l[f]:
		da += 1
	if b[f] != l[f]:
		db += 1
if da > 1 or db > 1:
	u = len(o) - 1
	for i in range(n):
		if a[i] != b[i]:
			pl[i] = o[u]
			u -= 1
	l = list(pl)
for j in l:
	stdout.write(str(j) + ' ')
print()


def reveries(size, seqA, seqB):
	answer = [0] * int(size)
	ref = set([int(i) for i in range(1, int(size) + 1)])
	for i in range(int(size)):
		if seqA[i] == seqB[i]:
			answer[i] = int(seqA[i])
			ref.remove(int(seqA[i]))
	for i in range(int(size)):
		if seqA[i] != seqB[i]:
			if int(seqA[i]) not in ref:
				if int(seqB[i]) in ref:
					answer[i] = int(seqB[i])
					ref.remove(int(seqB[i]))
		if int(seqB[i]) not in ref:
			if int(seqA[i]) in ref:
				answer[i] = int(seqA[i])
				ref.remove(int(seqA[i]))
	i = 0
	for j in ref:
		while int(answer[i]) != 0:
			i += 1
		answer[i] = j
		i += 1
	return answer
size = input()
seqA = input().strip().split()
seqB = input().strip().split()
set_Union = reveries(size, seqA, seqB)
ans = str(set_Union).replace('[', '').replace(']', '').replace(',', '')
print(ans)