#include <bits/stdc++.h>
using namespace std;
int a[1001], b[1001], p[10001], n;
bool used[1001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  vector<pair<int, int> > vec;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      used[a[i]] = 1;
      sum += a[i];
    } else {
      vec.push_back(make_pair(a[i], b[i]));
    }
  }
  if (vec.size() == 1) {
    for (int i = 0; i < n; i++) {
      if (a[i] == b[i]) {
        cout << a[i] << " ";
      } else {
        cout << n * (n + 1) / 2 - sum << " ";
      }
    }
    return 0;
  }
  vector<int> fans;
  for (int i = 0; i < vec.size(); i++) {
    if (vec[i].first == vec[i + 1].first && !used[vec[i + 1].second]) {
      fans.push_back(vec[i].first);
      fans.push_back(vec[i + 1].second);
      break;
    }
    if (vec[i].first == vec[i + 1].first && used[vec[i + 1].second]) {
      fans.push_back(vec[i].second);
      fans.push_back(vec[i + 1].first);
      break;
    }
    if (vec[i].second == vec[i + 1].second && !used[vec[i + 1].first]) {
      fans.push_back(vec[i].second);
      fans.push_back(vec[i + 1].first);
      break;
    }
    if (vec[i].second == vec[i + 1].second && used[vec[i + 1].first]) {
      fans.push_back(vec[i].first);
      fans.push_back(vec[i + 1].second);
      break;
    }
  }
  if (fans.size() == 0) {
    for (int i = 0; i < vec.size(); i++) {
      if (!used[vec[i].first]) {
        fans.push_back(vec[i].first);
      } else {
        fans.push_back(vec[i].second);
      }
    }
  }
  int l = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      cout << a[i] << " ";
    } else {
      cout << fans[l] << " ";
      l++;
    }
  }
  return 0;
}
