#include <bits/stdc++.h>
using namespace std;
long long tmp, cnt, b[100012];
struct data {
  long long type, x, id;
} a[100012];
struct node {
  long long l, r, w[8], cnt;
};
struct segtree {
  node tr[100012 * 4];
  void up(long long rt) {
    long long i;
    tr[rt].cnt = tr[rt << 1].cnt + tr[rt << 1 | 1].cnt;
    for (i = 0; i <= 4; i++) {
      tr[rt].w[i] = tr[rt << 1].w[i] +
                    tr[rt << 1 | 1].w[((i - tr[rt << 1].cnt) % 5 + 5) % 5];
    }
  }
  void mk(long long rt) {
    long long l = tr[rt].l, r = tr[rt].r, mid = (tr[rt].l + tr[rt].r) >> 1;
    if (l == r) return;
    tr[rt << 1].l = l;
    tr[rt << 1].r = mid;
    mk(rt << 1);
    tr[rt << 1 | 1].l = mid + 1;
    tr[rt << 1 | 1].r = r;
    mk(rt << 1 | 1);
    up(rt);
  }
  void add(long long a, long long b, long long num, long long rt) {
    long long l = tr[rt].l, r = tr[rt].r, mid = (tr[rt].l + tr[rt].r) >> 1;
    if (l == r) {
      tr[rt].w[1] = a * b;
      tr[rt].cnt += b;
      return;
    }
    if (a <= mid)
      add(a, b, num, rt << 1);
    else
      add(a, b, num, rt << 1 | 1);
    up(rt);
  }
} tree;
map<long long, long long> mp;
signed main() {
  long long i, m, x;
  char str[8];
  scanf("%lld\n", &m);
  for (i = 1; i <= m; ++i) {
    scanf("%s ", str);
    if (!strcmp(str, "add")) {
      scanf("%lld\n", &x);
      a[i].type = 1;
      a[i].x = x;
      b[++cnt] = x;
    } else if (!strcmp(str, "del")) {
      scanf("%lld\n", &x);
      a[i].type = 2;
      a[i].x = x;
      b[++cnt] = x;
    } else
      a[i].type = 0;
  }
  sort(b + 1, b + cnt + 1);
  for (i = 1; i <= cnt; ++i)
    if (b[i] != b[i - 1]) mp[b[i]] = ++tmp;
  for (i = 1; i <= m; ++i)
    if (a[i].x) a[i].id = mp[a[i].x];
  tree.tr[1].l = 1;
  tree.tr[1].r = cnt;
  tree.mk(1);
  for (i = 1; i <= m; ++i) {
    if (a[i].type == 1)
      tree.add(a[i].id, 1, a[i].x, 1);
    else if (a[i].type == 2)
      tree.add(a[i].id, -1, a[i].x, 1);
    else
      printf("%lld\n", tree.tr[1].w[3]);
  }
  return 0;
}
