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 <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
constexpr int MAX = 5000000;

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	int n; cin >> n;
	vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i], a[i]--;
	vector<int> b(n); for (int i = 0; i < n; i++) cin >> b[i], b[i]--;
	vector<int> cnt(n); for (int i = 0; i < n; i++) cnt[a[i]]++;
	map<pair<int, int>, int> mpa, mpb;
	map<int, vector<int>> res;
	for (int i = 0; i < n; i++) {
		mpb[{-cnt[b[i]], b[i]}]++;
	}
	for (int i = 0; i < n; i++) {
		mpa[{-cnt[a[i]], a[i]}]++;
	}
	for (auto itr = mpa.begin(); itr != mpa.end();) {
		auto& p = itr->first;
		int t = p.second;
		int s = itr->second;
		bool f = false;
		int x, y, z;

		while (!mpb.empty() and s > 0) {
			auto it = mpb.begin();
			if (it->first.second == t) {
				f = true;
				x = itr->first.first;
				y = itr->first.second;
				z = itr->second;
				mpb.erase(mpb.begin());
				continue;
			}
			if (s > it->second) {
				s -= it->second;
	
				for (int i = 0; i < it->second; i++) {
					res[t].emplace_back(it->first.second);
				}
				mpb.erase(it);
			}
			else {
				for (int i = 0; i < s; i++) {
					res[t].emplace_back(it->first.second);
				}
				it->second -= s;
				s = 0;
			}
		}
		if (s > 0) {
			cout << "No" << "\n";
			return 0;
		}
		if (f) {
			mpb[{0, y}] = z;
		}
		else {
			auto it = mpb.lower_bound({ -cnt[t],t });
			if (!(it == mpb.end() or it->first != make_pair(-cnt[t], t))) {
				int x = it->first.second;
				int y = it->second;
				mpb.erase(it);
				mpb[{0, x}] = y;
			}

		}
		itr = mpa.erase(itr);
	}
	cout << "Yes" << "\n";
	for (int i = 0; i < n; i++) {
		cout << res[a[i]].back() + 1<< " \n"[i + 1 == n];
		res[a[i]].pop_back();
	}
	return 0;
}