Language: C++



/*
	ID: sixathofpain
	TASK: friday
	LANG: C++   

*/


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 1000000007;
const int N = int(3e5) + 999;
#define int long long int

typedef pair<int, int> pii;

bool comp(pii &a,pii &b){
    return (a.ff+a.ss)<(b.ff+b.ss);
}
bool comp2(pii &a,pii &b){
    return (a.ff-a.ss)<(b.ff-b.ss);
}


int32_t main(){
    IOS;
	
    // freopen("friday.in","r",stdin);
    // freopen("friday.out","w",stdout);

    int n;
    cin>>n;
    vector<int> a(n),b(n);
    for(auto &it:a)
        cin>>it;
    for(auto &it:b)
        cin>>it;
    map<int,int> cnta,cntb;

    for(int i=0;i<n;i++){
        cnta[a[i]]++;
        cntb[b[i]]++;
    }

    for(int i=0;i<n;i++){
        if(cntb.count(a[i])==0)
            continue;
        if(min(cnta[a[i]],cntb[a[i]])>n/2){
            cout<<"No"<<endl;
            return 0;
        }
        
    }

    vector<int> notsame;
    set<int> same;

    for(int i=0;i<n;i++){
        if(cnta.count(b[i])==0){
            notsame.pb(b[i]);
        }else{
            same.insert({cntb[b[i]],b[i]});
        }
    }

    for(int i=0;i<n;i++){
    	b[i]=-1;
        if(same.size()){
            if(a[i]!=(*same.rbegin()).ss){
                b[i]=(*same.rbegin()).ss;
                auto ext = *same.rbegin();
                same.erase(ext);
                if(ext.ff>=2)
                same.insert({ext.ff-1,ext.ss});
                
            }
            else if(a[i]!=(*same.begin()).ss){
                b[i]=same.front();
                auto ext = *same.begin();
                same.erase(ext);
                if(ext.ff>=2)
                same.insert({ext.ff-1,ext.ss});
            }
        }
        if(b[i]==-1 and notsame.size()){
            b[i]=notsame.back();
            notsame.pop_back();
        }
        if(b[i]==-1){
        	cout<<"No";
        	cout<<endl;
        	return 0;
        }
        
    }
    cout<<"Yes"<<endl;
    for(int i=0;i<n;i++){
        assert(a[i]!=b[i]);
        cout<<b[i]<<" ";
    }
    cout<<endl;



    return 0;
}

Compiler output:
a.cc: In function 'int32_t main()':
a.cc:21:12: error: request for member 'second' in 'std::set<_Key, _Compare, _Alloc>::rbegin() const [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; reverse_iterator = std::reverse_iterator<std::_Rb_tree_const_iterator<long long int> >]().std::reverse_iterator<std::_Rb_tree_const_iterator<long long int> >::operator*()', which is of non-class type 'const long long int'
   21 | #define ss second
      |            ^~~~~~
a.cc:117:39: note: in expansion of macro 'ss'
  117 |             if(a[i]!=(*same.rbegin()).ss){
      |                                       ^~
a.cc:21:12: error: request for member 'second' in 'std::set<_Key, _Compare, _Alloc>::rbegin() const [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; reverse_iterator = std::reverse_iterator<std::_Rb_tree_const_iterator<long long int> >]().std::reverse_iterator<std::_Rb_tree_const_iterator<long long int> >::operator*()', which is of non-class type 'const long long int'
   21 | #define ss second
      |            ^~~~~~
a.cc:118:39: note: in expansion of macro 'ss'
  118 |                 b[i]=(*same.rbegin()).ss;
      |                                       ^~
a.cc:20:12: error: request for member 'first' in 'ext', which is of non-class type 'long long int'
   20 | #define ff first
      |            ^~~~~
a.cc:121:24: note: in expansion of macro 'ff'
  121 |                 if(ext.ff>=2)
      |                        ^~
a.cc:20:12: error: request for member 'first' in 'ext', which is of non-class type 'long long int'
   20 | #define ff first
      |            ^~~~~
a.cc:122:34: note: in expansion of macro 'ff'
  122 |                 same.insert({ext.ff-1,ext.ss});
      |                                  ^~
a.cc:21:12: error: request for member 'second' in 'ext', which is of non-class type 'long long int'
   21 | #define ss second
      |            ^~~~~~
a.cc:122:43: note: in expansion of macro 'ss'
  122 |                 same.insert({ext.ff-1,ext.ss});
      |                                           ^~
a.cc:122:28: error: no matching function for call to 'std::set<long long int>::insert(<brace-enclosed initializer list>)'
  122 |                 same.insert({ext.ff-1,ext.ss});
      |                 ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/set:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:158,
                 from a.cc:14:
/usr/include/c++/14/bits/stl_set.h:568:9: note: candidate: 'template<class _InputIterator> void std::set<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  568 |         insert(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~
/usr/include/c++/14/bits/stl_set.h:568:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:511:7: note: candidate: 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<long long int>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::rebind<long long int>; typename _Alloc::value_type = long long int; value_type = long long int]'
  511 |       insert(const value_type& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_set.h:511:32: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::set<long long int>::value_type&' {aka 'const long long int&'}
  511 |       insert(const value_type& __x)
      |              ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_set.h:520:7: note: candidate: 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(value_type&&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<long long int>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::rebind<long long int>; typename _Alloc::value_type = long long int; value_type = long long int]'
  520 |       insert(value_type&& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_set.h:520:27: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::set<long long int>::value_type&&' {aka 'long long int&&'}
  520 |       insert(value_type&& __x)
      |              ~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_set.h:548:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(const_iterator, const value_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator; const_iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator; value_type = long long int]'
  548 |       insert(const_iterator __position, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_set.h:548:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:553:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(const_iterator, value_type&&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator; const_iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator; value_type = long long int]'
  553 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_set.h:553:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:580:7: note: candidate: 'void std::set<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  580 |       insert(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_set.h:580:43: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::initializer_list<long long int>'
  580 |       insert(initializer_list<value_type> __l)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_set.h:600:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::insert_return_type std::set<_Key, _Compare, _Alloc>::insert(node_type&&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; insert_return_type = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::insert_return_type; node_type = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::node_type]'
  600 |       insert(node_type&& __nh)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_set.h:600:26: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::set<long long int>::node_type&&' {aka 'std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::node_type&&'}
  600 |       insert(node_type&& __nh)
      |              ~~~~~~~~~~~~^~~~
/usr/include/c++/14/bits/stl_set.h:605:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(const_iterator, node_type&&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator; const_iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator; node_type = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::node_type]'
  605 |       insert(const_iterator __hint, node_type&& __nh)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_set.h:605:7: note:   candidate expects 2 arguments, 1 provided
a.cc:21:12: error: request for member 'second' in 'same.std::set<long long int>::begin().std::_Rb_tree_const_iterator<long long int>::operator*()', which is of non-class type 'const long long int'
   21 | #define ss second
      |            ^~~~~~
a.cc:125:43: note: in expansion of mac