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 Java (OpenJDK 11.0.6) (judge verdict: Wrong Answer)

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	static int[] toArray(String s , int N){
		int ret[] = new int[N];
		String a[] = s.split(" ");
		for(int i = 0 ; i < N ; ++i){
			ret[i] =Integer.parseInt(a[i]);
		}
		return ret;
	}
	static class Pair implements Comparable<Pair>{
		int x;
		int cnt;
		int d;
		public Pair(int v , int c, int d) {
			x = v;
			cnt = c;
			this.d = d;
		}
		@Override
		public int compareTo(Pair o) {
			if(o.cnt == cnt){
//				return o.d - d;
			}
			return o.cnt - cnt;
		}
		@Override
		public String toString() {
			return x+" "+cnt;
		}
	}
	static class PComp implements Comparator<Pair>{
		@Override
		public int compare(Pair o1, Pair o2) {
			if(o1.d == o2.d){
				return o2.cnt - o1.cnt;
			}
			return o2.d - o1.d;
		}
	}
	static class P implements Comparable<P>{
		int a;
		int b;
		public P(int a , int b){
			this.a = a;
			this.b = b;
		}
		@Override
		public int compareTo(P o) {
			return a - o.a;
		}
		@Override
		public String toString() {
			return a+" "+b;
		}
	}
	static void add(List<P> lst , int a , int b , int N){
		for(int i = 0 ; i < N ; ++i){
			lst.add(new P(a, b));
		}
	}
	static void solve(int[] A , int[] B){
		int N = A.length;
		int countA[] = new int[N + 1];
		int countB[] = new int[N + 1];
		for(int x : A){
			countA[x]++;
		}
		for(int x : B){
			countB[x]++;		
		}
		List<Pair> lstA = new ArrayList<Pair>();
		for(int i = 0 ; i < countB.length ; ++i){
			int a = countA[i];
			int b = N - countB[i];
			if(a > b){
				System.out.println("No");
				return ;
			}
		}
//		System.out.println(Arrays.toString(countB));
		PriorityQueue<Pair> pb = new PriorityQueue<Pair>(new PComp());
		for(int i = 0 ; i < countA.length ; ++i){
			if(countA[i] != 0){
				lstA.add(new Pair(i, countA[i], 0));
			}
			if(countB[i] != 0){
				pb.add(new Pair(i, countB[i], countA[i]));
			}
		}
//		System.out.println(pb);
		List<P> result = new ArrayList<P>();
		Collections.sort(lstA);
		for(Pair p : lstA){
			int cnt = p.cnt;
			Pair top = pb.peek();
//			System.out.println(p.x+" "+p.cnt);
//			System.out.println(pb);
			if(p.x == top.x){
				Pair kp = pb.poll();
				while(!pb.isEmpty() && cnt > 0){
					Pair v = pb.poll();
					if(v.cnt <= cnt){
						cnt -= v.cnt;
						add(result, p.x, v.x , v.cnt);
					}else{ // v.cnt > cnt
						v.cnt -= cnt;
						add(result, p.x, v.x , cnt);
						cnt = 0;
						pb.add(v);
					}
				}
				pb.add(kp);
			}else{
				Pair kp = null;
				while(!pb.isEmpty() && cnt > 0){
					Pair v = pb.poll();
					if(v.x == p.x){
						kp = v;
					}else{
						if(v.cnt <= cnt){
							cnt -= v.cnt;
							add(result, p.x, v.x , v.cnt);
						}else{ // v.cnt > cnt
							v.cnt -= cnt;
							add(result, p.x, v.x , cnt);
							cnt = 0;
							pb.add(v);
						}						
					}
				}
				if(kp != null){
					pb.add(kp);
				}
			}
		}
		Collections.sort(result);
//		System.out.println(result);
		System.out.println("Yes");
		StringBuilder ret = new StringBuilder();
		for(P p : result){
			if(ret.length() > 0){
				ret.append(' ');
			}
			ret.append(p.b);
		}
		System.out.println(ret);
	}
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		String AS = br.readLine();
		String BS = br.readLine();
		int A[] = toArray(AS, N);
		int B[] = toArray(BS, N);
		solve(A, B);
	}
}