#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1e6 + 10;
const long long mod = 1e9 + 7;
const long double PI = acos((long double)-1);
long long pw(long long a, long long b, long long md = mod) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res = (a * res) % md;
    }
    a = (a * a) % md;
    b >>= 1;
  }
  return (res);
}
long long mx[maxn << 2], lazy[maxn << 2];
void add(int L, int R, long long x, int v = 1, int l = 0, int r = maxn) {
  if (r <= L or R <= l) return;
  if (L <= l and r <= R) {
    lazy[v] += x;
    return;
  }
  add(L, R, x, (v << 1), l, ((l + r) >> 1));
  add(L, R, x, ((v << 1) | 1), ((l + r) >> 1), r);
  mx[v] = max(mx[(v << 1)] + lazy[(v << 1)],
              mx[((v << 1) | 1)] + lazy[((v << 1) | 1)]);
}
long long get(int L, int R, int v = 1, int l = 0, int r = maxn) {
  if (r <= L or R <= l) return (-1e15);
  if (L <= l and r <= R) return (mx[v] + lazy[v]);
  return (max(get(L, R, (v << 1), l, ((l + r) >> 1)),
              get(L, R, ((v << 1) | 1), ((l + r) >> 1), r)) +
          lazy[v]);
}
int n;
pair<int, int> q[maxn];
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < maxn; i++) add(i, i + 1, i - maxn);
  for (int i = 0; i < n; i++) {
    char t;
    cin >> t;
    if (t == '?') {
      int ti;
      cin >> ti;
      cout << get(0, ti + 1) - get(ti + 1, ti + 2) + 1 << '\n';
    }
    if (t == '+') {
      int ti, d;
      cin >> ti >> d;
      q[i] = {ti, d};
      add(0, ti + 1, d);
    }
    if (t == '-') {
      int pos;
      cin >> pos;
      auto [ti, d] = q[pos - 1];
      add(0, ti + 1, -d);
    }
  }
  return (0);
}
