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++ (Clang 10.0.0) (judge verdict: Wrong Answer)

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10, MOD = 1e9 + 7;

ll dp[SIZE][2][2];

int main()
{
    fastInp;

    
    ll n;
    cin >> n;
    vector<ll> vec1(n), vec2(n);

    map<ll, ll> mp1, mp2;
    for (auto &cur : vec1) cin >> cur;
    for (auto &cur : vec2) cin >> cur;

    for (auto cur : vec1) {
        mp1[cur]++;
    }

    for (auto cur : vec2) {
        mp2[cur]++;
    }

    ll sh = 0;

    for (auto cur : mp1) {
        ll am = cur.second, vl = cur.first;

        if (am > n - mp2[vl]) {
            cout << "No";
            return 0;
        }
    }

    pair<ll, ll> mn = {-INF, INF};
    for (auto cur : mp2) {
        ll am = cur.second, vl = cur.first;
        mn.first = max(mn.first, am);
        mn.second = min(mn.second, am);
        if (am > n - mp1[vl]) {
            cout << "No";
            return 0;
        }
    }

    cout << "Yes\n";
    bool fl = true;
    for (int i = 0; i < vec2.size(); i++) {
        if (vec2[(i + n / 2) % n] == vec1[i]) fl = false;
    }

    if (fl) {
        for (int i = 0; i < vec2.size(); i++) {
            cout << vec2[(i + n / 2) % n] << " ";
        }
        return 0;
    } else {
        vector<ll> check;
        for (int i = 0; i < n; i++) check.push_back(i);
        std::random_device rd;
        std::mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
        shuffle(check.begin(), check.end(), rng);
        check.insert(check.begin(), mn.first);
        check.insert(check.begin(), mn.second);
        for (int k = 0; k < n; k++) {
            bool fl = true;
            for (int i = 0; i < vec2.size(); i++) {
                if (vec2[(i + check[k]) % n] == vec1[i]) fl = false;
            }

            if (fl) {
                for (int i = 0; i < vec2.size(); i++) {
                    cout << vec2[(i + check[k]) % n] << " ";
                }
                return 0;
            }
        }
    }

    return 0;
}