#include <bits/stdc++.h>
template <typename T>
T inline SQR(const T& a) {
  return a * a;
}
template <typename T>
T inline ABS(const T& a) {
  return a < 0 ? -a : a;
}
template <typename T>
T inline MIN(const T& a, const T& b) {
  if (a < b) return a;
  return b;
}
template <typename T>
T inline MAX(const T& a, const T& b) {
  if (a > b) return a;
  return b;
}
const double EPS = 1e-9;
inline int SGN(double a) {
  return ((a > EPS) ? (1) : ((a < -EPS) ? (-1) : (0)));
}
inline int CMP(double a, double b) { return SGN(a - b); }
using namespace std;
struct node_t {
  int key, sz, pr;
  long long acm[5];
  node_t *l, *r;
  node_t(int val = 0) : key(val), sz(0), pr(rand()), l(NULL), r(NULL) {
    memset(acm, 0, sizeof(acm));
  }
  void walk(int d = 0) {
    if (l) l->walk(d + 1);
    for (int i = 0; i < d; ++i) putchar('\t');
    printf("%d\n", key);
    if (r) r->walk(d + 1);
  }
};
void rotate_right(node_t*& t) {
  node_t* n = t->l;
  t->l = n->r;
  n->r = t;
  t = n;
}
void rotate_left(node_t*& t) {
  node_t* n = t->r;
  t->r = n->l;
  n->l = t;
  t = n;
}
void update(node_t* t) {
  if (!t) return;
  t->sz = ((t->l) ? (t->l->sz) : (0)) + 1 + ((t->r) ? (t->r->sz) : (0));
  for (int i = 0; i < 5; ++i) t->acm[i] = 0;
  int me = 1;
  if (t->l) {
    me += t->l->sz;
    for (int i = 0; i < 5; ++i) t->acm[i] = t->l->acm[i];
  }
  t->acm[me % 5] += t->key;
  if (t->r) {
    for (int i = 0; i < 5; ++i) t->acm[(me + i) % 5] += t->r->acm[i];
  }
}
void fix(node_t*& t) {
  if (!t) return;
  update(t->l);
  update(t->r);
  update(t);
}
void insert(node_t*& t, int val) {
  if (!t)
    t = new node_t(val);
  else {
    if (t->key == val) return;
    if (val < t->key)
      insert(t->l, val);
    else
      insert(t->r, val);
  }
  if (t->l && (t->l->pr > t->pr))
    rotate_right(t);
  else if (t->r && (t->r->pr > t->pr))
    rotate_left(t);
  fix(t);
}
inline int p(node_t* t) { return (t ? (t->pr) : (-1)); }
void erase(node_t*& t, int val) {
  if (!t) return;
  if (t->key != val)
    erase(((val < t->key) ? (t->l) : (t->r)), val);
  else {
    if (!(t->l) && !(t->r)) {
      delete t, t = NULL;
    } else {
      (p(t->l) < p(t->r)) ? rotate_left(t) : rotate_right(t);
      erase(t, val);
    }
  }
  fix(t);
}
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  int Q, x;
  string wut;
  srand(time(NULL));
  node_t* treap = NULL;
  cin >> Q;
  while (Q--) {
    cin >> wut;
    if (wut[0] != 's') cin >> x;
    switch (wut[0]) {
      case 'a':
        insert(treap, x);
        break;
      case 'd':
        erase(treap, x);
        break;
      case 's':
        long long ans = 0;
        if (treap) ans = treap->acm[3];
        cout << ans << "\n";
    }
  }
  return 0;
}
