#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
const int Q = 3e5 + 100;
struct node {
  bool any;
  int earliest, gap;
  long long latest;
  node() { any = earliest = latest = gap = 0; }
} tree[4 * N];
node merge(node L, node R) {
  if (!L.any) return R;
  if (!R.any) return L;
  node ret;
  ret.any = 1;
  if (L.latest <= R.earliest) {
    ret.earliest = L.earliest;
    ret.latest = R.latest;
    ret.gap = L.gap + R.gap + R.earliest - L.latest;
  } else if (R.gap >= L.latest - R.earliest) {
    ret.gap = L.gap + R.gap - (L.latest - R.earliest);
    ret.earliest = L.earliest;
    ret.latest = R.latest;
  } else {
    ret.gap = L.gap;
    ret.earliest = L.earliest;
    ret.latest = R.latest + (L.latest - R.earliest) - R.gap;
  }
  return ret;
}
void join(int idx, int s, int e, int t, int d) {
  if (s == e) {
    tree[idx].any = 1;
    tree[idx].earliest = s;
    tree[idx].latest = s + d;
    return;
  }
  int m = s + ((e - s) >> 1), L = (idx << 1) | 1, R = L + 1;
  if (t <= m)
    join(L, s, m, t, d);
  else
    join(R, m + 1, e, t, d);
  tree[idx] = merge(tree[L], tree[R]);
}
void cancel(int idx, int s, int e, int t) {
  if (s == e) {
    tree[idx].any = 0;
    return;
  }
  int m = s + ((e - s) >> 1), L = (idx << 1) | 1, R = L + 1;
  if (t <= m)
    cancel(L, s, m, t);
  else
    cancel(R, m + 1, e, t);
  tree[idx] = merge(tree[L], tree[R]);
}
node query(int idx, int s, int e, int t) {
  if (e <= t) return tree[idx];
  int m = s + ((e - s) >> 1), L = (idx << 1) | 1, R = L + 1;
  if (t <= m) return query(L, s, m, t);
  return merge(tree[L], query(R, m + 1, e, t));
}
int q;
char typ[Q];
int v1[Q], v2[Q];
int main() {
  scanf("%d", &q);
  for (int qi = 0; qi < q; qi++) {
    scanf(" %c", &typ[qi]);
    scanf("%d", &v1[qi]);
    v1[qi]--;
    if (typ[qi] == '+') {
      scanf("%d", &v2[qi]);
      join(0, 0, 1e6 - 1, v1[qi], v2[qi]);
    } else if (typ[qi] == '-') {
      cancel(0, 0, 1e6 - 1, v1[v1[qi]]);
    } else if (typ[qi] == '?') {
      node x = query(0, 0, 1e6 - 1, v1[qi]);
      if (!x.any || x.latest <= v1[qi])
        puts("0");
      else
        printf("%lld\n", x.latest - v1[qi]);
    }
  }
}
