#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
const long long mod2 = 998244353;
const long double eps = 1e-10;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = (int)(0); i < (int)(n); i++) cin >> A[i];
  vector<int> B(n);
  for (int i = (int)(0); i < (int)(n); i++) cin >> B[i];
  vector<int> ans(n);
  vector<int> id;
  set<int> st;
  for (int i = (int)(0); i < (int)(n); i++) st.insert(i + 1);
  for (int i = (int)(0); i < (int)(n); i++) {
    if (A[i] == B[i]) {
      ans[i] = A[i];
      st.erase(ans[i]);
    } else {
      id.push_back(i);
    }
  }
  if (st.size() == 2) {
    int p1 = *st.begin();
    int p2 = *(++st.begin());
    if (int(p1 != A[id[0]]) + int(p1 != B[id[0]]) == 1 &&
        int(p2 != A[id[1]]) + int(p2 != B[id[1]]) == 1) {
      ans[id[0]] = p1, ans[id[1]] = p2;
    } else {
      ans[id[0]] = p2, ans[id[1]] = p1;
    }
  } else if (st.size() == 1) {
    ans[id[0]] = *st.begin();
  } else {
    assert(false);
  }
  for (int i = (int)(0); i < (int)(n); i++) cout << ans[i] << ' ';
  cout << '\n';
  return 0;
}
