#include <bits/stdc++.h>
using namespace std;
long long ans, t1, mx, sum[4000001], wa[4000001], a[500001], b[500001];
void build(long long x, long long l, long long r) {
  if (l == r) {
    wa[x] = l;
    return;
  }
  int mid = (l + r) / 2;
  build(x * 2, l, mid);
  build(x * 2 + 1, mid + 1, r);
  wa[x] = wa[x * 2 + 1];
}
void ins(long long x, long long l, long long r, long long t, long long k) {
  if (l == r) {
    sum[x] += k;
    wa[x] += k;
    return;
  }
  long long mid = (l + r) / 2;
  if (mid >= t)
    ins(x * 2, l, mid, t, k);
  else
    ins(x * 2 + 1, mid + 1, r, t, k);
  wa[x] = max(wa[x * 2] + sum[x * 2 + 1], wa[x * 2 + 1]);
  sum[x] = sum[x * 2] + sum[x * 2 + 1];
}
long long query(long long x, long long l, long long r, long long t,
                long long k) {
  if (l == t && r == k) {
    ans = max(ans + sum[x], wa[x]);
    return ans;
  }
  long long mid = (l + r) / 2;
  if (mid >= k)
    query(x * 2, l, mid, t, k);
  else if (t > mid)
    query(x * 2 + 1, mid + 1, r, t, k);
  else
    query(x * 2, l, mid, t, mid), query(x * 2 + 1, mid + 1, r, mid + 1, k);
  return ans;
}
int main() {
  long long i;
  char op[101];
  mx = 1e6;
  scanf("%lld", &t1);
  build(1, 1, mx);
  for (i = 1; i <= t1; i++) {
    scanf("%s%lld", op, &a[i]);
    if (op[0] == '+') {
      scanf("%lld", &b[i]);
      ins(1, 1, mx, a[i], b[i]);
    } else if (op[0] == '-')
      ins(1, 1, mx, a[a[i]], -b[a[i]]);
    else {
      ans = 0;
      printf("%lld\n", query(1, 1, mx, 1, a[i]) - a[i]);
    }
  }
}
