#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, p[N], q[N];
struct state {
  int low, high;
  int wave;
  vector<int> ids;
};
struct node {
  int bal, suff;
  node() {
    bal = 0;
    suff = 0;
  }
};
struct seg_tree {
  node t[4 * N];
  node mrg(node &x, node &y) {
    node res;
    res.bal = x.bal + y.bal;
    res.suff = max(y.suff, x.suff + y.bal);
    return res;
  }
  int ask() { return t[1].suff; }
  void upd(int pos, int low, int high, int id, int x) {
    if (low == high) {
      t[pos].bal += x;
      t[pos].suff += x;
      return;
    }
    int mid = (low + high) / 2;
    if (id <= mid)
      upd(pos * 2, low, mid, id, x);
    else
      upd(pos * 2 + 1, mid + 1, high, id, x);
    t[pos] = mrg(t[pos * 2], t[pos * 2 + 1]);
  }
  void clean_up(int pos, int low, int high) {
    t[pos].bal = t[pos].suff = 0;
    if (low == high) return;
    int mid = (low + high) / 2;
    clean_up(pos * 2, low, mid);
    clean_up(pos * 2 + 1, mid + 1, high);
  }
} seg;
void update(int id, int x) { seg.upd(1, 1, n, id, x); }
int query() { return seg.ask(); }
state parallel[4 * N];
int at_pos[N];
int ans[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    at_pos[p[i]] = i;
  }
  for (int i = 1; i <= n; i++) cin >> q[i];
  int qh = 0, qt = 1;
  parallel[qh].low = 1;
  parallel[qh].high = n + 1;
  for (int i = 1; i < n; i++) parallel[qh].ids.push_back(i);
  ans[0] = n;
  sort(p + 1, p + n + 1);
  reverse(p + 1, p + n + 1);
  int last_added = 0;
  parallel[0].wave = 0;
  int pred_wave = -1;
  int last_id = 0;
  while (qh < qt) {
    state &st = parallel[qh++];
    if (st.wave != pred_wave) {
      last_added = 0;
      seg.clean_up(1, 1, n);
      last_id = 0;
    }
    pred_wave = st.wave;
    if (st.low == st.high) {
      for (int id : st.ids) {
        while (last_id + 1 < id) {
          last_id++;
          update(q[last_id], -1);
        }
        last_id = id;
        update(q[id], -1);
      }
      continue;
    }
    int mid = (st.low + st.high) / 2;
    while (last_added < n && p[last_added + 1] >= mid) {
      update(at_pos[p[last_added + 1]], 1);
      last_added++;
    }
    int r = qt++;
    int l = qt++;
    parallel[l].low = st.low;
    parallel[l].high = mid;
    parallel[r].low = mid + 1;
    parallel[r].high = st.high;
    parallel[l].wave = parallel[r].wave = st.wave + 1;
    for (int id : st.ids) {
      while (last_id + 1 < id) {
        last_id++;
        update(q[last_id], -1);
      }
      last_id = id;
      update(q[id], -1);
      if (query() > 0) {
        ans[id] = mid;
        parallel[r].ids.push_back(id);
      } else
        parallel[l].ids.push_back(id);
    }
  }
  for (int i = 0; i < n; i++) cout << ans[i] << ' ';
  cout << '\n';
  return 0;
}
