#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  vector<int> otv(n);
  set<int> s;
  int i1 = -1, i2 = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s.insert(i + 1);
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] == a[i]) {
      otv[i] = a[i];
      s.erase(a[i]);
    } else {
      if (i1 == -1)
        i1 = i;
      else
        i2 = i;
    }
  }
  if (s.size() == 1) {
    otv[i1] = *(s.begin());
  } else {
    if (a[i1] == a[i2] && b[i1] == b[i2]) {
      otv[i1] = *(s.begin());
      s.erase(*(s.begin()));
      otv[i2] = *(s.begin());
      s.erase(*(s.begin()));
    } else if (a[i1] == a[i2]) {
      if (s.find(b[i1]) != s.end()) {
        otv[i1] = b[i1];
        s.erase(b[i1]);
        otv[i2] = *(s.begin());
        s.erase(*(s.begin()));
      } else if (s.find(b[i2]) != s.end()) {
        otv[i2] = b[i2];
        s.erase(b[i2]);
        otv[i1] = *(s.begin());
        s.erase(*(s.begin()));
      }
    } else {
      if (s.find(a[i1]) != s.end()) {
        otv[i1] = a[i1];
        s.erase(a[i1]);
        otv[i2] = *(s.begin());
        s.erase(*(s.begin()));
      } else if (s.find(a[i2]) != s.end()) {
        otv[i2] = a[i2];
        s.erase(a[i2]);
        otv[i1] = *(s.begin());
        s.erase(*(s.begin()));
      }
    }
  }
  for (int i = 0; i < n; i++) cout << otv[i] << " ";
  return 0;
}
