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)


/*
    ID: sixathofpain
    TASK: friday
    LANG: C++   

*/


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 1000000007;
const int N = int(3e5) + 999;
#define int long long int

typedef pair<int, int> pii;

bool comp(pii &a,pii &b){
    return (a.ff+a.ss)<(b.ff+b.ss);
}
bool comp2(pii &a,pii &b){
    return (a.ff-a.ss)<(b.ff-b.ss);
}


int32_t main(){
    IOS;
    
    // freopen("friday.in","r",stdin);
    // freopen("friday.out","w",stdout);

    int n;
    cin>>n;
    vector<int> a(n),b(n);
    for(auto &it:a)
        cin>>it;
    for(auto &it:b)
        cin>>it;
    map<int,int> cnta,cntb;

    for(int i=0;i<n;i++){
        cnta[a[i]]++;
        cntb[b[i]]++;
    }

    for(int i=0;i<n;i++){
        if(cntb.count(a[i])==0)
            continue;
        if(min(cnta[a[i]],cntb[a[i]])>n/2){
            cout<<"No"<<endl;
            return 0;
        }
        
    }

    vector<int> notsame;
    deque<int> same;
    for(int i=0;i<n;i++){
        if(cnta.count(b[i])==0){
            notsame.pb(b[i]);
        }else{
            same.pb(b[i]);
        }
    }
    if(notsame.size()==0){
        
        set<pii,greater<pii> > cnt;

        for(int i=0;i<n;i++){
            cnt.in({cntb[b[i]],b[i]});
        }

        for(int i=0;i<n;i++){
            if(cnt.begin()->ff!=a[i]){
                b[i]=cnt.begin()->ff;
                auto ext = *cnt.begin();
                cnt.erase(ext);
                if(ext.ff>=2)
                    cnt.in({ext.ff-1,ext.ss});
            }else if((++cnt.begin())->ff!=a[i]){
                auto ext = *(++cnt.begin());
                b[i] = ext.ss;
                cnt.erase(ext);
                if(ext.ff>=2)
                    cnt.in({ext.ff-1,ext.ss});
            }
        }

        
        for(int i=0;i<n;i++){
            if(a[i]==b[i])
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout<<"Yes"<<endl;
        for(int i=0;i<n;i++)
            cout<<b[i]<<" ";
        cout<<endl;
        return 0;

    }

    for(int i=0;i<n;i++){
        b[i]=-1;
        if(same.size()){
            if(a[i]!=same.back()){
                b[i]=same.back();
                same.pop_back();
            }
            else if(a[i]!=same.front()){
                b[i]=same.front();
                same.pop_front();
            }
        }
        if(b[i]==-1 and notsame.size()){
            b[i]=notsame.back();
            notsame.pop_back();
        }
        if(b[i]==-1){
            cout<<"No";
            cout<<endl;
            return 0;
        }
        
    }
    cout<<"Yes"<<endl;
    for(int i=0;i<n;i++){
        assert(a[i]!=b[i]);
        cout<<b[i]<<" ";
    }
    cout<<endl;



    return 0;
}