#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
typedef tree<string,null_type,less<string>,rb_tree_tag,tree_order_statistics_node_update> indexed_set2;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{   
    i_os;
    ll n;
    cin>>n;
    
    ll a[n],b[n];
    REP(i,0,n) cin>>a[i];
    REP(i,0,n) cin>>b[i];

    priority_queue<pair<ll,ll>> pq,pq1;
    ll count[n+1] = {0};
    REP(i,0,n){
        count[b[i]]++;
    }
    REP(i,1,n+1){
        if(count[i] > 0){
            pq.push({count[i],i});
        }
    }
    vector<ll> v;
    ll count1[n+1] = {0};
    REP(i,0,n) count1[a[i]]++;
    REP(i,1,n+1){
        if(count1[i] > 0){
            pq1.push({count1[i],i});
        }
    }
    map<ll,set<pair<ll,ll>>> mp;
    ll val = 0;
    vector<ll> v1;

    while(pq1.size())
    {
        ll i = pq1.top().second;
        pq1.pop();

        pair<ll,ll> temp;
        bool f = 0;
        while(count1[i] > 0 && pq.size() > 0)
        {
            pair<ll,ll> p = pq.top();
            pq.pop();
            if(p.second == i){
                f = 1;
                temp = p;
            }
            else {
                if(count1[i] >= p.first){
                    count1[i] -= p.first;
                    REP(j,0,p.first){
                        mp[i].insert({p.second,val});
                        val++;
                    }
                }
                else {
                    pq.push({p.first - count1[i],p.second});
                    REP(j,0,count1[i]){
                        mp[i].insert({p.second,val});
                        val++;
                    }
                    count1[i] = 0;
                }
            }
        }
        if(f){
            pq.push(temp);
        }
        vector<ll> v2;
        vector<pair<ll,ll>> vtr;
        ll ct = 0;
        while(count1[i] > 0 && v1.size() > 0)
        {
            ll prev = v1.back();
            for(auto it:mp[prev]){
                if(it.first != i) vtr.push_back(it), ct++;
                if(ct >= count1[i]) break;
            }
            if(ct == count1[i])
            {
                for(auto it:vtr){
                    mp[i].insert({it.first,val});
                    val++;
                    mp[prev].erase(it);
                    mp[prev].insert({i,val});
                    val++;
                }
                count1[i] = 0;
                while(v2.size()){
                    v1.push_back(v2.back());
                    v2.pop_back();
                }
            }
            else {
                v2.push_back(v1.back());
                v1.pop_back();
            }
        }
        if(count1[i] > 0){
            cout<<"No"<<endl;
            return 0;
        }
        v1.push_back(i);
    }
    for(auto it:mp){
        for(auto itt:it.second){
            v.push_back(itt.first);
        }
    }
    cout<<"Yes"<<endl;
    for(auto it:v) cout<<it<<" ";
    cout<<endl;
    return 0;
}   
    

Measured memory_bytes: 52148