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: interview

Starter code:

Solutions:
# bを必要なだけ(strideの分)右にずらせばよい
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()))
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)

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n, = list(map(int,readline().split()))
*a, = list(map(int,readline().split()))
*b, = list(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]] # 重なる値は一種類しかない。これを v とおく。
    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
    # [p,q) でかぶる。[r,s)でどちらかが値 v をとる
    if q > n-s+r+p: # かぶりを吹っ飛ばせない
        print("No")
        return
    # かぶった部分を左、右によける
    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))



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]
    ans = [B[(i-ans)%N] for i in range(N)]
 
    print((*ans))


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)

from collections import Counter
from heapq import heapify, heappop, heappush
from itertools import groupby

n = int(input())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))

cnt_b = Counter(bbb)
hq_both = []
free_a = []
idx_a = {}
cnt_a = {}
i = 0
for a, itr in groupby(aaa):
    cnt = len(list(itr))
    idx_a[a] = i
    cnt_a[a] = cnt
    if a in cnt_b:
        cnt_ab = cnt + cnt_b[a]
        if cnt_ab > n:
            print('No')
            return
        hq_both.append((-cnt_ab, a))
    else:
        free_a.append(a)
    i += cnt
heapify(hq_both)

ans = [-1] * n
remaining = n

while hq_both:
    cnt_ab, b = heappop(hq_both)
    cnt_ab = -cnt_ab
    assert cnt_ab == cnt_a[b] + cnt_b[b]
    assert cnt_ab <= remaining

    cb = cnt_b[b]
    while cb:
        if hq_both:
            _, a = heappop(hq_both)
        else:
            a = free_a.pop()
        ca = cnt_a[a]

        fill_len = min(ca, cb)
        i = idx_a[a]
        ans[i:i + fill_len] = [b] * fill_len
        remaining -= fill_len
        idx_a[a] += fill_len
        cnt_a[a] -= fill_len
        cnt_b[b] -= fill_len
        cb -= fill_len

        if cnt_a[a] > 0:
            if a in cnt_b and cnt_b[a] > 0:
                heappush(hq_both, (-(cnt_a[a] + cnt_b[a]), a))
            else:
                free_a.append(a)

    free_a.append(b)

for b, cb in list(cnt_b.items()):
    if cb == 0:
        continue
    while cb:
        a = free_a.pop()
        ca = cnt_a[a]

        fill_len = min(ca, cb)
        i = idx_a[a]
        ans[i:i + fill_len] = [b] * fill_len
        idx_a[a] += fill_len
        cnt_a[a] -= fill_len
        cb -= fill_len

        if cnt_a[a] > 0:
            free_a.append(a)

print('Yes')
print((*ans))


# Reference: https://betrue12.hateblo.jp/entry/2020/09/15/180849

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


def __starting_point():
    main()

__starting_point()

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

#解説参照
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)

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)

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

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

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

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)

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 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=10e18
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)

#a,b,c,d = map(int, input().split())
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")


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")
        return
print("Yes")
print((" ".join(map(str, Ans))))


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

#!/usr/bin/env python


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


def __starting_point():
    main()

__starting_point()

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

from collections import Counter
from heapq import heapify, heappop, heappush
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))
    idx_a[a] = i
    cnt_a[a] = cnt
    i += cnt

cnt_b = Counter(bbb)
hq_both = []
hq_free = []
for a, ca in list(cnt_a.items()):
    if a in cnt_b:
        hq_both.append((-(ca + cnt_b[a]), a))
    else:
        hq_free.append(a)
heapify(hq_both)

# Aの個数とBの個数の和が大きいやつがヤバげ

ans = [-1] * n
remaining = n

while hq_both:
    cab, a1 = heappop(hq_both)
    cab = -cab
    assert cab == cnt_a[a1] + cnt_b[a1]

    # print(a1, cab, cnt_a, cnt_b, ans, hq_both, hq_free)

    if cab > remaining:
        print('No')
        return

    cb = cnt_b[a1]
    while cb:
        if hq_both:
            _, a2 = heappop(hq_both)
            pop_from_que = True
        else:
            a2 = hq_free.pop()
            pop_from_que = False
        ca = cnt_a[a2]
        # print('b', cb, a2, pop_from_que, ca <= cb, hq_both, hq_free)
        if ca <= cb:
            l = idx_a[a2]
            ans[l:l + ca] = [a1] * ca
            remaining -= ca
            idx_a[a2] += ca
            cnt_a[a2] -= ca
            cnt_b[a1] -= ca
            cb -= ca
        else:
            l = idx_a[a2]
            ans[l:l + cb] = [a1] * cb
            remaining -= cb
            idx_a[a2] += cb
            cnt_a[a2] -= cb
            cnt_b[a1] -= cb
            cb = 0
            if pop_from_que:
                heappush(hq_both, (-(cnt_a[a2] + cnt_b[a2]), a2))
            else:
                hq_free.append(a2)
        # print('b', cb, a2, pop_from_que, ca <= cb, hq_both, hq_free)
    hq_free.append(a1)

for b, cb in list(cnt_b.items()):
    if cb == 0:
        continue
    while cb:
        a = hq_free.pop()
        ca = cnt_a[a]
        if ca <= cb:
            l = idx_a[a]
            ans[l:l + ca] = [b] * ca
            cb -= ca
        else:
            l = idx_a[a]
            ans[l:l + cb] = [b] * cb
            idx_a[a] += cb
            cnt_a[a] -= cb
            cb = 0
            hq_free.append(a)

print('Yes')
print((*ans))


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
    else:
        if 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(tpA, tpB, t)
    print(" ".join([str(_) for _ in ans]))


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)


def __starting_point():
    resolve()
__starting_point()

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


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

    # move a
    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)
    # move b
    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)
    # print(a_list_1, a_list_2, b_list_1, b_list_2)
    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

    # need to modify
    if d * 2 > len(a_list_1):
        # a includes many k_max
        if count_a[k_max] >= count_b[k_max]:
            # swap a
            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:
            # swap b
            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]
    # print(a_list_moved, b_list_moved)
    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])
    # print(res_b)
    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
import numpy as np


def main():
    n = int(input())
    a = np.array([int(i) for i in input().split()])
    b = np.array([int(i) for i in input().split()])
    ca = Counter(a)
    cb = Counter(b)
    for k in list(cb.keys()):
        if cb[k] > n - ca[k]:
            print("No")
            return
    while any(a == b):
        s = max(ca[k] for k in list(cb.keys()))
        b = np.roll(b, s)
    print("Yes")
    print((*b))


def __starting_point():
    main()

__starting_point()

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)

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


print('Yes')
print(*(B[-diff:]+B[:-diff]))

import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
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

    for i in range(n):
        if A[i] != B[i]:
            continue
        while 1:
            j = randrange(0, 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()

import math
import numpy as np
import decimal
import collections
import itertools
import sys
import random
#Union-Find
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
#Prime-Factorize
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
#nCr
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
#拡張Euclidの互除法
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
#BIT
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
#Associative Array
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)
#Floor Sum
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
#Z-Algorithm
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
#mod-sqrt
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)

#!/usr/bin/env python3
from collections import Counter
INF = 1e12


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

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


def __starting_point():
    main()

__starting_point()

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


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


from heapq import heappush, heappop


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

all_freq = {}

cnt_b = [0] * 220000
for num in b:cnt_b[num] += 1


for num in a:
    if num not in all_freq:
        all_freq[num] = 0
    all_freq[num] += 1

for num in b:
    if num not in all_freq:
        all_freq[num] = 0
    all_freq[num] += 1

heap = []

for num, freq in list(all_freq.items()):
    if freq > n:
        print("No")
        return
    if cnt_b[num] > 0:
        heappush(heap, (-freq, num))

ans = []

def get_max():
    (freq, num) = heappop(heap)
    freq = -freq
    while all_freq[num] != freq:
        (freq, num) = heappop(heap)
        freq = -freq

    return num

for num in a:
    most_freq_num = get_max()
    if most_freq_num != num:
        ans.append(most_freq_num)
        all_freq[most_freq_num] -= 1
        cnt_b[most_freq_num] -= 1
        if cnt_b[most_freq_num] > 0:
            heappush(heap, (-all_freq[most_freq_num], most_freq_num))
    else:
        second_freq_num = get_max()
        heappush(heap, (-all_freq[most_freq_num], most_freq_num))
        ans.append(second_freq_num)
        all_freq[second_freq_num] -= 1
        cnt_b[second_freq_num] -= 1
        if cnt_b[second_freq_num] > 0:
            heappush(heap, (-all_freq[second_freq_num], second_freq_num))
    all_freq[num] -= 1
    if cnt_b[num] == 0:continue
    heappush(heap, (-all_freq[num], num))

print("Yes")
print((*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 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')
        return

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)

import collections

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

Atmp = 0
Btmp = 0

INF=10e18


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=[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(a[i],end=" ")
# print()
for i in range(n):
    print(b[(i-diff)%n],end=" ")
print()

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

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)
# print(all,arr)
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
# print(ng)
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)


#!/usr/bin/env python3
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")
        return
print("Yes")
print((*Ans))


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 = -100000000000000000
    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 = [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]
#print(C,D,E)
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
    #print(x)
    for i in range(N):
        B_[(i+x)%N] = B[i]
    print("Yes")
    print(*B_,sep=' ')

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


def __starting_point():
    main()

__starting_point()

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)

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 n<max(c):
  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]))

#!/usr/bin/env python3

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
    #print(key,blank,remain)
    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)
    #print(ans,head,pos)
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)

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 = B[N - ma:] + B[:N - ma]
    print((*ans))


def __starting_point():
    main()

__starting_point()

#!/usr/bin/env python3

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')
        return
    acum+=tcnt1
    tpos=max(acum,pos)
    remain=tcnt2
    #print(key,blank,remain)
    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)
    #print(ans,head,pos)
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)

# 解説を参考に作成
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
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
    # print(Ci)
    # print(Di)
    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(x)
    # print(' '.join([str(a) for a in Ai]))
    print((' '.join([str(Bi[(N - x + i) % N]) for i in range(N)])))


def __starting_point():
    # S = input()
    N = int(input())
    # N, M = map(int, input().split())
    Ai = [int(i) for i in input().split()]
    Bi = [int(i) for i in input().split()]
    # ABi = [[int(i) for i in input().split()] for _ in range(N)]
    solve(N, Ai, Bi)

    # # test
    # from random import randint
    # from func import random_str
    # solve()

__starting_point()

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

import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print((k.join(list(map(str, lst)))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = LI()
    B = sorted(LI(), reverse=True)
    tmp = []
    for i in range(N):
        if A[i] == B[i]:
            tmp.append((i, A[i]))

    j = 0
    while tmp:
        idx, x = tmp.pop()
        for i in range(j, N):
            b = B[i]
            j = i + 1
            if i == idx: continue
            if b != x and x != A[i]:
                B[i], B[idx] = B[idx], B[i]
                break
        else:
            print('No')
            return
    print('Yes')
    print((*B))


def __starting_point():
    solve()


__starting_point()

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

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 list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()
B = LIST()

CA = Counter(A)
CB = Counter(B)

for k in list(CB.keys()):
	if CB[k] > N-CA[k]:
		print("No")
		return
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))




# coding: utf-8
# Your code here!
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]] # b を逆順にしたので、重なる値は一種類しかない。これを v とおく。
    r = same[0]
    s = same[-1]+1
    notv = [i for i in range(n) if a[i]!=v and b[i]!=v] # どっちもvとかぶらない index
    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)

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番目と入れ替えてもかぶる場合
    i+=1
  b[i],b[l]=b[l],b[i] #かぶらないことを確認してから入れ替え
  l+=1
print('Yes')
print(' '.join([str(i) for i in b]))

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

from collections import Counter
import numpy as np


def main():
    n = int(input())
    a = np.array([int(i) for i in input().split()])
    b = np.array([int(i) for i in input().split()])
    ca = Counter(a)
    cb = Counter(b)
    for k in list(cb.keys()):
        if cb[k] > n - ca[k]:
            print("No")
            return
    shift = max(ca[k] for k in list(cb.keys()))
    while any(a == b):
        b = np.roll(b, shift)
    print("Yes")
    print((*b))


def __starting_point():
    main()

__starting_point()

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n, = list(map(int,readline().split()))
*a, = [2*int(x) for x in readline().split()]
*b, = [2*int(x)+1 for x in 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))
    else:
        if 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")
        return
print("Yes")
ans = [y for x,y in res]
print((*ans))




def solve():    
    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)
    
                        
def __starting_point():
    solve()
__starting_point()

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 list(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
#	print(c, a, b)
	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

#print(A_head)
#print(A_tail)
#print(B_head)
#print(B_tail)

A_tail.reverse()
B_head.reverse()

A_list = A_head + A_tail
B_list = B_tail + B_head

#print(A_list)
#print(B_list)

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


# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n, = list(map(int,readline().split()))
*a, = list(map(int,readline().split()))
*b, = list(map(int,readline().split()))
b = b[::-1]
from collections import Counter
d = Counter(a+b)
if max(d.values()) > n:
    print("No")
    return

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


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)

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

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


# 解説を参考に作成
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, A, B):
    buf = -1
    key = 0
    for i in range(N):
        if buf != A[i]:
            key = 0  # 前回(A[i - 1])と同じ値じゃなければリセット
        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])))


def __starting_point():
    # S = input()
    N = int(input())
    # N, M = map(int, input().split())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    # ABi = [[int(i) for i in input().split()] for _ in range(N)]
    solve(N, A, B)

    # # test
    # from random import randint
    # from func import random_str
    # solve()

__starting_point()

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


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)

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')
        return
    slide = max(slide, idx_a[a] - idx_b[a])

print('Yes')
if slide > 0:
    bbb = bbb[-slide:] + bbb[:-slide]
print((*bbb))


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 list(ca.items()):
    vb = cb[ka]
    if va + vb > n:
        print("No")
        return

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


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

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

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))
    else:
        if 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))


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


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

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

# coding: utf-8
# Your code here!
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]] # b を逆順にしたので、重なる値は一種類しかない。これを v とおく。
    notv = [i for i in range(n) if a[i]!=v and b[i]!=v] # どっちもvとかぶらない index
    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)

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')
                return
            cur-=bit
        b[i], b[cur] = b[cur], b[i]
print('Yes')
print((' '.join(list(map(str, b)))))
    
    


import numpy as np

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

l, r = 0, N + 1
while r - l > 1:
    m = (r + l) // 2
    if np.all(B[N - m:] > A[:m]):
        l = m
    else:
        r = m

if np.all(B[:N - l] < A[l:]):
    print('Yes')
    print((*np.roll(B, l)))
else:
    print('No')


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