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>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define Unique(v) sort(all(v));v.erase(unique(all(v)),v.end());
#define sz(v) (int)v.size()
#define int long long
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
#define left sefude
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl; 
#define prl cerr<<"called: "<< __LINE__ << endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

const int N = 200100;
int a[N],b[N];
vi match[N];
int cnt[N],cnt2[N];
int ptr[N];
int32_t main(){
  fastio;
  int n;
  cin >> n;
  for(int i=1;i<=n;i++){cin >> a[i],cnt[a[i]]++;}
  
  for(int i=1;i<=n;i++)cin >> b[i],cnt2[b[i]]++;
  
  set<pii> S;
  vector<int> order;
  for(int i=1;i<=n;i++){
    if(cnt[i] + cnt2[i] > n){
      cout <<"No" << endl;
      return 0;
    }
    if(cnt2[i]){
      S.insert(pii(cnt2[i],i));
    }
    if(cnt[i]){
      order.pb(i);
    }
  }
  sort(all(order),[&](int a,int b){
    return cnt[a] > cnt[b];
  });

  bool ok = 1;
  for(int i : order){
    int tirei = 0;
    
    if(S.count(pii(cnt2[i],i))){
      tirei = 1;
      S.erase(pii(cnt2[i],i));
    }

    if(sz(S) == 0){
      ok = 0;
      break;
    }
    pii cur = *S.rbegin();
    S.erase(cur);


    for(int iter = 1;iter<=cnt[i];iter++){
       if(cnt2[cur.ss] == 0){
        if(sz(S) == 0){
          ok = 0;
          break;
        }
        cur = *S.rbegin();
        S.erase(cur);
       }
      cnt2[cur.ss]--;
      match[i].pb(cur.ss);
    }
    
    if(cnt2[cur.ss] > 0)S.insert(pii(cnt2[cur.ss],cur.ss));

    if(tirei)S.insert(pii(cnt2[i],i));
  }
  for(int i=1;i<=n;i++){
    if(ptr[a[i]] == sz(match[a[i]])){
      ok =0;
      break;
    }
    b[i] = match[a[i]][ptr[a[i]]];
    ptr[a[i]]++;
  }
  if(!ok){
    cout <<"No"<<endl;
    return 0;
  }
  cout <<"Yes"<<endl;
  for(int i=1;i<=n;i++){
    cout << b[i]<<" ";
  }
  cout << endl;
  // math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}