#include <bits/stdc++.h>
using namespace std;
int n, m = 0;
int lsh[100010];
struct Question {
  int f, x;
} que[100010];
struct Segment_Tree {
  long long data[5];
  int num, l, r;
} a[100010 << 2];
inline int read() {
  int date = 0, w = 1;
  char c = 0;
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    date = date * 10 + c - '0';
    c = getchar();
  }
  return date * w;
}
inline void pushup(int rt) {
  a[rt].num = a[rt << 1].num + a[rt << 1 | 1].num;
  for (int i = 0; i < 5; i++)
    a[rt].data[i] = a[rt << 1].data[i] +
                    a[rt << 1 | 1].data[((i - a[rt << 1].num) % 5 + 5) % 5];
}
void buildtree(int l, int r, int rt) {
  a[rt].l = l;
  a[rt].r = r;
  a[rt].num = 0;
  if (l >= r) return;
  int mid = l + r >> 1;
  buildtree(l, mid, rt << 1);
  buildtree(mid + 1, r, rt << 1 | 1);
}
void update(int k, int c, long long v, int rt) {
  if (a[rt].l == a[rt].r) {
    a[rt].data[1] += v;
    a[rt].num += c;
    return;
  }
  int mid = a[rt].l + a[rt].r >> 1;
  if (k <= mid)
    update(k, c, v, rt << 1);
  else
    update(k, c, v, rt << 1 | 1);
  pushup(rt);
}
void work() {
  for (int i = 1, x; i <= n; i++) {
    if (que[i].f == 1) {
      x = lower_bound(lsh + 1, lsh + m + 1, que[i].x) - lsh;
      update(x, 1, que[i].x, 1);
    } else if (que[i].f == -1) {
      x = lower_bound(lsh + 1, lsh + m + 1, que[i].x) - lsh;
      update(x, -1, -que[i].x, 1);
    } else
      cout << a[1].data[3] << endl;
  }
}
void init() {
  char ch[2];
  n = read();
  for (int i = 1, x; i <= n; i++) {
    scanf("%s", ch);
    if (ch[0] == 'a') {
      x = read();
      lsh[++m] = que[i].x = x;
      que[i].f = 1;
    } else if (ch[0] == 'd') {
      x = read();
      que[i].x = x;
      que[i].f = -1;
    } else
      que[i].f = 0;
  }
  sort(lsh + 1, lsh + m + 1);
  m = unique(lsh + 1, lsh + m + 1) - lsh - 1;
  buildtree(1, m, 1);
}
int main() {
  init();
  work();
  return 0;
}
