#include <bits/stdc++.h>
typedef struct {
  long long exces, sum;
} aint;
int t[300000 + 1], d[300000 + 1];
aint arb[4 * 1000000 + 4];
long long ex;
inline void rebalance(int p, int st, int dr) {
  int f1 = 2 * p + 1, f2 = 2 * p + 2, mid = (st + dr) / 2;
  arb[p].sum = arb[f1].sum + arb[f2].sum;
  arb[p].exces = arb[f2].exces;
  long long cex;
  cex = arb[f1].exces + arb[f2].sum - (dr - mid);
  if (arb[p].exces < cex) arb[p].exces = cex;
}
void add(int p, int st, int dr, int t, int d) {
  if (st == dr) {
    arb[p].sum += d;
    if (arb[p].sum != 0) {
      arb[p].exces = arb[p].sum;
    } else {
      arb[p].exces = 0;
    }
  } else {
    int mid = (st + dr) / 2;
    if (t <= mid)
      add(2 * p + 1, st, mid, t, d);
    else
      add(2 * p + 2, mid + 1, dr, t, d);
    rebalance(p, st, dr);
  }
}
void exces(int p, int st, int dr, int t) {
  if (dr <= t) {
    long long cex = arb[p].exces;
    ex = ex + arb[p].sum - (dr - st + 1);
    if (cex > ex) ex = cex;
  } else {
    int mid = (st + dr) / 2;
    exces(2 * p + 1, st, mid, t);
    if (t > mid) exces(2 * p + 2, mid + 1, dr, t);
  }
}
int main() {
  int q, i, x;
  char ch;
  scanf("%d ", &q);
  for (i = 1; i <= q; i++) {
    ch = fgetc(stdin);
    if (ch == '+') {
      scanf("%d%d ", &t[i], &d[i]);
      add(0, 0, 1000000, t[i], d[i]);
    } else if (ch == '-') {
      scanf("%d ", &x);
      add(0, 0, 1000000, t[x], -d[x]);
    } else {
      scanf("%d ", &x);
      ex = 0;
      exces(0, 0, 1000000, x);
      printf("%I64d\n", ex);
    }
  }
  return 0;
}
