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: Vinay Khilwani
// Language: C++

// @vok8: Codeforces, AtCoder, LeetCode, HackerEarth, TopCoder, Google, FB, CSES, Spoj, GitHub
// @vok_8: CodeChef, GFG
// @vok8_khilwani: HackerRank

// Never Stop Trying.
// Trying to be Better than Myself.

// while(true)
// {
//     if(AC)
//     {
//         break;
//     }
//     else if(Contest Over)
//     {
//         Try.
//         Check out Editorial.
//         Understand.
//         Find out your Mistake.
//         Learn the topic (if new).
//         Solve Problems on that topic (if new).
//         Upsolve that problem.
//         break;
//     }
//     else
//     {
//         Try.
//         Use Pen-Paper.
//         Find errors, edge cases, etc.
//         continue;
//     }
// }

// Optimizations
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#pragma GCC optimize("Os")

// Libraries
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;

// Debugging
#define dbg(a) cerr<<a<<"\n";
#define debug_a(a) for(auto x:a) {cerr<<x<<" ";} cerr<<"\n";
#define debug_b(a) for(auto x:a) {cerr<<"["<<x.first<<", "<<x.second<<"]"<<"\n";} cerr<<"\n";
#define debug_c(a) for(auto x:a) {debug_a(x)} cerr<<"\n";
#define debug_d(a) for(auto x:a) {debug_b(x)} cerr<<"\n";
#define debug_e(a) cerr<<"["<<a.first<<", "<<a.second<<"]"<<"\n";

// Defines
#define fast ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL);
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define fr(i,a,n,b) for(int i=a; i<n; i+=b)
#define rfr(i,a,n,b) for(int i=a; i>=n; i-=b)
#define IN cin>>
#define OUT cout<<
#define nl "\n"
#define sz(a) int(a.size())
#define all(a) (a).begin(),(a).end()
#define each(a,b) for(auto &a:b)
#define pb push_back
#define set_bits(a) __builtin_popcountll(a)
#define ar array
#define write(a) for(auto x:a) {OUT x<<" ";} OUT nl;
#define read(a) for(auto &x:a) {IN x;}
// #define oset tree<int,null_type,less<int>,rb_tree_tag,tree_order_statisticnts_node_update>
using ll=long long int;
using ld=long double;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vi=vector<int>;
const ll mod=(ll)(1e9)+7LL;
const ll M=998244353LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ld pi=acos(-1);

// General Functions
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo) //Fast Power
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
void vok()
{
    fast
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("error.txt","w",stderr);
    #endif
}

// Global Variables
const int mxN=int(1e5)+10;

// Solver Function(s)
void solve()
{
    int n;
    IN n;
    vi a(n), b(n);
    read(a)
    read(b)
    if(n<=9)
    {
        sort(all(b));
        do
        {   
            bool yes=true;
            loop(i,0,n)
            {
                if(a[i]==b[i])
                {
                    yes=false;
                    break;
                }
            }
            if(yes)
            {
                OUT "Yes"<<nl;
                write(b)
                return;
            }
        }while(next_permutation(all(b)));
        OUT "No"<<nl;
        return;
    }
    multiset<int> m;
    each(x,b)
    {
        m.insert(x);
    }
    multiset<int> mm=m;
    vi ans;
    bool flag=true;
    loop(i,0,n)
    {
        int take1=*m.begin();
        int take2=*m.rbegin();
        if(take1!=a[i])
        {
            ans.pb(take1);
            m.erase(m.find(take1));
        }
        else if(take2!=a[i])
        {
            ans.pb(take2);
            m.erase(m.find(take2));
        }
        else
        {
            flag=false;
            break;
        }
    }
    if(flag)
    {
        OUT "Yes"<<nl;
        write(ans)
        return;
    }
    flag=true;
    ans.clear();
    m=mm;
    loop(i,0,n)
    {
        int take1=*m.begin();
        int take2=*m.rbegin();
        if(take2!=a[i])
        {
            ans.pb(take2);
            m.erase(m.find(take2));
        }
        else if(take1!=a[i])
        {
            ans.pb(take1);
            m.erase(m.find(take1));
        }
        else
        {
            flag=false;
            break;
        }
    }
    if(flag)
    {
        OUT "Yes"<<nl;
        write(ans)
        return;
    }
    flag=true;
    ans.clear();
    m=mm;
    loop(i,0,n)
    {
        int take1=*m.begin();
        int take2=*m.rbegin();
        int r=rand()%136;
        if(r>63)
        {
            if(take2!=a[i])
            {
                ans.pb(take2);
                m.erase(m.find(take2));
            }
            else if(take1!=a[i])
            {
                ans.pb(take1);
                m.erase(m.find(take1));
            }
            else
            {
                OUT "No"<<nl;
                return;
            }
        }
        else
        {
            if(take1!=a[i])
            {
                ans.pb(take1);
                m.erase(m.find(take1));
            }
            else if(take2!=a[i])
            {
                ans.pb(take2);
                m.erase(m.find(take2));
            }
            else
            {
                flag=false;
                break;
            }
        }
    }
    if(flag)
    {
        OUT "Yes"<<nl;
        write(ans)
        return;
    }
    ans.clear();
    m=mm;
    loop(i,0,n)
    {
        int take1=*m.begin();
        if(m.upper_bound(a[i])!=m.end())
        {
            take1=*(m.upper_bound(a[i]));
        }
        int take2=*m.rbegin();
        if(take2==a[i] && take1!=(*m.begin()))
        {
            take2=(*m.begin());
        }
        int r=rand()%1876414;
        if(r>987132)
        {
            if(take2!=a[i])
            {
                ans.pb(take2);
                m.erase(m.find(take2));
            }
            else if(take1!=a[i])
            {
                ans.pb(take1);
                m.erase(m.find(take1));
            }
            else
            {
                break;
            }
        }
        else
        {
            if(take1!=a[i])
            {
                ans.pb(take1);
                m.erase(m.find(take1));
            }
            else if(take2!=a[i])
            {
                ans.pb(take2);
                m.erase(m.find(take2));
            }
            else
            {
                break;
            }
        }
    }
    if(sz(ans)==n)
    {
        OUT "Yes"<<nl;
        write(ans)
        return;
    }
    ll times=10000000/n;
    while(times--)
    {
        bool yes=true;
        loop(i,0,n)
        {
            if(a[i]==b[i])
            {
                yes=false;
                break;
            }
        }
        if(yes)
        {
            OUT "Yes"<<nl;
            write(b)
            return;
        }
        random_shuffle(all(b));
    }
    OUT "No"<<nl;
}

// Main Function
int main()
{
    vok();
    int t=1;
    // IN t;
    while(t--)
    {
        solve();
    }
    return 0;
}