#include <bits/stdc++.h>
using namespace std;
struct segment_tree {
  vector<long long> st, sum, lazy;
  segment_tree(vector<int> &v)
      : st(4 * v.size()), sum(4 * v.size()), lazy(4 * v.size()) {
    init(1, 0, v.size(), v);
  }
  void init(int p, int b, int e, vector<int> &v) {
    if (b + 1 == e)
      st[p] = v[b];
    else {
      int l = p << 1, r = l | 1, m = (b + e) >> 1;
      init(l, b, m, v);
      init(r, m, e, v);
      st[p] = max(st[l], st[r]);
    }
  }
  void push(int p) {
    if (lazy[p]) {
      int l = p << 1, r = l | 1;
      st[l] += lazy[p];
      lazy[l] += lazy[p];
      st[r] += lazy[p];
      lazy[r] += lazy[p];
      lazy[p] = 0;
    }
  }
  void update_max(int p, int b, int e, int x, int y, long long v) {
    if (x <= b && e <= y)
      st[p] += v, lazy[p] += v;
    else {
      push(p);
      int l = p << 1, r = l | 1, m = (b + e) >> 1;
      if (x < m) update_max(l, b, m, x, y, v);
      if (m < y) update_max(r, m, e, x, y, v);
      st[p] = max(st[l], st[r]);
    }
  }
  void update_sum(int p, int b, int e, int x, long long v) {
    if (b + 1 == e)
      sum[p] += v;
    else {
      int l = p << 1, r = l | 1, m = (b + e) >> 1;
      if (x < m)
        update_sum(l, b, m, x, v);
      else
        update_sum(r, m, e, x, v);
      sum[p] = sum[l] + sum[r];
    }
  }
  long long query_max(int p, int b, int e, int x, int y) {
    if (x <= b && e <= y)
      return st[p];
    else {
      push(p);
      long long ans = 0;
      int l = p << 1, r = l | 1, m = (b + e) >> 1;
      if (x < m) ans = max(ans, query_max(l, b, m, x, y));
      if (m < y) ans = max(ans, query_max(r, m, e, x, y));
      return ans;
    }
  }
  long long query_sum(int p, int b, int e, int x, int y) {
    if (x <= b && e <= y)
      return sum[p];
    else {
      long long ans = 0;
      int l = p << 1, r = l | 1, m = (b + e) >> 1;
      if (x < m) ans += query_sum(l, b, m, x, y);
      if (m < y) ans += query_sum(r, m, e, x, y);
      return ans;
    }
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string op;
  vector<int> comp = {0, (int)1e9};
  vector<pair<int, int> > queries(n);
  for (int i = 0; i < n; ++i) {
    cin >> op;
    if (op == "+") {
      int t, d;
      cin >> t >> d;
      queries[i] = {t, d};
      comp.push_back(t);
    } else if (op == "-") {
      int p;
      cin >> p;
      queries[i] = queries[p - 1];
      queries[i].first = -queries[i].first;
    } else {
      int t;
      cin >> t;
      queries[i] = {0, t};
      comp.push_back(t);
    }
  }
  sort(comp.begin(), comp.end());
  comp.resize(distance(comp.begin(), unique(comp.begin(), comp.end())));
  for (auto &el : queries) {
    if (el.first == 0)
      el.second = distance(comp.begin(),
                           lower_bound(comp.begin(), comp.end(), el.second));
    else if (el.first > 0)
      el.first = distance(comp.begin(),
                          lower_bound(comp.begin(), comp.end(), el.first));
    else
      el.first = -distance(comp.begin(),
                           lower_bound(comp.begin(), comp.end(), -el.first));
  }
  n = comp.size();
  segment_tree st(comp);
  for (auto &q : queries) {
    if (q.first > 0) {
      st.update_max(1, 0, n, 0, q.first + 1, +q.second);
      st.update_sum(1, 0, n, q.first, +q.second);
    } else if (q.first < 0) {
      q.first = -q.first;
      st.update_max(1, 0, n, 0, q.first + 1, -q.second);
      st.update_sum(1, 0, n, q.first, -q.second);
    } else
      cout << st.query_max(1, 0, n, 0, q.second + 1) -
                  st.query_sum(1, 0, n, q.second + 1, n) - comp[q.second]
           << '\n';
  }
  return 0;
}
