#include <bits/stdc++.h>
static const int MAXN = 1e5 + 4;
static const int INF = 0x7fffffff;
namespace splay {
int sz;
struct node {
  int child[2], parent, subtree, val;
  long long sum[5];
} t[MAXN];
inline void recursive_print(int x, int dep = 0) {
  if (x == -1) return;
  recursive_print(t[x].child[0], dep + 1);
  for (int i = 0; i < dep; ++i) printf("  ");
  printf(
      "%d %c\n", t[x].val,
      t[t[x].parent].child[0] != x && t[t[x].parent].child[1] != x ? '!' : '*');
  recursive_print(t[x].child[1], dep + 1);
}
inline void inspect() {
  printf("%d node(s)\n", sz);
  for (int i = 0; i < sz; ++i)
    printf("%d | Val=%d Par=%d Lch=%d Rch=%d | %lld %lld %lld %lld %lld\n", i,
           t[i].val, t[i].parent, t[i].child[0], t[i].child[1], t[i].sum[0],
           t[i].sum[1], t[i].sum[2], t[i].sum[3], t[i].sum[4]);
  recursive_print(t[0].child[0]);
  putchar('\n');
}
inline void update(int x) {
  t[x].subtree = (t[x].child[0] == -1 ? 0 : t[t[x].child[0]].subtree) +
                 (t[x].child[1] == -1 ? 0 : t[t[x].child[1]].subtree) + 1;
  int lch_size = (t[x].child[0] == -1 ? 0 : t[t[x].child[0]].subtree);
  for (int i = 0; i < 5; ++i) {
    t[x].sum[i] = (t[x].child[0] == -1 ? 0 : t[t[x].child[0]].sum[i]) +
                  (t[x].child[1] == -1
                       ? 0
                       : t[t[x].child[1]].sum[(i - lch_size - 1 + 5000) % 5]);
  }
  if (t[x].val != INF) t[x].sum[lch_size % 5] += t[x].val;
}
inline void init() {
  sz = 3;
  for (int x = 0; x < MAXN; ++x) {
    t[x].child[0] = t[x].child[1] = t[x].parent = -1;
    t[x].subtree = 1;
    t[x].val = 0;
    memset(t[x].sum, 0, sizeof t[x].sum);
  }
  t[0].child[0] = 1;
  t[1].parent = 0;
  t[1].child[1] = 2;
  t[2].parent = 1;
  t[2].val = INF;
  update(1);
}
inline void rotate(int x) {
  int p = t[x].parent, g = t[p].parent, dir = (t[p].child[1] == x);
  if ((t[p].child[dir] = t[x].child[dir ^ 1]) != -1)
    t[t[p].child[dir]].parent = p;
  t[x].child[dir ^ 1] = p;
  t[p].parent = x;
  t[g].child[t[g].child[1] == p] = x;
  t[x].parent = g;
  update(p);
}
inline void splay(int x, int under = 0) {
  int p, g;
  while ((p = t[x].parent) != under) {
    if ((g = t[p].parent) != under)
      rotate((t[g].child[1] == p) ^ (t[p].child[1] == x) ? x : p);
    rotate(x);
  }
  update(x);
}
inline int lower_bound(int val) {
  int x = t[0].child[0], best = INF, best_node = -1, y;
  while (true) {
    if (t[x].val >= val && best >= t[x].val) best = t[x].val, best_node = x;
    y = (t[x].val >= val) ? t[x].child[0] : t[x].child[1];
    if (y == -1)
      break;
    else
      x = y;
  }
  return best_node;
}
inline int upper_bound(int val) {
  int x = t[0].child[0], best = INF, best_node = -1, y;
  while (true) {
    if (t[x].val > val && best >= t[x].val) best = t[x].val, best_node = x;
    y = (t[x].val > val) ? t[x].child[0] : t[x].child[1];
    if (y == -1)
      break;
    else
      x = y;
  }
  return best_node;
}
inline int leftmost(int x) {
  while (t[x].child[0] != -1) x = t[x].child[0];
  return x;
}
inline int rightmost(int x) {
  while (t[x].child[1] != -1) x = t[x].child[1];
  return x;
}
inline void insert(int val) {
  int u = upper_bound(val);
  splay(u);
  int v = rightmost(t[u].child[0]);
  splay(v, u);
  assert(t[v].child[1] == -1);
  t[sz].parent = v;
  t[sz].val = t[sz].sum[0] = val;
  t[v].child[1] = sz++;
  while (v != 0) update(v), v = t[v].parent;
}
inline void remove(int val) {
  int x = lower_bound(val);
  splay(x);
  int u = rightmost(t[x].child[0]), v = leftmost(t[x].child[1]);
  splay(u);
  splay(v, u);
  assert(t[v].child[0] == x && t[x].child[0] == -1 && t[x].child[1] == -1);
  t[v].child[0] = -1;
  while (v != 0) update(v), v = t[v].parent;
}
inline long long get_answer() {
  int x = t[0].child[0];
  return t[x].sum[3];
}
}  // namespace splay
int n;
int main() {
  scanf("%d", &n);
  splay::init();
  char op[24];
  int arg;
  for (int i = 0; i < n; ++i) {
    scanf("%s", op);
    switch (op[0]) {
      case 'a':
        scanf("%d", &arg);
        splay::insert(arg);
        break;
      case 'd':
        scanf("%d", &arg);
        splay::remove(arg);
        break;
      case 's':
        printf("%I64d\n", splay::get_answer());
        break;
      default:
        puts("> <");
    }
  }
  return 0;
}
