#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
struct tree {
  long long val, sum;
} t[N * 4];
int a[N];
void cha(int x, int l, int r, int p, int q) {
  if (l == r) {
    t[x].sum = q;
    if (q)
      t[x].val = l + q;
    else
      t[x].val = 0;
    return;
  }
  int mid = (l + r) >> 1;
  if (p <= mid)
    cha(x << 1, l, mid, p, q);
  else
    cha(x << 1 | 1, mid + 1, r, p, q);
  t[x].sum = t[x << 1].sum + t[x << 1 | 1].sum;
  t[x].val = max(t[x << 1].val + t[x << 1 | 1].sum, t[x << 1 | 1].val);
}
long long get2(int x, int l, int r, int p) {
  if (r <= p) return t[x].sum;
  int mid = (l + r) >> 1;
  if (p <= mid)
    return get2(x << 1, l, mid, p);
  else
    return get2(x << 1, l, mid, mid) + get2(x << 1 | 1, mid + 1, r, p);
}
long long get(int x, int l, int r, int p) {
  if (r <= p) return t[x].val;
  int mid = (l + r) >> 1;
  if (p <= mid)
    return get(x << 1, l, mid, p);
  else
    return max(get(x << 1, l, mid, mid) + get2(x << 1 | 1, mid + 1, r, p),
               get(x << 1 | 1, mid + 1, r, p));
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    char c = getchar();
    while (c != '?' && c != '+' && c != '-') c = getchar();
    if (c == '+') {
      int x, y;
      scanf("%d%d", &x, &y);
      a[i] = x;
      cha(1, 1, 1e6, x, y);
    } else if (c == '-') {
      int x;
      scanf("%d", &x);
      cha(1, 1, 1e6, a[x], 0);
    } else {
      int x;
      scanf("%d", &x);
      printf("%lld\n", max(get(1, 1, 1e6, x) - x, 0LL));
    }
  }
}
