#include <bits/stdc++.h>
using namespace std;
pair<int, int> ask[100010];
int a[100010];
struct node {
  long long sum[5 + 1];
  int size;
};
node tree[100010 << 2];
inline void pushUp(int rt) {
  int i, j;
  for (i = 1; i <= 5; i++) {
    j = 5 - (tree[rt << 1].size % 5) + i;
    j %= 5;
    if (j == 0) j = 5;
    tree[rt].sum[i] = tree[rt << 1].sum[i] + tree[rt << 1 | 1].sum[j];
  }
  tree[rt].size = tree[rt << 1].size + tree[rt << 1 | 1].size;
}
void update(int x, int val, int L, int R, int rt) {
  if (L == R) {
    if (val > 0)
      tree[rt].size = 1;
    else
      tree[rt].size = 0;
    tree[rt].sum[1] += val;
  } else {
    int mid = (L + R) >> 1;
    if (x <= mid)
      update(x, val, L, mid, rt << 1);
    else
      update(x, val, mid + 1, R, rt << 1 | 1);
    pushUp(rt);
  }
}
int main() {
  int n, cnt, i, x;
  char str[10];
  while (~scanf("%d", &n)) {
    for (cnt = i = 0; i < n; i++) {
      scanf(" %s", str);
      if (str[0] == 'a') {
        ask[i].first = 0;
        scanf("%d", &ask[i].second);
        a[cnt++] = ask[i].second;
      } else if (str[0] == 'd') {
        ask[i].first = 1;
        scanf("%d", &ask[i].second);
        a[cnt++] = ask[i].second;
      } else
        ask[i].first = 2;
    }
    sort(a, a + cnt);
    cnt = unique(a, a + cnt) - a;
    memset(tree, 0, sizeof(tree));
    for (i = 0; i < n; i++) {
      if (ask[i].first == 0) {
        x = lower_bound(a, a + cnt, ask[i].second) - a;
        update(x, ask[i].second, 0, cnt - 1, 1);
      } else if (ask[i].first == 1) {
        x = lower_bound(a, a + cnt, ask[i].second) - a;
        update(x, -ask[i].second, 0, cnt - 1, 1);
      } else
        printf("%I64d\n", tree[1].sum[3]);
    }
  }
  return 0;
}
