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;

using ll = long long;

constexpr char newl = '\n';

constexpr double ticks_per_sec = 3000000000; // AtCoder: 3000000000;
constexpr double ticks_per_sec_inv = 1.0 / ticks_per_sec;
inline double rdtsc() { // in seconds
    uint32_t lo, hi;
    asm volatile ("rdtsc" : "=a" (lo), "=d" (hi));
    return (((uint64_t)hi << 32) | lo) * ticks_per_sec_inv;
}
constexpr double TLE = 2; // sec
constexpr double time_limit = TLE * 0.99;

unsigned int randxor()
{
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}

template<typename hoge>
void my_shuffle(vector<hoge>& v) {
    int sz = v.size();
    for (int i = sz - 1; i >= 1; i--) {
        swap(v[i], v[randxor() % (i + 1)]);
    }
}

int main() {
    double begin_time = rdtsc();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    int pena = 0;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

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

    if (n == 1) {
        if (a[0] == b[0]) cout << "No\n";
        else {
            cout << "Yes\n";
            cout << b[0] << newl;
        }
        return 0;
    }

    my_shuffle(b);
    for (int i = 0; i < n; i++) {
        pena += (a[i] == b[i]);
    }

    while (rdtsc() - begin_time < time_limit && pena > 0) {
        if (pena == 0) break;
        int i1 = randxor() % n;
        int i2 = randxor() % (n - 1);
        i2 += (i2 >= i1);

        int nex_pena = pena - (a[i1] == b[i1]) + (a[i1] == b[i2]) - (a[i2] == b[i2]) + (a[i2] == b[i1]);
        if (nex_pena < pena) {
            swap(b[i1],b[i2]);
            pena = nex_pena;
        }
    }

    if (pena > 0) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
        for (int i = 0; i < n; i++) {
            cout << b[i] << " \n"[i + 1 == n];
        }
    }
    return 0;
}