#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  if (0) return;
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  if (0) return;
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
inline void INP();
const long long N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;
long long n, Q;
long long arr[N + 2], great[N];
long long bit[N];
void update(long long id, long long val) {
  for (long long i = id; i <= n; i += i & (-i)) bit[i] += val;
}
long long get(long long id) {
  long long sum = 0;
  for (long long i = id; i > 0; i -= i & (-i)) sum += bit[i];
  return sum;
}
long long query(long long l, long long r) { return get(r) - get(l - 1); }
long long p[N];
template <typename T>
class segment_tree {
 public:
  long long sz, lz = 1;
  vector<T> segt;
  vector<long long> lazy;
  void init(long long x) {
    lz = 1;
    sz = x;
    segt.assign(4 * sz, 0);
    lazy.assign(4 * sz, 0);
  }
  T first(T a, T b) { return max(a, b); }
  void push(long long i, long long l, long long r) {
    segt[i] += lazy[i];
    if (l != r) {
      lazy[2 * i + 1] += lazy[i];
      lazy[2 * i + 2] += lazy[i];
    }
    lazy[i] = 0;
  }
  T qry(long long l, long long r, long long i, long long L, long long R) {
    if (lazy[i] != 0 and lz) push(i, l, r);
    if (r < L or R < l) return -inf;
    if (L <= l and r <= R) return segt[i];
    long long mid = (l + r) / 2;
    T a = qry(l, mid, 2 * i + 1, L, R), b = qry(mid + 1, r, 2 * i + 2, L, R);
    if (lz) get(i);
    return first(a, b);
  }
  void upd(long long l, long long r, long long i, long long L, long long R,
           long long val) {
    if (lazy[i] != 0 and lz) push(i, l, r);
    if (l > R or L > r) return;
    if (L <= l and r <= R) {
      lazy[i] += val;
      push(i, l, r);
      return;
    }
    long long mid = (l + r) / 2;
    upd(l, mid, i * 2 + 1, L, R, val);
    upd(mid + 1, r, i * 2 + 2, L, R, val);
    get(i);
  }
  T query(long long L, long long R = -1) {
    if (R == -1) R = L;
    return qry(1, sz - 1, 0, L, R);
  }
  void update(long long val, long long L, long long R = -1) {
    if (R == -1) R = L;
    upd(1, sz - 1, 0, L, R, val);
  }
  void get(long long i) { segt[i] = first(segt[2 * i + 1], segt[2 * i + 2]); }
};
long long idx[N];
void solve() {
  cin >> n;
  for (long long i = 1; i < (long long)n + 1; i++)
    cin >> arr[i], idx[arr[i]] = i;
  for (long long i = 1; i < (long long)n + 1; i++) cin >> p[i];
  segment_tree<long long> sgt;
  sgt.init(n + 1);
  long long ans = n, cnt = 0;
  sgt.update(1, 1, idx[n]);
  long long res = sgt.query(1, n);
  for (long long i = 1; i < (long long)n + 1; i++) {
    long long res = sgt.query(1, n);
    while (res <= 0) {
      ans--;
      sgt.update(1, 1, idx[ans]);
      res = sgt.query(1, n);
    }
    cout << ans << " ";
    sgt.update(-1, 1, p[i]);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  INP();
  long long test = 1;
  while (test--) solve();
}
inline void INP() {}
