Language: C++

#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;

#if 0
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using Int = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
#endif

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

struct io_init
{
  io_init()
  {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(30) << setiosflags(ios::fixed);
  };
} io_init;
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

void f(vector<int> &a, vector<int> &b)
{
  Yes(1);
  int n = a.size();
  rep(i, n)
  {
    rotate(b.begin(), b.begin() + 1, b);
    bool ok = true;
    rep(j, n)
    {
      if (a[j] == b[j])
        ok = false;
      break;
    }
    if (ok)
    {
      rep(i, n) cout << b[i] << (i == n - 1 ? "\n" : " ");
      return;
    }
  }
}

void solve()
{
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n)
  {
    cin >> a[i];
    a[i]--;
  }
  rep(i, n)
  {
    cin >> b[i];
    b[i]--;
  }
  int cnt1[1000010] = {}, cnt2[1000010] = {};
  rep(i, n) cnt1[a[i]]++, cnt2[b[i]]++;
  rep(i, n)
  {
    if (cnt1[i] + cnt2[i] > n)
    {
      Yes(0);
      return;
    }
  }
  priority_queue<tuple<int, int, int>> que;
  set<int> used_b;
  rep(i, n)
  {
    if (used_b.count(b[i]))
      continue;
    que.push(MT(cnt1[a[i]] + cnt2[b[i]], cnt2[b[i]], b[i]));
    used_b.insert(b[i]);
  }
  vector<int> ans(n);
  rep(i, n)
  {
    auto [t, rem, num] = que.top();
    que.pop();
    if (num == a[i])
    {
      if (que.empty())
      {
        f(a, b);
        return;
      }
      auto [t2, rem2, num2] = que.top();
      que.pop();
      assert(a[i] != num2);
      ans[i] = num2 + 1;
      if (rem2 - 1 > 0)
      {
        if (i + 1 < n and a[i + 1] > num2)
          que.push(MT(-INF, rem2 - 1, num2));
        else
          que.push(MT(t2, rem2 - 1, num2));
      }
      if (i + 1 < n and a[i + 1] > num)
        que.push(MT(-INF, rem, num));
      else
        que.push(MT(t, rem, num));
    }
    else
    {
      ans[i] = num + 1;
      if (rem - 1 > 0)
      {
        if (i + 1 < n and a[i + 1] > num)
          que.push(MT(-INF, rem - 1, num));
        else
          que.push(MT(t, rem - 1, num));
      }
    }
    //dbg(ans[i]);
  }
  Yes(1);
  rep(i, n) cout << ans[i] << (i == n - 1 ? "\n" : " ");
}

int main()
{
  solve();
}


Compiler output:
a.cc: In function 'void f(std::vector<int>&, std::vector<int>&)':
a.cc:108:11: error: no matching function for call to 'rotate(std::vector<int>::iterator, __gnu_cxx::__normal_iterator<int*, std::vector<int> >, std::vector<int>&)'
  108 |     rotate(b.begin(), b.begin() + 1, b);
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:1348:5: note: candidate: 'template<class _FIter> _FIter std::_V2::rotate(_FIter, _FIter, _FIter)'
 1348 |     rotate(_ForwardIterator __first, _ForwardIterator __middle,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algo.h:1348:5: note:   template argument deduction/substitution failed:
a.cc:108:11: note:   deduced conflicting types for parameter '_FIter' ('__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'std::vector<int>')
  108 |     rotate(b.begin(), b.begin() + 1, b);
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:260:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::rotate(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _ForwardIterator)'
  260 | rotate(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last);
      | ^~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:260:1: note:   candidate expects 4 arguments, 3 provided