#include <bits/stdc++.h>
using namespace std;
struct node {
  int cnt;
  long long sum[5];
};
int inp[1000005][2];
node seg[1000005];
void init(int x) {
  int i;
  seg[x].cnt = 0;
  for (i = 0; i < 5; i++) seg[x].sum[i] = 0;
}
inline void merge(int x) {
  int i, m;
  seg[x].cnt = seg[x * 2].cnt + seg[x * 2 + 1].cnt;
  m = seg[x * 2].cnt % 5;
  for (i = 0; i < 5; i++)
    seg[x].sum[i] = seg[x * 2].sum[i] + seg[x * 2 + 1].sum[(i + 5 - m) % 5];
}
void goinsert(int x, int l, int r, int p, int v) {
  if (l == r) {
    seg[x].sum[0] = (long long)v;
    seg[x].cnt = 1;
    return;
  } else {
    int m = (l + r) / 2;
    if (p <= m)
      goinsert(x * 2, l, m, p, v);
    else
      goinsert(x * 2 + 1, m + 1, r, p, v);
    merge(x);
  }
}
void godelete(int x, int l, int r, int p) {
  if (l == r) {
    seg[x].sum[0] = 0;
    seg[x].cnt = 0;
    return;
  } else {
    int m = (l + r) / 2;
    if (p <= m)
      godelete(x * 2, l, m, p);
    else
      godelete(x * 2 + 1, m + 1, r, p);
    merge(x);
  }
}
int main() {
  int n, i, m;
  map<int, int> v;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    char cnt[100];
    scanf("%s", cnt);
    if (cnt[0] != 's') {
      scanf("%d", &inp[i][1]);
      v[inp[i][1]] = 1;
    }
    if (cnt[0] == 'a')
      inp[i][0] = 1;
    else if (cnt[0] == 'd')
      inp[i][0] = 2;
    else
      inp[i][0] = 3;
  }
  m = 0;
  for (map<int, int>::iterator it = v.begin(); it != v.end(); it++) {
    (it->second) = ++m;
  }
  init(1);
  for (i = 0; i < n; i++) {
    if (inp[i][0] == 1)
      goinsert(1, 1, m, v[inp[i][1]], inp[i][1]);
    else if (inp[i][0] == 2)
      godelete(1, 1, m, v[inp[i][1]]);
    else
      printf("%I64d\n", seg[1].sum[2]);
  }
  return 0;
}
