#include <bits/stdc++.h>
using namespace std;
const int maxq = 3e5 + 10;
const int maxt = 1e6 + 10;
int q;
pair<int, int> et[maxq];
struct Node {
  int l, r;
  long long sum, mx;
} node[4 * maxt];
void pushup(int rt) {
  node[rt].sum = node[(rt << 1)].sum + node[(rt << 1 | 1)].sum;
  node[rt].mx =
      max(node[(rt << 1 | 1)].mx, node[(rt << 1)].mx + node[(rt << 1 | 1)].sum);
}
void build(int rt, int l, int r) {
  node[rt].l = l;
  node[rt].r = r;
  if (l == r) {
    node[rt].sum = 0, node[rt].mx = l;
    return;
  }
  int mid = (l + r) / 2;
  build((rt << 1), l, mid);
  build((rt << 1 | 1), mid + 1, r);
  pushup(rt);
}
void update(int rt, int pos, int val) {
  if (node[rt].l == node[rt].r) {
    node[rt].sum += val;
    node[rt].mx += val;
    return;
  }
  int mid = (node[rt].l + node[rt].r) / 2;
  if (pos <= mid) update((rt << 1), pos, val);
  if (pos > mid) update((rt << 1 | 1), pos, val);
  pushup(rt);
}
long long ans;
void query(int rt, int t) {
  if (node[rt].r <= t) {
    ans = max(node[rt].mx, ans + node[rt].sum);
    return;
  }
  int mid = (node[rt].l + node[rt].r) / 2;
  query((rt << 1), t);
  if (mid < t) query((rt << 1 | 1), t);
}
int main() {
  cin >> q;
  build(1, 1, 1000000);
  for (int i = 1; i <= q; i++) {
    char op[2];
    scanf("%s", op);
    if (op[0] == '+') {
      int t, d;
      scanf("%d%d", &t, &d);
      update(1, t, d);
      et[i] = make_pair(t, d);
    }
    if (op[0] == '-') {
      int id;
      scanf("%d", &id);
      update(1, et[id].first, -et[id].second);
    }
    if (op[0] == '?') {
      int t;
      scanf("%d", &t);
      ans = 0;
      query(1, t);
      printf("%I64d\n", max(ans - t, 0ll));
    }
  }
}
