Language: C++

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

/*
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define md(l, r) l + (r - l) / 2
#define ll long long
#define btw(a, l, r) a.begin() + l, a.begin() + r + 1
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int(x.size()))
#define sqr(x) (x) * (x)
#define endl '\n'

#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define clr(x, y) memset((x), (y), sizeof (x))
#define ld long double

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<vector<pair<int, int> > > vvpii;
typedef vector<vector<pair<ll, ll> > > vvpll;
typedef pair<int, pair<int, int> > piii;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef vector<vector<ll> > vvll;
typedef vector<pair<ll, pair<ll, ll> > > vplll;
typedef pair<ll, ll> pll;

const ld eps = -1e9;
const long long N = 200001, P = 1e9 + 7, P1 = 1e9 + 13, iINF = 1e9, INF = 2e18, K = 73, K1 = 79;

ll dstF(ll x, ll y, ll xx, ll yy) {
    return (sqr(x - xx) + sqr(y - yy));
}

ld dstSqrtF(ll x, ll y, ll xx, ll yy) {
    return (sqrt(sqr(x - xx) + sqr(y - yy)));
}

ll _bp(ll val, ll st, ll p) {
    if (st == 0) {
        return 1;
    }
    ll temp = _bp(val, st / 2, p);
    temp = sqr(temp);
    temp %= p;
    if (st % 2 == 1) {
        temp *= val;
        temp %= p;
    }
    return temp;
}

ll _bp(ll val, ll st) {
    if (st == 0) {
        return 1;
    }
    ll temp = _bp(val, st / 2);
    temp = sqr(temp);
    if (st % 2 == 1) {
        temp *= val;
    }
    return temp;
}

ll nok(ll a, ll b) {
    return (a / __gcd(a, b) * b);
}


ll fact[1001000];

void buildFacts(ll n, ll p) {
    fact[0] = 1;
    for (ll i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i) % p;
    }
}

ll C(ll n, ll k, ll p = -1) {
    if (p == -1) {
        ll x = fact[n];
        ll y = (fact[k] * fact[n - k]);
        return (x / y);
    } else {
        ll x = fact[n];
        ll y = (fact[k] * fact[n - k]) % p;
        x = (x * _bp(y, p - 2, p)) % p;
        return x;
    }
}

int n, cntA[200200], cntB[200200], a[200200], b[200200];
stack<int> ans[200200];
set<pair<int, int> > sA, sB;
set<pair<int, int> >::iterator it;
pair<int, int> cur, cc;
void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        cntA[a[i]]++;
    }
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
        cntB[b[i]]++;
    }
    if (n == 1) {
        if (a[1] == b[1]) {
            cout << "No";
        } else {
            cout << b[1];
        }
        return;
    }
    for (int i = 1; i <= n; i++) {
        if (cntA[i] != 0) {
            sA.insert({cntA[i], i});
        }
        if (cntB[i] != 0) {
            sB.insert({cntB[i], i});
        }
    }
    for (int i = 1; i <= n - 2; i++) {
        cur = (*(--sA.end()));
        sA.erase(--sA.end());
        if (cur.F != 1) {
            sA.insert({cur.F - 1, cur.S});
        }
        it = --sB.end();
        if (it->second != cur.S) {
            cc = *it;
            sB.erase(it);
            cc.F--;
            if (cc.F != 0) {
                sB.insert(cc);
            }
            ans[cur.S].push(cc.S);
           // cout << "add " << cur.S << " " << cc.S << endl;
        } else {
            if (it == sB.begin()) {
                cout << "No";
                return;
            }
            --it;
            cc = *it;
            sB.erase(it);
            cc.F--;
            if (cc.F != 0) {
                sB.insert(cc);
            }
            ans[cur.S].push(cc.S);

            //cout << "add " << cur.S << " " << cc.S << endl;
        }
    }
    vi v;
    while (!sA.empty()) {
        v.pb(sA.begin()->S);
        cur = *sA.begin();
        sA.erase(sA.begin());
        cur.F--;
        if (cur.F != 0) {
            sA.insert(cur);
        }
    }
    while (!sB.empty()) {
        v.pb(sB.begin()->S);
        cur = *sB.begin();
        sB.erase(sB.begin());
        cur.F--;
        if (cur.F != 0) {
            sB.insert(cur);
        }
    }
    if (v[0] != v[2] && v[1] != v[3]) {
        ans[v[0]].push(v[2]);
        ans[v[1]].push(v[3]);
    } else {
        if (v[0] != v[3] && v[1] != v[2]) {
            ans[v[0]].push(v[3]);
            ans[v[1]].push(v[2]);
        } else {
            cout << "No";
            return;
        }
    }
    cout << "Yes\n"
    for (int i = 1; i <= n; i++) {
        cout << ans[a[i]].top() << " ";
        ans[a[i]].pop();
    }
}

signed main() {
    //freopen("checklist.in", "r", stdin);
    //freopen("checklist.out", "w", stdout);
    //fast_io;
    int q;
    q = 1;
    //cin >> q;
    while (q != 0) {
        solve();
        --q;
    }
}

/*
*/


Compiler output:
a.cc: In function 'void solve()':
a.cc:204:20: error: expected ';' before 'for'
  204 |     cout << "Yes\n"
      |                    ^
      |                    ;
  205 |     for (int i = 1; i <= n; i++) {
      |     ~~~             
a.cc:205:21: error: 'i' was not declared in this scope
  205 |     for (int i = 1; i <= n; i++) {
      |                     ^