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>
#define FOR(i,a,b) for(ll i=a; i<=b; ++i)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using vl=vector<ll>;
using vp=vector<pll>;
const ll INF=1e18;
const ll MOD=1e9+7;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;
    ll a[n+5],b[n+5];
    ll cnta[n+5]={},cntb[n+5]={};
    FOR(i,1,n){
        cin>>a[i];
        ++cnta[a[i]];
    }
    FOR(i,1,n){
        cin>>b[i];
        ++cntb[b[i]];
    }
    priority_queue<pll> pq;
    FOR(i,1,n) if(cntb[i]) pq.emplace(cntb[i],i);
    FOR(i,1,n){
        pll p1=pq.top();
        pq.pop();
        if(p1.se==a[i]){
            if(pq.empty()){
                cout<<"No";
                return 0;
            }
            pll p2=pq.top();
            pq.pop();
            pq.push(p1);
            b[i]=p2.se;
            if(--p2.fi) pq.push(p2);
        }
        else{
            b[i]=p1.se;
            if(--p1.fi) pq.push(p1);
        }
    }
    cout<<"Yes"<<endl;
    FOR(i,1,n) cout<<b[i]<<' ';
    return 0;
}