AtCoder Beginner Contest 178 - Contrast

Given are two sequences A and B, both of length N.
A and B are each sorted in the ascending order.
Check if it is possible to reorder the terms of B so that for each i (1 \leq i \leq N) A_i \neq B_i holds, and if it is possible, output any of the reorderings that achieve it.

-----Constraints-----
 - 1\leq N \leq 2 \times 10^5
 - 1\leq A_i,B_i \leq N
 - A and B are each sorted in the ascending order.
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
A_1 A_2 \cdots A_N
B_1 B_2 \cdots B_N

-----Output-----
If there exist no reorderings that satisfy the condition, print No.
If there exists a reordering that satisfies the condition, print Yes on the first line.
After that, print a reordering of B on the second line, separating terms with a whitespace.
If there are multiple reorderings that satisfy the condition, you can print any of them.

-----Sample Input-----
6
1 1 1 2 2 3
1 1 1 2 2 3

-----Sample Output-----
Yes
2 2 3 1 1 1

Difficulty: MEDIUM

Starter code:

Solutions:
from time import time
from random import randrange
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
start = time()
for i in range(n):
	if A[i] != B[i]:
		continue
	while time() - start < 1.8:
		j = randrange(n)
		if A[i] != B[j] and A[j] != B[i]:
			(B[i], B[j]) = (B[j], B[i])
			break
	else:
		print('No')
		exit(0)
print('Yes')
print(*B)


from collections import Counter
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
elem_max_count = max((Counter(As) + Counter(Bs)).values())
if elem_max_count > N:
	print('No')
	exit()
ok = 0
ng = N + 1
while ng - ok > 1:
	mid = (ok + ng) // 2
	isok = True
	for (b, a) in zip(Bs[-mid:], As[:mid]):
		if b <= a:
			isok = False
			break
	if isok:
		ok = mid
	else:
		ng = mid
print('Yes')
print(*Bs[-ok:] + Bs[:-ok])


import sys
readline = sys.stdin.readline
read = sys.stdin.read
(n,) = map(int, readline().split())
(*a,) = map(int, readline().split())
(*b,) = map(int, readline().split())
b = b[::-1]
same = [i for i in range(n) if a[i] == b[i]]
if same:
	v = a[same[0]]
	r = same[0]
	s = same[-1] + 1
	vidx = [i for i in range(n) if a[i] == v or b[i] == v]
	p = vidx[0]
	q = vidx[-1] + 1
	if q > n - s + r + p:
		print('No')
		exit()
	if p >= s - r:
		(b[r:s], b[:s - r]) = (b[:s - r], b[r:s])
	else:
		(b[r:r + p], b[:p]) = (b[:p], b[r:r + p])
		(b[r + p:s], b[n - s + r + p:]) = (b[n - s + r + p:], b[r + p:s])
print('Yes')
print(*b)


import sys
input = sys.stdin.readline

def I():
	return int(input())

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

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

def main():
	from collections import defaultdict
	dd = defaultdict(int)
	N = I()
	A = LI()
	B = LI()
	cntA = [0] * (N + 1)
	cntB = [0] * (N + 1)
	for i in range(N):
		cntA[A[i]] += 1
		cntB[B[i]] += 1
	cnt = [0] * (N + 1)
	for i in range(N + 1):
		v1 = cntA[i]
		v2 = cntB[i]
		if v1 + v2 > N:
			print('No')
			exit()
		cnt[i] = v1 + v2
	ans = B[::-1]
	same = -1
	for i in range(N):
		if A[i] == ans[i]:
			same = A[i]
			break
	sames = []
	nots = []
	for i in range(N):
		if A[i] == same and ans[i] == same:
			sames.append(i)
		elif A[i] != same and ans[i] != same:
			nots.append(i)
	if len(nots) < len(sames):
		print('No')
		exit()
	for i in range(len(sames)):
		(ans[sames[i]], ans[nots[i]]) = (ans[nots[i]], ans[sames[i]])
	print('Yes')
	print(' '.join(map(str, ans)))
main()


(N, *AB) = map(int, open(0).read().split())
(A, B) = (AB[:N], AB[N:])
C = [0] * (N + 1)
D = [0] * (N + 1)
for (i, (a, b)) in enumerate(zip(A, B)):
	C[a] += 1
	D[b] += 1
if any((c + d > N for (c, d) in zip(C, D))):
	print('No')
	quit()
for i in range(1, N + 1):
	C[i] += C[i - 1]
	D[i] += D[i - 1]
x = max((C[i] - D[i - 1] for i in range(1, N + 1)))
print('Yes')
print(*[B[(i + N - x) % N] for i in range(N)])


import collections
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
Atmp = 0
Btmp = 0
INF = 1e+19
C = collections.Counter(A)
D = collections.Counter(B)
currentC = 0
currentD = 0
rotation = 0
for n in range(N + 1):
	if N < C[n] + D[n]:
		rotation = INF
		break
	currentC += C[n]
	rotation = max(rotation, currentC - currentD)
	currentD += D[n]
if rotation == INF:
	print('No')
else:
	print('Yes')
	print(' '.join(map(str, B[-rotation:] + B[:-rotation])))


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
j = 0
bef = -1
for i in range(n):
	if bef != A[i]:
		j = 0
	if A[i] == B[i]:
		while j < n:
			if A[i] != B[j] and A[i] != A[j]:
				(B[i], B[j]) = (B[j], B[i])
				break
			j += 1
		else:
			print('No')
			exit()
	bef = A[i]
print('Yes')
print(*B)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
for i in a:
	if i in d:
		d[i][0] += 1
	else:
		d[i] = [1, 0]
for i in b:
	if i in d:
		d[i][0] += 1
		d[i][1] += 1
	else:
		d[i] = [1, 1]
l = []
for i in d:
	l.append([d[i][0], i, d[i][1]])
l.sort()
l.reverse()
if l[0][0] > n:
	print('No')
else:
	print('Yes')
	l.append(l[0])
	cc = 0
	ansa = []
	i = 1
	while l[i][2] == 0:
		i += 1
	j = i + 1
	while j != len(l) and l[j][2] == 0:
		j += 1
	(ic, jc) = (0, 0)
	for t in a:
		if t == l[0][1]:
			continue
		cc += 1
		if cc > n - l[0][0]:
			ansa.append(l[0][1])
		elif l[i][1] == t:
			ansa.append(l[j][1])
			jc += 1
			if jc == l[j][2]:
				j += 1
				while j != len(l) and l[j][2] == 0:
					j += 1
				jc = 0
		else:
			ansa.append(l[i][1])
			ic += 1
			if ic == l[i][2]:
				i = j
				j += 1
				while j != len(l) and l[j][2] == 0:
					j += 1
				ic = jc
				jc = 0
	ans = []
	ii = 0
	for t in a:
		if t == l[0][1]:
			ans.append(l[i][1])
			ic += 1
			if ic == l[i][2]:
				i = j
				j += 1
				while j != len(l) and l[j][2] == 0:
					j += 1
				ic = jc
				jc = 0
		else:
			ans.append(ansa[ii])
			ii += 1
	print(' '.join(map(str, ans)))


import heapq
import collections
import sys
input = sys.stdin.readline
n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
cnt1 = collections.Counter(arr1)
cnt2 = collections.Counter(arr2)
tmp = [[key, cnt1[key]] for key in cnt1.keys()]
tmp = sorted(tmp, reverse=True, key=lambda x: x[1])
arr3 = []
for (key, cnt) in tmp:
	for _ in range(cnt):
		arr3.append(key)
cnt3 = collections.Counter(arr3)
ans = [0] * n
acum = 0
pos = 0
head = []
tail = []
for key in cnt3.keys():
	tcnt1 = cnt3[key]
	tcnt2 = cnt2[key]
	if tcnt1 + tcnt2 > n:
		print('No')
		exit()
	acum += tcnt1
	tpos = max(acum, pos)
	remain = tcnt2
	for i in range(tpos, n):
		if remain == 0:
			break
		ans[i] = key
		remain -= 1
		cnt2[key] -= 1
	for _ in range(remain):
		if tpos != pos:
			head.append(key)
		else:
			tail.append(key)
		cnt2[key] -= 1
	pos = min(tpos + tcnt2, n)
for key in cnt2.keys():
	if cnt2[key] == 0:
		continue
	for _ in range(cnt2[key]):
		tail.append(key)
pos = 0
head += tail
for i in range(n):
	if ans[i] == 0:
		ans[i] = head[pos]
		pos += 1
q = []
for i in range(n):
	heapq.heappush(q, (arr3[i], ans[i]))
for i in range(n):
	(_, val) = heapq.heappop(q)
	ans[i] = val
print('Yes')
print(*ans)


from collections import defaultdict, deque
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ns = defaultdict(int)
for i in a:
	ns[i] += 1
for i in b:
	ns[i] += 1
if max(ns.values()) > n:
	print('No')
	exit()
j = -1
k = -1
md = 0
for i in range(2, n + 1):
	while j + 1 < n and a[j + 1] < i:
		j += 1
	while k + 1 < n and b[k + 1] < i - 1:
		k += 1
	md = max(md, j - k)
for i in range(n):
	if a[i] == b[(i - md) % n]:
		md += 1
		break
d = deque(b)
d.rotate(md)
print('Yes')
print(' '.join([str(x) for x in d]))


import sys
readline = sys.stdin.readline
read = sys.stdin.read
(n,) = map(int, readline().split())
(*a,) = map(int, readline().split())
(*b,) = map(int, readline().split())
b = b[::-1]
from collections import Counter
d = Counter(a + b)
if max(d.values()) > n:
	print('No')
	exit()
same = set((i for i in range(n) if a[i] == b[i]))
from random import randrange
while same:
	i = same.pop()
	while True:
		j = randrange(0, n)
		if a[j] != b[i] and a[i] != b[j]:
			(b[i], b[j]) = (b[j], b[i])
			same.discard(j)
			break
print('Yes')
print(*b)


N = int(input())
(*A,) = map(int, input().split())
(*B,) = map(int, input().split())
ac = [0] * (N + 1)
bc = [0] * (N + 1)
ok = True
for i in range(N):
	ac[A[i]] += 1
	bc[B[i]] += 1
d = 0
for i in range(1, N + 1):
	if ac[i] + bc[i] > N:
		ok = False
		break
	ac[i] += ac[i - 1]
	bc[i] += bc[i - 1]
	d = max(d, ac[i] - bc[i - 1])
if ok:
	print('Yes')
	print(*[B[(i - d) % N] for i in range(N)])
else:
	print('No')


import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))[::-1]
yaba = None
for i in range(N):
	if A[i] == B[i]:
		yaba = A[i]
if not yaba:
	print('Yes')
	print(*B)
	exit()
daijobu = []
for i in range(N):
	if A[i] != yaba and B[i] != yaba:
		daijobu.append(i)
for i in range(N):
	if A[i] == B[i]:
		if not daijobu:
			print('No')
			exit()
		else:
			p = daijobu.pop()
			(B[i], B[p]) = (B[p], B[i])
print('Yes')
print(*B)


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10 ** 9))
write = lambda x: sys.stdout.write(x + '\n')
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
h = []
from collections import Counter, defaultdict
from itertools import chain
ca = defaultdict(int)
ca.update(Counter(a))
cb = defaultdict(int)
cb.update(Counter(b))
ks = set(ca.keys()) | set(cb.keys())
ans = defaultdict(list)
done = 0
amari = 0
for k in ks:
	h.append((-ca[k], -cb[k], k))
h.sort(key=lambda x: x[0] + x[1])
la = []
lb = []
for (va, vb, k) in h:
	la.extend([k] * -va)
	lb.extend([k] * -vb)
na = [None] * n
nb = [None] * n
ia = 0
ib = n - 1
ib2 = 0
for (aa, bb, k) in h:
	aa *= -1
	bb *= -1
	for _ in range(aa):
		na[ia] = k
		ia += 1
	for _ in range(bb):
		if na[ib] != k:
			nb[ib] = k
			ib -= 1
		else:
			nb[ib2] = k
			ib2 += 1
if any((na[i] == nb[i] for i in range(n))):
	print('No')
else:
	d = defaultdict(list)
	for i in range(n):
		d[na[i]].append(nb[i])
	ans = []
	for i in range(n):
		ans.append(d[a[i]].pop())
	print('Yes')
	write(' '.join(map(str, ans)))


from collections import Counter, defaultdict, deque
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions, pprint
sys.setrecursionlimit(10 ** 8)
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
import random
n = inp()
a = inpl()
b = inpl()
c = [0] * (n + 1)
for i in range(n):
	c[a[i]] += 1
	c[b[i]] += 1
if max(c) > n:
	print('No')
	quit()
q = deque([])
for i in range(n):
	if a[i] == b[i]:
		q.append(i)
while q:
	now = q.popleft()
	nx = random.randint(0, n - 1)
	if a[now] != b[nx] and a[nx] != b[now]:
		(b[now], b[nx]) = (b[nx], b[now])
	else:
		q.append(now)
print('Yes')
print(*b)


import sys
INF = 1 << 60
MOD = 10 ** 9 + 7
sys.setrecursionlimit(2147483647)
input = lambda : sys.stdin.readline().rstrip()
from collections import Counter
from random import randrange

def resolve():
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	if Counter(A + B).most_common()[0][1] > n:
		print('No')
		return
	B.reverse()
	for i in range(n):
		if A[i] != B[i]:
			continue
		while 1:
			j = randrange(n)
			if A[i] != B[j] and A[j] != B[i]:
				(B[i], B[j]) = (B[j], B[i])
				break
	print('Yes')
	print(*B)
resolve()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = [[0, i] for i in range(n + 1)]
cnt_a = [0] * (n + 1)
cnt_b = [0] * (n + 1)
for (ai, bi) in zip(a, b):
	cnt[ai][0] += 1
	cnt[bi][0] += 1
	cnt_a[ai] += 1
	cnt_b[bi] += 1
cnt.sort(reverse=True)
new_al = []
new_ar = []
new_bl = []
new_br = []
done = 0
for (_, i) in cnt:
	if done >= n:
		new_ar += [i] * cnt_a[i]
		new_bl += [i] * cnt_b[i]
	elif done + cnt_a[i] + cnt_b[i] <= n:
		new_al += [i] * cnt_a[i]
		new_br += [i] * cnt_b[i]
	elif cnt_a[i] > n - done:
		new_al += [i] * (n - done)
		new_ar += [i] * (cnt_a[i] - n + done)
		new_bl += [i] * cnt_b[i]
	else:
		new_al += [i] * cnt_a[i]
		new_br += [i] * (n - done - cnt_a[i])
		new_bl += [i] * (cnt_b[i] - (n - done - cnt_a[i]))
	done += cnt_a[i] + cnt_b[i]
new_a = new_al + new_ar[::-1]
new_b = new_bl + new_br[::-1]
new = [[ai, bi] for (ai, bi) in zip(new_a, new_b)]
new.sort()
ans = []
for ni in new:
	(x, y) = ni
	if x == y:
		print('No')
		exit()
	ans.append(y)
print('Yes')
print(' '.join(map(str, ans)))


import collections
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A1 = collections.Counter(A)
B1 = collections.Counter(B)
A2 = A1.most_common()
B2 = B1.most_common()
if A2[0][0] == B2[0][0]:
	if min(A2[0][1], B2[0][1]) > int(N / 2):
		print('No')
		quit()
B.reverse()
s = 0
t = N - 1
for i in range(N):
	if A[i] == B[i]:
		if A[s] != B[i] and A[i] != B[s]:
			x = B[s]
			B[s] = B[i]
			B[i] = x
			s += 1
		elif A[t] != B[i] and A[i] != B[t]:
			x = B[t]
			B[t] = B[i]
			B[i] = x
			t -= 1
		else:
			print('No')
			quit()
print('Yes')
for i in range(N):
	print(B[i], end=' ')
print('')


def main():
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	cnt = [0] * (N + 1)
	for n in A + B:
		cnt[n] += 1
	if max(cnt) > N:
		print('No')
		return
	B = B[::-1]
	(dup, dup_indices) = (-1, list())
	for i in range(N):
		if A[i] == B[i]:
			dup = A[i]
			dup_indices.append(i)
	if dup == -1:
		print('Yes')
		print(' '.join(map(str, B)))
		return
	indices = list()
	for i in range(N):
		if A[i] != dup and B[i] != dup:
			indices.append(i)
	indices = indices[:len(dup_indices)]
	for (i, j) in zip(dup_indices, indices):
		(B[i], B[j]) = (B[j], B[i])
	print('Yes')
	print(' '.join(map(str, B)))

def __starting_point():
	main()
__starting_point()


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
R = list(reversed(B))
flag = True
for i in range(N):
	if A[i] == R[i]:
		flag = False
		break
if flag:
	print('Yes')
	print(*R)
	exit()
l1 = B[N // 2:] + B[:N // 2]
l2 = B[N // 2 + 1:] + B[:N // 2 + 1]
flag1 = True
for i in range(N):
	if A[i] == l1[i]:
		flag1 = False
		break
flag2 = True
for i in range(N):
	if A[i] == l2[i]:
		flag2 = False
		break
if flag1 == False and flag2 == False:
	print('No')
elif flag1 == True:
	print('Yes')
	print(*l1)
else:
	print('Yes')
	print(*l2)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AC = Counter(A)
BC = Counter(B)
if N < max((AC + BC).values()):
	print('No')
	exit()
curA = 0
curB = 0
while curA < N:
	a = A[curA]
	if a == B[curA]:
		while a == B[curB] or A[curB] == B[curA]:
			curB += 1
			curB %= N
		(B[curA], B[curB]) = (B[curB], B[curA])
	curA += 1
print('Yes')
print(*B)


import sys
from collections import Counter
input = sys.stdin.readline

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	judge_a = Counter(a)
	judge_b = Counter(b)
	judge = judge_a + judge_b
	flag = True
	for v in judge.values():
		if v > n:
			flag = False
	if flag:
		(i, j) = (0, 0)
		cycle = 0
		while i < n and j < n:
			(ii, jj) = (i, j)
			if a[i] < b[j]:
				i += 1
				continue
			if a[i] > b[j]:
				j += 1
				continue
			if a[i] == b[j]:
				while i < n - 1 and a[i] == a[i + 1]:
					i += 1
				while j < n - 1 and b[j] == b[j + 1]:
					j += 1
			cycle = max(cycle, i - jj + 1)
			i += 1
			j += 1
		ans = [0] * n
		for i in range(n):
			ans[(i + cycle) % n] = b[i]
		for i in range(n):
			if a[i] == ans[i]:
				print('No')
				sys.exit()
		print('Yes')
		print(*ans)
	else:
		print('No')
main()


import sys, queue, math, copy, itertools, bisect, collections, heapq

def main():
	LI = lambda : [int(x) for x in sys.stdin.readline().split()]
	NI = lambda : int(sys.stdin.readline())
	N = NI()
	A = LI()
	B = LI()
	c = collections.Counter()
	for x in A:
		c[x] += 1
	for x in B:
		c[x] += 1
		if c[x] > N:
			print('No')
			return
	s = 0
	for i in range(N):
		if A[i] == B[i]:
			p = bisect.bisect_left(B, B[i] + 1, i + 1)
			if p > N - 1:
				p = s
				s += 1
				while B[i] == B[s]:
					s += 1
			(B[i], B[p]) = (B[p], B[i])
	print('Yes')
	print(*B, sep=' ')
main()


from collections import Counter, deque
N = int(input())
A = list(map(int, input().split())) + [N + 1]
B = list(map(int, input().split())) + [N + 1]
C = [0]
D = [0]
AB_cn = Counter(A + B)
if AB_cn.most_common()[0][1] > N:
	print('No')
else:
	print('Yes')
	for i in range(N + 1):
		if len(C) != A[i]:
			C.extend([i] * (A[i] - len(C)))
		if len(D) != B[i]:
			D.extend([i] * (B[i] - len(D)))
	ans = 0
	for i in range(N):
		curr = C[i + 1] - D[i]
		ans = max(curr, ans)
	B = B[:-1]
	print(*[B[(i - ans) % N] for i in range(N)])


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
idx_B = 0
ma = 0
for (idx_A, a) in enumerate(A):
	while idx_B < N and B[idx_B] < a:
		idx_B += 1
	if ma < idx_A - idx_B:
		ma = idx_A - idx_B
Ans = (B + B)[N - ma - 1:2 * N - ma - 1]
for (a, b) in zip(A, Ans):
	if a == b:
		print('No')
		exit()
print('Yes')
print(' '.join(map(str, Ans)))


import sys
pin = sys.stdin.readline
N = int(pin())
A = list(map(int, pin().split()))
B = list(map(int, pin().split()))
C = list(reversed(B))
for i in range(N):
	if A[i] == C[i]:
		break
else:
	print('Yes')
	for k in C:
		sys.stdout.write(f'{k} ')
	print()
	return
D = B[N // 2:] + B[:N // 2]
for j in range(N):
	if A[j] == D[j]:
		print('No')
		break
else:
	print('Yes')
	for l in D:
		sys.stdout.write(f'{l} ')
	print()
	return


from collections import defaultdict

def solve(N, A, B):
	d1 = defaultdict(int)
	d2 = defaultdict(int)
	for i in range(N):
		d1[A[i]] += 1
		d2[B[i]] += 1
	for i in d1:
		if d1[i] + d2[i] > N:
			return ('No', [])
	else:
		return ('Yes', B[::-1])
N = int(input())
A = [int(i) for i in input().split()][:N]
B = [int(i) for i in input().split()][:N]
(a, b) = solve(N, A, B)
print(a)
if b != []:
	(k, z) = (0, N - 1)
	for i in range(N):
		if A[i] == b[i] and b[i] != b[k]:
			(b[i], b[k]) = (b[k], b[i])
			k += 1
		elif A[i] == b[i] and b[i] == b[k]:
			(b[i], b[z]) = (b[z], b[i])
			z -= 1
	(z, k) = (0, N - 1)
	for i in range(N):
		if A[i] == b[i] and b[i] != b[k]:
			(b[i], b[k]) = (b[k], b[i])
			k -= 1
		elif A[i] == b[i] and b[i] == b[k]:
			(b[i], b[z]) = (b[z], b[i])
			z += 1
	print(*b)


import collections
n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
cnt1 = collections.Counter(arr1)
cnt2 = collections.Counter(arr2)
acum1 = [0] * (n + 1)
acum2 = [0] * (n + 1)
for i in range(1, n + 1):
	acum1[i] = acum1[i - 1] + cnt1[i]
	acum2[i] = acum2[i - 1] + cnt2[i]
rotate = 0
for i in range(1, n + 1):
	rotate = max(rotate, acum1[i] - acum2[i - 1])
ans = [0] * n
for i in range(n):
	ans[(i + rotate) % n] = arr2[i]
for i in range(n):
	if arr1[i] == ans[i]:
		print('No')
		break
else:
	print('Yes')
	print(*ans)


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def lr(xx):
	ll = [-1] * (n + 1)
	rr = [-1] * (n + 1)
	for (i, x) in enumerate(xx):
		if ll[x] == -1:
			ll[x] = i
		if i == n - 1 or x != xx[i + 1]:
			rr[x] = i + 1
	return (ll, rr)
n = II()
aa = LI()
bb = LI()
(all, arr) = lr(aa)
(bll, brr) = lr(bb)
ca = [0] * (n + 1)
cb = [0] * (n + 1)
for a in aa:
	ca[a] += 1
for b in bb:
	cb[b] += 1
for i in range(n + 1):
	if ca[i] + cb[i] > n:
		print('No')
		return
ng = [0] * (n + 1)
for (al, ar, bl, br) in zip(all, arr, bll, brr):
	if al == -1 or bl == -1:
		continue
	if bl < ar:
		mn = max(0, al - br + 1)
		mx = ar - bl
		ng[mn] += 1
		ng[mx] -= 1
	else:
		mn = max(0, al + n - br + 1)
		mx = min(n, ar + n - bl)
		ng[mn] += 1
		ng[mx] -= 1
for i in range(n):
	ng[i + 1] += ng[i]
shift = -1
for i in range(n):
	if ng[i] == 0:
		shift = i
		break
ans = bb[-shift:] + bb[:-shift]
print('Yes')
print(*ans)


n = int(input())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
d_a = {}
d_b = {}
for i in range(-1, n):
	d_a[i] = 0
	d_b[i] = 0
for i in range(n):
	d_a[a[i] - 1] += 1
	d_b[b[i] - 1] += 1
diff = 0
(c, d) = (0, 0)
for i in range(n):
	if d_a[i] + d_b[i] > n:
		print('No')
		return
	c += d_a[i]
	d += d_b[i - 1]
	diff = max(diff, c - d)
print('Yes')
for i in range(n):
	print(b[(i - diff) % n], end=' ')
print()


from bisect import bisect_left, bisect_right
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
bset = set(b)
ans = 0
for i in range(n):
	if a[i] in bset:
		ans = max(bisect_right(b, a[i]) - i, ans)
b = (b + b)[ans:ans + n]
for i in range(n):
	if a[i] == b[i]:
		exit(print('No'))
print('Yes')
print(*b)


import sys
mod = 10 ** 9 + 7
inf = float('inf')
from math import sqrt, ceil
from collections import deque, Counter, defaultdict
input = lambda : sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP, Decimal as D
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
j = 0
bef = -1
for i in range(n):
	if bef != A[i]:
		j = 0
	if A[i] == B[i]:
		while j < n:
			if A[i] != B[j] and A[i] != A[j]:
				(B[i], B[j]) = (B[j], B[i])
				break
			j += 1
		else:
			print('No')
			exit()
	bef = A[i]
print('Yes')
print(*B)


import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache

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

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

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

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

def TUPLE():
	return tuple(map(int, input().split()))

def ZIP(n):
	return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 6
mod = 10 ** 9 + 7
N = INT()
A = LIST()
B = LIST()
CA = Counter(A)
CB = Counter(B)
for k in CB.keys():
	if CB[k] > N - CA[k]:
		print('No')
		exit()
else:
	print('Yes')
B = B[::-1]
j = 0
jdx = 1
for i in range(N):
	if A[i] == B[i]:
		if B[i] == B[j] or B[i] == A[j]:
			j = -1
			jdx = -1
		(B[i], B[j]) = (B[j], B[i])
		j += jdx
print(*B)


import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
RB = B[::-1]
start = v = -1
seq = 0
for (i, (a, b)) in enumerate(zip(A, RB)):
	if a == b:
		v = a
		seq += 1
		if start == -1:
			start = i
if v == -1:
	print('Yes')
	print(*RB)
	return
if A.count(v) + B.count(v) > N:
	print('No')
	return
from bisect import bisect_left, bisect
al = bisect_left(A, v)
bl = bisect_left(B, v)
br = bisect(B, v)
rbl = N - br
m = min(seq, start, al, rbl)
(RB[:m], RB[start:start + m]) = (RB[start:start + m], RB[:m])
seq -= m
start += m
if seq:
	(RB[start:start + seq], RB[-seq:]) = (RB[-seq:], RB[start:start + seq])
assert all((a != b for (a, b) in zip(A, RB)))
print('Yes')
print(*RB)


(N,) = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))[::-1]
on = []
z = 0
for i in range(N):
	if not X[i] - Y[i]:
		on.append(i)
		z = X[i]
for i in range(N):
	if X[i] != z and Y[i] != z and on:
		j = on.pop()
		(Y[i], Y[j]) = (Y[j], Y[i])
if on:
	print('No')
else:
	print('Yes')
	print(*Y)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b = b[::-1]
s = 0
e = 0
for i in range(n):
	if s == 0 and a[i] == b[i]:
		s = i + 1
	if s > 0 and a[i] != b[i]:
		e = i + 1
		break
if s == 0:
	print('Yes')
	print(*b)
	quit()
cl = a[s - 1]
k = e - s
j = 0
for i in range(n):
	if s - 1 <= i < e - 1:
		continue
	if cl != b[i] and cl != a[i]:
		b[s - 1 + j] = b[i]
		b[i] = cl
		j += 1
	if j == k:
		break
for i in range(n):
	if a[i] == b[i]:
		print('No')
		quit()
print('Yes')
print(*b)


def f_contrast():
	from collections import Counter
	N = int(input())
	A = [int(i) for i in input().split()]
	B = [int(i) for i in input().split()]
	c = [0] * (N + 1)
	d = [0] * (N + 1)
	for (a, b) in zip(A, B):
		c[a] += 1
		d[b] += 1
	for (s, t) in zip(c, d):
		if s + t > N:
			return 'No'
	for i in range(1, N + 1):
		c[i] += c[i - 1]
		d[i] += d[i - 1]
	shift = max((c[i] - d[i - 1] for i in range(1, N + 1)))
	ans = [B[(i + N - shift) % N] for i in range(N)]
	ret = ' '.join(map(str, ans))
	return f'Yes\n{ret}'
print(f_contrast())


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	alst = list(map(int, input().split()))
	blst = list(map(int, input().split()))
	a_s = [0 for _ in range(n)]
	b_s = [0 for _ in range(n)]
	for a in alst:
		a_s[a - 1] += 1
	for b in blst:
		b_s[b - 1] += 1
	for (a, b) in zip(a_s, b_s):
		if a + b > n:
			print('No')
			return
	print('Yes')
	a_total = 0
	b_total = 0
	cor = -100000
	for (a, b) in zip(a_s, b_s):
		a_total += a
		cor = max(cor, a_total - b_total)
		b_total += b
	ans = blst[-cor:] + blst[:-cor]
	print(*ans)
main()


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
T = [(A[i], i) for i in range(N)] + [(B[i], N + i) for i in range(N)]
T.sort()
P = [-1] * (2 * N)
for i in range(N):
	if T[i][0] == T[i + N][0]:
		print('No')
		exit(0)
	P[T[i][1]] = T[i + N][1]
	P[T[i + N][1]] = T[i][1]
bp1 = N
for ap1 in range(N):
	if P[ap1] // N == 1:
		continue
	while P[bp1] // N == 0:
		bp1 += 1
	ap2 = P[ap1]
	bp2 = P[bp1]
	if A[ap1] != B[bp1 - N] and A[ap2] != B[bp2 - N]:
		P[ap1] = bp1
		P[bp1] = ap1
		P[ap2] = bp2
		P[bp2] = ap2
	else:
		P[ap1] = bp2
		P[bp1] = ap2
		P[ap2] = bp1
		P[bp2] = ap1
print('Yes')
print(' '.join((str(B[P[i] - N]) for i in range(N))))


N = int(input())
from collections import Counter
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ca = Counter(A)
cb = Counter(B)
for i in range(1, N + 1):
	if ca[i] + cb[i] > N:
		print('No')
		exit()
print('Yes')
from collections import deque
lis = [deque() for _ in range(N + 1)]
da = deque(list(range(1, N + 1)))
db = deque(list(range(1, N + 1)))
while len(da) and len(db):
	a = da.popleft()
	b = db.popleft()
	if a == b:
		if len(db):
			db.append(b)
			b = db.popleft()
		elif len(da):
			da.append(a)
			a = da.popleft()
		else:
			for i in range(1, N + 1):
				for _ in range(len(lis[i])):
					c = lis[i].popleft()
					if c != b:
						lis[b].append(c)
						lis[i].append(b)
						ca[a] -= 1
						cb[b] -= 1
						if ca[a] == 0:
							break
					else:
						lis[i].append(c)
				else:
					continue
				break
	if ca[a] > cb[b]:
		for _ in range(cb[b]):
			lis[a].append(b)
		ca[a] -= cb[b]
		cb[b] = 0
		da.appendleft(a)
	else:
		for _ in range(ca[a]):
			lis[a].append(b)
		cb[b] -= ca[a]
		ca[a] = 0
		if cb[b] > 0:
			db.appendleft(b)
ans = []
for i in range(1, N + 1):
	for _ in range(len(lis[i])):
		b = lis[i].popleft()
		ans.append(b)
print(*ans)


from collections import Counter, deque
(N,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
freqA = Counter(A)
freqB = Counter(B)
for k in freqA.keys() & freqB.keys():
	if freqA[k] + freqB[k] > N:
		print('No')
		exit()
B = deque(B)
while True:
	rotate = 0
	for i in range(N):
		while A[(i + rotate) % N] == B[i]:
			rotate += 1
	bad = False
	B.rotate(rotate)
	for (a, b) in zip(A, B):
		if a == b:
			bad = True
	if not bad:
		break
print('Yes')
print(' '.join(map(str, B)))


from sys import stdin
from random import randint
from time import time
input = lambda : stdin.readline().rstrip()
start = time()
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.reverse()
ok = 0
t = time() - start
while t < 1.8:
	cnt = 0
	for i in range(n):
		if a[i] == b[i]:
			rng = randint(0, n - 1)
			(b[i], b[rng]) = (b[rng], b[i])
			cnt += 1
	if cnt == 0:
		ok = 1
		break
	t = time() - start
if ok == 1:
	print('Yes')
	print(*b)
else:
	print('No')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
be = [-1] * n
la = [-1] * n
be2 = [-1] * n
la2 = [-1] * n
for i in range(n):
	if be[a[i] - 1] == -1:
		be[a[i] - 1] = i
	la[a[i] - 1] = i + 1
	if be2[b[i] - 1] == -1:
		be2[b[i] - 1] = i
	la2[b[i] - 1] = i + 1
(l, r) = (0, 2 * n)
for i in range(n):
	if la[i] != -1 and la2[i] != -1:
		l = max(la[i] - be2[i], l)
		r = min(r, be[i] + n - la2[i])
if l > r:
	print('No')
else:
	print('Yes')
	print(*b[n - l:] + b[:n - l])


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b = b[::-1]
l = []
num = -1
for i in range(n):
	if a[i] == b[i]:
		l.append(i)
		num = a[i]
ind = 0
for i in range(n):
	if b[i] != num and a[i] != num and (ind < len(l)):
		(b[i], b[l[ind]]) = (b[l[ind]], b[i])
		ind += 1
if ind < len(l):
	print('No')
else:
	print('Yes')
	print(*b)


import sys
input = sys.stdin.readline
N = int(input())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
sum = [0] * N
for i in range(N):
	sum[A[i] - 1] += 1
	sum[B[i] - 1] += 1
if max(sum) > N:
	print('No')
	exit()
print('Yes')
for i in range(N):
	hit = False
	for j in range(N):
		a = A[j]
		b = B[(j + i) % N]
		if a == b:
			hit = True
			break
	if not hit:
		ans = []
		for j in range(N):
			ans.append(str(B[(j + i) % N]))
		print(' '.join(ans))
		exit()


from collections import defaultdict
dic = defaultdict(int)
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for (x, y) in zip(A, B):
	dic[x] += 1
	dic[y] += 1
L = list(dic.values())
MAX = max(L)
if MAX > N:
	print('No')
	exit()
INF = float('inf')
dicA_min = defaultdict(lambda : INF)
dicA_max = defaultdict(lambda : 0)
dicB_min = defaultdict(lambda : INF)
dicB_max = defaultdict(lambda : 0)
for i in range(N):
	dicA_min[A[i]] = min(dicA_min[A[i]], i)
	dicA_max[A[i]] = max(dicA_max[A[i]], i)
	dicB_min[B[i]] = min(dicB_min[B[i]], i)
	dicB_max[B[i]] = max(dicB_max[B[i]], i)
L = list(dicB_min.keys())
mink = -INF
maxk = INF
Flag = False
for t in L:
	if dicA_min[t] == INF:
		continue
	mink = max(dicA_max[t] - dicB_min[t] + 1, mink)
	maxk = min(dicA_min[t] + N - dicB_max[t] - 1, maxk)
	Flag = True
if not Flag:
	print('Yes')
	print(*B)
	exit()
if mink >= 0:
	ans = B[-mink:] + B[:-mink]
else:
	ans = B[-mink:] + B[:-mink]
print('Yes')
print(*ans)


def get_ints():
	return list(map(int, input().split()))
n = int(input())
a = get_ints()
b = get_ints()
cnt = [0] * (n + 1)
for x in a + b:
	cnt[x] += 1
q = [set() for i in range(n + 1)]
for i in range(1, n + 1):
	if cnt[i] > n:
		print('No')
		exit(0)
	q[cnt[i]].add(i)
print('Yes')

def make_cnt(a):
	cnt_ = {}
	for i in range(n):
		if a[i] not in cnt_:
			cnt_[a[i]] = [i]
		else:
			cnt_[a[i]].append(i)
	return cnt_
cnt_a = make_cnt(a)
cnt_b = make_cnt(b)

def get_any(cnt_, x):
	for key in cnt_.keys():
		if key != x:
			return key
	assert False
ans = [-1] * n
for i in range(n, 0, -1):
	s = list(q[i])
	(x, y) = (0, 0)
	if len(s) == 0:
		x = get_any(cnt_a, -1)
		y = get_any(cnt_b, x)
	elif len(s) == 1:
		x = s[0]
		if x not in cnt_a:
			y = x
			x = get_any(cnt_a, y)
		else:
			y = get_any(cnt_b, x)
	else:
		(x, y) = s
		if x not in cnt_a:
			(x, y) = (y, x)
	ans[cnt_a[x][-1]] = y

	def update_cnt(cnt_, x):
		cnt_[x].pop()
		if len(cnt_[x]) == 0:
			del cnt_[x]

	def use(x):
		q[cnt[x]].remove(x)
		cnt[x] -= 1
		q[cnt[x]].add(x)
	update_cnt(cnt_a, x)
	update_cnt(cnt_b, y)
	use(x)
	use(y)
print(' '.join(map(str, ans)))


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
f = True
A_Counter = Counter(A)
B_Counter = Counter(B)
for a in A_Counter.keys():
	if N - A_Counter[a] < B_Counter[a]:
		f = False
if f:
	print('Yes')
	B.sort(reverse=True)
	n = 0
	sw = True
	for i in range(N):
		if A[i] == B[i]:
			if sw:
				(B[i], B[n]) = (B[n], B[i])
				sw = False
			else:
				(B[i], B[-1 - n]) = (B[-1 - n], B[i])
				n += 1
				sw = True
	print(*B)
else:
	print('No')


N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
C = [0] * N
D = [0] * N
c = d = 0
for i in range(N):
	a = A[i]
	b = B[i]
	if C[a - 1] == 0:
		for j in range(c, a):
			C[j] = C[c]
		c = a - 1
		C[c] = C[c - 1] + 1
	else:
		C[a - 1] += 1
	if D[b - 1] == 0:
		for j in range(d, b):
			D[j] = D[d]
		d = b - 1
		D[d] = D[d - 1] + 1
	else:
		D[b - 1] += 1
for j in range(c, N):
	C[j] = C[c]
for j in range(d, N):
	D[j] = D[d]
E = [0] * N
for i in range(N):
	if i == 0:
		E[i] = C[i] + D[i]
	else:
		E[i] = C[i] - C[i - 1] + D[i] - D[i - 1]
if max(E) > N:
	print('No')
else:
	for i in range(N):
		if i == 0:
			x = C[i]
		if x < C[i] - D[i - 1]:
			x = C[i] - D[i - 1]
	B_ = [0] * N
	for i in range(N):
		B_[(i + x) % N] = B[i]
	print('Yes')
	print(*B_, sep=' ')


from collections import Counter

def resolve():
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	CNT = Counter(A + B)
	num = CNT.most_common()[0][1]
	if num > N:
		print('No')
		return
	(j, pre) = (0, -1)
	for i in range(N):
		if A[i] != pre:
			j = 0
		if A[i] == B[i]:
			while j < N:
				if A[i] != B[j] and A[j] != B[i]:
					(B[i], B[j]) = (B[j], B[i])
					break
				j += 1
		pre = A[i]
	print('Yes')
	print(*B)
resolve()


import sys
readline = sys.stdin.readline
read = sys.stdin.read
(n,) = map(int, readline().split())
(*a,) = map(lambda x: 2 * int(x), readline().split())
(*b,) = map(lambda x: 2 * int(x) + 1, readline().split())
c = sorted(a + b)
res = []
aa = []
bb = []
for (x, y) in zip(c[:n], c[n:]):
	if x % 2 == 0:
		if y % 2 == 0:
			aa.append((x // 2, y // 2))
		else:
			res.append((x // 2, y // 2))
	elif y % 2 == 0:
		res.append((y // 2, x // 2))
	else:
		bb.append((x // 2, y // 2))
while aa:
	(p, q) = aa.pop()
	(r, s) = bb.pop()
	if p != r and q != s:
		res.append((p, r))
		res.append((q, s))
	else:
		res.append((p, s))
		res.append((q, r))
from operator import itemgetter
res.sort(key=itemgetter(0))
for (x, y) in res:
	if x == y:
		print('No')
		exit()
print('Yes')
ans = [y for (x, y) in res]
print(*ans)


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
judge = True
A_num = [0] * (N + 1)
B_num = [0] * (N + 1)
C = [0] * (N + 1)
D = [0] * (N + 1)
for a in A:
	A_num[a] += 1
for b in B:
	B_num[b] += 1
for (a, b) in zip(A_num, B_num):
	if a + b > N:
		judge = False
		break
if judge:
	for i in range(1, N + 1):
		C[i] = C[i - 1] + A_num[i]
		D[i] = D[i - 1] + B_num[i]
	x = -float('inf')
	for i in range(1, N + 1):
		x = max(x, C[i] - D[i - 1])
	ans = B[-x:] + B[:-x]
	print('Yes')
	print(' '.join(map(str, ans)))
else:
	print('No')


import sys
INF = 1 << 60
MOD = 10 ** 9 + 7
sys.setrecursionlimit(2147483647)
input = lambda : sys.stdin.readline().rstrip()
from time import time
from random import randrange

def resolve():
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	start = time()
	B.reverse()
	for i in range(n):
		if A[i] != B[i]:
			continue
		while time() - start < 1.8:
			j = randrange(n)
			if A[i] != B[j] and A[j] != B[i]:
				(B[i], B[j]) = (B[j], B[i])
				break
		else:
			print('No')
			return
	print('Yes')
	print(*B)
resolve()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b = sorted(b, reverse=True)
inds = []
val = -1
for i in range(n):
	if a[i] == b[i]:
		val = a[i]
		inds.append(i)
if val == -1:
	print('Yes')
	print(*b)
	exit()
is_val = [False] * n
for i in range(n):
	if a[i] == val or b[i] == val:
		is_val[i] = True
for i in range(n):
	if not is_val[i] and inds:
		j = inds.pop()
		(b[i], b[j]) = (b[j], b[i])
if not inds:
	print('Yes')
	print(*b)
	exit()
print('No')


import collections
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = collections.Counter(a)
B = collections.Counter(b)
inf = 1e+19
(cc, cd) = (0, 0)
R = 0
for i in range(n + 1):
	if A[i] + B[i] > n:
		R = inf
	else:
		cc += A[i]
		R = max(R, cc - cd)
		cd += B[i]
if R == inf:
	print('No')
else:
	print('Yes')
	ans = ' '.join(map(str, b[-R:] + b[:-R]))
	print(ans)


from collections import Counter
from heapq import heappush, heappop
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AC = Counter(A)
BC = Counter(B)
S = AC + BC
q = []
for (k, v) in S.items():
	heappush(q, (-v, k))
ans = []
while q:
	(v, k) = heappop(q)
	v = -v
	if v != S[k]:
		if S[k] != 0:
			heappush(q, (-S[k], k))
	else:
		if v != 1:
			heappush(q, (-(v - 1), k))
		if v > N:
			print('No')
			exit()
		else:
			if AC[k] > 0:
				a = k
				for l in BC.keys():
					if l != k:
						b = l
						break
			else:
				b = k
				for l in AC.keys():
					if l != k:
						a = l
						break
			ans.append((a, b))
			S[a] -= 1
			S[b] -= 1
			AC[a] -= 1
			if not AC[a]:
				AC.pop(a)
			BC[b] -= 1
			if not BC[b]:
				BC.pop(b)
print('Yes')
ans.sort()
X = [b for (a, b) in ans]
print(*X)


from sys import exit
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B = B[::-1]
need_swap = [i for i in range(n) if A[i] == B[i]]
if len(need_swap) == 0:
	print('Yes')
	print(' '.join(map(str, B)))
	exit()
val = A[need_swap[0]]
for i in range(n):
	if len(need_swap) == 0:
		break
	if A[i] != val and B[i] != val:
		j = need_swap.pop()
		(B[i], B[j]) = (B[j], B[i])
if len(need_swap) == 0:
	print('Yes')
	print(' '.join(map(str, B)))
else:
	print('No')


import collections
import sys
input = sys.stdin.readline
n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
cnt1 = collections.Counter(arr1)
cnt2 = collections.Counter(arr2)
tmp = [[key, cnt1[key]] for key in cnt1.keys()]
tmp = sorted(tmp, reverse=True, key=lambda x: x[1])
arr3 = []
for (key, cnt) in tmp:
	for _ in range(cnt):
		arr3.append(key)
cnt1 = collections.Counter(arr3)
ans = [0] * n
acum = 0
pos = 0
blank = 0
ok = 0
head = []
for key in cnt1.keys():
	tcnt1 = cnt1[key]
	tcnt2 = cnt2[key]
	acum += tcnt1
	tpos = max(acum, pos)
	tmp = n - min(tpos, n)
	if blank + tmp < tcnt2:
		print('No')
		return
	blank = min(tpos, n) - ok
	remain = tcnt2
	for i in range(tpos, n):
		if remain == 0:
			break
		ans[i] = key
		ok += 1
		remain -= 1
		cnt2[key] -= 1
	for _ in range(remain):
		head.append(key)
		cnt2[key] -= 1
	pos = min(tpos + tcnt2, n)
for key in cnt2.keys():
	if cnt2[key] == 0:
		continue
	for _ in range(cnt2[key]):
		head.append(key)
pos = 0
for i in range(n):
	if ans[i] == 0:
		ans[i] = head[pos]
		pos += 1
tmp = [[ans[i], arr3[i]] for i in range(n)]
tmp = sorted(tmp, key=lambda x: x[1])
ans = [tmp[i][0] for i in range(n)]
print('Yes')
print(*ans)


def ans(N, A, B):
	B = B[::-1]
	match_vals = set()
	for i in range(N):
		if A[i] == B[i]:
			match_vals.add(A[i])
	if len(match_vals) == 0:
		print('Yes')
		print(*B)
		return
	assert len(match_vals) == 1
	[m] = list(match_vals)
	ok = []
	bad = []
	for i in range(N):
		if B[i] != m and A[i] != m:
			ok += [i]
		if A[i] == B[i]:
			bad += [i]
	if len(bad) > len(ok):
		print('No')
		return
	for i in range(len(bad)):
		(B[bad[i]], B[ok[i]]) = (B[ok[i]], B[bad[i]])
	print('Yes')
	print(*B)
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans(N, A, B)


import collections
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = A + B
if max(collections.Counter(C).values()) <= N:
	judge = 'Yes'
	B = B[::-1]
	fore = 0
	back = -1
	for i in range(len(A)):
		if A[i] == B[i]:
			dup = A[i]
			if A[fore] != dup and B[fore] != dup:
				(B[fore], B[i]) = (B[i], B[fore])
				fore += 1
			elif A[back] != dup and B[back] != dup:
				(B[back], B[i]) = (B[i], B[back])
				back -= 1
			else:
				judge = 'No'
else:
	judge = 'No'
if judge == 'Yes':
	print(judge)
	print(' '.join(map(str, B)))
else:
	print(judge)


def main():
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	B.reverse()
	(l, r) = (0, N - 1)
	for i in range(N):
		if A[i] != B[i]:
			continue
		if l < i and A[i] != B[l] and (A[l] != B[i]):
			(B[l], B[i]) = (B[i], B[l])
			l += 1
			continue
		if i < r and A[i] != B[r]:
			(B[i], B[r]) = (B[r], B[i])
			r -= 1
			continue
		return None
	return B
t = main()
if t is None:
	print('No')
else:
	print('Yes')
	print(' '.join(map(str, t)))


from collections import Counter, deque
N = int(input())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))
(ca, cb) = (Counter(A), Counter(B))
cab = ca + cb
if any((c > N for c in cab.values())):
	print('No')
else:
	print('Yes')
	B.rotate(N // 2)
	res = []
	while A:
		if A[0] != B[0]:
			A.popleft()
			res.append(str(B.popleft()))
		else:
			B.rotate()
	print(' '.join(res))


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()][::-1]
ng = []
for i in range(n):
	if a[i] == b[i]:
		ng.append(i)
if len(ng) == 0:
	print('Yes')
	print(*b)
	sys.exit()
min_ng = min(ng)
max_ng = max(ng)
left = 0
right = n - 1
for i in ng:
	if b[i] != b[left] and a[left] != b[i]:
		(b[i], b[left]) = (b[left], b[i])
		left += 1
		continue
	if b[i] != b[right] and a[right] != b[i]:
		(b[i], b[right]) = (b[right], b[i])
		right -= 1
flag = 1
for i in range(n):
	if a[i] == b[i]:
		flag = 0
if flag:
	print('Yes')
	print(*b)
else:
	print('No')


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
D = [[0, i] for i in range(N + 1)]
for i in range(N):
	a = A[i]
	b = B[i]
	D[a][0] += 1
	D[b][0] += 1
for d in D:
	if d[0] > N:
		print('No')
		exit()
print('Yes')
an = 0
am = 0
bn = 0
bm = 0
D = [1] * N
while an < N and bn < N:
	if A[an] == B[bn]:
		c = A[an]
	else:
		if A[an] > B[bn]:
			bn += 1
		else:
			an += 1
		continue
	am = an
	bm = bn
	while True:
		if am + 1 >= N:
			break
		if A[am + 1] == c:
			am += 1
		else:
			break
	while True:
		if bm + 1 >= N:
			break
		if B[bm + 1] == c:
			bm += 1
		else:
			break
	l = an - bm
	r = am - bn
	if l >= 0:
		for i in range(l, r + 1):
			D[i] = 0
	elif r >= 0:
		for i in range(l + N, N):
			D[i] = 0
		for i in range(r + 1):
			D[i] = 0
	else:
		for i in range(l + N, r + N):
			D[i] = 0
	an = am + 1
	bn = bm + 1
for i in range(N):
	if D[i] == 1:
		s = i
		break
else:
	print('No')
	exit()
Ans = [0] * N
for i in range(N):
	Ans[(i + s) % N] = B[i]
print(' '.join(list(map(str, Ans))))


def solve(N, A, B):
	buf = -1
	key = 0
	for i in range(N):
		if buf != A[i]:
			key = 0
		if A[i] == B[i]:
			for j in range(key, N):
				if A[i] != A[j] and B[j] != A[i]:
					(B[i], B[j]) = (B[j], B[i])
					key = j
					break
			else:
				print('No')
				return
		buf = A[i]
	print('Yes')
	print(' '.join([str(i) for i in B]))
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
solve(N, A, B)


from collections import Counter
import heapq
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cur = n - 1
bit = 1
for i in range(n):
	if a[i] == b[i]:
		while a[i] == b[cur] or a[cur] == b[i]:
			if cur == 0:
				bit = -1
			if bit == -1 and cur == n - 1:
				print('No')
				exit(0)
			cur -= bit
		(b[i], b[cur]) = (b[cur], b[i])
print('Yes')
print(' '.join(list(map(str, b))))


import heapq
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
d = defaultdict(list)
for i in range(N):
	a = A[i]
	b = B[i]
	if a == b:
		d[a].append(i)
h = []
for a in d:
	heapq.heappush(h, (-len(d[a]), a))
while len(h) >= 2:
	(x, a) = heapq.heappop(h)
	(y, b) = heapq.heappop(h)
	i = d[a].pop()
	j = d[b].pop()
	(B[i], B[j]) = (B[j], B[i])
	x += 1
	y += 1
	if x < 0:
		heapq.heappush(h, (x, a))
	if y < 0:
		heapq.heappush(h, (y, b))
ans = 'Yes'
if h:
	(x, a) = heapq.heappop(h)
	if len(d[a]) * 2 > N:
		ans = 'No'
	else:
		d[a] = d[a][::-1]
		for i in range(N):
			if len(d[a]) == 0:
				break
			if A[i] != a and B[i] != a:
				j = d[a].pop()
				(B[i], B[j]) = (B[j], B[i])
if len(d[a]) > 0:
	ans = 'No'
print(ans)
if ans == 'Yes':
	print(*B)


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cnt = 0
step = 0
for i in range(N):
	if A[step] == B[i]:
		cnt += 1
	else:
		step += 1
flag = 0
for j in range(300):
	C = B[cnt + j:] + B[:cnt + j]
	flag = 0
	for i in range(N):
		if A[i] == C[i]:
			flag = 1
			break
	if i == N - 1 and flag == 0:
		break
if flag == 1:
	print('No')
else:
	print('Yes')
	print(' '.join(map(str, C)))


n = int(input())
lst_a = [int(i) for i in input().split()]
lst_b = [int(i) for i in input().split()]
j = 0
flag = True
for i in range(n):
	if i > 0:
		if lst_a[i] != lst_a[i - 1]:
			j = 0
	if lst_a[i] != lst_b[i]:
		continue
	else:
		flag = False
		while j != n:
			if lst_a[i] != lst_b[j] and lst_a[j] != lst_b[i]:
				(lst_b[i], lst_b[j]) = (lst_b[j], lst_b[i])
				flag = True
				break
			j += 1
		if not flag:
			break
if not flag:
	print('No')
else:
	print('Yes')
	lst_b = [str(i) for i in lst_b]
	print(' '.join(lst_b))


import sys
import heapq
hpush = heapq.heappush
hpop = heapq.heappop
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ca = [0] * (N + 1)
cb = [0] * (N + 1)
for x in a:
	ca[x] += 1
for x in b:
	cb[x] += 1
for i in range(1, N + 1):
	if ca[i] + cb[i] > N:
		print('No')
		exit(0)
res = [0] * N
h = []
for i in range(1, N + 1):
	if cb[i]:
		r = N - ca[i] - cb[i] + 1
		hpush(h, (r, i))
s = []
table = [0] * (N + 1)
use = [0] * (N + 1)
for i in range(N):
	table[a[i]] += 1
	if len(s) and s[-1] != a[i]:
		x = s.pop()
		hpush(h, (N - ca[x] - cb[x] + 1 + table[x] + use[x], x))
	if len(h) == 0:
		print('No')
		exit(0)
	(r, x) = hpop(h)
	if x == a[i]:
		s.append(x)
		if len(h) == 0:
			print('No')
			exit(0)
		(r, x) = hpop(h)
	while r != N - ca[x] - cb[x] + 1 + table[x] + use[x]:
		hpush(h, (N - ca[x] - cb[x] + 1 + table[x] + use[x], x))
		(r, x) = hpop(h)
	res[i] = x
	use[x] += 1
	if cb[x] - use[x]:
		hpush(h, (r + 1, x))
for i in range(N):
	if res[i] == a[i]:
		print('No')
		break
else:
	print('Yes')
	print(*res)


from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float('inf')

def main():
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = [0] * (N + 1)
	D = [0] * (N + 1)
	for i in range(N):
		C[A[i]] += 1
		D[B[i]] += 1
	for i in range(N + 1):
		if C[i] + D[i] > N:
			print('No')
			return
	for i in range(N):
		C[i + 1] += C[i]
		D[i + 1] += D[i]
	x = 0
	for i in range(1, N + 1):
		if x < C[i] - D[i - 1]:
			x = C[i] - D[i - 1]
	print('Yes')
	for i in range(N):
		if i != 0:
			print(' ', end='')
		print(B[(i + N - x) % N], end='')
	print('')
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
d = [0] * n
g = 0
for i in range(n):
	c[a[i] - 1] += 1
	d[b[i] - 1] += 1
for i in range(n):
	g = max(g, c[i] + d[i])
e = [c[0]]
f = [d[0]]
h = e[0]
for i in range(1, n):
	e.append(c[i] + e[-1])
	f.append(d[i] + f[-1])
for i in range(n - 1):
	h = max(h, e[i + 1] - f[i])
if g > n:
	print('No')
else:
	print('Yes')
	print(*b[n - h:] + b[:n - h])


import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
start = 0
ind = 0
NG = [0] * (2 * N + 1)
bdic = {}
for (i, b) in enumerate(B):
	if not b in bdic:
		bdic[b] = [i, i]
	else:
		bdic[b] = [min(bdic[b][0], i), max(bdic[b][1], i)]
for (i, a) in enumerate(A):
	if a in bdic:
		(j1, j2) = bdic[a]
		if j1 >= i:
			NG[j1 - i] += 1
			NG[j2 - i + 1] -= 1
		elif j2 < i:
			NG[j1 - i + N] += 1
			NG[j2 - i + 1 + N] -= 1
		else:
			NG[j1 - i + N] += 1
			NG[0] += 1
			NG[j2 - i + 1] -= 1
start = -1
for i in range(N):
	if NG[i] == 0:
		start = i
		break
	NG[i + 1] += NG[i]
if start == -1:
	print('No')
else:
	print('Yes')
	ans = []
	for i in range(N):
		ans.append(B[(i + start) % N])
	print(*ans)


import sys
input = sys.stdin.readline
t = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b = b[::-1]
el = -10 ** 99
ok = 1
(pref, aft) = (-1, 9999999999)
pos = set()
for i in range(t):
	if a[i] == b[i]:
		pos.add(i)
		el = a[i]
		ok = 0
for i in range(t):
	if a[i] == el or b[i] == el:
		break
	pref = i
for i in range(t):
	if a[i] > el and b[i] != el:
		aft = i
		break
if ok == 1:
	print('Yes')
	print(*b)
	exit()
elif len(pos) > 1 + pref + (t - aft):
	print('No')
else:
	try:
		for i in range(pref + 1):
			x = pos.pop()
			(b[i], b[x]) = (b[x], b[i])
		for i in range(aft, t):
			x = pos.pop()
			(b[i], b[x]) = (b[x], b[i])
	except:
		pass
	print('Yes')
	print(*b)


import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
count = [0] * (N + 1)
for (a, b) in zip(A, B):
	count[a] += 1
	count[b] += 1
for i in range(N + 1):
	if count[i] > N:
		print('No')
		return
diff = 0
checked = set()
ida = 0
for (i, b) in enumerate(B):
	if b in checked:
		continue
	checked.add(b)
	while ida < N and A[ida] <= b:
		ida += 1
	diff = max(diff, ida - i)
idx = (np.arange(N) - diff) % N
print('Yes')
print(*np.array(B)[idx])


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * (n + 1)
d = [0] * (n + 1)
for i in range(n):
	c[a[i]] += 1
	d[b[i]] += 1
for i in range(n + 1):
	if c[i] + d[i] > n:
		print('No')
		sys.exit(0)
import itertools
c = list(itertools.accumulate(c))
d = list(itertools.accumulate(d))
max_gap = 0
for i in range(1, n + 1):
	max_gap = max(max_gap, c[i] - d[i - 1])
ans = [0] * n
for i in range(n):
	ans[(i + max_gap) % n] = str(b[i])
print('Yes')
print(' '.join(ans))


import collections
import sys

def solve(n, A, B):
	ans = B[:]
	same = collections.deque()
	for (i, (a, b)) in enumerate(zip(A, B)):
		if a == b:
			if same and B[same[0]] != a:
				j = same.popleft()
				(B[i], B[j]) = (B[j], B[i])
			else:
				same.append(i)
	if same:
		s = A[same[0]]
		to_swap = []
		possible = False
		for (i, (a, b)) in enumerate(zip(A, B)):
			if a != s and b != s:
				to_swap.append(i)
			if len(to_swap) == len(same):
				possible = True
				break
		if not possible:
			print('No')
			return
		for (i, j) in zip(same, to_swap):
			(B[i], B[j]) = (B[j], B[i])
	print('Yes')
	print(*B, sep=' ')

def main():
	input = sys.stdin.readline
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	solve(n, A, B)
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnta = [0] * (n + 1)
cntb = [0] * (n + 1)
ta = 0
tb = 0
s = [0] * (n + 1)
for i in range(n):
	cnta[a[i]] += 1
	cntb[b[i]] += 1
	s[a[i]] += 1
	s[b[i]] += 1
if max(s) > n:
	print('No')
	exit()
print('Yes')
m = 0
for i in range(1, n + 1):
	cnta[i] += cnta[i - 1]
	cntb[i] += cntb[i - 1]
for i in range(1, n + 1):
	m = max(m, cnta[i] - cntb[i - 1])
print(*b[-m:] + b[0:-m])


from collections import Counter, deque
from random import randint
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
CA = Counter(A)
CB = Counter(B)
keys = set(A + B)
M = 0
for k in keys:
	M = max(M, CA[k] + CB[k])
if M > N:
	print('No')
	exit()
CB = CB.most_common()
(L, R) = ([], [])
for (i, x) in enumerate(CB):
	if i % 2 == 0:
		L.append(list(x))
	else:
		R.append(list(x))
X = deque(L + R[::-1])
y = L + R
ans = [None] * N
for i in range(N):
	if X[0][0] != A[i] and X[-1][0] != A[i]:
		if X[0][1] > X[-1][1]:
			ans[i] = X[0][0]
			X[0][1] -= 1
			if X[0][1] == 0:
				X.popleft()
		else:
			ans[i] = X[-1][0]
			X[-1][1] -= 1
			if X[-1][1] == 0:
				X.pop()
	elif X[0][0] != A[i]:
		ans[i] = X[0][0]
		X[0][1] -= 1
		if X[0][1] == 0:
			X.popleft()
	else:
		ans[i] = X[-1][0]
		X[-1][1] -= 1
		if X[-1][1] == 0:
			X.pop()
for i in range(10):
	m = randint(0, N - 1)
	for i in range(N):
		if ans[i] != A[i]:
			continue
		(ans[i], ans[m]) = (ans[m], ans[i])
		m += 1
		m %= N
print('Yes')
print(*ans, sep=' ')


def main():
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))[::-1]
	Cnt = [0] * (n + 1)
	for (a, b) in zip(A, B):
		Cnt[a] += 1
		Cnt[b] += 1
	if max(Cnt) > n:
		print('No')
		return
	l = 0
	r = n - 1
	for i in range(n):
		if A[i] == B[i]:
			if B[l] != A[i] and A[l] != A[i]:
				(B[l], B[i]) = (B[i], B[l])
				l += 1
			else:
				(B[r], B[i]) = (B[i], B[r])
				r -= 1
	print('Yes')
	print(*B)
	return
main()


def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(ai, bi) = (0, 0)
	stride = 0
	while ai < n and bi < n:
		(ax, bx) = (a[ai], b[bi])
		if ax == bx:
			cnt = 2
			ai += 1
			while ai < n and a[ai] == ax:
				cnt += 1
				ai += 1
			bi_copy = bi
			bi += 1
			while bi < n and b[bi] == bx:
				cnt += 1
				bi += 1
			if cnt > n:
				print('No')
				return
			if stride < ai - bi_copy:
				stride = ai - bi_copy
		elif ax < bx:
			ai += 1
		else:
			bi += 1
	print('Yes')
	print(' '.join(map(str, b[n - stride:] + b[:n - stride])))
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))[::-1]
l = 0
r = n - 1
ans = []
for i in range(n):
	if a[i] == b[i]:
		ans.append(i)
for i in ans:
	if b[i] != a[l] and b[i] != b[l]:
		(b[l], b[i]) = (b[i], b[l])
		l += 1
		continue
	if b[i] != a[r] and b[i] != b[r]:
		(b[r], b[i]) = (b[i], b[r])
		r -= 1
f = 0
for i in range(n):
	if a[i] == b[i]:
		f = 1
		break
if f:
	print('No')
else:
	print('Yes')
	print(*b)


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
from collections import Counter
cA = Counter(A)
cB = Counter(B)
f = 0
for (num, val) in cA.items():
	if num not in cB:
		continue
	elif cB[num] + val > N:
		f = 1
tpA = [-1] * (N + 1)
tpB = [-1] * (N + 1)
a = A[0]
b = B[0]
tpB[b] = 0
for i in range(1, N):
	if a != A[i]:
		tpA[a] = i
		a = A[i]
	if b != B[i]:
		b = B[i]
		tpB[b] = i
tpA[a] = N
ans = [0] * N
if f == 1:
	print('No')
else:
	print('Yes')
	t = 0
	for i in range(N + 1):
		if tpA[i] >= 0 and tpB[i] >= 0:
			t = max(t, tpA[i] - tpB[i])
	for i in range(N):
		ans[i + t - N] = B[i]
	print(' '.join([str(_) for _ in ans]))


import sys
import heapq

def input():
	return sys.stdin.readline().rstrip()

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

	def diff(s, cc):
		count = 0
		for i in range(N):
			if A[i] == B[(i + s) % N]:
				count += 1
				if count > cc:
					return cc + 1
		if count == 0:
			print('Yes')
			L = []
			for i in range(N):
				L.append(B[(i + s) % N])
			print(*L)
			exit()
		return count
	n = N // 3
	l = 0
	r = N - 1
	diff(l, N)
	diff(r, N)
	while r - l > 2:
		m1 = l + (r - l) // 3
		m2 = l + 2 * (r - l) // 3
		a = diff(m1, N)
		b = diff(m2, a + 1)
		if a > b:
			l = m1
		else:
			r = m2
	diff((l + r) // 2, N)
	print('No')
main()


from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cntA = [0] * (N + 1)
cntB = [0] * (N + 1)
for i in range(N):
	cntA[A[i]] += 1
	cntB[B[i]] += 1
nums = [(cntA[i], cntB[i], i) for i in range(1, N + 1) if cntA[i] or cntB[i]]
nums.sort(key=lambda p: p[0] + p[1], reverse=True)
a = deque()
b = deque()
c = deque(list(range(N)))
ansa = [0] * N
ansb = [0] * N
for (x, y, n) in nums:
	if x + y > len(a) + len(b) + len(c):
		print('No')
		exit()
	ra = x - len(a)
	rb = y - len(b)
	for i in range(ra):
		ansa[c[0]] = n
		b.append(c[0])
		c.popleft()
		x -= 1
	for i in range(rb):
		ansb[c[0]] = n
		a.append(c[0])
		c.popleft()
		y -= 1
	while c and (x or y):
		if x:
			ansa[c[0]] = n
			b.append(c[0])
			x -= 1
		else:
			ansb[c[0]] = n
			a.append(c[0])
			y -= 1
		c.popleft()
	for i in range(x):
		ansa[a[0]] = n
		a.popleft()
	for i in range(y):
		ansb[b[0]] = n
		b.popleft()
ans = [(ansa[i], ansb[i]) for i in range(N)]
ans.sort()
print('Yes')
print(*[p[1] for p in ans])


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
from collections import Counter, deque
(x, y) = (Counter(a), Counter(b))
for i in range(1, n + 1):
	if x[i] + y[i] > n:
		print('No')
		exit()
ans = b[::-1]
change = deque()
num = -1
now = deque()
for i in range(n):
	if a[i] == ans[i]:
		change.append(i)
		num = ans[i]
	else:
		now.append(i)
if change == []:
	print('Yes')
	print(' '.join(map(str, ans)))
	exit()
while len(change):
	q = now.popleft()
	p = change.popleft()
	if a[q] != num and ans[q] != num:
		(ans[q], ans[p]) = (ans[p], ans[q])
	else:
		change.appendleft(p)
print('Yes')
print(' '.join(map(str, ans)))


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [0] * (N + 1)
D = [0] * (N + 1)
E = [0] * (N + 1)
for i in range(N):
	C[A[i]] += 1
	D[B[i]] += 1
	E[A[i]] += 1
	E[B[i]] += 1
if max(E) > N:
	print('No')
	exit()
for i in range(1, N + 1):
	C[i] += C[i - 1]
	D[i] += D[i - 1]
ans = 0
for i in range(1, N + 1):
	ans = max(ans, C[i] - D[i - 1])
B = [B[(i - ans) % N] for i in range(N)]
print('Yes')
print(' '.join(map(str, B)))


import sys
readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))
from collections import Counter
cA = Counter(A)
cB = Counter(B)
import heapq as hq
q = []
hq.heapify(q)
for (key, value) in cB.items():
	if key in cA:
		hq.heappush(q, (-(value + cA[key]), value, key))
		if value + cA[key] > N:
			print('No')
			exit(0)
	else:
		hq.heappush(q, (-value, value, key))
print('Yes')
a_ind = 0
ans = []
while a_ind < N:
	keep = []
	while True:
		(allcnt, bcnt, key) = hq.heappop(q)
		allcnt *= -1
		if A[a_ind] == key:
			keep.append((allcnt, bcnt, key))
		else:
			ans.append(key)
			if bcnt - 1 > 0:
				hq.heappush(q, (-(allcnt - 1), bcnt - 1, key))
			break
	for k in keep:
		hq.heappush(q, k)
	a_ind += 1
print(*ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.reverse()
c = []
cs = -1
e = -1
for i in range(n):
	if a[i] > b[i]:
		c.append(1)
	elif a[i] == b[i]:
		c.append(0)
		e = a[i]
		if cs == -1:
			cs = i
	else:
		c.append(-1)
ans = 0
db = 0
for i in range(n):
	if a[i] == e:
		ans += 1
	if b[i] == e:
		ans += 1
	if a[i] == b[i]:
		db += 1
if ans > n:
	print('No')
	exit()
print('Yes')
cnt = 0
for i in range(n):
	if cnt == db:
		break
	if a[i] != e and b[i] != e:
		(b[i], b[cs + cnt]) = (b[cs + cnt], b[i])
		cnt += 1
print(' '.join(map(str, b)))


import sys
from collections import Counter

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

def list2d(a, b, c):
	return [[c for j in range(b)] for i in range(a)]

def list3d(a, b, c, d):
	return [[[d for k in range(c)] for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

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

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** (-10)
N = INT()
A = LIST()
B = LIST()
C1 = Counter(A)
C2 = Counter(B)
for (k, v) in C1.items():
	if v > N - C2[k]:
		No()
		exit()
ans = B[ceil(N, 2):] + B[:ceil(N, 2)]

def check(A, B):
	for i in range(N):
		if A[i] == B[i]:
			return i
	return -1

def swap(x, A, B):
	for i in range(N):
		if A[x] != B[i] and A[i] != B[x]:
			(B[x], B[i]) = (B[i], B[x])
			return True
	return False
while 1:
	res = check(A, ans)
	if res == -1:
		Yes()
		print(*ans)
		break
	elif not swap(res, A, ans):
		No()
		break


import sys
import heapq
from functools import lru_cache

def input():
	return sys.stdin.readline().rstrip()

def main():
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	n = N // 3

	@lru_cache(maxsize=None)
	def diff(s):
		count = 0
		for i in range(N):
			if A[i] == B[(i + s) % N]:
				count += 1
		if count == 0:
			print('Yes')
			L = []
			for i in range(N):
				L.append(B[(i + s) % N])
			print(*L)
			exit()
		return count
	l = 0
	r = N - 1
	diff(l)
	diff(r)
	while r - l > 2:
		a = diff(l + (r - l) // 3)
		b = diff(l + 2 * (r - l) // 3)
		if a > b:
			l = l + (r - l) // 3
		else:
			r = l + 2 * (r - l) // 3
	diff((l + r) // 2)
	print('No')
main()


import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
	from collections import Counter
	N = int(readline())
	a = list(map(int, readline().split()))
	b = list(map(int, readline().split()))
	cnt_a = Counter(a)
	cnt_b = Counter(b)
	acc_a = [0] * 200001
	acc_b = [0] * 200001
	for i in range(1, 200001):
		acc_a[i] = acc_a[i - 1] + cnt_a[i]
		acc_b[i] = acc_b[i - 1] + cnt_b[i]
		if cnt_a[i] + cnt_b[i] > N:
			return print('No')
	ans = 0
	for i in range(200000, 0, -1):
		score = acc_b[i] - acc_a[i - 1]
		ans = max(ans, score)
	print('Yes')
	res = b[ans:] + b[:ans]
	print(*res)
main()


from collections import *
from bisect import *
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ca = Counter(a)
cb = Counter(b)
for i in a:
	if ca[i] + cb[i] > n:
		print('No')
		exit()
print('Yes')
ba = [bisect(a, i + 1) for i in range(n)]
bb = [bisect_left(b, i + 1) for i in range(n)]
i = 0
for (x, y) in zip(ba, bb):
	i = max(i, x - y)
ans = b[n - i:] + b[:n - i]
print(*ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
coa = [0] * (n + 1)
cob = [0] * (n + 1)
for i in a:
	coa[i] += 1
for i in b:
	cob[i] += 1
for i in range(n + 1):
	if coa[i] + cob[i] > n:
		print('No')
		exit()
b.sort(reverse=True)
ans = b[:]
changed = 0
for i in range(n):
	if a[i] == b[i]:
		(ans[i], ans[changed]) = (ans[changed], ans[i])
		changed += 1
chenged_b = -1
for i in range(n):
	if a[i] == ans[i]:
		(ans[i], ans[chenged_b]) = (ans[chenged_b], ans[i])
		chenged_b -= 1
print('Yes')
print(*ans)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_cnt = Counter(A)
B_cnt = Counter(B)
for i in range(1, N + 1):
	if N < A_cnt[i] + B_cnt[i]:
		print('No')
		break
else:
	print('Yes')
	cnt = 0
	indexes = {}
	alreadychecked = set()
	for i in range(N):
		if A[i] not in alreadychecked:
			indexes[A[i]] = i
			alreadychecked.add(A[i])
	zure = 0
	alreadychecked = set()
	for i in range(N - 1, -1, -1):
		if B[i] not in alreadychecked:
			if B[i] in indexes and indexes[B[i]] <= i:
				zure = max(zure, i - indexes[B[i]] + 1)
				alreadychecked.add(B[i])
	print(*B[zure:], *B[:zure])


import math
import numpy as np
import decimal
import collections
import itertools
import sys
import random

class UnionFind:

	def __init__(self, n):
		self.n = n
		self.par = [-1 for i in range(self.n)]

	def find(self, x):
		if self.par[x] < 0:
			return x
		else:
			self.par[x] = self.find(self.par[x])
			return self.par[x]

	def unite(self, x, y):
		p = self.find(x)
		q = self.find(y)
		if p == q:
			return None
		if p > q:
			(p, q) = (q, p)
		self.par[p] += self.par[q]
		self.par[q] = p

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def size(self, x):
		return -self.par[self.find(x)]

def prime_numbers(x):
	if x < 2:
		return []
	prime_numbers = [i for i in range(x)]
	prime_numbers[1] = 0
	for prime_number in prime_numbers:
		if prime_number > math.sqrt(x):
			break
		if prime_number == 0:
			continue
		for composite_number in range(2 * prime_number, x, prime_number):
			prime_numbers[composite_number] = 0
	return [prime_number for prime_number in prime_numbers if prime_number != 0]

def is_prime(x):
	if x < 2:
		return False
	if x == 2 or x == 3 or x == 5:
		return True
	if x % 2 == 0 or x % 3 == 0 or x % 5 == 0:
		return False
	prime_number = 7
	difference = 4
	while prime_number <= math.sqrt(x):
		if x % prime_number == 0:
			return False
		prime_number += difference
		difference = 6 - difference
	return True

def prime_factorize(n):
	res = []
	while n % 2 == 0:
		res.append(2)
		n //= 2
	f = 3
	while f ** 2 <= n:
		if n % f == 0:
			res.append(f)
			n //= f
		else:
			f += 2
	if n != 1:
		res.append(n)
	return res
mod = 10 ** 9 + 7

class nCr:

	def __init__(self, n):
		self.n = n
		self.fa = [1] * (self.n + 1)
		self.fi = [1] * (self.n + 1)
		for i in range(1, self.n + 1):
			self.fa[i] = self.fa[i - 1] * i % mod
			self.fi[i] = pow(self.fa[i], mod - 2, mod)

	def comb(self, n, r):
		if n < r:
			return 0
		if n < 0 or r < 0:
			return 0
		return self.fa[n] * self.fi[r] % mod * self.fi[n - r] % mod

def extgcd(a, b, d=0):
	g = a
	if b == 0:
		(x, y) = (1, 0)
	else:
		(x, y, g) = extgcd(b, a % b)
		(x, y) = (y, x - a // b * y)
	return (x, y, g)

class BinaryIndexedTree:

	def __init__(self, n):
		self.n = n
		self.BIT = [0] * (self.n + 1)

	def add(self, i, x):
		while i <= self.n:
			self.BIT[i] += x
			i += i & -i

	def query(self, i):
		res = 0
		while i > 0:
			res += self.BIT[i]
			i -= i & -i
		return res

class AssociativeArray:

	def __init__(self, q):
		self.dic = dict()
		self.q = q

	def solve(self):
		for i in range(self.q):
			Query = list(map(int, input().split()))
			if Query[0] == 0:
				(x, y, z) = Query
				self.dic[y] = z
			else:
				(x, y) = Query
				if y in self.dic:
					print(self.dic[y])
				else:
					print(0)

def floor_sum(n, m, a, b):
	res = 0
	if a >= m:
		res += (n - 1) * n * (a // m) // 2
		a %= m
	if b >= m:
		res += n * (b // m)
		b %= m
	y_max = (a * n + b) // m
	x_max = y_max * m - b
	if y_max == 0:
		return res
	res += y_max * (n + -x_max // a)
	res += floor_sum(y_max, a, m, (a - x_max % a) % a)
	return res

def z_algorithm(s):
	str_len = len(s)
	res = [0] * str_len
	res[str_len - 1] = str_len
	(i, j) = (1, 0)
	while i < str_len:
		while i + j < str_len and s[i + j] == s[j]:
			j += 1
		res[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < str_len and j > res[k] + k:
			res[i + k] = res[k]
			k += 1
		i += k
		j -= k
	return res

class Manacher:

	def __init__(self, s):
		self.s = s

	def coustruct(self):
		(i, j) = (0, 0)
		s_len = len(self.s)
		res = [0] * s_len
		while i < s_len:
			while i - j >= 0 and i + j < s_len and (self.s[i - j] == self.s[i + j]):
				j += 1
			res[i] = j
			k = 1
			while i - k >= 0 and k + res[i - k] < j:
				k += 1
			i += k
			j -= k

def mod_sqrt(a, p):
	if a == 0:
		return 0
	if p == 2:
		return 1
	k = (p - 1) // 2
	if pow(a, k, p) != 1:
		return -1
	while True:
		n = random.randint(2, p - 1)
		r = (n ** 2 - a) % p
		if r == 0:
			return n
		if pow(r, k, p) == p - 1:
			break
	k += 1
	(w, x, y, z) = (n, 1, 1, 0)
	while k:
		if k % 2:
			(y, z) = (w * y + r * x * z, x * y + w * z)
		(w, x) = (w * w + r * x * x, 2 * w * x)
		w %= p
		x %= p
		y %= p
		z %= p
		k >>= 1
	return y
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cur = 0
before = 0
for i in range(n):
	if before != a[i]:
		cur = 0
	if a[i] == b[i]:
		while cur < n:
			if a[i] != b[cur] and a[i] != a[cur]:
				(b[i], b[cur]) = (b[cur], b[i])
				break
			cur += 1
		else:
			print('No')
			return
	before = a[i]
print('Yes')
print(*b)


N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
a = [0] * (N + 1)
b = [0] * (N + 1)
for i in range(N):
	a[A[i]] += 1
	b[B[i]] += 1
ok = True
for i in range(1, N + 1):
	if a[i] + b[i] > N:
		ok = False
sa = [0] * (N + 1)
sb = [0] * (N + 1)
for i in range(N):
	sa[i + 1] = sa[i] + a[i + 1]
	sb[i + 1] = sb[i] + b[i + 1]
ans = 0
for i in range(N):
	ans = max(ans, sa[i + 1] - sb[i])
if ok:
	print('Yes')
	for i in range(N):
		print(B[(i + N - ans) % N], end='')
		if i == N - 1:
			print('')
		else:
			print(' ', end='')
else:
	print('No')


N = int(input())
(*A,) = map(int, input().split())
(*B,) = map(int, input().split())
B.reverse()
ac = [0] * (N + 1)
bc = [0] * (N + 1)
ok = True
for i in range(N):
	ac[A[i]] += 1
	bc[B[i]] += 1
for i in range(1, N + 1):
	if ac[i] + bc[i] > N:
		ok = False
		break
if ok:
	(l, r) = (0, N - 1)
	for i in range(N):
		if A[i] == B[i]:
			if A[i] != B[l] and A[l] != B[i]:
				(B[l], B[i]) = (B[i], B[l])
				l += 1
			elif A[i] != B[r] and A[r] != B[i]:
				(B[r], B[i]) = (B[i], B[r])
				r -= 1
	print('Yes')
	print(*B)
else:
	print('No')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.reverse()
c = [0] * (n + 1)
for i in a:
	c[i] += 1
for i in b:
	c[i] += 1
if max(c) > n:
	print('No')
	return
l = 0
while l < n and a[l] != b[l]:
	l += 1
i = 0
while l < n and a[l] == b[l]:
	while a[i] == b[l] or a[l] == b[i]:
		i += 1
	(b[i], b[l]) = (b[l], b[i])
	l += 1
print('Yes')
print(' '.join([str(i) for i in b]))


def solve(n, a, b):
	b.reverse()
	(l, r) = (0, n - 1)
	for i in range(n):
		if a[i] == b[i]:
			if l < i and a[i] != b[l] and (a[l] != b[i]):
				(b[l], b[i]) = (b[i], b[l])
				l += 1
			elif i < r and a[i] != b[r] and (a[r] != a[i]):
				(b[r], b[i]) = (b[i], b[r])
				r -= 1
			else:
				return 'No'
	return '\n'.join(['Yes', ' '.join(map(str, b))])
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(solve(n, a, b))


import sys
from itertools import accumulate
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	N = int(readline())
	A = list(map(int, readline().split()))
	B = list(map(int, readline().split()))
	C = [0] * (N + 1)
	D = [0] * (N + 1)
	for i in range(N):
		C[A[i]] += 1
		D[B[i]] += 1
	for i in range(1, N + 1):
		if C[i] + D[i] > N:
			print('No')
			return
	print('Yes')
	C = list(accumulate(C))
	D = list(accumulate(D))
	B.reverse()
	i = 0
	while i < N and A[i] != B[i]:
		i += 1
	if i == N:
		print(*B)
		return
	n = A[i]
	leftA = C[n - 1]
	rightA = C[n]
	leftB = N - D[n]
	rightB = N - D[n - 1]
	i1 = min(leftA, leftB)
	i2 = max(leftA, leftB)
	i3 = min(rightA, rightB)
	i4 = max(rightA, rightB)
	c = 0
	for i in range(i1):
		if c == i3 - i2:
			break
		(B[i], B[i2 + c]) = (B[i2 + c], B[i])
		c += 1
	for i in range(i4, N):
		if c == i3 - i2:
			break
		(B[i], B[i2 + c]) = (B[i2 + c], B[i])
		c += 1
	print(*B)
	return
main()


import bisect
n = int(input())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
sA = set(A)
sB = set(B)
x = 0
for i in sA & sB:
	r = bisect.bisect_right(A, i)
	l = bisect.bisect_left(B, i)
	x = max(x, r - l)
ans = B[-x:] + B[:-x]
for (a, b) in zip(A, ans):
	if a == b:
		print('No')
		break
else:
	print('Yes')
	print(*ans)


import sys
from itertools import accumulate
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	N = int(readline())
	A = list(map(int, readline().split()))
	B = list(map(int, readline().split()))
	C = [0] * (N + 1)
	D = [0] * (N + 1)
	for i in range(N):
		C[A[i]] += 1
		D[B[i]] += 1
	for i in range(1, N + 1):
		if C[i] + D[i] > N:
			print('No')
			return
	print('Yes')
	C = list(accumulate(C))
	D = list(accumulate(D))
	B.reverse()
	i = 0
	while i < N and A[i] != B[i]:
		i += 1
	if i == N:
		print(*B)
		return
	n = A[i]
	idx_ng = []
	idx_ok = []
	for i in range(N):
		if A[i] == n and B[i] == n:
			idx_ng.append(i)
		elif A[i] != n and B[i] != n:
			idx_ok.append(i)
	for (ng, ok) in zip(idx_ng, idx_ok):
		(B[ng], B[ok]) = (B[ok], B[ng])
	print(*B)
	return
main()


from itertools import accumulate
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def solve():
	INF = 10 ** 10
	N = int(input())
	As = list(map(int, input().split())) + [INF]
	Bs = list(map(int, input().split())) + [INF]

	def f(As):
		sts = [-1] * (N + 1)
		ens = [-1] * (N + 1)
		i = 0
		for v in range(1, N + 1):
			if As[i] == v:
				sts[v] = i
			else:
				continue
			while As[i] == v:
				i += 1
			ens[v] = i - 1
		return (sts, ens)
	(stAs, enAs) = f(As)
	(stBs, enBs) = f(Bs)
	imoss = [0] * (2 * N + 1)
	for v in range(1, N + 1):
		if stAs[v] == -1 or stBs[v] == -1:
			continue
		L = stAs[v] - enBs[v] + N
		R = enAs[v] - stBs[v] + N
		imoss[L] += 1
		imoss[R + 1] -= 1
	imoss = list(accumulate(imoss))
	Cs = [imoss[i] + imoss[i + N] for i in range(N)]
	numShift = -1
	for i in range(N):
		if Cs[i] == 0:
			numShift = i
			break
	if numShift == -1:
		print('No')
	else:
		print('Yes')
		anss = [Bs[(i - numShift) % N] for i in range(N)]
		print(' '.join(map(str, anss)))
solve()


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = list(reversed(list(map(int, input().split()))))
ac = Counter(A)
bc = Counter(B)
am = ac.most_common(1)[0]
if am[1] + bc[am[0]] > N:
	print('No')
	exit()
j = 0
for i in range(N):
	if A[i] == B[i]:
		while B[i] == A[j] or B[j] == A[i]:
			j += 1
			j %= N
		(B[i], B[j]) = (B[j], B[i])
print('Yes')
print(*B)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.reverse()
p = 1
c = 0
d = 0
for i in range(n):
	if a[i] == b[i]:
		v = a[i]
		h = i
		p = 0
		break
if p == 1:
	print('Yes')
	for i in range(n):
		print(b[i], end=' ')
else:
	for i in range(n):
		if a[i] != v and b[i] != v:
			c += 1
		if b[i] == a[i]:
			d += 1
	if c < d:
		print('No')
	else:
		print('Yes')
		o = 0
		for i in range(n):
			if a[i] != v and b[i] != v:
				(b[i], b[h + o]) = (b[o + h], b[i])
				o += 1
				if o == d:
					break
		for i in range(n):
			print(b[i], end=' ')


import sys
from bisect import bisect_right, bisect_left
from collections import Counter

def main():
	input = sys.stdin.buffer.readline
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cnt = Counter(a + b)
	(e, num) = cnt.most_common(1)[0]
	if num > n:
		print('No')
	else:
		step = 0
		for e in set(a) & set(b):
			s = bisect_right(a, e) - bisect_left(b, e)
			step = max(step, s)
		ans = [0] * n
		for i in range(n):
			ans[i] = b[(i - step) % n]
		print('Yes')
		print(*ans)
main()


import sys
readline = sys.stdin.readline
read = sys.stdin.read
(n,) = map(int, readline().split())
(*a,) = map(int, readline().split())
(*b,) = map(int, readline().split())
b = b[::-1]
same = [i for i in range(n) if a[i] == b[i]]
if same:
	v = a[same[0]]
	notv = [i for i in range(n) if a[i] != v and b[i] != v]
	if len(same) > len(notv):
		print('No')
		return
	for (i, j) in zip(same, notv):
		(b[i], b[j]) = (b[j], b[i])
print('Yes')
print(*b)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	b = list(reversed(b))
	bad = next((x for (x, y) in zip(a, b) if x == y), None)
	if bad is None:
		print('Yes')
		print(' '.join(map(str, b)))
	else:
		l_1 = sum((1 for (x, y) in zip(a, b) if x < bad < y))
		l_2 = sum((1 for (x, y) in zip(a, b) if x < y and bad in (x, y)))
		l_3 = sum((1 for (x, y) in zip(a, b) if x == y))
		l_4 = sum((1 for (x, y) in zip(a, b) if x > y and bad in (x, y)))
		l_5 = sum((1 for (x, y) in zip(a, b) if x > bad > y and x != bad))
		if l_3 > l_1 + l_5:
			print('No')
		else:
			good_part = b[:l_1] + b[l_1 + l_2 + l_3 + l_4:]
			bad_part = b[l_1 + l_2:l_1 + l_2 + l_3]
			b[l_1 + l_2:l_1 + l_2 + l_3] = good_part[:l_3]
			good_part[:l_3] = bad_part
			b[:l_1] = good_part[:l_1]
			b[l_1 + l_2 + l_3 + l_4:] = good_part[l_1:]
			assert all((x != y for (x, y) in zip(a, b)))
			print('Yes')
			print(' '.join(map(str, b)))
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
import collections
ac = collections.Counter(a)
bc = collections.Counter(b)
for i in range(1, n + 1):
	if ac[i] + bc[i] > n:
		print('No')
		exit()
from collections import defaultdict
a_right = defaultdict(int)
b_left = defaultdict(int)
for i in range(n):
	a_right[a[i]] = i
for i in reversed(range(n)):
	b_left[b[i]] = i
sft = [0]
for dup in set(a) & set(b):
	sft.append(a_right[dup] - b_left[dup] + 1)
from collections import deque
b = deque(b)
b.rotate(max(sft))
print('Yes')
print(*b)


import numpy as np
import sys
read = sys.stdin.readline
n = int(input())
a = np.fromstring(read(), dtype=np.int32, sep=' ')
b = np.fromstring(read(), dtype=np.int32, sep=' ')[::-1]
kokan = []
same = -1
for i in range(n):
	if a[i] == b[i]:
		same = a[i]
if same == -1:
	print('Yes')
	print(*b)
	return
for i in range(n):
	if a[i] != b[i] and a[i] != same and (b[i] != same):
		kokan.append(i)
for i in range(n):
	if a[i] == b[i]:
		if len(kokan) == 0:
			print('No')
			return
		else:
			j = kokan[-1]
			(b[i], b[j]) = (b[j], b[i])
			kokan.pop()
print('Yes')
print(*b)


import sys
import collections
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline

def main():
	N = int(input())
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	ac = collections.Counter(A)
	bc = collections.Counter(B)
	for i in range(1, N + 1):
		if ac[i] + bc[i] > N:
			print('No')
			return
	ma = 0
	cnta = 0
	cntb = 0
	for i in range(1, N + 1):
		cnta += ac[i]
		cntb += bc[i - 1]
		ma = max(ma, cnta - cntb)
	print('Yes')
	ans = []
	for i in range(N):
		ans.append(B[(i + N - ma) % N])
	print(*ans)
main()


from collections import defaultdict, deque
printn = lambda x: print(x, end='')
inn = lambda : int(input())
inl = lambda : list(map(int, input().split()))
inm = lambda : map(int, input().split())
ins = lambda : input().strip()
DBG = True
BIG = 10 ** 18
R = 10 ** 9 + 7

def ddprint(x):
	if DBG:
		print(x)
n = inn()
a = inl()
b = inl()
b.reverse()
left = n
same = -1
for i in range(n):
	if a[i] == b[i]:
		left = i
		same = a[i]
		break
if left == n:
	print('Yes')
	print(' '.join([str(x) for x in b]))
	exit()
for i in range(n):
	if same in [a[i], b[i]]:
		l2 = i
		break
right = r2 = -1
for i in range(n - 1, -1, -1):
	if r2 < 0 and same in [a[i], b[i]]:
		r2 = i + 1
	if a[i] == b[i]:
		right = i + 1
		break
if l2 >= right - left:
	tmp = b[:right - left]
	b[:right - left] = b[left:right]
	b[left:right] = tmp
else:
	tmp = b[:l2]
	b[:l2] = b[left:left + l2]
	b[left:left + l2] = tmp
	if right + r2 - left - l2 > n:
		print('No')
		exit()
	tmp = b[r2:r2 + right - l2 - left]
	b[r2:r2 + right - l2 - left] = b[l2 + left:right]
	b[l2 + left:right] = tmp
print('Yes')
print(' '.join([str(x) for x in b]))


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ca = Counter(a)
cb = Counter(b)
for k in cb:
	if k in ca:
		if cb[k] + ca[k] > n:
			print('No')
			exit()
ans = b.copy()
ans.reverse()
ng = set(())
ok = []
for i in range(n):
	if a[i] == ans[i]:
		ng.add(i)
	else:
		ok.append(i)
from random import randint
if ng:
	for x in ng:
		y = ok[randint(0, len(ok) - 1)]
		while ans[x] == a[y] or ans[y] == a[x]:
			y = ok[randint(0, len(ok) - 1)]
		(ans[x], ans[y]) = (ans[y], ans[x])
		ok.append(x)
print('Yes')
print(*ans, sep=' ')


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.sort(reverse=True)
Arev = sorted(A, reverse=True)
Brev = sorted(B)
atai = 0
s = 0
for i in range(len(A)):
	if A[i] == B[i]:
		atai = A[i]
		s += 1
C = []
for i in range(len(A)):
	C.append(A[i] - B[i])
if s > 0:
	hajime = C.index(0)
if s == 0:
	print('Yes')
	print(*B)
else:
	Acount = A.count(atai)
	Bcount = B.count(atai)
	if N - Acount < Bcount:
		print('No')
	else:
		afirst = A.index(atai)
		alast = N - 1 - Arev.index(atai)
		bfirst = B.index(atai)
		blast = N - 1 - Brev.index(atai)
		t = min(afirst, bfirst)
		if t >= s:
			for i in range(0, s):
				B[hajime + i] = B[i]
				B[i] = atai
		else:
			for i in range(0, t):
				B[hajime + i] = B[i]
				B[i] = atai
			ss = s - t
			for i in range(0, ss):
				B[hajime + t + i] = B[-i - 1]
				B[-i - 1] = atai
		print('Yes')
		print(*B)


import sys, itertools, collections, bisect
from collections import deque, Counter, defaultdict
from heapq import heappush, heappop, heapify
read = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
(cA, cB) = (Counter(A), Counter(B))
for i in range(1, N + 1):
	if cA.get(i, 0) + cB.get(i, 0) > N:
		print('No')
		exit()
(C, D) = ([0] * (N + 1), [0] * (N + 1))
for i in range(1, N + 1):
	C[i] = C[i - 1] + cA.get(i, 0)
	D[i] = D[i - 1] + cB.get(i, 0)
(x, y) = (0, 10 ** 30)
for i in range(1, N + 1):
	x = max(x, C[i] - D[i - 1])
	y = min(y, C[i - 1] + N - D[i])
print('Yes')
print(*B[N - x:] + B[:N - x])


N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
total_table = {}

def make_table(l):
	table = {}
	for v in l:
		if v in table:
			table[v] += 1
		else:
			table[v] = 1
		if v in total_table:
			total_table[v] += 1
		else:
			total_table[v] = 1
	return table
A_table = make_table(A_list)
B_table = make_table(B_list)
total_list = []
for (v, c) in total_table.items():
	total_list.append((c, v))
total_list.sort()
total_list.reverse()
A_head = []
A_tail = []
B_head = []
B_tail = []
for (c, v) in total_list:
	a = A_table[v] if v in A_table else 0
	b = B_table[v] if v in B_table else 0
	while a > 0 and len(A_head) + len(B_head) < N:
		A_head.append(v)
		a -= 1
	while b > 0 and len(A_head) + len(B_head) < N:
		B_head.append(v)
		b -= 1
	while a > 0:
		A_tail.append(v)
		a -= 1
	while b > 0:
		B_tail.append(v)
		b -= 1
A_tail.reverse()
B_head.reverse()
A_list = A_head + A_tail
B_list = B_tail + B_head

def check():
	for (a, b) in zip(A_list, B_list):
		if a == b:
			return False
	else:
		return True
if check():
	AB_list = list(zip(A_list, B_list))
	AB_list.sort()
	print('Yes')
	print(*(b for (a, b) in AB_list))
else:
	print('No')


from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from math import gcd
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 13

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

def I():
	return int(sys.stdin.readline())

def LS():
	return sys.stdin.readline().rstrip().split()

def S():
	return sys.stdin.readline().rstrip()

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]

def SRL(n):
	return [list(S()) for i in range(n)]

def MSRL(n):
	return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
n = I()
A = LI()
B = sorted(LI(), reverse=True)
s = []
c = 0
ret = 0
(g, h) = Counter(A + B).most_common()[0]
if h > n:
	print('No')
	exit()
for i in range(n):
	if A[i] == B[i]:
		ret += 2
		s += [i]
		c = A[i]
for j in range(n):
	if A[j] != c and B[j] != c and s:
		k = s.pop()
		(B[k], B[j]) = (B[j], B[k])
print('Yes')
print(*B)


import sys
input = lambda : sys.stdin.readline().rstrip()
N = int(input())
A = [int(a) - 1 for a in input().split()]
B = [int(a) - 1 for a in input().split()]
LA = [0] * N + [N]
LB = [0] * N + [N]
j = 0
for i in range(N):
	LA[i] = j
	while j < N and A[j] == i:
		j += 1
j = 0
for i in range(N):
	LB[i] = j
	while j < N and B[j] == i:
		j += 1
NG = [0] * (N + 1)
for (l1, r1, l2, r2) in zip(LA[:-1], LA[1:], LB[:-1], LB[1:]):
	ngl = l1 - r2 + 1
	ngr = r1 - l2
	if ngl < ngr < 0:
		NG[ngl + N] += 1
		NG[ngr + N] -= 1
	elif ngl < 0 <= ngr:
		NG[ngl + N] += 1
		NG[N] -= 1
		NG[0] += 1
		NG[ngr] -= 1
	elif 0 <= ngl < ngr:
		NG[ngl] += 1
		NG[ngr] -= 1
for i in range(N):
	NG[i + 1] += NG[i]
for i in range(N):
	if NG[i]:
		continue
	print('Yes')
	print(*[a + 1 for a in (B[-i:] + B[:-i] if i else B)])
	break
else:
	print('No')


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B = B[::-1]
(j, bef) = (0, -1)
for i in range(N):
	if A[i] != bef:
		j = 0
	if A[i] == B[i]:
		while j < N:
			if A[j] != B[i] and B[j] != A[i]:
				(B[i], B[j]) = (B[j], B[i])
				break
			j += 1
		if A[i] == B[i]:
			print('No')
			exit()
	bef = A[i]
print('Yes')
for b in B:
	print(b, end=' ')
print('')


from collections import Counter
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
CA = Counter(A)
CB = Counter(B)
for (key, value) in CB.items():
	if value + CA[key] > N:
		print('No')
		exit()
C = [0] * (N + 1)
D = [0] * (N + 1)
for i in range(N):
	C[i + 1] += C[i] + CA[i + 1]
	D[i + 1] += D[i] + CB[i + 1]
x = 0
for i in range(N):
	x = max(x, C[i + 1] - D[i])
ans = [B[(i - x) % N] for i in range(N)]
print('Yes')
print(*ans)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ca = Counter(A)
cb = Counter(B)
is_ok = 1
for (num, cnt) in ca.items():
	if cnt + cb[num] > N:
		is_ok = 0
		break
if not is_ok:
	print('No')
	exit()
C = [0] * (N + 1)
D = [0] * (N + 1)
for i in range(1, N + 1):
	C[i] = C[i - 1] + ca[i]
	D[i] = D[i - 1] + cb[i]
print('Yes')
x = max([-D[i - 1] + C[i] for i in range(1, N + 1)])
ans = B[-x:] + B[:N - x]
print(*ans)


from collections import Counter

def solve(n, a_list, b_list):
	count_a = Counter(a_list)
	count_b = Counter(b_list)
	count_ab = dict()
	for k in list(count_a.keys()):
		if k in list(count_b.keys()):
			if count_a[k] + count_b[k] > n:
				return ['No']
			count_ab[k] = min(count_a[k], count_b[k])
	a_list_1 = []
	a_list_2 = []
	a = 0
	for i in range(n):
		if a != a_list[i]:
			if a_list[i] in list(count_ab.keys()):
				c = count_ab[a_list[i]]
			else:
				c = 0
		a = a_list[i]
		if c > 0:
			a_list_1.append(a)
			c -= 1
		else:
			a_list_2.append(a)
	b_list_1 = []
	b_list_2 = []
	b = 0
	for i in range(n):
		if b != b_list[i]:
			if b_list[i] in list(count_ab.keys()):
				c = count_ab[b_list[i]]
			else:
				c = 0
		b = b_list[i]
		if c > 0:
			b_list_1.append(b)
			c -= 1
		else:
			b_list_2.append(b)
	k_max = -1
	if len(list(count_ab.values())) == 0:
		return ['Yes', ' '.join([str(b) for b in b_list])]
	d = max(count_ab.values())
	for k in list(count_ab.keys()):
		if count_ab[k] == d:
			k_max = k
			break
	a_list_moved = a_list_1 + a_list_2
	b_list_moved = b_list_1[d:] + b_list_1[:d] + b_list_2
	if d * 2 > len(a_list_1):
		if count_a[k_max] >= count_b[k_max]:
			j = len(a_list_1)
			for i in range(len(a_list_1)):
				if a_list_moved[i] == b_list_moved[i] == k_max:
					while a_list_moved[j] == k_max:
						j += 1
					(a_list_moved[i], a_list_moved[j]) = (a_list_moved[j], a_list_moved[i])
		else:
			j = len(a_list_1)
			for i in range(len(a_list_1)):
				if a_list_moved[i] == b_list_moved[i] == k_max:
					while b_list_moved[j] == k_max:
						j += 1
					(b_list_moved[i], b_list_moved[j]) = (b_list_moved[j], b_list_moved[i])
	res_ab = list(sorted([(a, b) for (a, b) in zip(a_list_moved, b_list_moved)], key=lambda x: x[0]))
	res_b = ' '.join([str(ab[1]) for ab in res_ab])
	return ['Yes', res_b]

def main():
	n = int(input())
	a_list = list(map(int, input().split()))
	b_list = list(map(int, input().split()))
	res = solve(n, a_list, b_list)
	for r in res:
		print(r)

def test():
	assert solve(6, [1, 1, 1, 2, 2, 3], [1, 1, 1, 2, 2, 3]) == ['Yes', '2 2 3 1 1 1']
	assert solve(3, [1, 1, 2], [1, 1, 3]) == ['No']
	assert solve(4, [1, 1, 2, 3], [1, 2, 3, 3]) == ['Yes', '2 3 3 1']

def __starting_point():
	test()
	main()
__starting_point()


from collections import Counter
INF = 1000000000000.0

def main():
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	lA = Counter(A)
	lB = Counter(B)
	if max(Counter(A + B).values()) > N:
		print('No')
		exit()
	C = [0] * (N + 1)
	D = [0] * (N + 1)
	for i in range(N):
		C[i + 1] = lA[i + 1] + C[i]
		D[i + 1] = lB[i + 1] + D[i]
	shift = -INF
	for i in range(1, N + 1):
		shift = max(shift, C[i] - D[i - 1])
	print('Yes')
	ans = (B + B + B)[N - shift:2 * N - shift]
	print(' '.join([str(a) for a in ans]))
main()


import bisect, heapq
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(1, N + 1):
	a = bisect.bisect_right(A, i) - bisect.bisect_left(A, i)
	b = bisect.bisect_right(B, i) - bisect.bisect_left(B, i)
	if a + b > N:
		print('No')
		return
B = B[::-1]
(j, bef) = (0, -1)
for i in range(N):
	if A[i] != bef:
		j = 0
	if A[i] == B[i]:
		while j < N:
			if A[j] != B[i] and B[j] != A[i]:
				(B[i], B[j]) = (B[j], B[i])
				break
			j += 1
	bef = A[i]
print('Yes')
for b in B:
	print(b, end=' ')
print('')


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C_A = Counter(A)
C_B = Counter(B)
for (k, v) in list(C_A.items()):
	if v + C_B[k] > N:
		print('No')
		return
B = B[::-1]
same_range = []
for (i, (a, b)) in enumerate(zip(A, B)):
	if a == b:
		same_range.append(i)
i = 0
while same_range:
	v = B[same_range[0]]
	if A[i] != v and B[i] != v:
		j = same_range.pop()
		(B[i], B[j]) = (B[j], B[i])
	i += 1
print('Yes')
print(' '.join(map(str, B)))


n = int(input())
(*a,) = map(int, input().split())
(*b,) = map(int, input().split())
shift = 0
from bisect import bisect_right, bisect_left
from collections import Counter
sb = Counter(b)
sa = Counter(a)
for bi in sb:
	if bi in sa:
		if sa[bi] + sb[bi] > n:
			print('No')
			return
for bi in sb:
	lb = bisect_left(b, bi)
	ra = bisect_right(a, bi)
	if a[ra - 1] == b[lb]:
		shift = max(shift, ra - lb)
ans = [b[(i - shift) % n] for i in range(n)]
print('Yes')
print(*ans)


import sys
input = sys.stdin.readline
import random
n = int(input())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]
b.reverse()
same_val = None
same_id = []
for (i, (ai, bi)) in enumerate(zip(a, b)):
	if ai == bi:
		same_val = ai
		same_id.append(i)
changeable = []
for (i, (ai, bi)) in enumerate(zip(a, b)):
	if b[i] != same_val and a[i] != same_val:
		changeable.append(i)
if len(same_id) > len(changeable):
	print('No')
	exit()
for (s, c) in zip(same_id, changeable):
	(b[s], b[c]) = (b[c], b[s])
print('Yes')
print(*b)


n = int(input())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
b = b[::-1]
first = 0
last = n - 1
for i in range(n):
	if a[i] == b[i]:
		if i < last and b[last] != a[i]:
			(b[i], b[last]) = (b[last], b[i])
			last -= 1
		elif first < i and b[first] != a[i]:
			(b[i], b[first]) = (b[first], b[i])
			first += 1
ok = True
for i in range(n):
	ok = ok and a[i] != b[i]
if ok:
	print('Yes')
	for i in range(n):
		print(b[i], end=' ')
else:
	print('No')


import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
mod = 10 ** 9 + 7
INF = 10 ** 18
eps = 10 ** (-7)
n = int(readline())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
c = [0] * (n + 1)
d = [0] * (n + 1)
for ai in a:
	c[ai] += 1
for bi in b:
	d[bi] += 1
for i in range(n + 1):
	if c[i] + d[i] > n:
		print('No')
		exit()
print('Yes')
for i in range(n):
	c[i + 1] += c[i]
	d[i + 1] += d[i]
divi = 0
for i in range(1, n + 1):
	divi = max(divi, c[i] - d[i - 1])
divi = n - divi
ans = b[divi:] + b[:divi]
print(' '.join(map(str, ans)))


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
Br = list(reversed(B))
NG = []
for i in range(N):
	if A[i] == Br[i]:
		NG.append(i)
		NGnumber = Br[i]
NGcnt = len(NG)
if NGcnt == 0:
	print('Yes')
	print(*Br)
else:
	OK = []
	for i in range(N):
		if Br[i] != NGnumber and A[i] != NGnumber:
			OK.append(i)
	OKcnt = len(OK)
	if NGcnt > OKcnt:
		print('No')
	else:
		for i in range(NGcnt):
			(Br[NG[i]], Br[OK[i]]) = (Br[OK[i]], Br[NG[i]])
		print('Yes')
		print(*Br)


from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
idx_B = 0
ma = 0
for (idx_A, a) in enumerate(A):
	while idx_B < N and B[idx_B] < a:
		idx_B += 1
	if ma < idx_A - idx_B:
		ma = idx_A - idx_B
Ans = (B + B)[N - ma - 1:2 * N - ma - 1]
for (a, b) in zip(A, Ans):
	if a == b:
		print('No')
		exit()
print('Yes')
print(*Ans)


from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return [list(x) for x in sys.stdin.readline().split()]

def S():
	res = list(sys.stdin.readline())
	if res[-1] == '\n':
		return res[:-1]
	return res

def IR(n):
	return [I() for _ in range(n)]

def LIR(n):
	return [LI() for _ in range(n)]

def SR(n):
	return [S() for _ in range(n)]

def LSR(n):
	return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
	n = I()
	a = LI()
	b = LI()
	cnt = defaultdict(lambda : 0)
	for i in a:
		cnt[i] += 1
	for i in b:
		if not cnt[i]:
			continue
		cnt[i] += 1
	for i in cnt.values():
		if i > n:
			print('No')
			return
	r = n - 1
	while 1:
		update = False
		for l in range(n):
			while r >= 0 and a[r] != b[r]:
				r -= 1
			if a[l] == b[l]:
				update = True
				(b[l], b[r]) = (b[r], b[l])
				r -= 1
		if not update:
			break
	print('Yes')
	print(*b)
	return
solve()


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.readline
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	B.reverse()
	idx = []
	x = -1
	for i in range(N):
		if A[i] == B[i]:
			idx.append(i)
			x = A[i]
	if len(idx) == 0:
		print('Yes')
		print(*B)
	else:
		l = 0
		r = N - 1
		for i in idx:
			if A[l] != x and B[l] != x:
				(B[l], B[i]) = (B[i], B[l])
				l += 1
			elif A[r] != x and B[r] != x:
				(B[r], B[i]) = (B[i], B[r])
				r -= 1
			else:
				print('No')
				exit()
		print('Yes')
		print(*B)
main()


from collections import Counter
N = int(input())
As = input().split()
Bs = input().split()
allct = Counter(As + Bs)
if allct.most_common(1)[0][1] > N:
	print('No')
	exit()
lastInA = {}
firstInB = {}
for (i, a) in enumerate(As):
	lastInA[a] = i
for (i, b) in enumerate(Bs):
	if b not in firstInB:
		firstInB[b] = i
offset = 0
for (k, v) in lastInA.items():
	if k not in firstInB:
		continue
	tmp = v - firstInB[k] + 1
	offset = offset if offset > tmp else tmp
print('Yes')
print(' '.join(Bs[-offset:] + Bs[:-offset]))


n = int(input())
y = lambda : [*map(int, input().split())]
(a, b) = (y(), y()[::-1])
c = 0
for i in range(n):
	if a[i] == b[i]:
		c = a[i]
if c < 1:
	print('Yes')
	print(' '.join(map(str, b)))
	return
(al, bl, ah, bh) = [-1] * 4
ea = eb = 0
for i in range(n):
	if al < 0 and a[i] == c:
		al = i
	if bl < 0 and b[i] == c:
		bl = i
	if al < 0:
		ea += 1
	if bl < 0:
		eb += 1
	if ah < 0 and al >= 0 and (a[i] != c):
		ah = i
	if bh < 0 and bl >= 0 and (b[i] != c):
		bh = i
if ah < 0:
	ah = n
if bh < 0:
	bh = n
t = ah + bh - al - bl
if ah + bh - al - bl > n:
	print('No')
	return
o1 = min(bh - bl, ea, ea - eb + ah - al)
print('Yes')
print(' '.join(map(str, [c] * o1 + b[:eb] + b[eb + bh - bl:] + [c] * (bh - bl - o1))))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = 0
c = True
for i in range(n):
	if i > 0:
		if a[i] != a[i - 1]:
			s = 0
	if a[i] != b[i]:
		continue
	else:
		c = False
		while s != n:
			if a[i] != b[s] and a[s] != b[i]:
				(b[i], b[s]) = (b[s], b[i])
				c = True
				break
			s += 1
		if not c:
			break
if not c:
	print('No')
else:
	print('Yes')
	print(*b)


import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
from functools import lru_cache
import copy
input = sys.stdin.readline
INF = float('inf')
mod = 10 ** 9 + 7
eps = 10 ** (-7)

def inp():
	return int(input())

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

def str_inp():
	return list(input()[:-1])
n = inp()
a = inpl()
b = inpl()
a_digest = collections.defaultdict(int)
b_digest = collections.defaultdict(int)
for i in range(n):
	a_digest[a[i]] += 1
	b_digest[b[i]] += 1
for i in range(1, n + 1):
	if a_digest[i] > n - b_digest[i]:
		print('No')
		exit()
print('Yes')
b.sort(reverse=True)
ptr = 0
for i in range(n):
	if a[i] == b[i]:
		while a[i] == b[ptr] or a[ptr] == b[i]:
			ptr += 1
			if ptr == n:
				ptr = 0
		(b[ptr], b[i]) = (b[i], b[ptr])
print(*b)


import sys
from collections import Counter
from itertools import accumulate
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	N = int(readline())
	A = list(map(int, readline().split()))
	B = list(map(int, readline().split()))
	counterA = Counter(A)
	counterB = Counter(B)
	for i in range(1, N + 1):
		if counterA[i] + counterB[i] > N:
			print('No')
			return
	C = [0] * (N + 1)
	D = [0] * (N + 1)
	for a in A:
		C[a] += 1
	for b in B:
		D[b] += 1
	C = list(accumulate(C))
	D = list(accumulate(D))
	x = max((C[i] - D[i - 1] for i in range(1, N + 1)))
	ans = [0] * N
	for i in range(N):
		ans[i] = B[(i - x) % N]
	print('Yes')
	print(*ans)
	return
main()


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
from random import randint
C = [-1] * (n + 2)
D = [-1] * (n + 2)
for i in range(1, n):
	if A[i - 1] != A[i]:
		C[A[i - 1]] = i - 1
C[A[-1]] = n - 1
ind = 0
D[B[0]] = 0
for i in range(1, n):
	if B[i - 1] != B[i]:
		D[B[i]] = i
sh = 0
for i in range(n + 2):
	if C[i] != -1 and D[i] != -1:
		sh = max(sh, C[i] - D[i] + 1)
N = [B[(i - sh) % n] for i in range(n)]
ng = 0
for i in range(n):
	if N[i] == A[i]:
		ng = 1
		break
if ng == 1:
	print('No')
else:
	print('Yes')
	print(*N)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AC = Counter(A)
BC = Counter(B)
for i in BC.keys():
	if i in AC and BC[i] + AC[i] > N:
		print('No')
		exit()
(AL, AR) = ({}, {})
(BL, BR) = ({}, {})
for i in range(N):
	if not A[i] in AL:
		AL[A[i]] = i
	AR[A[i]] = i
for i in range(N):
	if not B[i] in BL:
		BL[B[i]] = i
	BR[B[i]] = i
can = [1] * N
for i in BL.keys():
	if not i in AL:
		continue
	s = (N + AL[i] - BR[i]) % N
	e = (N + AR[i] - BL[i]) % N
	if e < s:
		e += N
	for j in range(s, e + 1):
		can[j % N] = 0
if 1 in can:
	print('Yes')
	ind = can.index(1)
	print(*(B + B)[N - ind:2 * N - ind])
else:
	print('No')


def Next():
	return input()

def NextInt():
	return int(Next())

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

def Nexts():
	return map(str, input().split())

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

def RowInts(n):
	return [input() for i in range(n)]

def output(ans):
	print('Yes')
	size = len(ans)
	for i in range(size):
		if i == size - 1:
			print(ans[i])
		else:
			print(ans[i], end=' ')
n = NextInt()
a = NextIntList()
b = NextIntList()[::-1]

def solve():
	border = n - 1
	for i in range(n):
		if a[i] >= b[i]:
			border = i
			break
	if a[border] != b[border]:
		output(b)
		return
	key = a[border]
	if a.count(key) + b.count(key) > n:
		print('No')
		return
	cnt = a[:border].count(key) + b[:border].count(key)
	for i in range(border, n):
		if a[i] != key or b[i] != key:
			output(b[i - 1::-1] + b[:i - 1:-1])
			return
		cnt += 2
		if cnt == i + 1:
			output(b[i::-1] + b[:i:-1])
			return
	output(b[::-1])
solve()


def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(ai, bi) = (0, 0)
	(al, bl) = ([], [])
	while ai < n and bi < n:
		(ax, bx) = (a[ai], b[bi])
		(la, lb) = ([], [])
		if ax == bx:
			cnt = 2
			la.append(ai)
			ai += 1
			while ai < n and a[ai] == ax:
				la.append(ai)
				cnt += 1
				ai += 1
			lb.append(bi)
			bi += 1
			while bi < n and b[bi] == bx:
				lb.append(bi)
				cnt += 1
				bi += 1
			if cnt > n:
				print('No')
				exit()
		elif ax < bx:
			la.append(ai)
			ai += 1
		else:
			lb.append(bi)
			bi += 1
		al.append(la)
		bl.append(lb)
	print('Yes')
	slit = 0
	for i in range(len(al)):
		if len(al[i]) == 0 or len(bl[i]) == 0:
			continue
		if al[i][-1] - bl[i][0] + 1 > slit:
			slit = al[i][-1] - bl[i][0] + 1
	print(' '.join(map(str, b[n - slit:] + b[:n - slit])))
main()


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C_A = Counter(A)
C_B = Counter(B)
for (k, v) in list(C_A.items()):
	if v + C_B[k] > N:
		print('No')
		return
B = B[::-1]
same_range = []
for (i, (a, b)) in enumerate(zip(A, B)):
	if a == b:
		same_range.append(i)
if same_range:
	same_v = B[same_range[0]]
	for i in range(N):
		if not same_range:
			break
		if A[i] == same_v or B[i] == same_v:
			continue
		j = same_range.pop()
		(B[i], B[j]) = (B[j], B[i])
print('Yes')
print(' '.join(map(str, B)))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cta = [0] * n
ctb = [0] * n
for i in range(n):
	cta[a[i] - 1] += 1
	ctb[b[i] - 1] += 1
for i in range(n):
	if cta[i] + ctb[i] > n:
		print('No')
		exit()
sa = [0]
sb = [0]
for i in range(n):
	sa.append(cta[i] + sa[-1])
	sb.append(ctb[i] + sb[-1])
l = []
for i in range(n):
	l.append(sa[i + 1] - sb[i])
ans = []
maxl = max(l)
for i in range(n):
	ans.append(str(b[(i - maxl) % n]))
print('Yes')
print(' '.join(ans))


from collections import Counter
import sys
import random
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ca = Counter(A)
cb = Counter(B)
for i in range(N + 1):
	if ca[i] + cb[i] > N:
		print('No')
		sys.exit()
C = [0] * (N + 1)
D = [0] * (N + 1)
for i in range(N):
	C[i + 1] += C[i] + ca[i + 1]
	D[i + 1] += D[i] + cb[i + 1]
x = 0
for i in range(N):
	x = max(x, C[i + 1] - D[i])
ans = [B[(i - x) % N] for i in range(N)]
print('Yes')
print(*ans)


from itertools import groupby
n = int(input())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
idx_a = {}
cnt_a = {}
i = 0
for (a, itr) in groupby(aaa):
	cnt = len(list(itr))
	i += cnt
	idx_a[a] = i
	cnt_a[a] = cnt
idx_b = {}
cnt_b = {}
i = 0
for (b, itr) in groupby(bbb):
	cnt = len(list(itr))
	idx_b[b] = i
	cnt_b[b] = cnt
	i += cnt
slide = 0
for a in idx_a:
	if a not in idx_b:
		continue
	if cnt_a[a] + cnt_b[a] > n:
		print('No')
		exit()
	slide = max(slide, idx_a[a] - idx_b[a])
print('Yes')
if slide > 0:
	bbb = bbb[-slide:] + bbb[:-slide]
print(*bbb)


def main():
	from collections import Counter
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	a_count = Counter(A)
	b_count = Counter(B)
	for (k, v) in (a_count + b_count).items():
		if N < v:
			print('No')
			return
	print('Yes')
	C = [0] * (N + 1)
	idx = 0
	for a in A:
		while idx < a:
			idx += 1
			C[idx] = C[idx - 1]
		C[idx] += 1
	while idx < N:
		idx += 1
		C[idx] = C[idx - 1]
	D = [0] * (N + 1)
	idx = 0
	for b in B:
		while idx < b:
			idx += 1
			D[idx] = D[idx - 1]
		D[idx] += 1
	while idx < N:
		idx += 1
		D[idx] = D[idx - 1]
	x = 0
	for i in range(1, N + 1):
		x = max(x, C[i] - D[i - 1])
	print(*B[N - x:] + B[:N - x])
main()


N = int(input())
from collections import Counter
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ca = Counter(A)
cb = Counter(B)
mod = 10 ** 6
cnts = [set() for _ in range(N + 1)]
for i in range(1, N + 1):
	if ca[i] + cb[i] > N:
		print('No')
		exit()
	if ca[i] + cb[i] > 0:
		cnts[ca[i] + cb[i]].add(i)

def get_any(counts, r):
	for k in counts.keys():
		if counts[k] > 0 and k != r:
			return k

def update_cnt(cnt_, r):
	cnt_[r] -= 1
	if cnt_[r] == 0:
		del cnt_[r]
lis = [[] for _ in range(N + 1)]
for i in range(N, 0, -1):
	if len(cnts[i]) == 2:
		(p, q) = cnts[i]
		for j in range(ca[p]):
			lis[p].append(q)
		for j in range(ca[q]):
			lis[q].append(p)
		break
	elif len(cnts[i]) == 1:
		(p,) = cnts[i]
		for j in range(ca[p]):
			q = get_any(cb, p)
			update_cnt(cb, q)
			lis[p].append(q)
		for j in range(cb[p]):
			q = get_any(ca, p)
			update_cnt(ca, q)
			lis[q].append(p)
		break
	else:
		p = get_any(ca, -1)
		q = get_any(cb, p)
		lis[p].append(q)
		cnts[ca[p] + cb[p]].remove(p)
		cnts[ca[q] + cb[q]].remove(q)
		update_cnt(ca, p)
		update_cnt(cb, q)
		cnts[ca[p] + cb[p]].add(p)
		cnts[ca[q] + cb[q]].add(q)
ans = []
for i in range(1, N + 1):
	for b in lis[i]:
		ans.append(b)
print('Yes')
print(*ans)


def solve(N, Ai, Bi):
	Ci = [0] * (N + 1)
	Di = [0] * (N + 1)
	j = 0
	k = 0
	for i in range(1, N + 1):
		while j < N and Ai[j] <= i:
			j += 1
		Ci[i] = j
		while k < N and Bi[k] <= i:
			k += 1
		Di[i] = k
	for i in range(1, N + 1):
		if Ci[i] - Ci[i - 1] + Di[i] - Di[i - 1] > N:
			print('No')
			return
	x = 0
	for i in range(1, N + 1):
		x = max(x, Ci[i] - Di[i - 1])
	print('Yes')
	print(' '.join([str(Bi[(N - x + i) % N]) for i in range(N)]))

def __starting_point():
	N = int(input())
	Ai = [int(i) for i in input().split()]
	Bi = [int(i) for i in input().split()]
	solve(N, Ai, Bi)
__starting_point()


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AB = [(a, i, 0) for (i, a) in enumerate(A)] + [(b, i, 1) for (i, b) in enumerate(B)]
AB.sort()
X = AB[:N]
Y = AB[N:]
if any((x[0] == y[0] for (x, y) in zip(X, Y))):
	print('No')
	exit()
swapA = []
swapB = []
ans = [-1] * N
for ((_, i, sx), (_, j, sy)) in zip(X, Y):
	if sx == sy == 0:
		swapA.append((i, j))
	elif sx == sy == 1:
		swapB.append((i, j))
	elif sx == 0:
		ans[i] = B[j]
	else:
		ans[j] = B[i]
for ((i, j), (x, y)) in zip(swapA, swapB):
	ans[i] = B[x]
	ans[j] = B[y]
	if A[i] == ans[i] or A[j] == ans[j]:
		(ans[i], ans[j]) = (ans[j], ans[i])
print('Yes')
print(*ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.reverse()
mondai = -1
kasho = 0
mondai_basho = -1
for i in range(n):
	if a[i] == b[i]:
		mondai = a[i]
		kasho += 1
		if kasho == 1:
			mondai_basho = i
kano = True
ans = []
if kasho == 0:
	ans = b
else:
	hajimea = 0
	hajimeb = 0
	owaria = 0
	owarib = 0
	for i in range(n):
		if a[i] < mondai:
			hajimea += 1
		if a[i] > mondai:
			owaria += 1
		if b[i] > mondai:
			hajimeb += 1
		if b[i] < mondai:
			owarib += 1
	hajime = min(hajimea, hajimeb)
	owari = min(owaria, owarib)
	if kasho > hajime + owari:
		kano = False
	else:
		for i in range(kasho):
			if i < hajime:
				temp = b[mondai_basho + i]
				b[mondai_basho + i] = b[i]
				b[i] = temp
			else:
				temp = b[mondai_basho + i]
				b[mondai_basho + i] = b[n - owari + i - hajime]
				b[n - owari + i - hajime] = temp
		ans = b
if not kano:
	print('No')
else:
	print('Yes')
	for i in range(n):
		b[i] = str(b[i])
	print(' '.join(b))


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

def construct():
	A_queue = [(-c, x) for (x, c) in collections.Counter(A).items()]
	heapq.heapify(A_queue)
	index = [None] * (N + 1)
	for (i, a) in enumerate(A):
		if index[a] is None:
			index[a] = i
	B_queue = [(-c, x) for (x, c) in collections.Counter(B).items()]
	heapq.heapify(B_queue)
	answer = [None] * N
	while B_queue:
		(neg_cb, b) = heapq.heappop(B_queue)
		(neg_ca, a) = heapq.heappop(A_queue)
		if a == abs(b):
			if not A_queue:
				return None
			hold = (neg_ca, a)
			(neg_ca, a) = heapq.heappop(A_queue)
		else:
			hold = None
		answer[index[a]] = b
		index[a] += 1
		if neg_cb < -1:
			heapq.heappush(B_queue, (neg_cb + 1, b))
		if neg_ca < -1:
			heapq.heappush(A_queue, (neg_ca + 1, a))
		if hold is not None:
			heapq.heappush(A_queue, hold)
	else:
		return answer
answer = construct()
if answer is None:
	B = [-x for x in B]
	answer = construct()
	if answer is not None:
		answer = [-x for x in answer]
if answer:
	print('Yes')
	print(*answer)
else:
	print('No')


from collections import Counter, deque
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cnt_a = Counter(A)
cnt_b = Counter(B)
cnt_ab = cnt_a + cnt_b
for i in cnt_ab.values():
	if i > N:
		print('No')
		exit()
print('Yes')
dq_a = deque(A)
dq_b = deque(B)
ans = []
dq_b.rotate(N // 2)
while dq_a:
	if dq_a[0] != dq_b[0]:
		dq_a.popleft()
		p = dq_b.popleft()
		ans.append(p)
	else:
		dq_b.rotate()
print(*ans)


from collections import deque
n = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
ans = [-1 for i in range(n)]
newB = []
cnt = 1
old = B[0]
for i in range(1, n):
	if old != B[i]:
		newB.append((old, cnt))
		cnt = 1
		old = B[i]
	else:
		cnt += 1
else:
	newB.append((old, cnt))
B = deque(newB)

def firstDec():
	now = B.popleft()
	if now[1] > 1:
		B.appendleft((now[0], now[1] - 1))
tori = 0
for i in range(n):
	if B[0][0] != A[i]:
		ans[i] = B[0][0]
		firstDec()
		continue
	B.rotate(-1)
	if B[0][0] != A[i]:
		ans[i] = B[0][0]
		firstDec()
		continue
	OK = False
	while tori < i:
		if ans[tori] != B[0][0] and A[tori] != B[0][0]:
			ans[i] = ans[tori]
			ans[tori] = B[0][0]
			OK = True
			break
		B.rotate()
		if ans[tori] != B[0][0] and A[tori] != B[0][0]:
			ans[i] = ans[tori]
			ans[tori] = B[0][0]
			OK = True
			break
		tori += 1
	if OK:
		continue
	print('No')
	break
else:
	print('Yes')
	print(' '.join([str(num) for num in ans]))


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
count = [0] * (N + 1)
for (a, b) in zip(A, B):
	count[a] += 1
	count[b] += 1
for i in range(N + 1):
	if count[i] > N:
		print('No')
		quit()
diff = 0
checked = set()
ida = 0
for (i, b) in enumerate(B):
	if b in checked:
		continue
	checked.add(b)
	while ida < N and A[ida] <= b:
		ida += 1
	diff = max(diff, ida - i)
print('Yes')
print(*B[-diff:] + B[:-diff])


def numcount(x):
	ans = [0] * n
	res = 1
	for i in range(n - 1):
		if x[i] != x[i + 1]:
			ans[x[i] - 1] = res
			res = 0
		res += 1
	ans[x[n - 1] - 1] = res
	return ans
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a2 = numcount(a)
b2 = numcount(b)
ans1 = False
for i in range(n):
	if a2[i] + b2[i] > n:
		ans1 = True
		break
ans2 = a2[0]
res = a2[0]
for i in range(n - 1):
	res += a2[i + 1] - b2[i]
	ans2 = max(ans2, res)
if ans1:
	print('No')
else:
	print('Yes')
	c = [0] * n
	for i in range(n):
		c[(i + ans2) % n] = b[i]
	print(' '.join([str(n) for n in c]))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0 for _ in range(n + 1)]
for ai in a:
	c[ai] += 1
for bi in b:
	c[bi] += 1
if max(c) > n:
	print('No')
	exit()
print('Yes')
b.reverse()
flag = True
si = -1
ti = -1
for i in range(n):
	if flag:
		if a[i] == b[i]:
			si = i
			flag = False
	elif a[i] != b[i]:
		ti = i - 1
		break
if si == -1:
	for bi in b:
		print(bi, end=' ')
	exit()
if ti == -1:
	ti = n - 1
s = a[si]
ni = [0 for _ in range(ti - si + 1)]
xi = 0
for i in range(n):
	if xi >= ti - si + 1:
		break
	if a[i] != s and b[i] != s:
		ni[xi] = b[i]
		b[i] = s
		xi += 1
nb = b[0:si] + ni + b[ti + 1:]
for nbi in nb:
	print(nbi, end=' ')


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ca = Counter(a)
cb = Counter(b)
for k in cb:
	if k in ca:
		if cb[k] + ca[k] > n:
			print('No')
			exit()
tmpc = 0
tmpd = 0
c = [0]
d = [0]
for i in range(1, n + 1):
	if i in ca:
		tmpc += ca[i]
	if i in cb:
		tmpd += cb[i]
	c.append(tmpc)
	d.append(tmpd)
x = 0
for i in range(n + 1):
	x = max(x, c[i] - d[i - 1])
ans = b[-x:] + b[:-x]
print('Yes')
print(*ans, sep=' ')
exit()
print(c)
print(d)


import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 6)
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
nn = lambda : list(stdin.readline().split())
ns = lambda : stdin.readline().rstrip()
n = ni()
a = na()
b = na()
from collections import deque
d = deque(b)
i = 0
j = 0
ans = []
while d:
	k = d.popleft()
	if k == a[i]:
		d.append(k)
		j += 1
		if j > n:
			break
		continue
	ans.append(k)
	i += 1
else:
	print('Yes')
	print(*ans)
	exit()
d = deque(b)
i = 0
j = 0
ans = []
while d:
	k = d.pop()
	if k == a[i]:
		d.appendleft(k)
		j += 1
		if j > n:
			print('No')
			exit()
		continue
	ans.append(k)
	i += 1
print('Yes')
print(*ans)


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
from collections import Counter as co
from collections import defaultdict
(D, E) = (co(A), co(B))
for i in D:
	if D[i] + E[i] > N:
		print('No')
		return
d = defaultdict(int)
for (i, e) in enumerate(A):
	d[e] = i
ans = 0
for (i, e) in enumerate(B):
	ans = max(ans, d[e] - i + 1)
s = B[-ans:] + B[:-ans]
print('Yes')
print(*s)


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
CA = [0] * (N + 1)
CB = [0] * (N + 1)
for a in A:
	CA[a] += 1
for b in B:
	CB[b] += 1
X = 0
x = 0
y = 0
ans = [[0, 0] for i in range(N)]
for i in range(1, N + 1):
	if CA[i] + CB[i] > N:
		print('No')
		exit()
	if X + CA[i] + CB[i] < N:
		for j in range(X, X + CA[i]):
			ans[j][0] = i
		for j in range(X + CA[i], X + CA[i] + CB[i]):
			ans[j][1] = i
		X += CA[i] + CB[i]
		x += CA[i]
		y += CB[i]
		CA[i] = 0
		CB[i] = 0
	else:
		k = min(N, N + x - CB[i], X + CA[i])
		for j in range(X, k):
			ans[j][0] = i
		for j in range(k, N):
			ans[j][1] = i
		CA[i] -= k - X
		CB[i] -= N - k
		break
x = 1
y = 1
for j in range(N):
	while x < N + 1 and CA[x] == 0:
		x += 1
	if ans[j][0] == 0:
		ans[j][0] = x
		CA[x] -= 1
for j in range(N):
	while y < N + 1 and CB[y] == 0:
		y += 1
	if ans[j][1] == 0:
		ans[j][1] = y
		CB[y] -= 1
ans.sort()
print('Yes')
print(*(ans[i][1] for i in range(N)))


import sys, io, os, time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b = b[::-1]
c = -1
for i in range(n):
	if a[i] == b[i]:
		c = a[i]
		break
l = 0
for i in range(n):
	if a[i] == c and b[i] == c:
		l = i
		break
r = -1
for i in range(n - 1, -1, -1):
	if a[i] == c and b[i] == c:
		r = i
		break
for i in range(n):
	if a[i] != c and b[i] != c and (l <= r):
		(b[i], b[l]) = (b[l], b[i])
		l += 1
if l <= r:
	print('No')
	exit()
print('Yes')
print(*b)


import random
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
a = [0 for i in range(N + 1)]
b = [0 for i in range(N + 1)]
for i in range(N):
	a[A[i]] += 1
	b[B[i]] += 1
if max([a[i] + b[i] for i in range(1, N + 1)]) <= N:
	print('Yes')
else:
	print('No')
	exit()
B = B[::-1]
point = 0
for i in range(N):
	if A[i] == B[i]:
		point += 1
while point > 0:
	x = random.randrange(N)
	y = random.randrange(N)
	if x == y:
		continue
	before = 0
	after = 0
	if A[x] == B[x]:
		before += 1
	if A[y] == B[y]:
		before += 1
	if A[x] == B[y]:
		after += 1
	if A[y] == B[x]:
		after += 1
	if before > after:
		(B[x], B[y]) = (B[y], B[x])
		point = point + after - before
print(*B)


from collections import Counter, defaultdict
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ca = Counter(a)
cb = Counter(b)
for (ka, va) in ca.items():
	vb = cb[ka]
	if va + vb > n:
		print('No')
		exit()
print('Yes')
end = defaultdict(int)
for (i, e) in enumerate(a):
	end[e] = i
mx = 0
for (i, e) in enumerate(b):
	diff = end[e] - i + 1
	mx = max(mx, diff)
ans = b[-mx:] + b[:-mx]
print(*ans)


import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
from collections import Counter
CA = Counter(A)
CB = Counter(B)
H = []
for ca in CA:
	if CA[ca] > 0 and CB[ca] > 0:
		if CA[ca] + CB[ca] > N:
			print('No')
			sys.exit()
		H.append((-(CA[ca] + CB[ca]), ca))
import heapq
heapq.heapify(H)
ANSDICT = dict()
while len(H) >= 2:
	(c1, x1) = heapq.heappop(H)
	c1 = -c1
	(c2, x2) = heapq.heappop(H)
	c2 = -c2
	if x1 in ANSDICT:
		ANSDICT[x1].append(x2)
	else:
		ANSDICT[x1] = [x2]
	if x2 in ANSDICT:
		ANSDICT[x2].append(x1)
	else:
		ANSDICT[x2] = [x1]
	CA[x1] -= 1
	CA[x2] -= 1
	CB[x1] -= 1
	CB[x2] -= 1
	if CA[x1] > 0 and CB[x1] > 0:
		heapq.heappush(H, (-(c1 - 2), x1))
	if CA[x2] > 0 and CB[x2] > 0:
		heapq.heappush(H, (-(c2 - 2), x2))
ANS = [-1] * N
for i in range(N):
	a = A[i]
	if a in ANSDICT and len(ANSDICT[a]) != 0:
		x = ANSDICT[a].pop()
		ANS[i] = x
if H:
	(cc, xx) = H[0]
	cc = -cc
	for i in range(N):
		if ANS[i] == -1 and A[i] != xx:
			ANS[i] = xx
			CB[xx] -= 1
			if CB[xx] == 0:
				break
ind = 0
for cb in CB:
	while CB[cb] != 0:
		while ANS[ind] != -1:
			ind += 1
		ANS[ind] = cb
		CB[cb] -= 1
print('Yes')
print(*ANS)


n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))[::-1]
start = end = -1
for i in range(n):
	if arr[i] == brr[i]:
		if start == -1:
			start = end = i
		else:
			end = i
if start == -1:
	print('Yes')
	print(*brr)
else:
	i = 0
	while i < n and start <= end:
		if brr[i] != arr[end] and arr[i] != arr[end]:
			(brr[i], brr[start]) = (brr[start], brr[i])
			start += 1
		i += 1
	if start > end:
		print('Yes')
		print(*brr)
	else:
		print('No')


from collections import Counter
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = Counter(A)
D = Counter(B)
for (k, v) in C.items():
	if v + D[k] > n:
		print('No')
		exit()
print('Yes')
seen = set()
L = []
E = dict()
for (i, a) in enumerate(A):
	if a not in seen:
		seen.add(a)
		if i != 0:
			E[A[i - 1]] = i - 1
E[A[-1]] = -1
seen = [False] * n
K = [-1] * n
M = []
for (k, v) in D.items():
	if k in C:
		M.append((C[k] + v, k))
M.sort(reverse=True)
for (p, q) in M:
	if q in D:
		s = D[q]
		i = E[q]
		for j in range(s):
			if seen[(i + j + 1) % n]:
				break
			seen[(i + j + 1) % n] = True
			K[(i + j + 1) % n] = q
			D[q] -= 1
		else:
			D.pop(q)
for i in range(n - 1, -1, -1):
	if K[i] == -1:
		for k in D.keys():
			if A[i] != k:
				K[i] = k
				break
		D[k] -= 1
		if D[k] == 0:
			D.pop(k)
print(*K)


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

def LI():
	return list(map(int, input().split()))
from collections import Counter, deque
n = II()
a = LI()
b = LI()
ac = Counter(a)
bc = Counter(b)
abc = ac + bc
for i in abc.values():
	if i > n:
		print('No')
		exit()
print('Yes')
a = deque(a)
b = deque(b)
ans = []
b.rotate(n // 2)
while a:
	if a[0] != b[0]:
		a.popleft()
		ans.append(b.popleft())
	else:
		b.rotate()
print(*ans)


import sys
from collections import Counter
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
CA = Counter(A)
CB = Counter(B)
right_idx = defaultdict(lambda : -1)
left_idx = defaultdict(lambda : -1)
for i in range(N):
	a = A[i]
	right_idx[a] = i
for i in range(N)[::-1]:
	b = B[i]
	left_idx[b] = i
for X in [A, B]:
	for x in X:
		if CA[x] + CB[x] > N:
			print('No')
			exit()
shift = 0
for x in range(1, N + 1):
	if right_idx[x] == -1 or left_idx[x] == -1:
		continue
	shift = max(right_idx[x] - left_idx[x] + 1, shift)
ANS = B[-shift:] + B[:-shift]
print('Yes')
print(' '.join(map(str, ANS)))


import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
from fractions import Fraction
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.reverse()
for i in range(N):
	if A[i] == B[i]:
		k = A[i]
		break
else:
	print('Yes')
	print(*B)
	exit()
possible = []
impossible = []
for i in range(N):
	if A[i] != k and B[i] != k:
		possible.append(i)
	elif A[i] == k and B[i] == k:
		impossible.append(i)
for i in impossible:
	if not possible:
		print('No')
		exit()
	j = possible.pop()
	(B[i], B[j]) = (B[j], B[i])
print('Yes')
print(*B)


mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.sort(reverse=True)
el = -1
same = list()
for i in range(n):
	if a[i] == b[i]:
		el = a[i]
		same.append(i)
l = len(same)
c = 0
for i in range(n):
	if c < l and b[i] != el and (a[i] != el):
		(b[i], b[same[c]]) = (b[same[c]], b[i])
		c += 1
if c != l:
	print('No')
else:
	print('Yes')
	print(*b)


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

def lb(x):
	(l, r) = (0, n)
	while l < r:
		m = (l + r) // 2
		if a[m] < x:
			l = m + 1
		else:
			r = m
	return l

def ub(x):
	(l, r) = (0, n)
	while l < r:
		m = (l + r) // 2
		if a[m] <= x:
			l = m + 1
		else:
			r = m
	return l
for i in range(n):
	l = lb(b[i])
	r = ub(b[i]) - 1
	if l > r:
		continue
	if l < i and i <= r:
		cnt[l + n - i] += 1
		cnt[0] += 1
		cnt[r - i + 1] -= 1
	elif i <= l:
		cnt[l - i] += 1
		cnt[r - i + 1] -= 1
	elif i > r:
		cnt[l + n - i] += 1
		cnt[r + n + 1 - i] -= 1
res = 0
ans = -1
for i in range(n):
	res += cnt[i]
	if res == 0:
		ans = i
if ans == -1:
	print('No')
else:
	print('Yes')
	for i in range(n):
		print(b[(i - ans + n) % n], end=' ')


def solve(n):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))[::-1]
	ind = [-1] * (n + 1)
	for i in range(n):
		if i == 0:
			ind[b[i]] = 0
		elif b[i] != b[i - 1]:
			ind[b[i]] = i
	cnt = 0
	for i in range(n):
		if a[i] != b[i]:
			continue
		else:
			swap = 0
			for j in range(b[i] - 1, 0, -1):
				if ind[j] != -1 or ind[j] >= ind[j - 1]:
					swap = ind[j]
					ind[j] += 1
					break
			if n <= swap:
				swap = cnt
				cnt += 1
				cnt %= n
			(b[i], b[swap]) = (b[swap], b[i])
	return (a, b)

def main():
	n = int(input())
	(a, b) = solve(n)
	if all((a[i] != b[i] for i in range(n))):
		print('Yes')
		print(' '.join(map(str, b)))
	else:
		print('No')

def __starting_point():
	main()
__starting_point()