#include <bits/stdc++.h>
const int maxn = 1e6 + 5;
int n, m;
long long sum[maxn << 2], wait[maxn << 2], a[maxn], b[maxn];
inline void pushup(int k) {
  sum[k] = sum[k << 1] + sum[k << 1 | 1];
  wait[k] = std::max(wait[k << 1] + sum[k << 1 | 1], wait[k << 1 | 1]);
}
void build(int k, int l, int r) {
  if (l == r) return wait[k] = l, void();
  int mid = l + r >> 1;
  build(k << 1, l, mid), build(k << 1 | 1, mid + 1, r);
}
void update(int k, int l, int r, int pos, int v) {
  if (l == r) return sum[k] += v, wait[k] += v, void();
  int mid = l + r >> 1;
  if (pos <= mid)
    update(k << 1, l, mid, pos, v);
  else
    update(k << 1 | 1, mid + 1, r, pos, v);
  pushup(k);
}
long long ans;
void query(int k, int l, int r, int upb) {
  if (r <= upb) return ans = std::max(ans + sum[k], wait[k]), void();
  int mid = l + r >> 1;
  query(k << 1, l, mid, upb);
  if (upb > mid) query(k << 1 | 1, mid + 1, r, upb);
}
int main() {
  scanf("%d", &m);
  build(1, 1, 1e6);
  for (int i = 1; i <= m; ++i) {
    char c[2];
    scanf("%s %lld", c, &a[i]);
    if (c[0] == '+') scanf("%lld", &b[i]), update(1, 1, 1e6, a[i], b[i]);
    if (c[0] == '-') update(1, 1, 1e6, a[a[i]], -b[a[i]]);
    if (c[0] == '?')
      ans = 0,
      printf("%lld\n", std::max((query(1, 1, 1e6, a[i]), ans), a[i]) - a[i]);
  }
  return 0;
}
