#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int maxn = 1e6 + 10;
struct node {
  long long sum, Max;
  node() { sum = Max = 0; }
  node operator+(const node &other) const {
    node res;
    res.sum = sum + other.sum;
    res.Max = max(other.Max, Max + other.sum);
    return res;
  }
} tree[maxn << 2], res;
void build(int id, int l, int r) {
  tree[id] = node();
  if (l == r) {
    tree[id].sum = 0;
    tree[id].Max = l;
    return;
  }
  int mid = (l + r) >> 1;
  build(id << 1, l, mid);
  build(id << 1 | 1, mid + 1, r);
  tree[id] = tree[id << 1] + tree[id << 1 | 1];
}
void update(int id, int l, int r, int pos, long long val) {
  if (l == r) {
    tree[id].sum += val;
    tree[id].Max += val;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    update(id << 1, l, mid, pos, val);
  else
    update(id << 1 | 1, mid + 1, r, pos, val);
  tree[id] = tree[id << 1] + tree[id << 1 | 1];
}
void query(int id, int l, int r, int ql, int qr) {
  if (l >= ql && r <= qr) {
    res = res + tree[id];
    return;
  }
  int mid = (l + r) >> 1;
  if (ql <= mid) query(id << 1, l, mid, ql, qr);
  if (qr > mid) query(id << 1 | 1, mid + 1, r, ql, qr);
}
int n;
int arr[maxn], brr[maxn];
void RUN() {
  int limit = 1e6;
  while (~scanf("%d", &n)) {
    build(1, 1, limit);
    for (int i = 1; i <= n; ++i) {
      char c;
      scanf(" %c", &c);
      if (c == '+') {
        scanf("%d %d", arr + i, brr + i);
        update(1, 1, limit, arr[i], brr[i]);
      } else if (c == '-') {
        scanf("%d", arr + i);
        update(1, 1, limit, arr[arr[i]], -brr[arr[i]]);
      } else if (c == '?') {
        scanf("%d", arr + i);
        res = node();
        query(1, 1, limit, 1, arr[i]);
        printf("%lld\n", res.Max - arr[i]);
      }
    }
  }
}
int main() {
  RUN();
  return 0;
}
