#include <bits/stdc++.h>
using namespace std;
int n, k, a[100005], cnt;
struct Op {
  string s;
  int val;
} op[100005];
struct Tree {
  int l, r, cnt, mod[7];
} tree[4 * 100005];
void push_up(int x) {
  for (int i = 0; i < 5; i++)
    tree[x].mod[i] = tree[x << 1].mod[i] +
                     tree[x << 1 | 1].mod[((i - tree[x].cnt) % 5 + 5) % 5];
}
void build(int x, int l, int r) {
  tree[x].l = l, tree[x].r = r, tree[x].cnt = 0;
  if (l == r) {
    memset(tree[x].mod, 0, sizeof(tree[x].mod));
    return;
  }
  int mid = (l + r) >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  push_up(x);
}
void update(int x, int pos, int val) {
  tree[x].cnt += val;
  int l = tree[x].l, r = tree[x].r;
  if (l == r) {
    if (tree[x].cnt == 0)
      tree[x].mod[0] = 0;
    else
      tree[x].mod[0] = a[pos];
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    update(x << 1, pos, val);
  else
    update(x << 1 | 1, pos, val);
  push_up(x);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> op[i].s;
    if (op[i].s != "sum") {
      cin >> op[i].val;
      a[++cnt] = op[i].val;
    }
  }
  sort(a + 1, a + 1 + cnt);
  int len = unique(a + 1, a + 1 + cnt) - a - 1;
  build(1, 1, len);
  for (int i = 1; i <= n; i++) {
    string ty = op[i].s;
    if (ty == "add") {
      int pos = lower_bound(a + 1, a + 1 + len, op[i].val) - a;
      update(1, pos, 1);
    } else if (ty == "del") {
      int pos = lower_bound(a + 1, a + 1 + len, op[i].val) - a;
      update(1, pos, -1);
    } else
      cout << tree[1].mod[3] << endl;
  }
}
