#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
constexpr auto MOD = 1000000007LL;
constexpr auto LINF = (1LL << 60);
constexpr auto INF = 2147483647LL;
constexpr auto PI = 3.1415926535897932384626433;
constexpr auto EPS = 1E-9;
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> p) {
  out << p.first << ' ' << p.second;
  return out;
}
template <typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
  in >> p.first >> p.second;
  return in;
}
template <typename T>
istream &operator>>(istream &in, vector<T> &v) {
  for (auto &x : v) in >> x;
  return in;
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> v) {
  for (int i = 0; i < v.size(); i++)
    out << v[i] << (i + 1 == v.size() ? '\n' : ' ');
  out.flush();
  return out;
}
struct Node {
  int l, r;
  int emp;
  ll end;
  Node() {}
} T[1000010 << 2];
void maintain(int id) {
  ll ext = max(0LL, T[id << 1].end - T[id << 1 | 1].l);
  T[id].emp = T[id << 1].emp + max(0LL, T[id << 1 | 1].emp - ext) +
              max(0LL, T[id << 1 | 1].l - T[id << 1].end);
  T[id].end = max(0LL, ext - T[id << 1 | 1].emp) + T[id << 1 | 1].end;
  return;
}
void build(int id = 1, int l = 0, int r = 1e6) {
  T[id].l = l;
  T[id].r = r;
  T[id].emp = 0;
  T[id].end = l;
  if (l + 1 == r) {
    return;
  }
  build(id << 1, l, l + r >> 1);
  build(id << 1 | 1, l + r >> 1, r);
  return;
}
void add(int t, int d, int id = 1, int l = 0, int r = 1e6) {
  if (t >= r || l > t) return;
  if (l + 1 == r) {
    T[id].emp = 0;
    T[id].end = t + d;
    return;
  }
  add(t, d, id << 1, l, l + r >> 1);
  add(t, d, id << 1 | 1, l + r >> 1, r);
  maintain(id);
  return;
}
void rem(int t, int id = 1, int l = 0, int r = 1e6) {
  if (t >= r || l > t) return;
  if (l + 1 == r) {
    T[id].emp = 0;
    T[id].end = l;
    return;
  }
  rem(t, id << 1, l, l + r >> 1);
  rem(t, id << 1 | 1, l + r >> 1, r);
  maintain(id);
  return;
}
void ask(int t, ll &res, int id = 1, int l = 0, int r = 1e6) {
  if (l > t) return;
  if (t + 1 >= r) {
    ll ext = max(0LL, res - T[id].l);
    ext = max(0LL, ext - T[id].emp);
    res = T[id].end + ext;
    return;
  }
  ask(t, res, id << 1, l, l + r >> 1);
  ask(t, res, id << 1 | 1, l + r >> 1, r);
  return;
}
int records[300010];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  build();
  string op;
  for (int i = 1; i <= n; i++) {
    cin >> op;
    if (op == "?") {
      int t;
      ll res = -1;
      cin >> t;
      --t;
      ask(t, res);
      cout << max(0LL, res - t) << endl;
    } else if (op == "+") {
      int d;
      cin >> records[i] >> d;
      --records[i];
      add(records[i], d);
    } else if (op == "-") {
      int id;
      cin >> id;
      rem(records[id]);
    }
  }
  return 0;
}
