Problem:
Score : 600 points

Problem Statement

Given are two sequences A and B, both of length N.
A and B are each sorted in the ascending order.
Check if it is possible to reorder the terms of B so that for each i (1 \leq i \leq N) A_i \neq B_i holds, and if it is possible, output any of the reorderings that achieve it.

Constraints

1\leq N \leq 2 \times 10^5

1\leq A_i,B_i \leq N

A and B are each sorted in the ascending order.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N
B_1 B_2 \cdots B_N

Output

If there exist no reorderings that satisfy the condition, print No.

If there exists a reordering that satisfies the condition, print Yes on the first line.
After that, print a reordering of B on the second line, separating terms with a whitespace.

If there are multiple reorderings that satisfy the condition, you can print any of them.

Sample Input 1

6
1 1 1 2 2 3
1 1 1 2 2 3

Sample Output 1

Yes
2 2 3 1 1 1

Sample Input 2

3
1 1 2
1 1 3

Sample Output 2

No

Sample Input 3

4
1 1 2 3
1 2 3 3

Sample Output 3

Yes
3 3 1 2

Solution in C++ (Clang 10.0.0) (judge verdict: Wrong Answer)

#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>
#include <unordered_set>

using namespace std;
using ll = long long;
const int BIG = 1000000007;

using Co = struct TRP{
    ll num,count,end;
};


int main() {
    ll n;
    cin >> n;
    vector<ll> veca(n,0);
    vector<Co> ac(n + 1);
    vector<ll> vecb(n,0);
    vector<Co> bc(n + 1);
    for(ll i = 0;i < n;++i){
        ac[i].num = i;
        bc[i].num = i;
    }

    for(ll i = 0;i < n;++i){
        cin >> veca[i];
        --veca[i];
        ac[veca[i]].end = i;
        ++ac[veca[i]].count;

    }
    for(ll i = 0;i < n;++i){
        cin >> vecb[i];
        --vecb[i];
        bc[vecb[i]].end = i;
        ++bc[vecb[i]].count;
    }

    sort(ac.begin(),ac.end(),[] (const auto& lhs, const auto& rhs) {
        return lhs.count > rhs.count;
    });

    sort(bc.begin(),bc.end(),[] (const auto& lhs, const auto& rhs) {
        return lhs.count > rhs.count;
    });

    ll apos = 0;
    ll bpos = 0;

    deque<ll> askipped,bskipped;

    if(ac[apos].num == bc[bpos].num){
        bpos = 1;
        if(bc[bpos].count == 0){
            cout << "No" << endl;
            return 0;
        }
        else{
            bskipped.push_back(0);
        }
    }


    vector<ll> ans(n);
    bool failed = false;

    for(ll i = 0;i < n;++i){
        if(ac[apos].count == 0){
            bool updated = false;
            if(askipped.size() > 0){
                for(auto itr = askipped.begin();itr != askipped.end();++itr){
                    if(bc[bpos].count == 0 || ac[*itr].num != bc[bpos].num){
                        apos = *itr;
                        updated = true;
                        askipped.erase(itr);
                        break;
                    }
                }
            }

            if(!updated){
                ++apos;
                for(;apos < n;++apos){
                    if(ac[apos].count > 0 && (bc[bpos].count == 0 || ac[apos].num != bc[bpos].num)){
                        updated = true;
                        break;
                    }
                    else if(ac[apos].count > 0) askipped.push_back(apos);
                }
                if(!updated){
                    failed = true;
                    break;
                }
            }
        }

        if(bc[bpos].count == 0){
            bool updated = false;
            if(bskipped.size() > 0){
                for(auto itr = bskipped.begin();itr != bskipped.end();++itr){
                    if(ac[apos].num != bc[*itr].num){
                        bpos = *itr;
                        updated = true;
                        bskipped.erase(itr);
                        break;
                    }
                }
            }

            if(!updated){
                ++bpos;
                for(;bpos < n;++bpos){
                    if(bc[bpos].count > 0 && (ac[apos].num != bc[bpos].num)){
                        updated = true;
                        break;
                    }
                    else if(bc[bpos].count > 0)bskipped.push_back(apos);
                }
                if(!updated){
                    failed = true;
                    break;
                }
            }
        }

       // cout << "apos = " << apos << ",count = " << ac[apos].count << ",num = " << ac[apos].num << ",bpos = " << bpos << ",count = " << bc[bpos].count << ",num = " << bc[bpos].num << endl;


        --ac[apos].count;
        --bc[bpos].count;

        ans[ac[apos].end - ac[apos].count] = bc[bpos].num;
    }

    if(failed){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
        string ansstr;
        for(ll i = 0;i < n;++i){
            ansstr += to_string(ans[i] + 1);
            if(i + 1 != n)ansstr += ' ';
        }
        cout << ansstr << endl;
    }
}