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: Time Limit Exceeded)

#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

inline void check (vector <int> a, vector <int> b) {
    for (int i = 0; i < sz(a); i++) {
        if (a[i] == b[i]) return;
    }
    cout << "Yes\n";
    for (auto &i : b) cout << i << ' ';
    cout << '\n';
    exit(0);
}

inline void solve (vector <int> a, vector <int> b) {
    check(a, b);
    reverse(all(b));
    check(a, b);
    while (clock() / CLOCKS_PER_SEC < 1.5) {
        random_shuffle(all(b));
        check(a, b);
    }
}
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    for (auto &i : a) cin >> i;
    vector <int> b(n);
    for (auto &i : b) cin >> i;
    map <int, int> A, B;
    for (auto &i : a) ++A[i];
    for (auto &i : b) ++B[i];
    set <pair<int, pii> > have;
    for (auto &i : B) {
        have.insert({min(A[i.x], i.y), {i.y, i.x}});
    }
    vector <pii> t(n);
    for (int i = 0; i < n; i++) {
        t[i] = {A[a[i]], i};
    }
    sort(all(t));
    reverse(all(t));
    vector <int> ans(n);
    for (int i = 0; i < n; i++) {
        if (have.empty()) {
            solve(a, b);
            cout << "No\n";
            rr;
        }
        int cur = a[t[i].y];
        auto it = --have.end();
        if (it->y.y == cur) {
            if (sz(have) == 1) {
                solve(a, b);
                cout << "No\n";
                rr;
            }
            --it;
        }
        ans[t[i].y] = it->y.y;
        auto nice = *it;
        have.erase(it);
        if (nice.y.x - 1 > 0) {
            have.insert({min(A[nice.y.y], nice.y.x - 1), {nice.y.x - 1, nice.y.y}});
        }
    }
    cout << "Yes\n";
    for (int i = 0; i < n; i++) {
        assert(ans[i] != a[i]);
    }
    for (auto &i : ans) cout << i << ' ';
    cout << '\n';
}