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 ll;
#include<string.h>
#define pi 3.1415926535897932384626433832795028841971
#define fastttt std::ios::sync_with_stdio(false);std::cin.tie(NULL);std::cout.tie(NULL);
#define str_max_len 4294967295
#define mod 1000000007
#define max_ll LLONG_MAX
#define min_ll LLONG_MIN
#define cps CLOCKS_PER_SEC
#define pb push_back
#define fi first
#define se second
#define in insert
#define m_p make_pair
#define pii pair<int,int>
#define p_q priority_queue
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define vii vector <pair<int,int>> 
#define pii pair<int,int>
ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);} 
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll maximum(ll a[],ll n)
{
	ll max1=min_ll;
	fo(i,n)
	{
		max1=max(max1,a[i]);
	}
	return max1;
}
ll minimum(ll a[],ll n)
{
	ll min1=max_ll;
	fo(i,n)
	{
		min1=min(min1,a[i]);
	}
	return min1;
}

ll power(ll x,ll y,ll m){            //power(x,y)=x^y  %m;
    if(y==0)return 1;
    ll a=power(x,y/2,m);
    if(y%2){
        return (a*((a*x)%m))%m;
    }
    else{
        return (a*a)%m;
    }
}
ll mod_inverse(ll x,ll m){
    return power(x,m-2,m);
}
ll fact(ll n,ll m){
    if(n<=1)return 1;
    return (fact(n-1,m)*n)%m;
}
ll ncr(ll n,ll r,ll m){
    if(r>n)return 0;
    ll n1=1,d1=1,d2=1;
    n1=fact(n,m);d1=fact(r,m);d2=fact(n-r,m);
    ll ans=mod_inverse((d1*d2)%m,m);
    ans=(ans*n1)%m;
    return ans;
}
ll gcd(ll a, ll b){ 
	if(a==0||b==0)return max(a,b);
    if (a < b)return gcd(b, a); 
    if (a % b == 0) return b; 
    return gcd(b,a % b);}

ll ispal(string s){
    ll len=s.size();
    ll flag=1;
    for(ll i=0;i<len;++i){
        if(s[i]!=s[len-i-1]){
            flag=0;break;
        }
    }
    return flag;
}
 
ll sroot(ll n,ll low=1,ll high=1e9+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid;
    if(a>n)return sroot(n,low,mid-1);
    else return sroot(n,mid,high);
}
ll croot(ll n,ll low=1,ll high=1e6+1){
    if(low==high)return low;
    if(low==high-1){
        if(high*high*high<=n)return high;
        else return low;
    }
    ll mid=(low+high)/2;
    ll a=mid*mid*mid;
    if(a>n)return croot(n,low,mid-1);
    else return croot(n,mid,high);
 
}

bool sortbysec(const pair<ll,ll> &a, 
              const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
}  
//A^A=0   2^10=10^3, 2^20=10^6  2^30=10^9.......
// map <ll,ll> mp can give TLE over ll mp[n+5]
//ind mod ques .... always do ans=(ans+mod)%mod;
//auto it=lower_bound(v.begin(),v.end(),n-a[i]);    auto it=v.lower_bound(n-a[i]);   2nd one is faster(and can be used only for set and multiset)
//-----------------FUCK RATING------------------
    
/***************************code begins here*****************************/


class solver{
	public:
	
		
	void solve()
	{	
		ll n;cin>>n;
		ll a[n],b[n];
		fo(i,n)cin>>a[i];
		fo(i,n)cin>>b[i];
		
		p_q <ll> p;
		
		p_q <pair<ll,pair<ll,ll>>> p1;
		
		
		fo(i,n)
		{
			ll c=1;ll j=i;
			while(i+1<n && a[i]==a[i+1])
			c++,i++;
			p1.push({c,{j*(-1),i}});
		}
		
		
		set <ll> s;
		fo(i,n)s.in(b[i]);
		map <ll,ll> mp;
		fo(i,n)mp[b[i]]++;
		
		auto it=s.begin();
		while(it!=s.end())
		{
			ll x=*it;it++;
			p.push(x);
		}
		
		ll f=0;
		vector <ll> v;
		
		map <ll,ll> dp;
		while(!p1.empty())
		{
			auto bh=p1.top();
			pii s4=bh.se;
			ll i=bh.se.fi;
			ll j=bh.se.se;
			i=abs(i);
			p1.pop();
		
		for( ;i<=j;i++)
		{
		//	cout<<i<<" ";
			ll t=p.top();
			if(t!=a[i])
			{
				mp[t]--;
				v.pb(t);
				dp[i]=t;
				if(mp[t]==0)p.pop();
			}
			else
			{
				if(p.size()==1)
				{
					f=1;break;
				}
				else
				{
					p.pop();
					ll s=p.top();
					v.pb(s);
					dp[i]=s;
					mp[s]--;
					if(mp[s]==0)p.pop();
					
					p.push(t);
				}
			}
		}
		
	}
		
		
		
		if(f==0)
		{
			cout<<"Yes\n";
			fo(i,n)cout<<dp[i]<<" ";
		}
		else cout<<"No";
    }
};
 
int main(){
	fastttt
	//	cout<<fixed<<setprecision(10);
	int test=1,c=1;
	//cin>>test;
	while(test--){
		//cout<<"Case #"<<c<<": ";c++;
		solver o;
		o.solve();
	}
}