#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
const int MAX_TIME = 1000000;
struct TreeNode {
  long long sum, maximum;
  TreeNode() : sum(0), maximum(0){};
  TreeNode(long long sum, long long maximum) {
    this->sum = sum;
    this->maximum = maximum;
  }
  TreeNode update(const TreeNode& left, const TreeNode& right) {
    return TreeNode(right.sum + left.sum,
                    std::max(right.maximum, left.maximum + right.sum));
  }
};
TreeNode _array[4 * MAX_TIME + 10];
struct SegTree {
  inline int get_left_child(int index) { return 2 * index + 1; }
  inline int get_right_child(int index) { return 2 * index + 2; }
  inline int get_middle(int left, int right) { return (left + right) / 2; }
  void update_statistics(int index) {
    _array[index] = _array[index].update(_array[get_left_child(index)],
                                         _array[get_right_child(index)]);
  }
  void build(int index, int left_time, int right_time) {
    if (left_time == right_time) {
      _array[index] = TreeNode(0, left_time);
      return;
    }
    int middle = get_middle(left_time, right_time);
    build(get_left_child(index), left_time, middle);
    build(get_right_child(index), middle + 1, right_time);
    update_statistics(index);
  }
  void update(int index, int left_bound, int right_bound,
              int modification_index, int delta) {
    if (left_bound == right_bound) {
      _array[index].sum += delta;
      _array[index].maximum += delta;
      return;
    }
    int middle = get_middle(left_bound, right_bound);
    if (modification_index <= middle) {
      update(get_left_child(index), left_bound, middle, modification_index,
             delta);
    } else {
      update(get_right_child(index), middle + 1, right_bound,
             modification_index, delta);
    }
    update_statistics(index);
  }
  long long get_delay(int index, int left, int right, int T,
                      long long current_result) {
    if (right <= T) {
      return std::max(_array[index].maximum,
                      _array[index].sum + current_result);
    }
    int middle = get_middle(left, right);
    current_result = std::max(
        current_result,
        get_delay(get_left_child(index), left, middle, T, current_result));
    if (middle < T) {
      current_result =
          std::max(current_result, get_delay(get_right_child(index), middle + 1,
                                             right, T, current_result));
    }
    return current_result;
  }
};
int main() {
  int q;
  scanf("%d", &q);
  char operation[2];
  std::vector<int> times(q, 0);
  std::vector<int> durations(q, 0);
  SegTree tree;
  tree.build(0, 0, MAX_TIME);
  for (size_t i = 0; i < q; ++i) {
    scanf("%s", &operation);
    if (operation[0] == '+') {
      int t, d;
      scanf("%d %d", &t, &d);
      times[i] = t - 1;
      durations[i] = d;
      tree.update(0, 0, MAX_TIME, t - 1, d);
    }
    if (operation[0] == '-') {
      int join_idx;
      scanf("%d", &join_idx);
      tree.update(0, 0, MAX_TIME, times[join_idx - 1],
                  -durations[join_idx - 1]);
    }
    if (operation[0] == '?') {
      int T;
      scanf("%d", &T);
      long long delay = tree.get_delay(0, 0, MAX_TIME, T - 1, 0) - (T - 1);
      if (delay < 0) {
        delay = 0;
      }
      std::cout << delay << std::endl;
    }
  }
}
