#include <bits/stdc++.h>
using namespace std;
struct TREE {
  int len;
  long long sum[5];
};
struct Q {
  char c;
  int x;
  void read() {
    char s[7];
    scanf("%s", s);
    c = s[0];
    if (c != 's') scanf("%d", &x);
  }
};
const int maxn = 100007;
int n;
Q q[maxn];
TREE tree[maxn * 4];
void build(int mark, int L, int R) {
  tree[mark].len = 0;
  memset(tree[mark].sum, 0, sizeof(tree[mark].sum));
  if (L == R) return;
  int mid = (L + R) / 2;
  build(mark * 2, L, mid);
  build(mark * 2 + 1, mid + 1, R);
}
void update(TREE &mid, TREE L, TREE R) {
  mid.len = L.len + R.len;
  for (int i = 0; i < 5; i++) mid.sum[i] = L.sum[i];
  for (int i = 0; i < 5; i++) mid.sum[(L.len + i) % 5] += R.sum[i];
}
void insert(int mark, int L, int R, int x, int val, int len) {
  if (L == R) {
    tree[mark].len = len;
    tree[mark].sum[1] = val;
    return;
  }
  int mid = (L + R) / 2;
  if (x <= mid)
    insert(mark * 2, L, mid, x, val, len);
  else
    insert(mark * 2 + 1, mid + 1, R, x, val, len);
  update(tree[mark], tree[mark * 2], tree[mark * 2 + 1]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) q[i].read();
  build(1, 1, n);
  map<int, int> X;
  for (int i = 1; i <= n; i++) X[q[i].x];
  int sign = 0;
  for (map<int, int>::iterator it = X.begin(); it != X.end(); it++)
    it->second = ++sign;
  for (int i = 1; i <= n; i++) {
    if (q[i].c == 'a') insert(1, 1, n, X[q[i].x], q[i].x, 1);
    if (q[i].c == 'd') insert(1, 1, n, X[q[i].x], 0, 0);
    if (q[i].c == 's') cout << tree[1].sum[3] << endl;
  }
  return 0;
}
