#include <bits/stdc++.h>
using namespace std;
struct treap {
  treap *l, *r;
  const int h;
  int k, size;
  long long sum;
  treap(int k) : l(NULL), r(NULL), h(rand()), k(k), sum(0), size(0) { upd(); }
  static long long psum(treap *p) { return p ? p->sum : 0; }
  static int psize(treap *p) { return p ? p->size : 0; }
  void upd() {
    sum = psum(l) + psum(r) + k;
    size = psize(l) + psize(r) + 1;
  }
  ~treap() {
    delete l;
    delete r;
  }
};
struct t_pair {
  treap *l, *r;
  t_pair(treap *l = NULL, treap *r = NULL) : l(l), r(r) {}
};
treap *merge(treap *l, treap *r) {
  if (!l || !r) return l ? l : r;
  if (l->h > r->h) {
    l->r = merge(l->r, r);
    l->upd();
    return l;
  } else {
    r->l = merge(l, r->l);
    r->upd();
    return r;
  }
}
t_pair split(treap *p, int k) {
  if (!p) return t_pair();
  if (p->k > k) {
    t_pair t = split(p->l, k);
    p->l = t.r;
    p->upd();
    t.r = p;
    return t;
  } else {
    t_pair t = split(p->r, k);
    p->r = t.l;
    p->upd();
    t.l = p;
    return t;
  }
}
treap *rem(treap *p, int k) {
  if (!p)
    return NULL;
  else if (p->k > k)
    p->l = rem(p->l, k), p->upd();
  else if (p->k < k)
    p->r = rem(p->r, k), p->upd();
  else {
    treap *t = p;
    p = merge(p->l, p->r);
    t->l = t->r = NULL;
    delete t;
  }
  return p;
}
int main() {
  int _, tmp;
  cin >> _;
  char op[10];
  treap *tree[5];
  t_pair t[5];
  memset(tree, 0, sizeof(tree));
  while (_--) {
    scanf("%s", op);
    if (op[0] == 'a') {
      int pos(1);
      scanf("%d", &tmp);
      for (int i(0); i != 5; ++i) {
        t[i] = split(tree[i], tmp);
        pos += treap::psize(t[i].l);
      }
      for (int i(0); i != 5; ++i) {
        if (pos % 5 == i) t[i].l = merge(t[i].l, new treap(tmp));
        tree[i] = merge(t[i].l, t[(i + 4) % 5].r);
      }
    } else if (op[0] == 'd') {
      int pos(0);
      scanf("%d", &tmp);
      for (int i(0); i != 5; ++i) {
        t[i] = split(tree[i], tmp);
        pos += treap::psize(t[i].l);
      }
      for (int i(0); i != 5; ++i) {
        if (pos % 5 == i) t[i].l = rem(t[i].l, tmp);
        tree[i] = merge(t[i].l, t[(i + 1) % 5].r);
      }
    } else if (op[0] == 's')
      cout << treap::psum(tree[3]) << '\n';
  }
  return 0;
}
