#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 5;
struct Tree {
  bool lf, rf;
  bool flag;
  long long val, lval, rval;
} tree[maxn << 2];
int n;
int b[maxn];
inline void push_up(int o) {
  int lb = o << 1, rb = o << 1 | 1;
  if (tree[lb].flag && tree[rb].flag) {
    tree[o].lf = tree[o].rf = true;
    tree[o].lval = tree[o].rval = tree[o].val = tree[lb].val + tree[rb].val;
    return;
  }
  tree[o].flag = false;
  if (tree[lb].lf == false)
    tree[o].lf = false, tree[o].lval = 0;
  else {
    tree[o].lf = true;
    if (tree[lb].flag && tree[rb].lf)
      tree[o].lval = tree[lb].lval + tree[rb].lval;
    else
      tree[o].lval = tree[lb].lval;
  }
  if (tree[rb].rf == false)
    tree[o].rf = false, tree[o].rval = 0;
  else {
    tree[o].rf = true;
    if (tree[rb].flag && tree[lb].rf)
      tree[o].rval = tree[rb].rval + tree[lb].rval;
    else
      tree[o].rval = tree[rb].rval;
  }
  tree[o].val = max(tree[lb].val, tree[rb].val);
  if (tree[lb].rf && tree[rb].lf) {
    tree[o].val = max(tree[o].val, tree[lb].rval + tree[rb].lval);
  }
}
void build_tree(int l, int r, int o) {
  if (l == r) {
    long long val;
    scanf("%lld", &val);
    tree[o].val = tree[o].lval = tree[o].rval = val;
    tree[o].flag = tree[o].lf = tree[o].rf = true;
    return;
  }
  tree[o].lf = tree[o].rf = tree[o].flag = true;
  int mid = (l + r) / 2;
  if (l <= mid) build_tree(l, mid, o << 1);
  if (r > mid) build_tree(mid + 1, r, o << 1 | 1);
  push_up(o);
}
void update(int l, int r, int pos, int o) {
  if (l == r && l == pos) {
    tree[o].val = 0;
    tree[o].flag = tree[o].lf = tree[o].rf = false;
    return;
  }
  int mid = (l + r) / 2;
  if (pos <= mid) update(l, mid, pos, o << 1);
  if (pos > mid) update(mid + 1, r, pos, o << 1 | 1);
  push_up(o);
}
int main() {
  scanf("%d", &n);
  build_tree(1, n, 1);
  for (int i = 1; i <= n; i++) {
    int pos;
    scanf("%d", &pos);
    update(1, n, pos, 1);
    printf("%lld\n", tree[1].val);
  }
  return 0;
}
