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++ (GCC 9.2.1) (judge verdict: Time Limit Exceeded)

#include <bits/stdc++.h>
using namespace std;
#ifdef __DEBUG__
    void debug_out() { cerr << endl; } 
    template <typename Head, typename... Tail>
    void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);}
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 
#endif

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int M;
vector<int> X,Y;
inline void input(){
    fast_io();
    cin >> M;
    X = fetch_vec<int>(M);
    Y = fetch_vec<int>(M);
}

inline int solve(int N, vector<int> A, vector<int> B){
    vector<int> cntA(N+1,0), cntB(N+1,0);
    for(int x:A) cntA[x]++;
    for(int x:B) cntB[x]++;
    for (int i = 1; i <= N; i++)
    {
        if((cntA[i]+cntB[i])>N){
            cout << "No" << "\n";
            return 0; 
        }
    }

    cout << "Yes" << "\n";
    vector<int> Ans;

    // auto cmp_b = [&](int x, int y){
    //     if(cntA[x]+cntB[x] == cntA[y]+cntB[y]) return cntA[x]+cntB[x] > cntA[y]+cntB[y];
    //     return cntA[x] > cntA[y];
    // };
    // sort(B.begin(),B.end(),cmp_b);
    std::mt19937 get_rand_mt;
    std::shuffle( B.begin(), B.end(), get_rand_mt );
    // reverse(B.begin(),B.end());
    debug(B);
    vector<bool> usedB(N,false);
    int j = 0;
    for (int i = 0; i < N; i++)
    {
        while(A[i]==B[j] || usedB[j]){
            j++;
            j%=N;
        }
        Ans.push_back(B[j]);
        usedB[j] = true;
    }
    cout << Ans << endl;
    return 0;
}   

#include <experimental/random>

int test(){
    int n = 10;
    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0; i < n; i++)
    {
        a[i] = std::experimental::randint(1, n);
        b[i] = std::experimental::randint(1, n);
    }
    sort(a.begin(),a.end());    
    sort(b.begin(),b.end());

    debug(n);
    debug(a);
    debug(b);
    solve(n, a, b);
    return 0;
}

int main()
{
    input();
    // int t = 10;
    // while(t--) test();
    solve(M,X,Y);
    return 0;
}