#include <bits/stdc++.h>
using namespace std;
int n, ma, a1;
long long ans;
char ch;
struct point {
  int a, b;
} s[1000005];
struct node {
  int l, r;
  long long add, sum, ma;
  node *ch[2];
} * nil, *root;
long long gets() {
  long long v = 0;
  bool f = 0;
  char ch;
  while (!isdigit(ch)) {
    f |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    v = (v << 3) + (v << 1) + ch - 48;
    ch = getchar();
  }
  return f ? -v : v;
}
void init() {
  nil = new node();
  nil->ch[0] = nil->ch[1] = nil;
  nil->add = nil->ma = nil->sum = 0;
}
void pushup(node *x) {
  x->ma = max(x->ch[0]->ma + x->ch[1]->sum, x->ch[1]->ma);
  x->sum = x->ch[0]->sum + x->ch[1]->sum;
}
void build(node *&x, int l, int r) {
  x = new node();
  x->l = l, x->r = r;
  x->ma = x->sum = 0;
  if (l == r) {
    x->ma = x->l;
    return;
  }
  int mid = l + r >> 1;
  build(x->ch[0], l, mid);
  build(x->ch[1], mid + 1, r);
  pushup(x);
}
void insert(node *x, int pos, long long v) {
  if (x->r == x->l && x->r == pos) {
    x->ma += v, x->sum += v;
    return;
  }
  int mid = x->l + x->r >> 1;
  if (pos <= mid)
    insert(x->ch[0], pos, v);
  else
    insert(x->ch[1], pos, v);
  pushup(x);
}
void ask(node *x, int l, int r) {
  if (l == x->l && r == x->r) {
    ans = max(ans + x->sum, x->ma);
    return;
  }
  int mid = x->l + x->r >> 1;
  if (r <= mid)
    ask(x->ch[0], l, r);
  else if (l > mid)
    ask(x->ch[1], l, r);
  else
    ask(x->ch[0], l, mid), ask(x->ch[1], mid + 1, r);
}
int main() {
  n = gets();
  ma = 1000000;
  init();
  build(root, 1, ma);
  for (int i = 1; i <= n; i++) {
    scanf("%c", &ch);
    if (ch == '?') {
      a1 = gets();
      ans = 0;
      ask(root, 1, a1);
      ans -= a1;
      printf("%I64d\n", ans);
    }
    if (ch == '+') {
      s[i].a = gets(), s[i].b = gets();
      insert(root, s[i].a, s[i].b);
    }
    if (ch == '-') {
      a1 = gets();
      insert(root, s[a1].a, -s[a1].b);
    }
  }
  return 0;
}
