#include <bits/stdc++.h>
const int N = 1e5 + 7;
struct SplayTree {
  long long T[N], siz[N], sum[N][7];
  int Rt, Ts, fa[N], ls[N][2];
  void Up(int x) {
    siz[x] = siz[ls[x][0]] + siz[ls[x][1]] + 1;
    for (int i = 0; i < 5; ++i)
      sum[x][i] = sum[ls[x][0]][i] +
                  sum[ls[x][1]][(i - (siz[ls[x][0]] + 1) % 5 + 5) % 5];
    sum[x][(siz[ls[x][0]] + 1) % 5] += T[x];
  }
  void Rotate(int x) {
    int y = fa[x], z = fa[y], s = ls[y][1] == x;
    fa[ls[z][ls[z][1] == y] = x] = z;
    fa[ls[y][s] = ls[x][s ^ 1]] = y;
    fa[ls[x][s ^ 1] = y] = x;
    Up(y);
    Up(x);
  }
  void Splay(int x) {
    for (; fa[x]; Rotate(x)) {
      if (fa[fa[x]])
        if ((x == ls[fa[x]][0]) ^ (fa[x] == ls[fa[fa[x]]][0]))
          Rotate(x);
        else
          Rotate(fa[x]);
    }
  }
  void Ins(long long x) {
    T[++Ts] = x;
    int v = Rt;
    if (v) {
      for (int u = Rt; u = ls[u][T[u] < x]; v = u)
        ;
      fa[ls[v][T[v] < x] = Ts] = v;
      Splay(Rt = Ts);
    } else {
      Splay(Rt = Ts);
    }
  }
  int Next(int x) {
    if (!ls[x][0]) return 0;
    for (x = ls[x][0]; ls[x][1]; x = ls[x][1])
      ;
    return x;
  }
  int Find(int v, long long x) {
    if (T[v] == x) return v;
    if (x < T[v]) return Find(ls[v][0], x);
    if (T[v] < x) return Find(ls[v][1], x);
  }
  void Del(long long x) {
    int v = Find(Rt, x), ne;
    Splay(Rt = v);
    if (ne = Next(v)) {
      fa[ls[ne][1] = ls[v][1]] = ne;
      fa[ls[v][0]] = 0;
      if (ls[v][1])
        Splay(Rt = ls[v][1]);
      else
        Rt = ls[v][0];
    } else {
      fa[ls[v][1]] = 0;
      if (ls[v][1])
        Splay(Rt = ls[v][1]);
      else
        Rt = ls[v][0];
    }
  }
  long long Sum() { return sum[Rt][3]; }
} BBST;
int main() {
  int n;
  scanf("%d", &n);
  for (char s[4]; n; --n) {
    scanf("\n%s", s);
    if (s[0] == 'a') {
      long long x;
      scanf("%I64d", &x);
      BBST.Ins(x);
    } else if (s[0] == 'd') {
      long long x;
      scanf("%I64d", &x);
      BBST.Del(x);
    } else if (s[0] == 's') {
      long long ans = BBST.Sum();
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
