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 int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cerr<<#x<<" = "<<x<<endl

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

void solve()
{
    li n;

    cin>>n;

    li a[n],b[n];

    map<li,li> m;

    f(i,0,n-1)
    {
    	cin>>a[i];
    	m[a[i]]=1;
    }

    vi wildcard;
    vi bb;

    f(i,0,n-1)
    {
    	cin>>b[i];

    	if(!m.count(b[i]))
    	{
    		wildcard.PB(b[i]);
    	}
    	else
    	{
    		bb.PB(b[i]);
    	}
    }

    li tp=wildcard.size();

    li sz=bb.size();

    li l=0,r=sz-1,pos=0;

    vi ans;

    f(i,0,n-1)
    {
    	if(l>r)
    	{
    		if(pos<tp)
	    	{
	    		ans.PB(wildcard[pos++]);
	    	}
	    	else
	    	{
	    		cout<<"No";
	    		return;
	    	}
	    	continue;
    	}

    	if(a[i]!=bb[r])
    	{
    		ans.PB(bb[r--]);
    		continue;
    	}
    	else if(a[i]!=bb[l])
    	{
    		ans.PB(bb[l++]);
    		continue;
    	}

    	if(pos<tp)
    	{
    		ans.PB(wildcard[pos++]);
    	}
    	else
    	{
    		cout<<"No";
    		return;
    	}
    }

    cout<<"Yes\n";

    for(li i:ans)
    	cout<<i<<' ';
}

int main()
{    
    //remove this in kickstart

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li t=1;

    // cin>>t;

    f(i,1,t)
    {
        // cout<<"Case #"<<i<<": ";

        solve();
    }

    return 0;
}