#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long large = 2000000000000000000LL;
int sz;
map<int, int> comp;
vector<long long> addv, maxi;
int ul, ur;
long long uv;
void update(int o, int l, int r) {
  if (ur < ul) return;
  if (ul <= l && ur >= r) {
    addv[o] += uv;
    maxi[o] += uv;
  } else {
    int m = (l + r) / 2;
    if (ul <= m) update(o * 2, l, m);
    if (ur > m) update(o * 2 + 1, m + 1, r);
    maxi[o] = max(maxi[o * 2], maxi[o * 2 + 1]);
    maxi[o] += addv[o];
  }
}
int ql, qr;
long long re;
void query(int o, int l, int r, long long add) {
  if (qr < ql || ql >= sz || qr < 0) return;
  if (ql <= l && qr >= r) {
    re = max(re, maxi[o] + add);
  } else {
    int m = (l + r) / 2;
    if (ql <= m) query(o * 2, l, m, add + addv[o]);
    if (qr > m) query(o * 2 + 1, m + 1, r, add + addv[o]);
  }
}
int main() {
  int n;
  cin >> n;
  vector<pair<int, pair<int, int> > > eve;
  for (int i = 0; i < n; i++) {
    char c;
    cin >> c;
    int a, b;
    if (c == '?') {
      cin >> a;
      eve.push_back(pair<int, pair<int, int> >(-1, pair<int, int>(a, -1)));
    }
    if (c == '+') {
      cin >> a >> b;
      eve.push_back(pair<int, pair<int, int> >(0, pair<int, int>(a, b)));
    }
    if (c == '-') {
      cin >> a;
      eve.push_back(pair<int, pair<int, int> >(1, pair<int, int>(a, -1)));
    }
  }
  n++;
  eve.push_back(pair<int, pair<int, int> >(0, pair<int, int>(0, 0)));
  vector<int> t;
  for (int i = 0; i < n; i++) {
    if (eve[i].first == 0) {
      t.push_back(eve[i].second.first);
    }
  }
  sort(t.begin(), t.end());
  t.erase(unique(t.begin(), t.end()), t.end());
  sz = (int)t.size();
  for (int i = 0; i < (int)t.size(); i++) {
    comp[t[i]] = i;
  }
  vector<long long> ti(sz, 0), du(sz, 0);
  vector<int> id(n + 1, -1);
  for (int i = 0; i < n; i++) {
    if (eve[i].first == 0) {
      int p = comp[eve[i].second.first];
      id[i + 1] = p;
    }
  }
  addv.assign(4 * sz + 10, 0);
  maxi.assign(4 * sz + 10, 0);
  vector<long long> act(sz, 0);
  for (int i = 0; i < n; i++) {
    int ty = eve[i].first;
    if (ty == -1) {
      int p = upper_bound(t.begin(), t.end(), eve[i].second.first) - t.begin();
      p--;
      ql = 0;
      qr = p;
      re = 0;
      query(1, 0, sz - 1, 0);
      long long temp = re;
      if (p + 1 < sz) {
        ql = p + 1;
        qr = p + 1;
        re = 0;
        query(1, 0, sz - 1, 0);
        temp -= re;
        temp += ti[p + 1] * act[p + 1];
      }
      temp = max(temp, 1LL * eve[i].second.first);
      temp -= eve[i].second.first;
      temp = max(temp, 0LL);
      cout << temp << endl;
    }
    if (ty == 0) {
      int p = comp[eve[i].second.first];
      act[p]++;
      ti[p] = eve[i].second.first;
      du[p] = eve[i].second.second;
      ul = ur = p;
      uv = ti[p];
      update(1, 0, sz - 1);
      ul = 0;
      ur = p;
      uv = du[p];
      update(1, 0, sz - 1);
    }
    if (ty == 1) {
      int p = id[eve[i].second.first];
      act[p]--;
      ul = ur = p;
      uv = -ti[p];
      update(1, 0, sz - 1);
      ul = 0;
      ur = p;
      uv = -du[p];
      update(1, 0, sz - 1);
    }
  }
  return 0;
}
