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;
typedef long long ll;

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define  mod 1000000007

int cnt[200000];


int main()
{


    int i,j,k,l,m,n,r;

    cin >> n;

    int ar[n+10];
    int br[n+10];

    for(i=0; i<n; i++)cin >> ar[i];
    for(i=0; i<n; i++)cin >> br[i],cnt[br[i]]++;

    reverse(br,br+n);

    l = -1;

    for(i=0; i<n; i++)
    {
        if(ar[i] == br[i])
        {
            l = i;

            while(ar[i] == br[i] && i<n)i++;

            r = i-1;

            break;
        }
    }


    if(l == -1)
    {
        cout << "Yes" << endl;

        for(i = 0 ; i<n; i++)cout<<br[i]<<" ";

        cout<<endl;

        return 0;
    }





    {
        int lmx,lmn;
        int st = br[l];

        for(i=0;i<n;i++)
        {
            if(br[i] == st)
            {
                lmn= i-1;
                break;
            }
        }
        for(i=n-1;i>=0;i--)
        {
            if(br[i] == st)
            {
                lmx = i+1;
                break;
            }
        }

        for(i=0; i<=lmn; i++)
        {
            if(l>r)break;

            swap(br[i],br[l]);
            l++;
        }

        for(i = n-1; i>=lmx; i--)
        {
            if(r<l)break;
            swap(br[i],br[r]);
            r--;
        }


        for(i=0; i<n; i++)
        {
            if(ar[i] == br[i])return cout << "No" << endl,0;
        }

       // if(l<r)return cout << "No" << endl,0;

        cout << "Yes" << endl;

        for(i = 0 ; i<n; i++)cout<<br[i]<<" ";

        cout<<endl;
    }

}