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 ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> A, std::vector<long long> B) {
  priority_queue<pair<ll, ll>> a;
  ll cur = A[0];
  ll count = 1;
  FOR(i, 1, N) {
    if (cur != A[i]) {
      a.emplace(count, cur);
      cur = A[i];
      count = 1;
    } else {
      count++;
    }
  }
  a.emplace(count, cur);
  priority_queue<pair<ll, ll>> b;
  cur = B[0];
  count = 1;
  FOR(i, 1, N) {
    if (cur != B[i]) {
      b.emplace(count, cur);
      cur = B[i];
      count = 1;
    } else {
      count++;
    }
  }
  b.emplace(count, cur);
  vector<pair<ll, ll>> ans;
  REP(i, N) {
    auto x = a.top();
    a.pop();
    auto y = b.top();
    b.pop();
    if (x.first == 1 && y.first == 1) {
      a.emplace(x);
      b.emplace(y);
      break;
    }
    if (x.second == y.second) {
      if (b.empty()) {
        cout << NO << endl;
        return;
      }
      auto z = b.top();
      b.pop();
      swap(y, z);
      b.push(z);
    }
    ans.emplace_back(x.second, y.second);
    if (x.first > 1) {
      a.emplace(x.first - 1, x.second);
    }
    if (y.first > 1) {
      b.emplace(y.first - 1, y.second);
    }
  }
  vector<ll> c;
  vector<ll> d;
  while (!a.empty()) {
    auto x = a.top();
    a.pop();
    c.push_back(x.second);
    auto y = b.top();
    b.pop();
    d.push_back(y.second);
  }
  sort(ALL(c));
  sort(ALL(d));
  rotate(c.begin(), c.begin() + 1, c.end());
  REP(i, c.size()) {
    if (c[i] == d[i]) {
      cout << NO << endl;
      return;
    }
    ans.emplace_back(c[i], d[i]);
  }
  sort(ALL(ans));
  cout << YES << endl;
  REP(i, N) {
    cout << ans[i].second << " ";
  }
  cout << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  std::vector<long long> B(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &B[i]);
  }
  solve(N, std::move(A), std::move(B));
  return 0;
}