#include <bits/stdc++.h>
using namespace std;
const int size = 100010;
char s[size][4];
struct node {
  int l, r, cnt;
  long long sum[6];
} tree[size * 4];
int tmp[size], q[size];
void pushup(int rt) {
  int i;
  for (i = 0; i < 5; ++i)
    tree[rt].sum[i] =
        tree[rt << 1].sum[i] +
        tree[rt << 1 | 1].sum[(i - tree[rt << 1].cnt % 5 + 5) % 5];
  return;
}
void build(int rt, int l, int r) {
  int i, mid;
  tree[rt].cnt = 0;
  if (l == r) return;
  memset(tree[rt].sum, 0, sizeof(tree[rt].sum));
  mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
}
void update(int pos, int cnt, int l, int r, int add, int rt) {
  tree[rt].cnt += cnt;
  if (l == r) {
    tree[rt].sum[0] += add;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    update(pos, cnt, l, mid, add, rt << 1);
  else
    update(pos, cnt, mid + 1, r, add, rt << 1 | 1);
  pushup(rt);
}
int main() {
  int n, cnt, i, j, pos;
  while (scanf("%d", &n) != EOF) {
    cnt = 0;
    for (i = 0; i < n; ++i) {
      scanf("%s", s[i]);
      if (s[i][0] != 's') {
        scanf("%d", &q[i]);
        tmp[cnt++] = q[i];
      }
    }
    if (cnt > 0) {
      sort(tmp, tmp + cnt);
      cnt = unique(tmp, tmp + cnt) - tmp;
      build(1, 0, cnt - 1);
    }
    for (i = 0; i < n; ++i) {
      if (s[i][0] == 's') {
        cout << tree[1].sum[2] << endl;
      } else {
        pos = lower_bound(tmp, tmp + cnt, q[i]) - tmp;
        if (s[i][0] == 'a')
          update(pos, 1, 0, cnt - 1, q[i], 1);
        else
          update(pos, -1, 0, cnt - 1, -q[i], 1);
      }
    }
  }
  return 0;
}
