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>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FOREACH(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define SIZE(v) ((int)(v).size())
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define llint long long
#define pii pair<int, int>
#define UNVISITED -1


template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}
 
template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
 
class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

const int MAX = 600600;
int A[MAX], B[MAX];
vector<int> cA[MAX], cB[MAX];
bool dA[MAX], dB[MAX];
int ans[MAX];

int main() {
    int N; scanf("%d", &N);
    REP(i, N) scanf("%d", A + i);
    REP(i, N) scanf("%d", B + i);

    REP(i, N) {
        cA[A[i]].pb(i);
        cB[B[i]].pb(i);
    }

    vector<pii> ps;
    bool possible = true;

    int sz = 0;
    for(int i = 1; i <= N; i++) {
        int len = min(cA[i].size(), cB[i].size());
        if((int)cA[i].size() + (int)cB[i].size() > N) possible = false;
        sz = max(sz, len);
        REP(j, len) {
            ps.pb(mp(cA[i][j], cB[i][j]));
            dA[cA[i][j]] = true;
            dB[cB[i][j]] = true;
        }
    }
    if(!possible) {
        printf("No\n");
        return 0;
    }



    int y = 0;
    REP(i, N) if(dA[i] == false) {
        while(dB[y]) y++;
        ans[i] = B[y];
    }

    int n = (int)ps.size();
    if(2*sz > n) {
        printf("No\n");
    }
    else {
        printf("Yes\n");
        REP(i, n) {
            ans[ps[(i + sz)%n].first] = B[ps[i].second];
        }
        REP(i, N) printf("%d%c", ans[i], " \n"[i == N - 1]);
    }



}