#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int N = 1e6 + 5;
const int MAX = 1e6;
long long ans;
struct node {
  int l, r;
  long long mx, sum;
} tree[N << 2];
void pushup(int rt) {
  tree[rt].sum = tree[rt << 1].sum + tree[rt << 1 | 1].sum;
  tree[rt].mx =
      max(tree[rt << 1 | 1].mx, tree[rt << 1].mx + tree[rt << 1 | 1].sum);
}
void build(int rt, int l, int r) {
  tree[rt].l = l;
  tree[rt].r = r;
  tree[rt].sum = 0;
  if (l == r) {
    tree[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 l, int z) {
  if (tree[rt].l == tree[rt].r) {
    tree[rt].sum += z;
    tree[rt].mx += z;
    return;
  }
  int mid = (tree[rt].l + tree[rt].r) / 2;
  if (l <= mid)
    update(rt << 1, l, z);
  else
    update(rt << 1 | 1, l, z);
  pushup(rt);
}
void query(int rt, int t) {
  if (tree[rt].r <= t) {
    ans = max(tree[rt].mx, ans + tree[rt].sum);
    return;
  }
  int mid = (tree[rt].l + tree[rt].r) / 2;
  query(rt << 1, t);
  if (mid < t) query(rt << 1 | 1, t);
}
char s[5];
struct NODE {
  int t, d;
} a[N];
int main() {
  build(1, 1, MAX);
  int n, t, d;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    if (s[0] == '?') {
      ans = 0;
      scanf("%d", &t);
      query(1, t);
      printf("%lld\n", max(ans - t, 0ll));
    } else if (s[0] == '+') {
      scanf("%d%d", &t, &d);
      a[i].t = t;
      a[i].d = -d;
      update(1, t, d);
    } else {
      scanf("%d", &t);
      update(1, a[t].t, a[t].d);
    }
  }
  return 0;
}
