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)

#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

const int INF = 1e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

int i, n, a[N], b[N], ans[N];

void solve()
{
    cin >> n;
    for (i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    multiset<int> s;
    for (i = 1; i <= n; i++)
    {
        cin >> b[i];
        s.insert(b[i]);
    }
    int ok1 = 1, ok2 = 1;
    for (i = n; i >= 1; i--)
    {
        int val = a[i];
        int small = *s.begin(), big = *s.rbegin();
        if (small == val && big == val)
        {
            ok1 = 0;
            break;
        }
        else if (small == val)
        {
            ans[i] = big;
            s.erase(s.find(big));
        }
        else
        {
            ans[i] = small;
            s.erase(s.find(small));
        }
    }
    if (ok1)
    {
        cout << "Yes" << endl;
        for (i = 1; i <= n; i++)
        {
            cout << ans[i] << " ";
        }
        return;
    }
    s.clear();
    for (i = 1; i <= n; i++)
    {
        s.insert(b[i]);
    }
    for (i = n; i >= 1; i--)
    {
        int val = a[i];
        int small = *s.begin(), big = *s.rbegin();
        if (small == val && big == val)
        {
            ok2 = 0;
            break;
        }
        else if (big == val)
        {
            ans[i] = small;
            s.erase(s.find(small));
        }
        else
        {
            ans[i] = big;
            s.erase(s.find(big));
        }
    }
    if (ok1)
    {
        cout << "Yes" << endl;
        for (i = 1; i <= n; i++)
        {
            cout << ans[i] << " ";
        }
        return;
    }
    cout << "No";
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fastio;
    int t;
    //cin >> t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}