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: Wrong Answer)

#include <bits/stdc++.h>

#define int long long

using namespace std;

const int MAXN = 2e5 + 100;

#ifdef LOCAL 
#include "/media/brayand/BrayanD/debugger.h"
#else
#define db(...) false
#define dbl(...) false
#define dbg(...) false
#endif

int mp1[MAXN];
int mp2[MAXN];

set<pair<int,int>> st;

vector<int> arr[MAXN];

int mp3[MAXN];

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N;
    cin >> N;

    vector<int> v1, v2;

    for(int i = 0 ; i < N ; i++)
    {
    	int n;
    	cin >> n;
    	v1.push_back(n);

    	arr[n].push_back(i);

    	mp1[n]++;
    }

    for(int i = 0 ; i < N ; i++)
    {
    	int n;
    	cin >> n;
    	v2.push_back(n);

    	mp2[n]++;
    }

    bool flag = false;

    for(int i = 1 ; i <= N ; i++)
    {
    	st.insert({mp2[i], i});
    	if(mp1[i] + mp2[i] > N)flag = true;
    }

    if(flag)
    {
    	cout << "No" << '\n';
    	return 0;
    }

    vector<pair<int,int>> vect;

    vector<int> temp;

    for(int i = 0 ; i < N ; i++)
    {
    	if(arr[v2[i]].size())
    	{
    		vect.push_back({v2[i], arr[v2[i]].back()});
    		arr[v2[i]].pop_back();
    	}
    	else
    	{
    		temp.push_back(v2[i]);
    	}
    }

    int may = -1;
    int val = -1;

    for(auto x : vect)
    {
    	mp3[x.first]++;

    	if(mp3[x.first] > may)
    	{
    		may = mp3[x.first];
    		val = x.first;
    	}
    }

    if(val == -1)
    {
    	cout << "Yes" << '\n';
    	for(auto x : v2)
    	{
    		cout << x << " ";
    	}
    	return 0;
    }

    int del = 0;

    while(may > vect.size()/2)
    {
    	may--;
    	del++;
    }

    int cont = 0;

    vector<pair<int,int>> good;

    vector<pair<int,int>> otro;

    for(auto x : vect)
    {
    	if(del && x.first == val)
    	{
    		otro.push_back(x);
    		del--;
    		cont++;
    		continue;
    	}
    	good.push_back(x);
    }

    vector<int> res(N);

    for(int i = 0 ; i < good.size() ; i++)
    {
    	res[good[(i+may)%good.size()].second] = good[i].first;
    }

    vector<pair<int,int>> nw;

    vector<pair<int,int>> tipo;

    for(int i = 1 ; i <= N ; i++)
    {
    	while(arr[i].size())
    	{
    		if(i == may)tipo.push_back({temp.back(), arr[i].back()});
    		else nw.push_back({temp.back(), arr[i].back()});

    		temp.pop_back();
    		arr[i].pop_back();
    	}
    }

    for(auto x : tipo)nw.push_back(x);
    for(auto x : otro)nw.push_back(x);

    	db(nw);

    db(cont);
    db(good);

    for(int i = 0 ; i < nw.size() ; i++)
    {
    	res[nw[(i+cont)%nw.size()].second] = nw[i].first;
    }

    cout << "Yes" << '\n';

    for(auto x : res)
    {
    	cout << x << " ";
    }
    cout << '\n';

    return 0;
}