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: Runtime Error)

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) 
#define dumpL(x) 
#define LINE 
#define LINEL 
#define dumpV(v) 
#define dumpVL(v) 
#define STOP assert(false)
#endif
#define mp make_pair
 
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
    out << '(' << a.first << ", " << a.second << ')';
    return out;
}
}

int main(){
    int n;
    cin >> n;
    vi a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    map<int, int> ma, mb;
    rep(i, n) {
        ma[a[i]]++;
        mb[b[i]]++;
    }
    for(auto&& p : mb) {
        if(ma.count(p.first)) continue;
        if(p.second + ma[p.first] > n) {
            cout << "No" << '\n';
            return 0;
        }
    }
    using P = pair<int, int>;
    priority_queue<P> pa, pb;
    for(auto&& p: ma) pa.emplace(p.second, p.first);
    for(auto&& p: mb) pb.emplace(p.second, p.first);
    vector<vector<int>> ind(n+1);
    rep(i, n) ind[a[i]].emplace_back(i);

    vi ans(n,-1);
    vi one;
    vi one_ind;

    while(pa.size()) {
        auto p = pa.top(); pa.pop();

        if(p.first == 1) {
            pa.emplace(p);
            break;
        }
        
        
        auto q = pb.top(); pb.pop();
        P x = q;

        if(p.second == q.second) {
            x = pb.top(); pb.pop();
            pb.emplace(q);
        }
        
        int a = p.second;
        ans[ind[a].back()] = x.second;
        ind[a].pop_back();
        x.first--;
        p.first--;
        if(x.first > 0) pb.emplace(x);
        if(p.first > 0) pa.emplace(p);
    }
    {
        
        auto k = pa.top(); pa.pop();
        while(pa.size()) {
            int a = pa.top().second; pa.pop();
            int b = pb.top().second; pb.pop();
            ans[ind[a].back()] = b;
            ind[a].pop_back();
        }
        ans[ind[k.second].back()] = pb.top().second;
    }



    cout << "Yes" << '\n';
    rep(i, n) {
        cout << ans[i] << (i+1 == n ? '\n' : ' ');
    }

    return 0;
}