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: Wrong Answer)

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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif

template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c, neg = 0; while(isspace(c = getchar_unlocked()));
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar_unlocked())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }

const int MAXN = 2e5 + 5, INF = 0x3f3f3f3f;

int cntA[MAXN];
int cntB[MAXN];
clock_t ck;

struct CMP {
	bool operator() (pii const& a, pii const& b) const {
		return mk(a.se + cntA[a.fi], a.fi) > mk(b.se + cntA[b.fi], b.fi);
	}
};

inline void gogo(vector<int> const& a, vector<int> b, int n) {

	while(double(clock() - ck) / CLOCKS_PER_SEC <= 1) {
		shuffle(b.begin(), b.end(), rng);

		bool ok = true;
		for (int i = 0; i < n; i++) {
			if (a[i] == b[i]) {
				ok = false;
				break;
			}
		}
		if (ok) {
			puts("Yes");
			for (int i : b) printf("%d ", i);
			exit(0);
		}
	}

	puts("No");
	exit(0);
}

int main() {
	ck = clock();

	int n; rd(n);
	vector<int> a(n);
	for (int& i : a) rd(i);
	vector<int> b(n);
	for (int& i : b) rd(i);

	set<pii, CMP> B;
	vector<pii> A;
	for (int i : a) cntA[i]++;
	for (int i : b) cntB[i]++;
	for (int i = 1; i <= n; i++) if (cntA[i]) A.emplace_back(i, cntA[i]);
	for (int i = 1; i <= n; i++) if (cntB[i]) B.emplace(i, cntB[i]);

	sort(A.begin(), A.end(), [](pii const& a, pii const& b) {
		return mk(a.se, a.fi) > mk(b.se, b.fi);
	});

	vector<vector<int>> edges(n+1);
	bool ok = true;
	for (auto& pa : A) if (ok) {
		int el = pa.fi, cn = pa.se;
		for (int i = 0; i < cn; i++) {
			auto it = prev(B.end());
			if(it != B.begin() && it->fi == el) it = prev(it);

			if (it->fi == el) {
				ok = false;
				break;
			}

			edges[el].push_back(it->fi);
			pii newValue = *it;
			B.erase(it);
			if (newValue.second > 1) {
				newValue.second--;
				B.insert(newValue);
			}
		}
	}

	for (int i = 0; i <= n; i++) {
		ok &= (int) edges[i].size() == cntA[i];
	}

	if (!ok) {
		gogo(a, b, n);
		puts("No");
	} else {
		puts("Yes");
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j < cntA[i]; j++) {
				printf("%d ", edges[i][j]);
			}
		}
		puts("");
	}


}