#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n, a[maxn], b[maxn], c[maxn], p[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  int pos[2], sz = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] != b[i])
      pos[sz++] = i;
    else
      c[a[i]] = 1;
  if (sz == 1) {
    for (int i = 1; i <= n; i++)
      if (!c[i]) p[pos[0]] = i;
    for (int i = 1; i <= n; i++)
      if (i != pos[0]) p[i] = a[i];
  } else if (sz == 2) {
    int mis[2];
    sz = 0;
    for (int i = 1; i <= n; i++)
      if (!c[i]) mis[sz++] = i;
    for (int i = 1; i <= n; i++)
      if (i != pos[0] && i != pos[1]) p[i] = a[i];
    if (((a[pos[0]] == mis[0]) ^ (a[pos[1]] == mis[1])) == 0)
      swap(mis[0], mis[1]);
    if (((b[pos[0]] == mis[0]) ^ (b[pos[1]] == mis[1])) == 0)
      swap(mis[0], mis[1]);
    p[pos[0]] = mis[0];
    p[pos[1]] = mis[1];
  } else
    assert(false);
  for (int i = 1; i <= n; i++) cout << p[i] << " ";
  cout << endl;
  return 0;
}
