Language: C++

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define MOD 1000000007
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) (v).begin() , (v).end()
#define sumof(v) accumulate(all(v), 0LL, plus<ll>())
#define maxof(v) max_element(all(v))
#define minof(v) min_element(all(v))
#define inf INT_MAX

int returnMajority(vector<int> array){
    int current = array[0];
    int count = 1;
    for(int i=1; i<array.size(); ++i){
        if(array[i]!=current) count--;
        else count++;
        if(!count) current = array[i], count = 1;
    }
    int count = 0;
    for(int i=0; i<array.size(); ++i){
        if(array[i]==current) count++;
    }
    if(count>(array.size()/2)) return current;
    else return -1;
}

int main(){
    FASTIO
    int N; cin>>N;
    vector<int> A(N), B(N);
    for(int i=0; i<N; ++i) cin>>A[i];
    for(int i=0; i<N; ++i) cin>>B[i];
    int x = returnMajority(A), y = returnMajority(B);
    if(x!=-1 && y!=-1 && x==y){
        cout<<"No"<<endl;
        return 0;
    }
    priority_queue<int> pq1, pq2;
    // Initially pq2 would be empty
    for(auto x: B) pq1.push(x);
    bool valid = true;
    for(int i=0; i<N; ++i)
    {
        if(pq2.size() && pq2.top()!=A[i]){
            B[i] = pq2.top();
            pq2.pop();
            continue;
        }
        if(pq1.size() && pq1.top()!=A[i]){
            B[i] = pq1.top();
            pq1.pop();
            continue;
        }
        while(pq1.size() && pq1.top()==A[i]){
            pq2.push(pq1.top());
            pq1.pop();
        }
        if(pq1.size() && pq1.top()!=A[i]){
            B[i] = pq1.top();
            pq1.pop();
            continue;
        }
        while(pq2.size() && pq2.top()==A[i]){
            pq1.push(pq2.top());
            pq2.pop();
        }
        if(pq2.size() && pq2.top()!=A[i]){
            B[i] = pq2.top();
            pq2.pop();
            continue;
        }
        valid = false;
        break;
    }
    if(!valid) cout<<"No"<<endl;
    else{
        cout<<"Yes"<<endl;
        for(auto x: B) cout<<x<<" "; cout<<endl;
    }
}



/*
int N; cin>>N;
    vector<int> A(N), B(N);
    for(int i=0; i<N; ++i) cin>>A[i];
    for(int i=0; i<N; ++i) cin>>B[i];
    priority_queue<int> pq1, pq2;
    // Initially pq2 would be empty
    for(auto x: B) pq1.push(x);
    bool valid = true;
    for(int i=0; i<N; ++i)
    {
        if(pq2.size() && pq2.top()!=A[i]){
            B[i] = pq2.top();
            pq2.pop();
            continue;
        }
        if(pq1.size() && pq1.top()!=A[i]){
            B[i] = pq1.top();
            pq1.pop();
            continue;
        }
        while(pq1.size() && pq1.top()==A[i]){
            pq2.push(pq1.top());
            pq1.pop();
        }
        if(pq1.size() && pq1.top()!=A[i]){
            B[i] = pq1.top();
            pq1.pop();
            continue;
        }
        while(pq2.size() && pq2.top()==A[i]){
            pq1.push(pq2.top());
            pq2.pop();
        }
        if(pq2.size() && pq2.top()!=A[i]){
            B[i] = pq2.top();
            pq2.pop();
            continue;
        }
        valid = false;
        break;
    }
    if(!valid) cout<<"No"<<endl;
    else{
        cout<<"Yes"<<endl;
        for(auto x: B) cout<<x<<" "; cout<<endl;
    }
    */

Compiler output:
a.cc: In function 'int returnMajority(std::vector<int>)':
a.cc:20:9: error: redeclaration of 'int count'
   20 |     int count = 0;
      |         ^~~~~
a.cc:14:9: note: 'int count' previously declared here
   14 |     int count = 1;
      |         ^~~~~