#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
using namespace std;
using lli = long long;
using ld = long double;
using ii = pair<int, int>;
using vi = vector<int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 3e5 + 5;
const int inf = 1e6 + 5;
struct Lazy {
  int l, r;
  lli sum = 0, lazy = 0;
  Lazy *L, *R;
  Lazy(int l, int r) : l(l), r(r), L(0), R(0) {
    if (l == r) {
      sum = 0;
      return;
    }
    int m = (l + r) >> 1;
    L = new Lazy(l, m);
    R = new Lazy(m + 1, r);
    pull();
  }
  void push() {
    if (!lazy) return;
    sum += lazy;
    if (l != r) {
      L->lazy += lazy;
      R->lazy += lazy;
    }
    lazy = 0;
  }
  void pull() { sum = max(L->sum, R->sum); }
  void update(int ll, int rr, lli v) {
    push();
    if (rr < l || r < ll) return;
    if (ll <= l && r <= rr) {
      lazy += v;
      push();
      return;
    }
    L->update(ll, rr, v);
    R->update(ll, rr, v);
    pull();
  }
  lli query(int ll, int rr) {
    push();
    if (rr < l || r < ll) return 0;
    if (ll <= l && r <= rr) return sum;
    return max(L->query(ll, rr), R->query(ll, rr));
  }
} * tree;
char op;
pair<lli, lli> knight[N];
bitset<inf> vis;
lli x, d;
int q, j;
int main() {
  cin.tie(0)->sync_with_stdio(0), cout.tie(0);
  cin >> q;
  tree = new Lazy(0, inf);
  for (auto i = (1) - ((1) > (q + 1)); i != q + 1 - ((1) > (q + 1));
       i += 1 - 2 * ((1) > (q + 1))) {
    cin >> op;
    if (op == '+') {
      cin >> x >> d;
      ;
      knight[i] = {x, d};
      tree->update(x, x, x);
      tree->update(1, x, d);
      vis[x] = 1;
    } else if (op == '-') {
      cin >> j;
      x = knight[j].first, d = knight[j].second;
      ;
      tree->update(x, x, -x);
      tree->update(1, x, -d);
      vis[x] = 0;
    } else {
      cin >> x;
      ;
      lli wait = tree->query(x + 1, x + 1) - (vis[x + 1] ? x + 1 : 0);
      ;
      ;
      cout << max(0LL, tree->query(1, x) - wait - x) << '\n';
    };
    ;
  }
  return 0;
}
