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;

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//デバッグ
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug1(x1) cout<<#x1<<": "<<x1<<endl
#define debug2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug5,debug4,debug3,debug2,debug1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//省略
using vi  = vector<int>;
using vii = vector<vector<int>>;
using vl  = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
    ll N;
    cin>>N;
    vl A(N),B(N);
    map<ll,ll> mp,mpA,mpB;

    REP(i,N){
        cin>>A[i];
        mp[A[i]]++;
        mpA[A[i]]++;
    }

    REP(i,N){
        cin>>B[i];
        mp[B[i]]++;
        mpB[B[i]]++;
    }

    priority_queue<pll> que;//first:登場数の和 second:中身
    ll saidai=0;
    REP2(i,1,N+1){
        if(mp.count(i)) saidai=max(saidai,mp[i]);
        if(mpB.count(i)&&mpA.count(i)){
            que.push(make_pair(mp[i],i));
        }
    }

    if(saidai>N){
        cout<<"No"<<endl;
        return 0;
    }

    priority_queue<pll,vector<pll>,greater<pll>> pair_AB;
    queue<ll> listA;
    while(!que.empty()){
        pll tmp=que.top();
        que.pop();
        ll wa1 = tmp.first;
        ll val1 = tmp.second;

        ll nokori1B = mpB[val1];
        
        if(!que.empty()){
            tmp=que.top();
            que.pop();
            ll wa2=tmp.first;
            ll val2=tmp.second;

            ll nokori2A = mpA[val2];

            // debug2(val1,mpB[val1]);
            // debug2(val2,mpB[val2]);
            pair_AB.push(make_pair(val2,val1));
            wa1--;
            wa2--;
            mpA[val2]--;
            mpB[val1]--;

            nokori1B = mpB[val1];
            nokori2A = mpA[val2];
            
            if(nokori1B>0){
                que.push(make_pair(wa1,val1));
            }
            if(nokori2A>0){
                que.push(make_pair(wa2,val2));
            }

        }else{
            //Aの残りの選択肢を追加
            for(auto itr=mpA.begin();itr!=mpA.end();itr++){
                if(itr->first==val1) continue;
                REP(j,itr->second){
                    listA.push(itr->first);
                }
            }

            REP(j,nokori1B){
                ll val2=listA.front();
                listA.pop();
                pair_AB.push(make_pair(val2,val1));
                mpA[val2]--;
                mpB[val1]--;
            }

            REP(j,mpA[val1]){
                listA.push(val1);
            }
        }
    }

    if(listA.empty()){
        //Aの残りの選択肢を追加
        for(auto itr=mpA.begin();itr!=mpA.end();itr++){
            REP(j,itr->second){
                listA.push(itr->first);
            }
        }
    }

    //最後にBとAのペア作成
    for(auto itr=mpB.begin();itr!=mpB.end();itr++){
        REP(j,itr->second){
            listA.push(itr->first);
            ll val2=listA.front();
            listA.pop();
            pair_AB.push(make_pair(val2,itr->first));
        }
    }
    
    while(!pair_AB.empty()){
        cout<<"Yes"<<endl;
        pll tmp=pair_AB.top();
        pair_AB.pop();
        cout<<tmp.second;
        if(pair_AB.empty()){
            cout<<endl;
        }else{
            cout<<" ";
        }
    }
}