#include <bits/stdc++.h>
using namespace std;
struct qt {
  char t[2];
  int d1;
  int d2;
};
qt qq[333333];
multimap<int, int> tmap;
int inx[333333];
struct block {
  int parent;
  int start;
  int delay;
  bool alloc;
};
struct header {
  int alloc;
  int l, r;
  long long start;
  long long end;
  long long gap;
  long long ovf;
  long long laststart;
  long long total;
};
header hd[111111];
block blk[333333];
int rind[333333];
int rnk = 0;
int main() {
  int q;
  scanf("%i", &q);
  for (int i = 0; i < q; i++) {
    scanf("%s", &qq[i].t);
    switch (qq[i].t[0]) {
      case '?':
        scanf("%i", &qq[i].d1);
        break;
      case '+':
        scanf("%i", &qq[i].d1);
        scanf("%i", &qq[i].d2);
        tmap.insert(make_pair(qq[i].d1, i));
        break;
      case '-':
        scanf("%i", &qq[i].d1);
        break;
    }
  }
  int pff = 0;
  for (auto x : tmap) {
    inx[x.second] = pff++;
  }
  int n = sqrt(pff);
  double step = pff / ((double)n);
  for (int i = 0; i < n; i++) {
    int l = i * step;
    int r = (i + 1) * step;
    r--;
    if (i == n - 1) r = pff - 1;
    hd[i].alloc = 0;
    hd[i].l = l;
    hd[i].r = r;
    for (int j = l; j <= r; j++) {
      blk[j].parent = i;
      blk[j].alloc = 0;
    }
  }
  for (int qn = 0; qn < q; qn++) {
    qt *cq = &qq[qn];
    if (cq->t[0] == '+') {
      int ind = inx[qn];
      rind[qn] = ind;
      block *bl = &blk[ind];
      header *bh = &hd[bl->parent];
      bl->start = cq->d1;
      bl->delay = cq->d2;
      bh->alloc++;
      bl->alloc = 1;
      if (bh->alloc) {
        bh->start = 1LL << 60;
        bh->laststart = -1LL << 60;
        bh->total = 0;
        bh->gap = 0;
        bh->ovf = 0;
        long long timer = -1;
        for (int j = bh->l; j <= bh->r; j++) {
          block *bl = &blk[j];
          if (!bl->alloc) continue;
          if (timer == -1) timer = blk[j].start;
          if (timer < blk[j].start) {
            bh->gap += blk[j].start - timer;
            timer = blk[j].start + blk[j].delay;
          } else {
            bh->ovf += timer - blk[j].start;
            timer += blk[j].delay;
          }
          bh->start = min<long long>(bh->start, blk[j].start);
          bh->laststart = blk[j].start;
          bh->total += blk[j].delay;
          bh->end = blk[j].start + blk[j].delay;
        }
        long long tt = max<long long>(0, timer - bh->end);
        bh->ovf = tt;
      }
    } else if (cq->t[0] == '-') {
      int ind = rind[cq->d1 - 1];
      block *bl = &blk[ind];
      header *bh = &hd[bl->parent];
      bl->alloc = 0;
      bh->alloc--;
      if (bh->alloc) {
        bh->start = 1LL << 60;
        bh->laststart = -1LL << 60;
        bh->total = 0;
        bh->gap = 0;
        bh->ovf = 0;
        long long timer = -1;
        for (int j = bh->l; j <= bh->r; j++) {
          block *bl = &blk[j];
          if (!bl->alloc) continue;
          if (timer == -1) timer = blk[j].start;
          if (timer < blk[j].start) {
            bh->gap += blk[j].start - timer;
            timer = blk[j].start + blk[j].delay;
          } else {
            bh->ovf += timer - blk[j].start;
            timer += blk[j].delay;
          }
          bh->start = min<long long>(bh->start, blk[j].start);
          bh->laststart = blk[j].start;
          bh->total += blk[j].delay;
          bh->end = blk[j].start + blk[j].delay;
        }
        long long tt = max<long long>(0, timer - bh->end);
        bh->ovf = tt;
      }
    } else {
      static int pLine = 0;
      if (++pLine == 38) pLine = 38;
      int j = 0;
      long long pct = cq->d1;
      long long timer = 0;
      for (j = 0; j < n; j++) {
        header *bh = &hd[j];
        if (!bh->alloc) continue;
        if (j == 63) j = 63;
        if (pct < bh->laststart) break;
        long long start = bh->start;
        long long laststart = bh->laststart;
        long long total = bh->total;
        long long end = bh->end + bh->ovf;
        long long ovf = max<long long>(0, timer - start);
        long long gap = bh->gap;
        ovf = max<long long>(0, ovf - gap);
        timer = end + ovf;
      }
      if (j == n) {
        long long ans = max<long long>(timer - pct, 0);
        printf("%lld\n", ans);
      } else {
        header *bh = &hd[j];
        int l = bh->l;
        int r = bh->r;
        for (int j = l; j <= r; j++) {
          block *bl = &blk[j];
          if (!bl->alloc) continue;
          if (bl->start <= pct) {
            long long start = bl->start;
            long long end = bl->delay + start;
            long long ovf = max<long long>(0, timer - start);
            timer = ovf + end;
          } else
            break;
        }
        long long ans = max<long long>(timer - pct, 0);
        printf("%lld\n", ans);
      }
    }
  }
}
