Language: C++

#include<bits/stdc++.h>
#include<algorithm>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define S second
#define vi vector
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define mod 1000000007
#define pb push_back
#define ll long long int
#define db double
#define all(v) v.begin(),v.end()
#define inf 10000000000


using namespace std;

/*

ll expo(ll n){
    ll t;
    if(n==0)return 1;
    else if(n==1) return 2;
    t=expo(n/2);
    if(n%2){
        return t*t*2;
    }
    else return t*t;
}

//ffrom geek for geek
ll exponentMod(ll A, ll B, ll C)  
{  
    if (A == 0)  
        return 0;  
    if (B == 0)  
        return 1;  
    ll y;  
    if (B % 2 == 0) {  
        y = exponentMod(A, B / 2, C);  
        y = (y * y) % C;  
    }  
    else {  
        y = A % C;  
        y = (y * exponentMod(A, B - 1, C) % C) % C;  
    }  
  
    return (ll)((y + C) % C);  
}

*/
/*
class dsu{
public:    
vi<ll> v;


void init(ll n){
    v.assign(n+1,-1);
}

 
ll dsufind(ll x){
    if(v[x]<0){
        return x;
    }
    v[x]=dsufind(v[x]);
    return v[x];
}
 
void dsujoin(ll x,ll y){
    x=dsufind(x);
    y=dsufind(y);
    
    if(x==y)
    return;
    if(v[x]>v[y])swap(x,y);
    v[y]+=v[x];
    v[x]=y;
}

};
*/



int main(){
    IOS;
    ll t;
    t=1;
   //cin>>t;
    while(t--){
        ll n,x;
        cin>>n;
        vi<ll> a;
        vi<ll> b;
        map<ll,ll> mp;
        set<ll> s;
        FOR(i,n){
            cin>>x;
            a.pb(x);
        }
        FOR(i,n){
            cin>>x;
            mp[x]++;
            s.insert(x);
            b.pb(x);
        }

        bool er=false;
        ll nm;
        vi<ll> ans;
        reverse(all(a));
        FOR(i,n){
            if(mp[a[i]]){
                s.erase(s.find(a[i]));
                er=true;
                nm=a[i];
            }
            if(*s.begin()==0){
                cout<<"No";
                return 0;
            }
            ans.push_back(*s.begin());
            mp[*s.begin()]--;
            if(mp[*s.begin()]==0 ){
                s.erase(s.find(*s.begin()));
            }
            if(er){
                s.insert(nm);
                er=false;
            }
        }

        reverse(all(ans));
        reverse(all(a));
        bool tr=true;
        FOR(i,n){
            if(ans[i]==a[i]){
                tr=false;
                break;
            }
           // cout<<ans[i]<<" ";
        }

        if(tr){
            cout<<"Yes\n";
            FOR(i,n){
                cout<<ans[i]<<" ";
            }
        }
        else{
            cout<<"No";
        }


        
    }    
    return 0;
} #include<bits/stdc++.h>
#include<algorithm>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define S second
#define vi vector
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define mod 1000000007
#define pb push_back
#define ll long long int
#define db double
#define all(v) v.begin(),v.end()
#define inf 10000000000


using namespace std;

/*

ll expo(ll n){
    ll t;
    if(n==0)return 1;
    else if(n==1) return 2;
    t=expo(n/2);
    if(n%2){
        return t*t*2;
    }
    else return t*t;
}

//ffrom geek for geek
ll exponentMod(ll A, ll B, ll C)  
{  
    if (A == 0)  
        return 0;  
    if (B == 0)  
        return 1;  
    ll y;  
    if (B % 2 == 0) {  
        y = exponentMod(A, B / 2, C);  
        y = (y * y) % C;  
    }  
    else {  
        y = A % C;  
        y = (y * exponentMod(A, B - 1, C) % C) % C;  
    }  
  
    return (ll)((y + C) % C);  
}

*/
/*
class dsu{
public:    
vi<ll> v;


void init(ll n){
    v.assign(n+1,-1);
}

 
ll dsufind(ll x){
    if(v[x]<0){
        return x;
    }
    v[x]=dsufind(v[x]);
    return v[x];
}
 
void dsujoin(ll x,ll y){
    x=dsufind(x);
    y=dsufind(y);
    
    if(x==y)
    return;
    if(v[x]>v[y])swap(x,y);
    v[y]+=v[x];
    v[x]=y;
}

};
*/



int main(){
    IOS;
    ll t;
    t=1;
   //cin>>t;
    while(t--){
        ll n,x;
        cin>>n;
        vi<ll> a;
        vi<ll> b;
        map<ll,ll> mp;
        set<ll> s;
        FOR(i,n){
            cin>>x;
            a.pb(x);
        }
        FOR(i,n){
            cin>>x;
            mp[x]++;
            s.insert(x);
            b.pb(x);
        }

        bool er=false;
        ll nm;
        vi<ll> ans;
        reverse(all(a));
        FOR(i,n){
            if(mp[a[i]]){
                s.erase(s.find(a[i]));
                er=true;
                nm=a[i];
            }
            if(*s.begin()==0){
                cout<<"No";
                return 0;
            }
            ans.push_back(*s.begin());
            mp[*s.begin()]--;
            if(mp[*s.begin()]==0 ){
                s.erase(s.find(*s.begin()));
            }
            if(er){
                s.insert(nm);
                er=false;
            }
        }

        reverse(all(ans));
        reverse(all(a));
        bool tr=true;
        FOR(i,n){
            if(ans[i]==a[i]){
                tr=false;
                break;
            }
           // cout<<ans[i]<<" ";
        }

        if(tr){
            cout<<"Yes\n";
            FOR(i,n){
                cout<<ans[i]<<" ";
            }
        }
        else{
            cout<<"No";
        }


        
    }    
    return 0;
} 

Compiler output:
a.cc:163:3: error: stray '#' in program
  163 | } #include<bits/stdc++.h>
      |   ^
a.cc:163:4: error: 'include' does not name a type
  163 | } #include<bits/stdc++.h>
      |    ^~~~~~~
a.cc:252:5: error: redefinition of 'int main()'
  252 | int main(){
      |     ^~~~
a.cc:90:5: note: 'int main()' previously defined here
   90 | int main(){
      |     ^~~~