#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
const int INF = (long long)1e9 + 5;
struct ST {
  long long f[4 * MAXN], tag[4 * MAXN];
  void pushdown(int idx) {
    if (tag[idx] == 0) return;
    f[idx << 1] += tag[idx];
    f[idx << 1 | 1] += tag[idx];
    tag[idx << 1] += tag[idx];
    tag[idx << 1 | 1] += tag[idx];
    tag[idx] = 0;
  }
  void add(int ql, int qr, int v, int l, int r, int idx) {
    if (r < ql || qr < l) return;
    if (ql <= l && r <= qr) {
      tag[idx] += v;
      f[idx] += v;
      return;
    }
    int m = (l + r) >> 1;
    pushdown(idx);
    add(ql, qr, v, l, m, idx << 1);
    add(ql, qr, v, m + 1, r, idx << 1 | 1);
    f[idx] = max(f[idx << 1], f[idx << 1 | 1]);
  }
  long long RMQ(int ql, int qr, int l, int r, int idx) {
    if (r < ql || qr < l) return -1e18;
    if (ql <= l && r <= qr) return f[idx];
    int m = (l + r) >> 1;
    pushdown(idx);
    long long q1 = RMQ(ql, qr, l, m, idx << 1);
    long long q2 = RMQ(ql, qr, m + 1, r, idx << 1 | 1);
    return max(q1, q2);
  }
} tree;
pair<int, int> past[MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  const int N = 1000001;
  for (int i = 1; i <= N; i++) {
    tree.add(i, i, i, 1, N, 1);
  }
  int Q;
  cin >> Q;
  for (int i = 1; i <= Q; i++) {
    char c;
    int t, d;
    cin >> c >> t;
    if (c == '?') {
      cout << tree.RMQ(1, t, 1, N, 1) - tree.RMQ(t + 1, t + 1, 1, N, 1) + 1
           << "\n";
    } else if (c == '+') {
      cin >> d;
      past[i] = {t, d};
      tree.add(t + 1, N, -d, 1, N, 1);
    } else {
      tie(t, d) = past[t];
      tree.add(t + 1, N, d, 1, N, 1);
    }
  }
}
