#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
struct Tnode {
  int l, r, cnt;
  long long sum[5];
  int mid() { return (l + ((r - l) >> 1)); }
} node[maxn << 2];
int n;
int a[maxn], b[maxn];
char str[maxn][10];
void build(int t, int l, int r) {
  node[t].l = l;
  node[t].r = r;
  node[t].cnt = 0;
  for (int i = 0; i < 5; i++) node[t].sum[i] = 0;
  if (l == r) return;
  int mid = node[t].mid();
  build((t << 1), l, mid);
  build((t << 1 | 1), mid + 1, r);
}
void pushup(int t) {
  for (int i = 0; i < 5; i++) {
    int j = ((i - node[(t << 1)].cnt) % 5 + 5) % 5;
    node[t].sum[i] = node[(t << 1)].sum[i] + node[(t << 1 | 1)].sum[j];
  }
}
void update(int t, int p, int v, int op) {
  node[t].cnt += op;
  if (node[t].l == node[t].r) {
    node[t].sum[0] += v;
  } else {
    int mid = node[t].mid();
    if (p <= mid)
      update((t << 1), p, v, op);
    else
      update((t << 1 | 1), p, v, op);
    pushup(t);
  }
}
int main() {
  while (~scanf("%d", &n)) {
    int num = 0;
    for (int i = 0; i < n; i++) {
      scanf("%s", str[i]);
      if (str[i][0] != 's') {
        scanf("%d", &b[i]);
        a[num++] = b[i];
      }
    }
    sort(a, a + num);
    num = unique(a, a + num) - a;
    if (!num) {
      printf("0");
      continue;
    }
    build(1, 0, num - 1);
    for (int i = 0; i < n; i++) {
      int p = lower_bound(a, a + num, b[i]) - a;
      if (str[i][0] == 'a')
        update(1, p, b[i], 1);
      else if (str[i][0] == 'd')
        update(1, p, -b[i], -1);
      else
        printf("%I64d\n", node[1].sum[2]);
    }
  }
  return 0;
}
