#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int lt[maxn], rt[maxn], fa[maxn], siz[maxn], val[maxn], laz[maxn];
long long int s[maxn][5];
int N, root, cnt;
int New(int x) {
  int p = ++cnt;
  lt[p] = rt[p] = fa[p] = 0;
  siz[p] = 1;
  s[p][1] = x;
  val[p] = x;
  return p;
}
int mod(int x) { return (x % 5 + 5) % 5; }
bool isrs(int p) { return p == rt[fa[p]]; }
void update(int p) {
  siz[p] = siz[lt[p]] + siz[rt[p]] + 1;
  for (int i = 0; i <= 4; i++) {
    s[p][i] = s[lt[p]][i] + s[rt[p]][mod(i - siz[lt[p]] - 1)];
    if (i == mod(siz[lt[p]] + 1)) s[p][i] += val[p];
  }
}
void print(int p, int dp) {
  if (!dp) printf("!!!!!!!!!\n");
  if (!p) {
    for (int i = 0; i < dp; i++) printf("\t");
    printf("#\n");
    return;
  }
  print(lt[p], dp + 1);
  for (int i = 0; i < dp; i++) printf("\t");
  printf("%d %d %d %d\n", p, siz[p], val[p], s[p][3]);
  print(rt[p], dp + 1);
}
void rotate(int p) {
  int f = fa[p], ff = fa[f];
  bool b = isrs(p);
  if (ff) {
    if (isrs(f))
      rt[ff] = p;
    else
      lt[ff] = p;
  }
  fa[p] = ff;
  if (b) {
    int l = lt[p];
    rt[f] = l;
    if (l) fa[l] = f;
    lt[p] = f;
    fa[f] = p;
  } else {
    int r = rt[p];
    lt[f] = r;
    if (r) fa[r] = f;
    rt[p] = f;
    fa[f] = p;
  }
  update(f);
}
void splay(int p, int tf) {
  while (fa[p] != tf && fa[fa[p]] != tf) {
    if (isrs(p) == isrs(fa[p]))
      rotate(fa[p]);
    else
      rotate(p);
    rotate(p);
  }
  if (fa[p] != tf) rotate(p);
  update(p);
  if (!tf) root = p;
}
void opr_add(int x) {
  if (!root)
    root = New(x);
  else {
    int p = root, xx = New(x);
    while (1) {
      if (val[xx] > val[p]) {
        if (rt[p])
          p = rt[p];
        else {
          rt[p] = xx;
          fa[xx] = p;
          break;
        }
      } else {
        if (lt[p])
          p = lt[p];
        else {
          lt[p] = xx;
          fa[xx] = p;
          break;
        }
      }
    }
    splay(xx, 0);
  }
}
void opr_del(int x) {
  int p = root;
  while (1) {
    if (!p) return;
    if (x > val[p])
      p = rt[p];
    else if (x < val[p])
      p = lt[p];
    else
      break;
  }
  splay(p, 0);
  int l = lt[p], r = rt[p];
  if (!l) {
    root = r;
    fa[r] = 0;
    rt[p] = 0;
  } else if (!r) {
    root = l;
    fa[l] = 0;
    lt[p] = 0;
  } else {
    splay(l, 0);
    splay(r, l);
    fa[p] = 0;
    lt[r] = 0;
    update(r);
    update(l);
  }
}
long long int opr_sum() { return s[root][3]; }
int main() {
  int i, j, k;
  char o[10];
  scanf("%d", &N);
  for (i = 1; i <= N; i++) {
    scanf("%s", o);
    if (o[0] == 'a') {
      scanf("%d", &j);
      opr_add(j);
    } else if (o[0] == 's') {
      printf("%I64d\n", opr_sum());
    } else {
      scanf("%d", &j);
      opr_del(j);
    }
  }
}
