#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
cin.sync_with_stdio(false);
int bcount;
cin >> bcount;
vector<int> alive(bcount), killed(bcount), uList(bcount), mList(bcount), kList(bcount);
for (int i = 0; i < bcount; i++) {
int a;
cin >> a;
uList[i] = a - 1;
alive[i] = i;
}
for (int i = 0; i < bcount; i++) {
int a;
cin >> a;
mList[i] = a - 1;
}
int i = 0;
int fail = 0;
while (1) {
int rnd = rand() % (bcount-i);
if (alive[rnd] == uList[i] || alive[rnd] == mList[i]) {
if (fail < 4) {
fail++;
continue;
}
else {
int retcount = (i < 2) ? i : 2;
if (i == bcount - 1) {
retcount = ceil(bcount / 1.5);
}
for (int j = 0; j < retcount; j++) {
alive.push_back(killed[i - j - 1]);
}
i = i - retcount;
}
}
kList[i] = alive[rnd] + 1;
killed[i] = alive[rnd];
alive.erase(alive.begin() + rnd);
if (i < bcount-1) {
i++;
}
else {
for (int j = 0; j < bcount; j++){
cout << kList[j] << " ";
}
break;
}
}
}