#include <bits/stdc++.h>
using namespace std;
const int MAX = 4 * 1e6;
const int N = 1000000;
const int sz = 3e5 + 5;
struct segment {
  long long sum, mx;
  segment(long long _mx = 0, long long _sum = 0) {
    mx = _mx;
    sum = _sum;
  }
};
segment event[MAX];
int t[sz], dur[sz];
void initialize(int s, int f, int idx) {
  if (s == f) {
    event[idx].mx = (long long)s;
    event[idx].sum = 0;
    return;
  }
  int mid = (s + f) / 2;
  initialize(s, mid, idx * 2 + 1);
  initialize(mid + 1, f, idx * 2 + 2);
  event[idx].mx = max(event[2 * idx + 2].mx,
                      event[2 * idx + 1].mx + event[2 * idx + 2].sum);
  event[idx].sum = event[2 * idx + 1].sum + event[2 * idx + 2].sum;
}
void update(int s, int f, int idx, int x, long long val) {
  if (s == f && s == x) {
    event[idx].sum += val;
    event[idx].mx = event[idx].mx + val;
    return;
  }
  int mid = (s + f) / 2;
  if (x <= mid) update(s, mid, 2 * idx + 1, x, val);
  if (x > mid) update(mid + 1, f, 2 * idx + 2, x, val);
  event[idx].mx = max(event[2 * idx + 2].mx,
                      event[2 * idx + 1].mx + event[2 * idx + 2].sum);
  event[idx].sum = event[2 * idx + 1].sum + event[2 * idx + 2].sum;
}
segment query(int s, int f, int idx, int x) {
  segment res = segment(0, 0), a = segment(0, 0), b = segment(0, 0);
  if (x >= f) {
    res.sum = event[idx].sum;
    res.mx = event[idx].mx;
    return res;
  }
  if (x < s) return res;
  int mid = (s + f) / 2;
  a = query(s, mid, 2 * idx + 1, x);
  b = query(mid + 1, f, 2 * idx + 2, x);
  res.sum = a.sum + b.sum;
  res.mx = max(b.mx, a.mx + b.sum);
  return res;
}
int main() {
  int n, x;
  char ch;
  long long y;
  initialize(1, N, 0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> ch >> x;
    if (ch == '?') {
      segment ans = query(1, N, 0, x);
      cout << ans.mx - x << endl;
    } else if (ch == '+') {
      cin >> y;
      t[i] = x, dur[i] = y;
      update(1, N, 0, x, y);
    } else if (ch == '-') {
      update(1, N, 0, t[x], -dur[x]);
    }
  }
  return 0;
}
