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>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define ll long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
#define smax(a,b) a=max(a,b)
// #if !defined(ONLINE_JUDGE)
// #include "debugging.h"
// #endif
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

// int const mod = 7340033;
// int const mod = 998244353;
long long const mod = 1e9+7;
int power(int a,int b,int m){
    int res = 1;
    while(b){
        if(b&1){
            // res = res*a;
            res = (res*a)%m;
        }
        a=(a*a)%m;
        // a%=m;
        b=b/2;
    }
    return res;
}

int inverse(int x , int m){
    return power(x,m-2,m);
}


int const N = 2e5+5;
int const inf = 1e18;

int cnta[N];
int cntb[N];
int a[N];

void solve(){
    int i,j;
    int n;
    cin>>n;
    for(i=0;i<n;i++){
        int x;
        cin>>x;
        cnta[x]++;
        a[i] = x;
    }
    for(i=0;i<n;i++){
        int x;
        cin>>x;
        cntb[x]++;
    }

    int is = 1;
    for(i=1;i<=n;i++){
        int rem = n-cnta[i];
        if(cntb[i] > rem){
            is = 0;
        }
    }
    if(!is) {
        cout<<"No"<<endl; return;
    }
    cout<<"Yes"<<endl;
    
    int mx = 0;
    for(i=1;i<=n;i++){
        mx = max(mx , cnta[i]);
    }

    int b[n] = {0};

    i=1;
    j=mx;

    while(j < n){
        while(cntb[i] == 0) {
            i++;
        }
        b[j] = i;
        cntb[i]--;
        j++;
    }
    j=0;

    while(j < mx){
        while(cntb[i] == 0){
            i++;
        }
        b[j] = i;
        cntb[i]--;
        j++;
    }

    for(i=0;i<n;i++){
        cout<<b[i]<<" ";
    }
    cout<<endl;
}   


int32_t main(){
    IOS;
    int t;
    t = 1;
    // precompute();
    // cin>>t;  
    for(int tt=1;tt<=t;tt++){
        // cout << "Case #"<<tt<<": ";
        solve();
    }
    return 0;
}

/* 

*/