#include <bits/stdc++.h>
using namespace std;
int n, q, a[500000], b[500000];
long long ans;
char s[100];
struct segment_tree {
  long long a[8000005], b[8000005];
  void build(int l, int r, int k) {
    a[k] = r;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(l, mid, k << 1);
    build(mid + 1, r, (k << 1) | 1);
  }
  void update(int l, int r, int k, int x, int y) {
    if (l == r) {
      a[k] += y;
      b[k] += y;
      return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid) update(l, mid, k << 1, x, y);
    if (x > mid) update(mid + 1, r, (k << 1) | 1, x, y);
    a[k] = max(a[k << 1] + b[(k << 1) | 1], a[(k << 1) | 1]);
    b[k] = b[k << 1] + b[(k << 1) | 1];
  }
  void find(int l, int r, int k, int x, int y) {
    if (l >= x && r <= y) {
      ans = max(ans + b[k], a[k]);
      return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid) find(l, mid, k << 1, x, y);
    if (y > mid) find(mid + 1, r, (k << 1) | 1, x, y);
  }
} st;
int main() {
  scanf("%d", &q);
  n = 1000000;
  st.build(1, n, 1);
  for (int i = 1; i <= q; i++) {
    int x, y;
    scanf("%s", s);
    if (s[0] == '+') {
      scanf("%d%d", &x, &y);
      st.update(1, n, 1, x, y);
      a[i] = x;
      b[i] = y;
    }
    if (s[0] == '-') {
      scanf("%d", &x);
      st.update(1, n, 1, a[x], -b[x]);
    }
    if (s[0] == '?') {
      ans = 0;
      scanf("%d", &x);
      st.find(1, n, 1, 1, x);
      printf("%lld\n", ans - x);
    }
  }
}
