#include <bits/stdc++.h>
using namespace std;
int T, i, l, tot, b[100001], a[100001], Cnt[400001];
long long Sum[400001][5];
char s[32], ch[100005];
inline void Pushup(int p) {
  Cnt[p] = Cnt[p * 2] + Cnt[p * 2 + 1];
  int i;
  for (i = 0; i < 5; i++)
    Sum[p][(Cnt[p * 2] + i) % 5] =
        Sum[p * 2][(Cnt[p * 2] + i) % 5] + Sum[p * 2 + 1][i];
}
inline int find(int X, int Y, int x) {
  int l = X, r = Y, mid;
  while (l + 1 < r) {
    mid = (l + r) >> 1;
    if (b[mid] > x)
      r = mid;
    else
      l = mid;
  }
  if (b[r] > x) r--;
  return r;
}
inline void Build(int l, int r, int p) {
  Cnt[p] = 0;
  for (int i = 0; i < 5; i++) Sum[p][i] = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  Build(l, mid, p * 2);
  Build(mid + 1, r, p * 2 + 1);
}
inline void Chang(int l, int r, int x, int t, int p) {
  if (l == r) {
    Cnt[p] = t;
    Sum[p][1] = (t > 0) ? b[x] : 0;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    Chang(l, mid, x, t, p * 2);
  else
    Chang(mid + 1, r, x, t, p * 2 + 1);
  Pushup(p);
}
int main() {
  while (scanf("%d", &T) != EOF) {
    l = 0;
    for (i = 1; i <= T; i++) {
      scanf("%s", s);
      ch[i] = s[0];
      if (ch[i] != 's') scanf("%d", &a[i]), b[++l] = a[i];
    }
    sort(&b[1], &b[l + 1]);
    tot = 1;
    for (i = 2; i <= l; i++)
      if (b[i] != b[tot]) b[++tot] = b[i];
    l = tot;
    for (i = 1; i <= T; i++)
      if (ch[i] != 's') a[i] = find(1, l, a[i]);
    Build(1, l, 1);
    for (i = 1; i <= T; i++)
      if (ch[i] == 's')
        printf("%I64d\n", Sum[1][3]);
      else if (ch[i] == 'a')
        Chang(1, l, a[i], 1, 1);
      else
        Chang(1, l, a[i], 0, 1);
  }
  return 0;
}
