#include <bits/stdc++.h>
using namespace std;
struct tree {
  int x, y, si;
  long long sum[5];
  tree *l, *r;
};
tree mem[100100];
int mpos = 1;
tree *nil = mem;
void Calc(tree *t) {
  if (t == nil) return;
  t->si = 1 + t->l->si + t->r->si;
  for (int i = 0; i < 5; i++) t->sum[i] = t->l->sum[i];
  int sh = t->l->si;
  t->sum[sh % 5] += t->x;
  sh++;
  for (int i = 0; i < 5; i++) t->sum[(i + sh) % 5] += t->r->sum[i];
}
tree *NewT(int x) {
  tree *t = mem + mpos++;
  t->y = (rand() << 15) + rand();
  t->x = x;
  t->l = t->r = nil;
  Calc(t);
  return t;
}
void Split(tree *t, tree **l, tree **r, int x) {
  if (t == nil)
    *l = *r = nil;
  else if (t->x < x)
    *l = t, Split(t->r, &t->r, r, x);
  else
    *r = t, Split(t->l, l, &t->l, x);
  Calc(*l), Calc(*r);
}
void Merge(tree **t, tree *l, tree *r) {
  if (l == nil || r == nil) {
    *t = max(l, r);
    return;
  }
  if (l->y < r->y)
    *t = l, Merge(&(*t)->r, (*t)->r, r);
  else
    *t = r, Merge(&(*t)->l, l, (*t)->l);
  Calc(*t);
}
void Add(tree **t, int x) {
  tree *l, *r, *m;
  Split(*t, &l, &r, x);
  Merge(&m, l, NewT(x));
  Merge(t, m, r);
}
void Del(tree **t, int x) {
  tree *l, *m, *r, *tmp;
  Split(*t, &l, &tmp, x);
  Split(tmp, &m, &r, x + 1);
  Merge(t, l, r);
}
int main() {
  nil->l = nil->r = nil;
  tree *root = nil;
  int n;
  scanf("%d", &n);
  srand(unsigned(time(NULL)));
  while (n--) {
    char com[9];
    int x;
    scanf("%s", com);
    if (!strcmp(com, "add")) {
      scanf("%d", &x);
      Add(&root, x);
    } else if (!strcmp(com, "del")) {
      scanf("%d", &x);
      Del(&root, x);
    } else
      printf("%I64d\n", root->sum[2]);
  }
  return 0;
}
