#include <bits/stdc++.h>
using namespace std;
const int M = 1e6 + 10, m = 1e6;
long long ed[M << 2], s[M << 2], ans;
int ax[M], ay[M];
void build(int k, int l, int r) {
  s[k] = 0;
  ed[k] = r;
  if (l == r) return;
  int mid = l + r >> 1;
  build(k << 1, l, mid);
  build(k << 1 | 1, mid + 1, r);
}
void del(int k, int l, int r, int x) {
  if (l == r) {
    ed[k] = l;
    s[k] = 0;
    return;
  }
  int mid = l + r >> 1;
  if (x <= mid)
    del(k << 1, l, mid, x);
  else
    del(k << 1 | 1, mid + 1, r, x);
  ed[k] = max(ed[k << 1] + s[k << 1 | 1], ed[k << 1 | 1]);
  s[k] = s[k << 1] + s[k << 1 | 1];
}
void ins(int k, int l, int r, int x, int z) {
  s[k] += z;
  if (l == r) {
    ed[k] = l + z;
    return;
  }
  int mid = l + r >> 1;
  if (x <= mid)
    ins(k << 1, l, mid, x, z);
  else
    ins(k << 1 | 1, mid + 1, r, x, z);
  ed[k] = max(ed[k << 1] + s[k << 1 | 1], ed[k << 1 | 1]);
}
void qy(int k, int l, int r, int x) {
  if (r <= x) {
    ans = max(ans + s[k], ed[k]);
    return;
  }
  int mid = l + r >> 1;
  qy(k << 1, l, mid, x);
  if (mid < x) qy(k << 1 | 1, mid + 1, r, x);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q, x;
  string opt;
  build(1, 1, m);
  cin >> q;
  for (register int i = (1); i <= (q); ++i) {
    cin >> opt;
    if (opt[0] == '?') {
      cin >> x;
      ans = 0;
      qy(1, 1, m, x);
      cout << ans - x << '\n';
    }
    if (opt[0] == '+') {
      cin >> ax[i] >> ay[i];
      ins(1, 1, m, ax[i], ay[i]);
    }
    if (opt[0] == '-') {
      cin >> x;
      del(1, 1, m, ax[x]);
    }
  }
  return 0;
}
