#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long maxn = 1e6 + 5, mod = 1e9 + 7, inf = mod;
long long q;
long long d[maxn], dur[maxn];
long long late[4 * maxn];
long long sum[4 * maxn];
void up(long long i, long long l, long long r, long long pos, long long dur) {
  if (l > pos or pos > r) return;
  if (l == r) {
    if (!dur) {
      late[i] = sum[i] = 0;
    } else {
      late[i] = pos + dur;
      sum[i] = dur;
    }
  } else {
    long long m = (l + r) / 2;
    up(2 * i, l, m, pos, dur);
    up(2 * i + 1, m + 1, r, pos, dur);
    if (!late[2 * i + 1])
      late[i] = late[2 * i];
    else
      late[i] = max(late[2 * i + 1], late[2 * i] + sum[2 * i + 1]);
    sum[i] = sum[2 * i] + sum[2 * i + 1];
  }
}
pair<long long, long long> get(long long i, long long l, long long r,
                               long long ll, long long rr) {
  if (l > rr or ll > r) return {0, 0};
  if (ll <= l and r <= rr) {
    return {late[i], sum[i]};
  } else {
    long long m = (l + r) / 2;
    pair<long long, long long> t1 = get(2 * i, l, m, ll, rr);
    pair<long long, long long> t2 = get(2 * i + 1, m + 1, r, ll, rr);
    if (!t2.first) {
      return t1;
    }
    return {max(t2.first, t1.first + t2.second), t1.second + t2.second};
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> q;
  for (long long i = (long long)1; i <= (long long)q; i++) {
    char t;
    cin >> t;
    if (t == '+') {
      cin >> d[i] >> dur[i];
      up(1, 1, maxn - 1, d[i], dur[i]);
    } else if (t == '-') {
      long long id;
      cin >> id;
      up(1, 1, maxn - 1, d[id], 0);
    } else {
      long long d;
      cin >> d;
      pair<long long, long long> t = get(1, 1, maxn - 1, 1, d);
      cout << max(t.first - d, 0ll) << '\n';
    }
  }
}
