#include <bits/stdc++.h>
using namespace std;
const int N = 100050;
int gi() {
  int x = 0, flag = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * flag;
}
int a[N], b[N], n, dif[N], tong[N], hh[N], tong2[N], p[N];
bool check() {
  for (int i = 1; i <= n; i++) tong2[i] = 0;
  for (int i = 1; i <= n; i++) tong2[p[i]]++;
  for (int i = 1; i <= n; i++)
    if (tong2[p[i]] > 1) return 0;
  return 1;
}
int main() {
  n = gi();
  int cnt = 0, tot = 0;
  for (int i = 1; i <= n; i++) {
    a[i] = gi();
    if (tong[a[i]] == 0) tong[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    b[i] = gi();
    if (tong[b[i]] == 0) tong[b[i]]++;
  }
  for (int i = 1; i <= n; i++)
    if (a[i] != b[i]) {
      dif[++cnt] = i;
    }
  for (int i = 1; i <= n; i++)
    if (tong[i] == 0) hh[++tot] = i;
  if (cnt == 1) {
    for (int i = 1; i <= n; i++) {
      if (i == dif[1])
        cout << hh[1] << ' ';
      else
        cout << a[i] << ' ';
    }
  }
  if (cnt == 2) {
    for (int i = 1; i <= n; i++) {
      if (i == dif[1])
        p[i] = a[i];
      else if (i == dif[2])
        p[i] = b[i];
      else
        p[i] = a[i];
    }
    if (check()) {
      for (int i = 1; i <= n; i++) cout << p[i] << ' ';
      return 0;
    }
    for (int i = 1; i <= n; i++) {
      if (i == dif[1])
        p[i] = b[i];
      else if (i == dif[2])
        p[i] = a[i];
      else
        p[i] = a[i];
    }
    if (check()) {
      for (int i = 1; i <= n; i++) cout << p[i] << ' ';
    }
  }
  return 0;
}
