#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long MD = 1e9 + 7;
const long long MAXN = 1e5 + 1;
const long long BASE = 1e9;
long long maxN;
long long sumT[4000006];
long long mainT[8000007];
long long pushMainT[8000007];
pair<long long, long long> zp[800006];
void updateSumTree(long long v, long long tl, long long tr, long long pos,
                   long long val) {
  if (tl > tr) return;
  if (tl == pos && tr == pos) {
    sumT[v] = val;
    return;
  }
  long long tm = (tl + tr) / 2;
  if (pos <= tm)
    updateSumTree(v * 2, tl, tm, pos, val);
  else
    updateSumTree(v * 2 + 1, tm + 1, tr, pos, val);
  sumT[v] = sumT[v * 2] + sumT[v * 2 + 1];
}
long long getSumTree(long long v, long long tl, long long tr, long long l,
                     long long r) {
  if (l > r) return 0;
  if (tl == l && tr == r) {
    return sumT[v];
  }
  long long tm = (tl + tr) / 2;
  return getSumTree(v * 2, tl, tm, l, min(tm, r)) +
         getSumTree(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
}
void doPushMainT(long long v) {
  if (!pushMainT[v]) return;
  mainT[v * 2] += pushMainT[v];
  mainT[v * 2 + 1] += pushMainT[v];
  pushMainT[v * 2] += pushMainT[v];
  pushMainT[v * 2 + 1] += pushMainT[v];
  pushMainT[v] = 0;
}
void updateMainTree(long long v, long long tl, long long tr, long long l,
                    long long r, long long val) {
  doPushMainT(v);
  if (l > r) return;
  if (tl == l && tr == r) {
    mainT[v] += val;
    pushMainT[v] += val;
    return;
  }
  long long tm = (tl + tr) / 2;
  updateMainTree(v * 2, tl, tm, l, min(tm, r), val);
  updateMainTree(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r, val);
  mainT[v] = max(mainT[v * 2], mainT[v * 2 + 1]);
}
void updateMainTreeP(long long v, long long tl, long long tr, long long pos,
                     long long val) {
  doPushMainT(v);
  if (tl == pos && tr == pos) {
    mainT[v] = val;
    pushMainT[v] = val;
    return;
  }
  long long tm = (tl + tr) / 2;
  if (pos <= tm)
    updateMainTreeP(v * 2, tl, tm, pos, val);
  else
    updateMainTreeP(v * 2 + 1, tm + 1, tr, pos, val);
  mainT[v] = max(mainT[v * 2], mainT[v * 2 + 1]);
}
long long getMainTree(long long v, long long tl, long long tr, long long l,
                      long long r) {
  doPushMainT(v);
  if (l > r) return 0;
  if (tl == l && tr == r) {
    return mainT[v];
  }
  long long tm = (tl + tr) / 2;
  return max(getMainTree(v * 2, tl, tm, l, min(tm, r)),
             getMainTree(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
void printMainTree(long long a, long long b) {
  for (long long i = a; i <= b; i++)
    cout << getMainTree(1, 1, maxN, i, i) << " ";
  cout << endl;
}
signed main() {
  long long q;
  cin >> q;
  maxN = 1;
  while (maxN < 1e6) {
    maxN *= 2;
  }
  long long it = 0;
  while (q--) {
    it++;
    char ch;
    cin >> ch;
    if (ch == '+') {
      long long ti, di;
      cin >> ti >> di;
      updateSumTree(1, 1, maxN, ti, di);
      updateMainTree(1, 1, maxN, 1, ti - 1, di);
      long long sum = getSumTree(1, 1, maxN, ti, maxN);
      updateMainTreeP(1, 1, maxN, ti, ti + sum);
      zp[it] = {ti, di};
    }
    if (ch == '?') {
      long long ti;
      cin >> ti;
      long long val = getMainTree(1, 1, maxN, 1, ti);
      long long toMinus = getSumTree(1, 1, maxN, ti + 1, maxN);
      cout << max(0ll, val - toMinus - ti) << endl;
    }
    if (ch == '-') {
      long long i;
      cin >> i;
      long long ti = zp[i].first;
      long long di = zp[i].second;
      updateSumTree(1, 1, maxN, ti, 0);
      updateMainTree(1, 1, maxN, 1, ti - 1, -di);
      updateMainTreeP(1, 1, maxN, ti, 0);
    }
  }
}
