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)

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll A[200010], B[200010];
ll cntA[200010] = {}, cntB[200010] = {};
vector<ll> pos[200010];

void solve(){
    ll N;
    cin >> N;
    rep(i,0,N) cin >> A[i];
    rep(i,0,N) cin >> B[i];
    rep(i,0,N){
        pos[A[i]].push_back(i);
    }

    rep(i,0,N){
        cntA[A[i]]++;
        cntB[B[i]]++;
    }
    rep(i,0,N+1){
        if(cntA[i] + cntB[i] > N){
            print("No");
            return;
        }
    }
    vector<lpair> lp;
    rep(i,0,N+1){
        if(cntA[i] > 0 && cntB[i] > 0){
            lp.push_back({N - cntA[i] - cntB[i], i});
        }
    }

    sort(lp.begin(), lp.end());
    queue<ll> que;
    vector<lpair> v;
    if(lp.size() == 0){
        print("Yes");
        printa(B,N);
        return;
    }
    rep(i,0,N){
        if(A[i] != lp[0].second){
            v.push_back({N-cntA[A[i]] - cntB[A[i]], i});
        }
    }
    sort(v.begin(), v.end());
    for(auto &e: v){
        que.push(e.second);
    }
    ll ans[200010] = {};

    for(auto &e: lp){
        // print(e.second);
        ll n = cntB[e.second];
        while(n--){
            ll q = que.front();
            que.pop();
            ans[q] = e.second;
        }
        for(auto &f: pos[e.second]){
            if(ans[f] == 0){
                que.push(f);
            }
        }
    }
    stack<ll> st;

    rep(i,0,N){
        if(cntA[B[i]] == 0 && cntB[B[i]] > 0){
            st.push(B[i]);
        }
    }
    rep(i,0,N){
        if(ans[i] == 0){
            ans[i] = st.top();
            st.pop();
        }
    }
    print("Yes");
    printa(ans, N);

    

}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}