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: Runtime Error)

#include <bits/stdc++.h>

template <typename T, typename = void>
struct is_iterable : std::false_type {};
template <typename T>
struct is_iterable<T, std::void_t<decltype(std::begin(std::declval<T>())),
                                  decltype(std::end(std::declval<T>()))>>
    : std::true_type {};

template <typename T, typename = void>
struct is_pair : std::false_type {};
template <typename T>
struct is_pair<T, std::void_t<decltype(std::declval<T>().first),
                              decltype(std::declval<T>().second)>>
    : std::true_type {};

template <typename T>
void debug(const T& v) {
  if constexpr (is_pair<T>::value) {
    std::cerr << "{";
    debug(v.first);
    std::cerr << ", ";
    debug(v.second);
    std::cerr << "}";
  } else if constexpr (is_iterable<T>::value &&
                       !std::is_same<T, std::string>::value) {
    std::cerr << "{";
    for (auto it = std::begin(v); it != std::end(v); ++it) {
      if (it != std::begin(v)) std::cerr << ", ";
      debug(*it);
    }
    std::cerr << "}";
  } else {
    std::cerr << v;
  }
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  debug(value);
  std::cerr << ", ";
  debug(args...);
}
#if DEBUG
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);
#define ints(...) rd(int, __VA_ARGS__);
#define strings(...) rd(string, __VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  if constexpr (std::is_same<T, bool>::value) {
    std::cout << (value ? "Yes" : "No");
  } else {
    std::cout << value;
  }
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  write_to_cout(value);
  std::cout << ' ';
  write_to_cout(args...);
}
#define wt(...)                 \
  do {                          \
    write_to_cout(__VA_ARGS__); \
    cout << '\n';               \
  } while (0)

#define all(x) (x).begin(), (x).end()

#define rep_dispatch(_1, _2, _3, name, ...) name

#define rep3(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep2(i, n) rep3(i, 0, n)
#define rep1(n) rep2(_loop_variable_, n)
#define rep(...) rep_dispatch(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)

#define rrep3(i, a, b) for (int i = (int)(b)-1; i >= a; --i)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep1(n) rrep2(_loop_variable_, n)
#define rrep(...) rep_dispatch(__VA_ARGS__, rrep3, rrep2, rrep1)(__VA_ARGS__)

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
  for (T& vi : v) is >> vi;
  return is;
}

template <typename T, typename U>
std::istream& operator>>(std::istream& is, std::pair<T, U>& p) {
  is >> p.first >> p.second;
  return is;
}

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

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

template <typename T>
int sz(const T& v) {
  return v.size();
}

template <typename T>
int popcount(T i) {
  return std::bitset<std::numeric_limits<T>::digits>(i).count();
}

#include <boost/hana/functional/fix.hpp>
const auto& Fix = boost::hana::fix;

using ll = long long;

template <typename T>
using low_priority_queue =
    std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

int main() {
  ints(n);
  V<int> a(n), b(n);
  cin >> a >> b;

  map<int, int> ac, bc, tot;
  rep(i, n) {
    ac[a[i]]++;
    bc[b[i]]++;
    tot[a[i]]++;
    tot[b[i]]++;
  }

  for (auto [_, v] : tot) {
    if (v > n) {
      wt("No");
      return 0;
    }
  }

  multiset<tuple<int, int, int>, greater<>> rac, rbc;
  multiset<pair<int, int>> rem;
  for (auto [x, c] : ac) rac.insert({c, tot[x] - c, x});
  for (auto [x, c] : bc) {
    if (ac.count(x)) {
      rbc.insert({c, tot[x] - c, x});
    } else {
      rem.insert({c, x});
    }
  }

  V<pair<int, int>> ans;
  for (auto ait = rac.begin(); ait != rac.end(); ++ait) {
    auto [c, _, x] = *ait;
    rep(ci, c) {
      auto it = rbc.begin();
      while (it != rbc.end() && get<2>(*it) == x) {
        auto jt = it;
        ++it;
        rem.insert({get<0>(*jt), get<2>(*jt)});
        rbc.erase(jt);
      }
      if (it == rbc.end()) {
        V<int> ra;
        rep(c - ci) ra.push_back(x);
        for (++ait; ait != rac.end(); ++ait) {
          rep(get<0>(*ait)) ra.push_back(get<2>(*ait));
        }
        dbg(ra);

        V<int> rb;
        for (auto [c, x] : rem) rep(c) rb.push_back(x);
        reverse(all(rb));
        dbg(rb);

        assert(sz(ra) == sz(rb));
        rep(i, sz(ra)) ans.push_back({ra[i], rb[i]});
        goto out;
      }
      auto [d, t, y] = *it;
      rbc.erase(it);
      ans.push_back({x, y});
      if (d > 1) rbc.insert({d - 1, t, y});

      dbg(ans);
      dbg(rem);
      // dbg(rac);
      // dbg(rbc);
    }
  }

out:

  rep(i, n) assert(ans[i].first != ans[i].second);
  /*
  map<int, int> adbg, bdbg;
  rep(i, n) {
    adbg[ans[i].first]++;
    bdbg[ans[i].second]++;
  }
  assert(ac == adbg);
  assert(bc == bdbg);
  */

  wt("Yes");
  sort(all(ans));
  rep(i, n) {
    if (i) cout << " ";
    cout << ans[i].second;
  }
  cout << endl;
}