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++ (GCC 9.2.1) (judge verdict: Runtime Error)

// Oh damn, cann't you see I'm fine?

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'

const int max_n = 1e5 + 5;

int n;
bool seen[max_n];
int a[max_n], b[max_n];
int L[max_n], R[max_n];

int r() {
	int x = (rand()%1000)*1000 + rand()%1000;
	return x%n;
}

bool FindMatch(int i) {
	for(int j = 0; j < 100; j++) {
		int foo = r();
		if(a[i] != b[foo] && !seen[foo]) {
			seen[foo] = true;
			if(R[foo] < 0 || FindMatch(R[foo])) {
				L[i] = foo;
				R[foo] = i;
				return true;
			}
		}
	}
	return false;
}

int BipartiteMatching() {
	memset(L, -1, sizeof L);
	memset(R, -1, sizeof R);
	for(int i = 0; i < n; i++) {
		memset(seen, 0, sizeof seen);
		if(!FindMatch(i)) return 0;
	}
	return 1;
}

int A[max_n], B[max_n];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	srand(time(NULL));

	cin >> n;
	for(int i=0; i<n; i++) {
		cin >> a[i];
		A[a[i]]++;
	}
	for(int i=0; i<n; i++) {
		cin >> b[i];
		B[b[i]]++;
	}

	for(int i=0; i<n; i++) {
		if(B[i] > n - A[i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	if(BipartiteMatching()) {
		cout << "Yes" << endl;
		for(int i=0; i<n; i++) {
			cout << b[L[i]] << " ";
		}
	}
	else cout << "No" << endl;


	return 0;
}