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 <iterator>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vector<int> > 
#define vl vector<long long>
#define vc vector<char> 
#define vvc vector<vector<char> > 
#define vpi vector<pair<int,int> >
#define ll long long 
#define sz(a) int(a.size())
#define forn(i,n) for(int i = 0 ; i < int(n) ; i++)
#define all(x) x.begin(),x.end()
#define vpl vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define len(s) s.length()
#define un unsigned
# define M_PI           3.14159265358979323846  /* pi */
#define modulo 998244353ll
#define mod 1000000007ll
#define MAXN  1000001 
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
ll gcd(ll a,ll b){if(a==0 || b == 0) return max(a,b);if(a == 1 || b == 1)return 1;return gcd(max(a,b)%min(a,b),min(a,b));}


void solve()
{
    int n;
    cin>>n;
    vi a(n,0);
    vi b(n,0);
    forn(i,n)
    cin>>a[i];
    forn(i,n)
    cin>>b[i];
    reverse(b.begin(),b.end());
    int i = -1;
    int j = n;
    for(int k = 0 ; k < n ; k++)
    {
        if(a[k] == b[k])
        {
            i = k;
            break;
        }
    }    
    for(int k = n-1 ; k >= 0 ; k--)
    {
        if(a[k] == b[k])
        {
            j = k;
            break;    
        }
    }
    if(i == -1 && j == n)
    {
        cout<<"YES"<<endl;
        for(auto u : b)
        {
            cout<<u<<" ";
        }
        cout<<endl;
        return;
    }
    int c = a[i];
    int curr = i;
    for(int k = 0 ; k < i && curr <= j ; k++)
    {
        if(a[k] != c && b[k] != c)
        {
            swap(b[k],b[curr]);
            curr++;
        }
    }
    for(int k = j+1 ; k < n && curr <= j ; k++)
    {
        if(a[k] != c && b[k] != c)
        {
            swap(b[k],b[curr]);
            curr++;
        }
    }
    for(int k = 0 ; k < n ; k++)
    {
        if(a[i] == b[i])
        {
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
    for(auto u : b)
    cout<<u<<" ";
    cout<<endl;
}


int main()
{
    fast();
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}