#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MAX = 2e6 + 50;
const int mod = 51123987;
int p[MAX], v[MAX];
long long sum[MAX << 2], mx[MAX << 2], ans;
void build(int rt, int l, int r) {
  if (l == r) {
    mx[rt] = l;
    return;
  }
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  mx[rt] = max(mx[rt << 1 | 1], mx[rt << 1] + sum[rt << 1 | 1]);
}
void updata(int rt, int l, int r, int x, long long val) {
  if (l == r) {
    mx[rt] += val;
    sum[rt] += val;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    updata(rt << 1, l, mid, x, val);
  else
    updata(rt << 1 | 1, mid + 1, r, x, val);
  mx[rt] = max(mx[rt << 1 | 1], mx[rt << 1] + sum[rt << 1 | 1]);
  sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
  return;
}
long long query(int rt, int l, int r, int x) {
  if (x >= r) {
    ans = max(mx[rt], ans + sum[rt]);
    return ans;
  }
  int mid = (l + r) >> 1;
  query(rt << 1, l, mid, x);
  if (x > mid) query(rt << 1 | 1, mid + 1, r, x);
  return ans;
}
int main() {
  char op;
  int N = 1e6;
  build(1, 1, N);
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> op >> p[i];
    if (op == '+') {
      cin >> v[i];
      updata(1, 1, N, p[i], v[i]);
    } else if (op == '-') {
      updata(1, 1, N, p[p[i]], -v[p[i]]);
    } else {
      ans = 0;
      cout << query(1, 1, N, p[i]) - p[i] << "\n";
    }
  }
  return 0;
}
