Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10, MOD = 1e9 + 7;

ll dp[SIZE][2][2];

int main()
{
    fastInp;

    
    ll n;
    cin >> n;
    vector<ll> vec1(n), vec2(n);

    map<ll, ll> mp1, mp2;
    for (auto &cur : vec1) cin >> cur;
    for (auto &cur : vec2) cin >> cur;

    for (auto cur : vec1) {
        mp1[cur]++;
    }

    for (auto cur : vec2) {
        mp2[cur]++;
    }

    ll sh = 0;

    for (auto cur : mp1) {
        ll am = cur.second, vl = cur.first;

        if (am > n - mp2[vl]) {
            cout << "No";
            return 0;
        }
    }

    for (auto cur : mp2) {
        ll am = cur.second, vl = cur.first;

        if (am > n - mp1[vl]) {
            cout << "No";
            return 0;
        }
    }

    cout << "Yes\n";
    bool fl = true;
    for (int i = 0; i < vec2.size(); i++) {
        if (vec2[(i + n / 2) % n] == vec1[i]) fl = false;
    }

    if (fl) {
        for (int i = 0; i < vec2.size(); i++) {
            cout << vec2[(i + n / 2) % n] << " ";
        }
        return 0;
    } else {
        while (true) {
        bool fl = true;
        shuffle(vec2.begin(), vec2.end(), rand());
            for (int i = 0; i < vec2.size(); i++) {
                if (vec2[(i + n / 2) % n] == vec1[i]) fl = false;
            }

            if (fl) {
                for (int i = 0; i < vec2.size(); i++) {
                    cout << vec2[(i + n / 2) % n] << " ";
                }
                return 0;
            }
        }
    }

    return 0;
}

Compiler output:
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h: In instantiation of 'void std::shuffle(_RAIter, _RAIter, _UGenerator&&) [with _RAIter = __gnu_cxx::__normal_iterator<long long int*, vector<long long int> >; _UGenerator = int]':
a.cc:79:16:   required from here
   79 |         shuffle(vec2.begin(), vec2.end(), rand());
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:3718:9: error: 'std::remove_reference<int>::type' {aka 'int'} is not a class, struct, or union type
 3718 |         __uc_type;
      |         ^~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:3720:41: error: request for member 'max' in '__g', which is of non-class type 'int'
 3720 |       const __uc_type __urngrange = __g.max() - __g.min();
      |                                     ~~~~^~~
/usr/include/c++/14/bits/stl_algo.h:3720:53: error: request for member 'min' in '__g', which is of non-class type 'int'
 3720 |       const __uc_type __urngrange = __g.max() - __g.min();
      |                                                 ~~~~^~~
/usr/include/c++/14/bits/stl_algo.h:3746:44: error: 'std::remove_reference<int>::type' {aka 'int'} is not a class, struct, or union type
 3746 |           const pair<__uc_type, __uc_type> __pospos =
      |                                            ^~~~~~~~