#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
using namespace std;
long long poww(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}
const int maxn = 1000 * 1000 + 5;
const long long inf = 9223372036854775807;
const long long mod = 1e9 + 7;
const int lg = 20;
long long seg[4 * maxn], lazy[4 * maxn], q, cnt;
pair<long long, long long> p[maxn];
void build(int x = 1, int lx = 0, int rx = maxn) {
  if (rx - lx == 1) {
    seg[x] = rx;
    return;
  }
  int mid = lx + rx >> 1;
  build(x << 1, lx, mid);
  build(x << 1 | 1, mid, rx);
  seg[x] = max(seg[x << 1], seg[x << 1 | 1]);
}
void upd(int l, int r, long long v, int x = 1, int lx = 0, int rx = maxn) {
  if (lx >= r || rx <= l) return;
  if (lx >= l && rx <= r) {
    lazy[x] += v;
    seg[x] += v;
    return;
  }
  int mid = lx + rx >> 1;
  upd(l, r, v, x << 1, lx, mid);
  upd(l, r, v, x << 1 | 1, mid, rx);
  seg[x] = max(seg[x << 1], seg[x << 1 | 1]) + lazy[x];
}
long long get(int l, int r, int x = 1, int lx = 0, int rx = maxn) {
  if (lx >= r || rx <= l) return -inf;
  if (lx >= l && rx <= r) return seg[x];
  int mid = lx + rx >> 1;
  return max(get(l, r, x << 1, lx, mid), get(l, r, x << 1 | 1, mid, rx)) +
         lazy[x];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  build();
  char t;
  long long x, y;
  cin >> q;
  while (q--) {
    cin >> t;
    cnt++;
    if (t == '+') {
      cin >> x >> y;
      p[cnt].first = x;
      p[cnt].second = y;
      upd(x, maxn, -y);
    }
    if (t == '-') {
      cin >> x;
      y = p[x].second;
      x = p[x].first;
      upd(x, maxn, y);
    }
    if (t == '?') {
      cin >> x;
      y = get(0, x);
      x = get(x, x + 1);
      if (y - x + 1 > 0)
        cout << y - x + 1 << "\n";
      else
        cout << 0 << "\n";
    }
  }
}
