#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct fastio {
  char s[100000];
  int it, len;
  fastio() { it = len = 0; }
  inline char get() {
    if (it < len) return s[it++];
    it = 0;
    len = fread(s, 1, 100000, stdin);
    if (len == 0)
      return EOF;
    else
      return s[it++];
  }
  bool notend() {
    char c = get();
    while (c == ' ' || c == '\n') c = get();
    if (it > 0) it--;
    return c != EOF;
  }
} _buff;
inline long long getnum() {
  long long r = 0;
  bool ng = 0;
  char c;
  c = _buff.get();
  while (c != '-' && (c < '0' || c > '9')) c = _buff.get();
  if (c == '-') ng = 1, c = _buff.get();
  while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = _buff.get();
  return ng ? -r : r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline char getreal() {
  char c = _buff.get();
  while (c <= 32) c = _buff.get();
  return c;
}
long long qpow(long long x, long long k) {
  return k == 0 ? 1
                : 1ll * qpow(1ll * x * x % mod, k >> 1) * (k & 1 ? x : 1) % mod;
}
const int maxn = 4000111;
struct SGT {
  struct node {
    long long mx, lz;
    void addlz(long long L) {
      lz += L;
      mx += L;
    }
  } a[maxn];
  void pushdown(int p) {
    if (a[p].lz) {
      a[p << 1].addlz(a[p].lz);
      a[p << 1 | 1].addlz(a[p].lz);
      a[p].lz = 0;
    }
  }
  void update(int p) { a[p].mx = max(a[p << 1].mx, a[p << 1 | 1].mx); }
  void add(int x, int y, long long v, int l, int r, int p) {
    if (x <= l && r <= y) {
      a[p].addlz(v);
      return;
    }
    pushdown(p);
    int m = l + r >> 1;
    if (x <= m) add(x, y, v, l, m, p << 1);
    if (m < y) add(x, y, v, m + 1, r, p << 1 | 1);
    update(p);
  }
  long long query(int x, int y, int l, int r, int p) {
    if (x <= l && r <= y) return a[p].mx;
    pushdown(p);
    int m = l + r >> 1;
    long long ret = -1e18;
    if (x <= m) ret = max(ret, query(x, y, l, m, p << 1));
    if (m < y) ret = max(ret, query(x, y, m + 1, r, p << 1 | 1));
    return ret;
  }
  void build(int l, int r, int p) {
    if (l == r) {
      a[p].mx = l;
      a[p].lz = 0;
      return;
    }
    int m = l + r >> 1;
    build(l, m, p << 1);
    build(m + 1, r, p << 1 | 1);
    update(p);
  }
} sgt;
const int M = 1000111;
int n;
pair<int, int> q[maxn];
long long querysum(int x) { return -sgt.query(x + 1, x + 1, 1, M, 1) + x + 1; }
int main() {
  n = getnum();
  sgt.build(1, M, 1);
  for (int i = 1; i <= n; i++) {
    char op = getreal();
    int x, y;
    x = getnum();
    if (op == '?') {
      putnum(querysum(x) + sgt.query(1, x, 1, M, 1) - x), putchar('\n');
    } else if (op == '+') {
      y = getnum();
      q[i] = make_pair(x, y);
      sgt.add(x + 1, M, -y, 1, M, 1);
    } else {
      sgt.add(q[x].first + 1, M, q[x].second, 1, M, 1);
    }
  }
  return 0;
}
