Language: C++

//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

ll kai(ll x,ll y){
  if(y == 0)return 1;
  if(y == 1)return x;
  if(y&1){
    return (x*kai(x,y-1))%MOD;
  }else{
    ll t = kai(x,y/2);
    return (t*t)%MOD;
  }
}

ll comb(ll a,ll b,vector<ll> &p){
  if(a == 0)return 1;
  if(b == 0)return 1;
  ll ans = p[a+b];
  ans = (ans*kai(p[a],MOD-2))%MOD;
  ans = (ans*kai(p[b],MOD-2))%MOD;
  return ans;
}

int main(){
  ll N;
  cin >> N;
  vector<ll> A(N),B(N);
  rep(i,N)cin >> A[i];
  rep(i,N)cin >> B[i];
  vector<ll> cnt_a(200010,0),cnt_b(200010,0),cnt(200010,0);
  rep(i,N){
    cnt_a[A[i]]++;
    cnt_b[B[i]]++;
    cnt[A[i]]++;
    cnt[B[i]]++;
  }
  bool hantei = true;
  rep(i,200010){
    if(cnt_a[i] + cnt_b[i] > N){
      hantei = false;
      break;
    }
  }

  if(hantei){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
    return 0;
  }

  multiset<pair<ll,ll>> ans,unused;

  multiset<ll> used;
  rep(i,N)used.insert(B[i]);
  multiset<ll> aused;
  rep(i,N)aused.insert(A[i]);

  ll all = N*2;
  rep(i,200010){
    if(cnt[i] > 0)unused.insert(make_pair(cnt[i],i));
  }

  cout << "OK" << endl;

  while(used.size() != 0){
    cout << used.size() << endl;
    if(((*rbegin(unused)).first)*2 == all){
      if(unused.size() == 2){
        //cout << "patan1-1" << endl;
        ll a = (*begin(unused)).second , b = (*rbegin(unused)).second;

        rep(i,cnt_a[a]){
          ans.insert(make_pair(a,b));
          used.erase(used.find(b));
        }
        rep(i,cnt_a[b]){
          ans.insert(make_pair(b,a));
          used.erase(used.find(a));
        }
        break;
      }else{
        //cout << "patan1-2" << endl;
        ll  a,b,fa,fb;
        a = (*rbegin(unused)).second;

        if(aused.count(a)){
          fa = (*rbegin(unused)).first;
          b = *begin(used);
          if(a == b)b = *rbegin(used);
          fb = cnt[b];
        }else{
          b = a;
          fb = cnt[b];
          a = *begin(aused);
          fa = cnt[a];
        }

        //cout << a    << " " << b << endl;
          ans.insert(make_pair(a,b));
          cnt[a]--;
          cnt[b]--;
          used.erase(used.find(b));
          aused.erase(aused.find(a));

        //cout << "OK" << endl;
        all -= 2;
        unused.erase(unused.find(make_pair(fa,a)));
        unused.erase(unused.find(make_pair(fb,b)));
        unused.insert(make_pair(fa-1,a));
        unused.insert(make_pair(fb-1,b));
      }
    }else{
      //cout << "patan2" << endl;
      ll  a,b,fa,fb;
      a = (*rbegin(unused)).second;

      if(aused.count(a)){
        fa = (*rbegin(unused)).first;
        b = *begin(used);
        if(a == b)b = *rbegin(used);
        fb = cnt[b];
      }else{
        b = a;
        fb = cnt[b];
        a = *begin(aused);
        fa = cnt[a];
      }

      //cout << a    << " " << b << endl;
        ans.insert(make_pair(a,b));
        cnt[a]--;
        cnt[b]--;
        used.erase(used.find(b));
        aused.erase(aused.find(a));

      //cout << "OK" << endl;
      all -= 2;
      (*(unused.find(make_pair(fa,a))))--;
      (*(unused.find(make_pair(fb,b))))--;
      unused.insert(make_pair(fa-1,a));
      unused.insert(make_pair(fb-1,b));
    }
  }

  for(auto x : ans){
    cout << x.second << " ";
  }
  cout << endl;
/*

  map<ll,ll> m;
  rep(i,200010){
    if(cnt_a[i] > 0){
      m[i] = cnt_a[i];
    }
  }

  if(!hantei){
    cout << "No" << endl;
    return 0;
  }else{
    cout << "Yes" << endl;
    ll tmp = *rbegin(m).first;
    while(m[tmp] > 0){
      ans[cur] =
    }
  }

  rep(i,N){
    cout << ans[i] << " ";
  }
  cout << endl;
*/



  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:166:40: error: no 'operator--(int)' declared for postfix '--' [-fpermissive]
  166 |       (*(unused.find(make_pair(fa,a))))--;
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
a.cc:167:40: error: no 'operator--(int)' declared for postfix '--' [-fpermissive]
  167 |       (*(unused.find(make_pair(fb,b))))--;
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~