#include <bits/stdc++.h>
using namespace std;
const int QMAX = 3e5;
const int NMAX = 1e6;
int op[QMAX + 2];
pair<long long, long long> aint[4 * NMAX];
int pos, t;
pair<long long, long long> ans;
pair<long long, long long> Join(pair<long long, long long> A,
                                pair<long long, long long> B) {
  return {max(B.first, A.first + B.second), A.second + B.second};
}
void Update(int node, int st, int dr) {
  if (st > pos || dr < pos) return;
  if (st == dr) {
    if (t == 0)
      aint[node] = {0, 0};
    else
      aint[node] = {st + t, t};
    return;
  }
  int mid = (st + dr) >> 1;
  Update(2 * node, st, mid);
  Update(2 * node + 1, mid + 1, dr);
  aint[node] = Join(aint[2 * node], aint[2 * node + 1]);
}
void Query(int node, int st, int dr) {
  if (st > pos) return;
  if (dr <= pos) {
    ans = Join(ans, aint[node]);
    return;
  }
  int mid = (st + dr) >> 1;
  Query(2 * node, st, mid);
  Query(2 * node + 1, mid + 1, dr);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  for (int i = 1; i <= T; i++) {
    char c;
    int x, y;
    cin >> c;
    if (c == '+') {
      cin >> x >> y;
      op[i] = x;
      pos = x;
      t = y;
      Update(1, 1, NMAX);
    } else if (c == '-') {
      cin >> x;
      pos = op[x];
      t = 0;
      Update(1, 1, NMAX);
    } else {
      cin >> x;
      pos = x;
      ans = {0, 0};
      Query(1, 1, NMAX);
      cout << max(0LL, ans.first - x) << '\n';
    }
  }
  return 0;
}
