#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
struct node {
  int l, r;
  long long cnt[5];
  int p;
} src[MAXN * 4 + 10];
int n, od[MAXN + 10], s_len;
long long inf[MAXN + 10], SP[MAXN + 10];
void Build(int u, int l, int r) {
  src[u].l = l, src[u].r = r;
  src[u].p = 4;
  if (l >= r) return;
  int mid = (l + r) >> 1;
  Build(u * 2, l, mid);
  Build(u * 2 + 1, mid + 1, r);
}
int ID(int num) { return lower_bound(SP, SP + s_len, num) - SP + 1; }
void Init() {
  sort(SP, SP + s_len);
  s_len = unique(SP, SP + s_len) - SP;
}
void Read() {
  char ord[10];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", ord);
    if (ord[0] == 's') {
      od[i] = 1;
      continue;
    } else if (ord[0] == 'a')
      od[i] = 2;
    else
      od[i] = 3;
    scanf("%I64d", &inf[i]);
    SP[s_len++] = inf[i];
  }
}
void Ref(int u) {
  src[u].p = (src[u * 2].p + src[u * 2 + 1].p + 1) % 5;
  for (int i = 0; i < 5; i++)
    src[u].cnt[i] =
        src[u * 2].cnt[i] + src[u * 2 + 1].cnt[(i - src[u * 2].p + 4) % 5];
}
void Insert(int u, int id, long long val, long long le) {
  if (src[u].l == src[u].r) {
    if (le < 0) src[u].cnt[src[u].p] -= val;
    src[u].p = (src[u].p + le + 5) % 5;
    if (le > 0) src[u].cnt[src[u].p] += val;
  } else {
    int mid = (src[u].l + src[u].r) >> 1;
    if (id <= mid)
      Insert(u * 2, id, val, le);
    else
      Insert(u * 2 + 1, id, val, le);
    Ref(u);
  }
}
int main() {
  Read();
  Init();
  Build(1, 1, s_len);
  for (int i = 0; i < n; i++) {
    if (od[i] == 1)
      printf("%I64d\n", src[1].cnt[2]);
    else if (od[i] == 2)
      Insert(1, ID(inf[i]), inf[i], 1LL);
    else
      Insert(1, ID(inf[i]), inf[i], -1LL);
  }
  return 0;
}
