Problem:
Score : 600 points

Problem Statement

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 1

6
1 1 1 2 2 3
1 1 1 2 2 3

Sample Output 1

Yes
2 2 3 1 1 1

Sample Input 2

3
1 1 2
1 1 3

Sample Output 2

No

Sample Input 3

4
1 1 2 3
1 2 3 3

Sample Output 3

Yes
3 3 1 2

Solution in C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int[] ca = new int[N+1];
		int[] cb = new int[N+1];
		foreach(var n in A) ca[n]++;
		foreach(var n in B) cb[n]++;
		
		bool chk = false;
		int ma = 0;
		int idx = -1;
		for(int i=0;i<=N;i++){
			if(ca[i] + cb[i] > N) chk = true;
			if(ca[i] + cb[i] > ma){
				idx = i;
				ma = ca[i] + cb[i];
			}
		}
		if(chk){
			Console.WriteLine("No");
			return;
		}
		
		int[] a = new int[N];
		int[] b = new int[N];
		
		for(int i=0;i<ca[idx];i++) a[i] = idx;
		for(int i=0;i<cb[idx];i++) b[i + ca[idx]] = idx;
		int cnt = ca[idx] + cb[idx];
		ca[idx] = 0;
		cb[idx] = 0;
		
		int r = 1;
		for(int i=1;i<=N;i++){
			if(cnt == N) break;
			if(ca[i] == 0) continue;
			while(ca[i] > 0){
				while(cb[r] == 0 || r == i){
					r++;
					if(r > N) r = 1;
				}
				a[cnt] = i;
				b[cnt] = r;
				ca[i]--;
				cb[r]--;
				cnt++;
				if(cnt == N) break;
			}
		}
		
//Console.WriteLine(String.Join(" ",a));		
//Console.WriteLine(String.Join(" ",b));		
		
		
		Queue<int> qa = new Queue<int>();
		for(int i=1;i<=N;i++){
			if(ca[i] != 0){
				while(ca[i] > 0){
					qa.Enqueue(i);
					ca[i]--;
				}
			}
		}
		Queue<int> qb = new Queue<int>();
		for(int i=1;i<=N;i++){
			if(cb[i] != 0){
				while(cb[i] > 0){
					qb.Enqueue(i);
					cb[i]--;
				}
			}
		}
		for(int i=0;i<N;i++){
			if(a[i] == 0) a[i] = qa.Dequeue();
		}
		for(int i=0;i<N;i++){
			if(b[i] == 0) b[i] = qb.Dequeue();
		}
//Console.WriteLine(String.Join(" ",a));		
//Console.WriteLine(String.Join(" ",b));		
		
		Array.Sort(a, b);
		
		Console.WriteLine("Yes");
		Console.WriteLine(String.Join(" ",b));
		
		
		
	}
	int N;
	int[] A;
	int[] B;
	public Sol(){
		N = ri();
		A = ria();
		B = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}