#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 20);
struct Tree {
  long long sum[2 * N] = {}, last[2 * N];
  void touch(int v) {
    sum[v] = sum[2 * v] + sum[2 * v + 1];
    last[v] = max(last[2 * v] + sum[2 * v + 1], last[2 * v + 1]);
  }
  Tree() {
    for (int i = 0; i < N; ++i) last[i + N] = i;
    for (int i = N - 1; i >= 1; --i) touch(i);
  }
  void update(int v, long long d) {
    v += N;
    last[v] = v - N + d;
    sum[v] = d;
    while (v / 2 != 0) {
      v /= 2;
      touch(v);
    }
  }
  long long query(int t) {
    t += N;
    long long res = last[t], s = sum[t];
    while (t != 1) {
      if (t % 2 == 1) {
        res = max(res, last[t - 1] + s);
        s += sum[t - 1];
      }
      t /= 2;
    }
    return res;
  }
};
Tree tr;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int n;
  cin >> n;
  vector<int> hist;
  while (n--) {
    char q;
    cin >> q;
    if (q == '?') {
      int t;
      cin >> t;
      hist.push_back(0);
      cout << tr.query(t) - t << "\n";
    } else if (q == '+') {
      int t, d;
      cin >> t >> d;
      hist.push_back(t);
      tr.update(t, d);
    } else if (q == '-') {
      int num;
      cin >> num;
      --num;
      hist.push_back(0);
      tr.update(hist[num], 0);
    }
  }
}
