#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int T[N], D[N], n, q;
long long int fen[N], mx[N << 2], lzy[N << 2];
void upd(int pos, int x) {
  for (pos++; pos < N; pos += pos & -pos) fen[pos] += x;
}
long long int get(int pos) {
  long long int res = 0;
  for (pos++; pos; pos -= pos & -pos) res += fen[pos];
  return res;
}
void shift(int id, int l, int r) {
  mx[id] += lzy[id];
  if (r - l > 1) {
    lzy[id << 1] += lzy[id];
    lzy[id << 1 | 1] += lzy[id];
  }
  lzy[id] = 0;
}
void update(int ql, int qr, int x, int id = 1, int l = 0, int r = N) {
  shift(id, l, r);
  if (qr <= l || r <= ql) return;
  if (ql <= l && r <= qr) {
    lzy[id] += x;
    return shift(id, l, r);
  }
  int mid = (l + r) >> 1;
  update(ql, qr, x, id << 1, l, mid);
  update(ql, qr, x, id << 1 | 1, mid, r);
  mx[id] = max(mx[id << 1], mx[id << 1 | 1]);
}
long long int get(int ql, int qr, int id = 1, int l = 0, int r = N) {
  shift(id, l, r);
  if (qr <= l || r <= ql) return 0;
  if (ql <= l && r <= qr) return mx[id];
  int mid = (l + r) >> 1;
  return max(get(ql, qr, id << 1, l, mid), get(ql, qr, id << 1 | 1, mid, r));
}
int main() {
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    char second;
    int t;
    cin >> second >> t;
    if (second == '+') {
      T[i] = t;
      scanf("%d", &D[i]);
      upd(T[i], D[i]);
      update(T[i], T[i] + 1, T[i]);
      update(0, T[i] + 1, D[i]);
    } else if (second == '-') {
      upd(T[t], -D[t]);
      update(T[t], T[t] + 1, -T[t]);
      update(0, T[t] + 1, -D[t]);
    } else {
      printf("%lld\n", max(0ll, get(0, t + 1) - t - (get(N - 2) - get(t))));
    }
  }
  return 0;
}
