#include <bits/stdc++.h>
using namespace std;
const int N = 1010101;
int q, n = 1000000;
pair<int, int> a[N];
long long ma[N << 2], la[N << 2];
void gao(int rt, long long c) {
  ma[rt] += c;
  la[rt] += c;
}
void down(int rt) {
  if (!la[rt]) return;
  gao(rt << 1, la[rt]);
  gao(rt << 1 | 1, la[rt]);
  la[rt] = 0;
}
void up(int rt) { ma[rt] = max(ma[rt << 1], ma[rt << 1 | 1]); }
void build(int l, int r, int rt) {
  ma[rt] = r;
  if (l == r) return;
  int mid = l + r >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
}
void upd(int L, int R, long long c, int l, int r, int rt) {
  if (L > R) return;
  if (L <= l && r <= R) {
    gao(rt, c);
    return;
  }
  int mid = l + r >> 1;
  down(rt);
  if (L <= mid) upd(L, R, c, l, mid, rt << 1);
  if (R > mid) upd(L, R, c, mid + 1, r, rt << 1 | 1);
  up(rt);
}
long long qry(int L, int R, int l, int r, int rt) {
  if (L > R) return -1e18;
  if (L <= l && r <= R) return ma[rt];
  int mid = l + r >> 1;
  down(rt);
  long long ans = -1e18;
  if (L <= mid) ans = max(ans, qry(L, R, l, mid, rt << 1));
  if (R > mid) ans = max(ans, qry(L, R, mid + 1, r, rt << 1 | 1));
  up(rt);
  return ans;
}
long long tot[N];
void Upd(int p, int c) {
  for (; p <= n; p += ((p) & -(p))) tot[p] += c;
}
long long Qry(int p) {
  long long res = 0;
  for (; p >= 1; p ^= ((p) & -(p))) res += tot[p];
  return res;
}
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  cin >> q;
  build(1, n, 1);
  for (int i = (1); i < (q + 1); ++i) {
    char s[11];
    int t, d;
    cin >> s >> t;
    if (s[0] == '+') {
      cin >> d;
      Upd(t, d);
      upd(t + 1, n, -d, 1, n, 1);
    } else if (s[0] == '-') {
      d = a[t].second;
      t = a[t].first;
      Upd(t, -d);
      upd(t + 1, n, d, 1, n, 1);
    } else {
      long long ans = Qry(t) - t + qry(1, t, 1, n, 1);
      cout << ans << "\n";
    }
    a[i] = make_pair(t, d);
  }
  return 0;
}
