Language: C++

include <bits/stdc++.h>
#define M 1000005
#define FI first
#define SE second
#define MP std::make_pair
#define PB push_back
#define INF 1000000000
typedef long long ll;
int n, A[M], B[M], X[M], Y[M], cnt[M];
std::mt19937_64 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
int read() {
	int ans = 0; char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	while (c >= '0' && c <= '9') ans = ans * 10 + c - '0', c = getchar();
	return ans;
}
void Write(int x) {
	if (x < 10) putchar(x + '0');
	else Write(x / 10), putchar(x % 10 + '0');
	return;
}
int Random(int l, int r) {return rnd() % (r - l + 1) + l;}
void work() {
	for (int i = 1; i <= n; i++) cnt[i] = 0;
	for (int i = 1; i <= n; i++) cnt[A[i]]++, cnt[B[i]]++;
	for (int i = 1; i <= n; i++)
		if (cnt[i] > n) return puts("No"), void();
	puts("Yes");
	std::reverse(B + 1, B + 1 + n); *X = *Y = 0;
	for (int i = 1; i <= n; i++)
		if (A[i] == B[i]) X[++*X] = i;
	for (int i = 1; i <= n; i++)
		if (!*X || (A[i] != A[X[1]] && B[i] != A[X[1]])) Y[++*Y] = i;
	assert(*X <= *Y);
	while (*X) std::swap(B[X[*X]], B[Y[*Y]]), --*X, --*Y;
	for (int i = 1; i <= n; i++) assert(A[i] != B[i]);
	for (int i = 1; i <= n; i++) Write(B[i]), putchar(' ');
	return putchar('\n'), void();
}
int main() {
	n = read();
	for (int i = 1; i <= n; i++) A[i] = read();
	for (int i = 1; i <= n; i++) B[i] = read();
	return work(), 0;
}

Compiler output:
a.cc:1:1: error: 'include' does not name a type
    1 | include <bits/stdc++.h>
      | ^~~~~~~
a.cc:10:6: error: 'mt19937_64' in namespace 'std' does not name a type
   10 | std::mt19937_64 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
      |      ^~~~~~~~~~
a.cc: In function 'int read()':
a.cc:12:31: error: 'getchar' was not declared in this scope
   12 |         int ans = 0; char c = getchar();
      |                               ^~~~~~~
a.cc:1:1: note: 'getchar' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | include <bits/stdc++.h>
a.cc: In function 'void Write(int)':
a.cc:18:21: error: 'putchar' was not declared in this scope; did you mean 'char'?
   18 |         if (x < 10) putchar(x + '0');
      |                     ^~~~~~~
      |                     char
a.cc:19:29: error: 'putchar' was not declared in this scope; did you mean 'char'?
   19 |         else Write(x / 10), putchar(x % 10 + '0');
      |                             ^~~~~~~
      |                             char
a.cc: In function 'int Random(int, int)':
a.cc:22:34: error: 'rnd' was not declared in this scope
   22 | int Random(int l, int r) {return rnd() % (r - l + 1) + l;}
      |                                  ^~~
a.cc: In function 'void work()':
a.cc:27:40: error: 'puts' was not declared in this scope
   27 |                 if (cnt[i] > n) return puts("No"), void();
      |                                        ^~~~
a.cc:28:9: error: 'puts' was not declared in this scope
   28 |         puts("Yes");
      |         ^~~~
a.cc:29:14: error: 'reverse' is not a member of 'std'
   29 |         std::reverse(B + 1, B + 1 + n); *X = *Y = 0;
      |              ^~~~~~~
a.cc:34:9: error: 'assert' was not declared in this scope
   34 |         assert(*X <= *Y);
      |         ^~~~~~
a.cc:1:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
  +++ |+#include <cassert>
    1 | include <bits/stdc++.h>
a.cc:35:25: error: 'swap' is not a member of 'std'
   35 |         while (*X) std::swap(B[X[*X]], B[Y[*Y]]), --*X, --*Y;
      |                         ^~~~
a.cc:37:51: error: 'putchar' was not declared in this scope; did you mean 'char'?
   37 |         for (int i = 1; i <= n; i++) Write(B[i]), putchar(' ');
      |                                                   ^~~~~~~
      |                                                   char
a.cc:38:16: error: 'putchar' was not declared in this scope; did you mean 'char'?
   38 |         return putchar('\n'), void();
      |                ^~~~~~~
      |                char