#include <bits/stdc++.h>
using namespace std;
const int m = 1e6;
const long long oo = 1e12;
int n, d[1000002], q[1000002];
long long bit[1000002];
struct node {
  long long val, lazy;
};
node it[4000002];
void update_bit(int i, long long val) {
  for (i; i <= m; i += i & (-i)) bit[i] += val;
}
long long get(int i) {
  long long ans = 0;
  for (i; i >= 1; i -= i & (-i)) ans += bit[i];
  return ans;
}
void down(int id) {
  long long t = it[id].lazy;
  it[id].lazy = 0;
  it[id * 2].val += t;
  it[id * 2].lazy += t;
  it[id * 2 + 1].val += t;
  it[id * 2 + 1].lazy += t;
}
void update(int id, int l, int r, int a, int b, long long val) {
  if (l > b || r < a) return;
  if (l >= a && r <= b) {
    it[id].val += val;
    it[id].lazy += val;
    return;
  }
  int mid = (l + r) / 2;
  down(id);
  update(id * 2, l, mid, a, b, val);
  update(id * 2 + 1, mid + 1, r, a, b, val);
  it[id].val = max(it[id * 2].val, it[id * 2 + 1].val);
}
long long query(int id, int l, int r, int a, int b) {
  if (l > b || r < a) return -1e12;
  if (l >= a && r <= b) return it[id].val;
  int mid = (l + r) / 2;
  down(id);
  return max(query(id * 2, l, mid, a, b), query(id * 2 + 1, mid + 1, r, a, b));
}
void solve() {
  cin >> n;
  for (int i = 1; i <= 4 * m; i++) it[i].val = -oo, it[i].lazy = 0;
  for (int i = 1; i <= n; i++) {
    char c;
    cin >> c;
    if (c == '+') {
      int t;
      cin >> t;
      cin >> d[t];
      update(1, 1, m, t, t, (long long)t + oo);
      if (t < m) update(1, 1, m, t + 1, m, -d[t]);
      update_bit(t, d[t]);
      q[i] = t;
    }
    if (c == '-') {
      int t;
      cin >> t;
      t = q[t];
      if (t < m) update(1, 1, m, t + 1, m, d[t]);
      update(1, 1, m, t, t, (long long)-t - oo);
      update_bit(t, -d[t]);
      d[t] = 0;
    }
    if (c == '?') {
      int t;
      cin >> t;
      long long res = query(1, 1, m, 1, t);
      res += get(t);
      if (res - t < 0)
        cout << 0 << '\n';
      else
        cout << res - t << '\n';
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
