King Kog got annoyed of the usual laxity of his knights — they can break into his hall without prior notice! Thus, the King decided to build a reception with a queue where each knight chooses in advance the time when he will come and how long the visit will take. The knights are served in the order of the recorded time, but each knight has to wait until the visits of all the knights before him are finished.

Princess Keabeanie wants to see her father. However, she does not want to interrupt the knights so she joins the queue. Unfortunately, the knights change their minds very often — they can join the queue or cancel their visits. Please help the princess to understand how long she will have to wait until she sees her father if she enters the queue at the specified moments of time given the records at the reception.

Input

The first line of the input contains a single integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of events. An event can be of three types: join, cancel, or query.

  * Join "+ t d" (1 ≤ t, d ≤ 10^6) — a new knight joins the queue, where t is the time when the knight will come and d is the duration of the visit.
  * Cancel "- i" (1 ≤ i ≤ q) — the knight cancels the visit, where i is the number (counted starting from one) of the corresponding join event in the list of all events.
  * Query "? t" (1 ≤ t ≤ 10^6) — Keabeanie asks how long she will wait if she comes at the time t. 



It is guaranteed that after each event there are no two knights with the same entrance time in the queue. Cancel events refer to the previous joins that were not cancelled yet.

Keabeanie can come at the same time as some knight, but Keabeanie is very polite and she will wait for the knight to pass.

Output

For each query write a separate line with the amount of time Keabeanie will have to wait.

Example

Input


19
? 3
+ 2 2
? 3
? 4
+ 5 2
? 5
? 6
+ 1 2
? 2
? 3
? 4
? 5
? 6
? 7
? 9
- 8
? 2
? 3
? 6


Output


0
1
0
2
1
3
2
1
2
1
0
0
2
1
1
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
const int M = 1000007;
struct Node {
  long long sum, suf;
  Node Merge(const Node& nd) {
    Node ret;
    ret.sum = sum + nd.sum;
    ret.suf = max(suf + nd.sum, nd.suf);
    return ret;
  }
};
int q;
int tt[N], dd[N];
int add[M];
Node T[M << 2];
void build(int v, int l, int r) {
  if (l == r) {
    T[v].sum = -1;
    T[v].suf = 0;
    return;
  }
  build(v << 1, l, ((l + r) >> 1));
  build(v << 1 | 1, ((l + r) >> 1) + 1, r);
  T[v] = T[v << 1].Merge(T[v << 1 | 1]);
}
void upd(int v, int l, int r, int u, int z) {
  if (l == r) {
    T[v].sum += 1LL * z;
    T[v].suf = max(0LL, T[v].sum);
    return;
  }
  if (u <= ((l + r) >> 1))
    upd(v << 1, l, ((l + r) >> 1), u, z);
  else
    upd(v << 1 | 1, ((l + r) >> 1) + 1, r, u, z);
  T[v] = T[v << 1].Merge(T[v << 1 | 1]);
}
Node get(int v, int l, int r, int L, int R) {
  if (L == l && R == r) return T[v];
  if (R <= ((l + r) >> 1))
    return get(v << 1, l, ((l + r) >> 1), L, R);
  else if (L > ((l + r) >> 1))
    return get(v << 1 | 1, ((l + r) >> 1) + 1, r, L, R);
  else {
    return get(v << 1, l, ((l + r) >> 1), L, ((l + r) >> 1))
        .Merge(get(v << 1 | 1, ((l + r) >> 1) + 1, r, ((l + r) >> 1) + 1, R));
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> q;
  build(1, 0, M - 1);
  for (int i = 1; i <= q; ++i) {
    char op;
    cin >> op;
    if (op == '+') {
      cin >> tt[i] >> dd[i];
      add[tt[i]] += dd[i];
      upd(1, 0, M - 1, tt[i], dd[i]);
    } else if (op == '-') {
      int id;
      cin >> id;
      add[tt[id]] -= dd[id];
      upd(1, 0, M - 1, tt[id], -dd[id]);
    } else {
      int t;
      cin >> t;
      long long ans = get(1, 0, M - 1, 0, t - 1).suf;
      ans += add[t];
      cout << ans << '\n';
    }
  }
}
