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: Accepted)

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using ld = long double;

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N),B(N);
  rep(i,N)  cin >> A.at(i);
  rep(i,N)  cin >> B.at(i);

  vector<int> cnt(N+1);
  rep(i,N){
    cnt.at(A.at(i))++;
    cnt.at(B.at(i))++;
  }
  rep(i,N+1){
    if(cnt.at(i) > N){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  vector<pair<int,pair<int,pair<int,int>>>> X(N+1);
  rep(i,N+1)  X.at(i) = m_p(0, m_p(0, m_p(0, i)));
  rep(i,N){
    X.at(A.at(i)).fi++;
    X.at(A.at(i)).se.fi++;
    X.at(B.at(i)).fi++;
    X.at(B.at(i)).se.se.fi++;
  }
  sort(all(X));
  reverse(all(X));

  vector<int> c,d;
  rep(i,N){
    int tmp = X.at(i).se.se.se;
    rep(j,X.at(i).se.fi)  c.e_b(tmp);
    rep(j,X.at(i).se.se.fi) d.e_b(tmp);
  }
  debug_vec(c);
  debug_vec(d);

  int r = 0;
  rep(i,N){
    if(c.at(i) != d.at(i))  continue;
    if(i == N-1)  break;
    chmax(r,i+1);

    while(c.at(i) == d.at(r)){
      r++;
      if(r >= N) break;
    }
    if(r >= N) break;
    swap(d.at(i), d.at(r));
  }
  int l=0;
  for(int i=N-1;i>=0;i--){
    if(c.at(i) == d.at(i)){
      swap(d.at(i), d.at(l));
      l++;
    }
  }

  vector<vector<int>> ans(N+1);
  rep(i,N)  ans.at(c.at(i)).e_b(d.at(i));
  rep(i,N+1){
    rep(j,sz(ans.at(i)))  cout << ans.at(i).at(j) << " ";
  }
  cout << endl;

  return 0;
}