Language: C++

/* 	* In the name of GOD 
 * Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second
const int N = 201234;
int a[N], b[N], ans[N];
vector <int> ha[N], hb[N], ha2[N], hb2[N];

void solve() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i], ha[a[i]].push_back(i), ha2[a[i]].push_back(i);
	for (int i = 0; i < n; i++)
		cin >> b[i], hb[b[i]].push_back(i), hb2[b[i]].push_back(i);
	if (n <= 10) {
		vector <int> x;
		for (int i = 1; i <= n; i++) {
			x.push_back(i);
		}
		do {
			bool f = true;
			for (int i = 0; i < n; i++) {
				if (b[x[i] - 1] == a[i]) {
					f = false;
					break;
				}
			}
			if (f) {
				cout << "Yes\n";
				for (int i = 0; i < n; i++)
					cout << b[x[i] - 1] << ' ';
				return;
			}
		} while (next_permutation(x.begin(), x.end()));
		cout << "No";
		return;
	}
	set <int> st;
	for (int i = 0; i < n; i++)
		st.insert(i);
	for (int i = 0; i < N; i++) {
		vector <int> all;
		for (auto x : ha[i]) {
			if (st.count(x))
				all.push_back(x);
			st.erase(x);
		}
		vector <int> v = hb[i];
		while (st.size() && v.size()) {
			int in = *st.rbegin();
			ans[in] = i;
			st.erase(in);
			v.pop_back();
		}
		if (v.size()) {
			goto ed;
		}
		for (auto x : all)
			st.insert(x);
	}
	cout << "Yes\n";
	for (int i = 0; i < n; i++)
		cout << ans[i] << ' ';
	return;
	ed:
	st.erase();
	for (int i = 0; i < n; i++)
		st.insert(i);
	for (int i = 0; i < N; i++) 
		ans[i] = 0, ha[i] = ha2[i], hb[i] = hb2[i];
	for (int i = 0; i < N; i++) {
		vector <int> all;
		for (auto x : ha[i]) {
			if (st.count(x))
				all.push_back(x);
			st.erase(x);
		}
		vector <int> v = hb[i];
		while (st.size() && v.size()) {
			int in = *st.begin();
			ans[in] = i;
			st.erase(in);
			v.pop_back();
		}
		if (v.size()) {
			cout << "No";
			return;
		}
		for (auto x : all)
			st.insert(x);
	}
	cout << "Yes\n";
	for (int i = 0; i < n; i++)
		cout << ans[i] << ' ';
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
}



Compiler output:
a.cc: In function 'void solve()':
a.cc:73:17: error: no matching function for call to 'std::set<int>::erase()'
   73 |         st.erase();
      |         ~~~~~~~~^~
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:3:
/usr/include/c++/14/bits/stl_set.h:656:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(const_iterator) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator]'
  656 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/stl_set.h:656:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_set.h:686:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; size_type = long unsigned int; key_type = int]'
  686 |       erase(const key_type& __x)
      |       ^~~~~
/usr/include/c++/14/bits/stl_set.h:686:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_set.h:708:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(const_iterator, const_iterator) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator; const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator]'
  708 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/14/bits/stl_set.h:708:7: note:   candidate expects 2 arguments, 0 provided