#include <bits/stdc++.h>
using namespace std;
long long h[100010], dat[100010], s[100010][5];
int n, root, tot, l[100010], r[100010], sum[100010];
bool now[100010];
void update(int x) {
  int ss = sum[l[x]];
  if (now[x]) ss++;
  for (int i = 0; i < 5; i++)
    s[x][i] = (long long)(s[l[x]][i] + s[r[x]][(i - ss % 5 + 5) % 5]);
  if (now[x]) s[x][ss % 5] += (long long)dat[x];
  sum[x] = ss + sum[r[x]];
  h[x] = max(h[l[x]], h[r[x]]) + 1;
}
inline void zig(int &x) {
  int y = l[x];
  l[x] = r[y];
  r[y] = x;
  update(x);
  update(y);
  x = y;
}
inline void zag(int &x) {
  int y = r[x];
  r[x] = l[y];
  l[y] = x;
  update(x);
  update(y);
  x = y;
}
inline void balance(int &x) {
  if (h[l[x]] > h[r[x]] + 1) {
    if (h[l[l[x]]] < h[l[r[x]]]) zag(l[x]);
    zig(x);
  }
  if (h[r[x]] > h[l[x]] + 1) {
    if (h[r[r[x]]] < h[r[l[x]]]) zig(r[x]);
    zag(x);
  }
}
void ins(int &x, long long v) {
  if (!x) {
    dat[x = ++tot] = v;
    l[x] = r[x] = 0;
    now[x] = 1;
  } else if (dat[x] == v)
    now[x] = 1;
  else
    ins(v < dat[x] ? l[x] : r[x], v);
  balance(x);
  update(x);
}
inline void del(int &x, long long v) {
  if (dat[x] == v)
    now[x] = 0;
  else
    del(v < dat[x] ? l[x] : r[x], v);
  update(x);
}
int main() {
  scanf("%d\n", &n);
  memset(l, 0, sizeof(l));
  memset(r, 0, sizeof(r));
  memset(s, 0, sizeof(s));
  memset(h, 0, sizeof(h));
  memset(dat, 0, sizeof(dat));
  memset(sum, 0, sizeof(sum));
  memset(now, 0, sizeof(now));
  root = tot = 0;
  h[0] = -1;
  while (n--) {
    char x[10];
    scanf("%s", &x);
    char y = x[0];
    long long z;
    if (y == 'a') {
      scanf("%I64d", &z);
      ins(root, z);
    } else if (y == 'd') {
      scanf("%I64d", &z);
      del(root, z);
    } else
      printf("%I64d\n", s[root][3]);
  }
  return 0;
}
