Language: C++

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

void no(){
	printf("No\n");
	exit(0);
}

#define N 212345
int a[N] = {}, b[N] = {};
vi v;
queue<int> va, vb;
vi u;
multiset<int> s;
queue<int> que[N];
void ad(int a, int b){
	if(a < 0){
		a = va.front();
		va.pop();
	}
	if(b < 0){
		b = vb.front();
		vb.pop();
	}
	que[a].emplace(b);
}

int main(){
	int n; scanf("%d", &n);
	REP(i, n) {
		int x; scanf("%d", &x);
		a[x]++;
		u.EB(x);
	}
	REP(i, n) {
		int x; scanf("%d", &x);
		b[x]++;
		s.emplace(x);
	}
	assert(u.size() == (size_t)n);
	assert(s.size() == (size_t)n);

	REP(i, N){
		int c = min(a[i], b[i]);
		REP(j, c) v.EB(i);
		REP(j, a[i]-c) va.emplace(i);
		REP(j, b[i]-c) vb.emplace(i);
	}
	assert(va.size() == vb.size());
	assert(va.size() + v.size() == (size_t)n);
	REP(i, (int)va.size()) v.EB(-1-i);
	assert(v.size() == (size_t)n)

	int m = v.size() / 2, j = -1;
	DEBUG("v: "); for(int i : v) DEBUG("%d ", i); DEBUG("\n");
	REP(i, m) if(v[i] == v[m+i]) no();
	if(v.size() % 2){
		REP(i, m){
			if(v[i] == v.back() || v[m+i] == v.back()) continue;
			j = i;
			ad(v[i], v[m+i]);
			ad(v[m+i], v.back());
			ad(v.back(), v[i]);
			break;
		}
		if(j == -1) no();
	}
	REP(i, m) {
		if(i != j){
			ad(v[i], v[m+i]);
			ad(v[m+i], v[i]);
		}
	}
	// printf("Yes\n");
	// for(int i : u) {
	// 	// assert(que[i].size());
	// 	int j = que[i].front(); que[i].pop();
	// 	printf("%d ", j);
	// 	// assert(i != j);
	// 	auto it = s.find(j);
	// 	// assert(it != s.end());
	// 	s.erase(s.find(j));
	// }
	// REP(i, N) assert(que[i].empty());
	// // assert(s.empty());
}


Compiler output:
a.cc: In function 'int main()':
a.cc:75:9: error: expected ';' before 'int'
   75 |         int m = v.size() / 2, j = -1;
      |         ^~~
a.cc:77:16: error: 'm' was not declared in this scope
   77 |         REP(i, m) if(v[i] == v[m+i]) no();
      |                ^
a.cc:4:40: note: in definition of macro 'FOR'
    4 | #define FOR(i, a, b) for(int i=(a); i<(b); i++)
      |                                        ^
a.cc:77:9: note: in expansion of macro 'REP'
   77 |         REP(i, m) if(v[i] == v[m+i]) no();
      |         ^~~
a.cc:79:24: error: 'm' was not declared in this scope
   79 |                 REP(i, m){
      |                        ^
a.cc:4:40: note: in definition of macro 'FOR'
    4 | #define FOR(i, a, b) for(int i=(a); i<(b); i++)
      |                                        ^
a.cc:79:17: note: in expansion of macro 'REP'
   79 |                 REP(i, m){
      |                 ^~~
a.cc:81:25: error: 'j' was not declared in this scope
   81 |                         j = i;
      |                         ^
a.cc:87:20: error: 'j' was not declared in this scope
   87 |                 if(j == -1) no();
      |                    ^
a.cc:89:16: error: 'm' was not declared in this scope
   89 |         REP(i, m) {
      |                ^
a.cc:4:40: note: in definition of macro 'FOR'
    4 | #define FOR(i, a, b) for(int i=(a); i<(b); i++)
      |                                        ^
a.cc:89:9: note: in expansion of macro 'REP'
   89 |         REP(i, m) {
      |         ^~~
a.cc:90:25: error: 'j' was not declared in this scope
   90 |                 if(i != j){
      |                         ^