#include <bits/stdc++.h>
using namespace std;
map<long long, int> map1;
map<long long, int> map2;
long long a[200010];
struct Node {
  int left, right, cnt;
  long long s[5];
} node[200010 * 10];
void Build(int l, int r, int p) {
  node[p].left = l;
  node[p].right = r;
  node[p].cnt = 0;
  for (int i = 0; i < 5; i++) node[p].s[i] = 0;
  if (l == r) {
    map1[a[l]] = p;
    return;
  }
  int mid = (l + r) >> 1;
  Build(l, mid, p << 1);
  Build(mid + 1, r, p << 1 | 1);
}
void Add(long long x) {
  int tt = map1[x];
  node[tt].cnt = 1;
  node[tt].s[0] = x;
  tt >>= 1;
  while (tt) {
    node[tt].cnt++;
    int tmp = node[tt << 1].cnt;
    for (int i = 0; i < 5; i++) node[tt].s[i] = node[tt << 1].s[i];
    for (int i = 0; i < 5; i++)
      node[tt].s[(tmp + i) % 5] += node[tt << 1 | 1].s[i];
    tt >>= 1;
  }
}
void Del(long long x) {
  int tt = map1[x];
  node[tt].cnt = 0;
  for (int i = 0; i < 5; i++) node[tt].s[i] = 0;
  tt >>= 1;
  while (tt) {
    if (node[tt].cnt > 0) node[tt].cnt--;
    int tmp = node[tt << 1].cnt;
    for (int i = 0; i < 5; i++) node[tt].s[i] = node[tt << 1].s[i];
    for (int i = 0; i < 5; i++)
      node[tt].s[(tmp + i) % 5] += node[tt << 1 | 1].s[i];
    tt >>= 1;
  }
}
struct Data {
  int id;
  long long x;
} data[200010 * 5];
char str[10];
string s;
int main() {
  string s;
  int n, m, i, j;
  while (~scanf("%d", &n)) {
    m = 0;
    for (i = 1; i <= n; i++) {
      scanf("%s", &str);
      if (strcmp(str, "add") == 0) {
        scanf("%I64d", &data[i].x);
        data[i].id = 0;
        a[++m] = data[i].x;
      } else if (strcmp(str, "del") == 0) {
        scanf("%I64d", &data[i].x);
        data[i].id = 1;
      } else
        data[i].id = 2;
    }
    a[++m] = 0;
    sort(a + 1, a + m + 1);
    map1.clear();
    Build(1, m, 1);
    map2.clear();
    Add(0);
    map2[0] = 1;
    for (i = 1; i <= n; i++) {
      if (data[i].id == 0) {
        if (map2[data[i].x] == 0) {
          map2[data[i].x] = 1;
          Add(data[i].x);
        }
      } else if (data[i].id == 1) {
        if (map2[data[i].x] == 1) {
          map2[data[i].x] = 0;
          Del(data[i].x);
        }
      } else
        printf("%I64d\n", node[1].s[3]);
    }
  }
  return 0;
}
