#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)3e5 + 5;
const long long LINF = (long long)1e18;
long long fenw[MAXN << 2];
long long t[MAXN << 2], ext[MAXN << 2];
array<int, 3> que[MAXN];
pair<int, int> knight[MAXN];
int n, m, q;
vector<int> pts;
void build(int v, int tl, int tr) {
  t[v] = pts[tr];
  ext[v] = 0;
  if (tl != tr) {
    int c1 = (v << 1), c2 = (c1 | 1);
    int mid = (tl + tr) >> 1;
    build(c1, tl, mid);
    build(c2, mid + 1, tr);
  }
}
void push(int v, int tl, int tr) {
  t[v] += ext[v];
  if (tl != tr) {
    int c1 = (v << 1), c2 = (c1 | 1);
    ext[c1] += ext[v];
    ext[c2] += ext[v];
  }
  ext[v] = 0;
}
long long query(int v, int tl, int tr, int l, int r) {
  push(v, tl, tr);
  if (l > r || tl > r || tr < l) {
    return -LINF;
  }
  if (l <= tl && tr <= r) {
    return t[v];
  }
  int mid = (tl + tr) >> 1;
  int c1 = (v << 1), c2 = (c1 | 1);
  return max(query(c1, tl, mid, l, r), query(c2, mid + 1, tr, l, r));
}
void update(int v, int tl, int tr, int l, int r, int x) {
  push(v, tl, tr);
  if (l > r || tl > r || tr < l) {
    return;
  }
  if (l <= tl && tr <= r) {
    ext[v] += x;
    push(v, tl, tr);
    return;
  }
  int mid = (tl + tr) >> 1;
  int c1 = (v << 1), c2 = (c1 | 1);
  update(c1, tl, mid, l, r, x);
  update(c2, mid + 1, tr, l, r, x);
  t[v] = max(t[c1], t[c2]);
}
void fenwUpd(int p, long long x) {
  for (; p < m; p |= (p + 1)) {
    fenw[p] += x;
  }
}
long long fenwPref(int p) {
  long long ret = 0;
  for (; p >= 0; --p) {
    ret += fenw[p];
    p &= (p + 1);
  }
  return ret;
}
long long fenwSeg(int l, int r) { return fenwPref(r) - fenwPref(l - 1); }
void solve() {
  cin >> q;
  for (int i = (1); i < (q + 1); ++i) {
    char tp;
    cin >> tp;
    if (tp == '+') {
      int t, d;
      cin >> t >> d;
      que[i] = {1, t, d};
      pts.push_back(t);
    } else if (tp == '-') {
      int id;
      cin >> id;
      que[i] = {2, id, -1};
    } else {
      int t;
      cin >> t;
      pts.push_back(t);
      que[i] = {3, t, -1};
    }
  }
  sort((pts).begin(), (pts).end());
  pts.resize(unique((pts).begin(), (pts).end()) - pts.begin());
  m = (int)(pts).size();
  build(1, 0, m - 1);
  for (int i = (1); i < (q + 1); ++i) {
    int tp = que[i][0];
    if (tp == 1) {
      int t = que[i][1], d = que[i][2];
      int pos = lower_bound((pts).begin(), (pts).end(), t) - pts.begin();
      update(1, 0, m - 1, 0, pos, d);
      fenwUpd(pos, d);
    } else if (tp == 2) {
      int id = que[i][1];
      int t = que[id][1], d = que[id][2];
      int pos = lower_bound((pts).begin(), (pts).end(), t) - pts.begin();
      fenwUpd(pos, -d);
      update(1, 0, m - 1, 0, pos, -d);
    } else {
      int t = que[i][1];
      int pos = lower_bound((pts).begin(), (pts).end(), t) - pts.begin();
      long long ans = query(1, 0, m - 1, 0, pos);
      ans -= fenwSeg(pos + 1, m - 1);
      cout << max(0ll, ans - t) << '\n';
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
