#include <bits/stdc++.h>
using namespace std;
int a[100009 + 1], v[100009 + 1];
struct node {
  long long v[5];
  int s;
} aint[265009];
int k, poz, val;
inline int caut(int a, int v[], int n) {
  int rez = 0;
  for (int pas = 1 << 16; pas; pas >>= 1)
    if (rez + pas <= n && v[rez + pas] <= a) rez += pas;
  return rez;
}
inline void unite(node &n, node a, node b) {
  n.s = a.s + b.s;
  if (n.s >= 5) n.s -= 5;
  for (int i = 0; i < 5; i++) n.v[i] = a.v[i];
  for (int i = 0; i + a.s < 5; i++) n.v[i + a.s] += b.v[i];
  for (int i = 5 - a.s; i < 5; i++) n.v[i + a.s - 5] += b.v[i];
}
void update(int p, int st, int dr) {
  if (st == dr) {
    aint[p].v[0] += val;
    if (aint[p].v[0] == 0)
      aint[p].s = 0;
    else
      aint[p].s = 1;
    return;
  }
  int m = (st + dr) / 2;
  if (poz <= m)
    update(2 * p, st, m);
  else
    update(2 * p + 1, m + 1, dr);
  unite(aint[p], aint[2 * p], aint[2 * p + 1]);
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    if (s == "sum")
      v[i] = 0;
    else {
      cin >> v[i];
      if (v[i] == 0) return 1;
      if (s == "add")
        a[++k] = v[i];
      else
        v[i] = -v[i];
    }
  }
  sort(a + 1, a + k + 1);
  int u = 1;
  for (int i = 2; i <= k; i++)
    if (a[u] != a[i]) a[++u] = a[i];
  for (int i = 1; i <= n; i++) {
    if (v[i] == 0)
      cout << aint[1].v[2] << "\n";
    else {
      val = v[i];
      poz = caut(abs(v[i]), a, u);
      update(1, 1, u);
    }
  }
  return 0;
}
