#include <bits/stdc++.h>
using namespace std;
struct Node {
  int l, r, sum;
  long long a[5];
} t[100010 << 2];
struct Query {
  int opt, x;
} query[100010];
int n, tmp[100010], tot;
map<int, int> mp;
void pushup(int rt) {
  t[rt].sum = t[rt << 1].sum + t[rt << 1 | 1].sum;
  memset(t[rt].a, 0, sizeof(t[rt].a));
  int d = t[rt << 1].sum % 5;
  for (int i = 0; i < 5; i++) {
    t[rt].a[i] += t[rt << 1].a[i];
    t[rt].a[i] += t[rt << 1 | 1].a[(i - d + 5) % 5];
  }
}
void build(int rt, int l, int r) {
  if (r < l) return;
  t[rt].l = l;
  t[rt].r = r;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
}
void add(int rt, int pos, int c) {
  if (t[rt].l == t[rt].r) {
    t[rt].sum = 1;
    t[rt].a[1] = c;
    return;
  }
  int mid = (t[rt].l + t[rt].r) >> 1;
  if (pos <= mid) add(rt << 1, pos, c);
  if (mid < pos) add(rt << 1 | 1, pos, c);
  pushup(rt);
}
void del(int rt, int pos, int c) {
  if (t[rt].l == t[rt].r) {
    t[rt].sum = 0;
    t[rt].a[1] = 0;
    return;
  }
  int mid = (t[rt].l + t[rt].r) >> 1;
  if (pos <= mid) del(rt << 1, pos, c);
  if (mid < pos) del(rt << 1 | 1, pos, c);
  pushup(rt);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    char ch[10];
    scanf("%s", ch);
    if (ch[0] == 'a') {
      query[i].opt = 1;
      scanf("%d", &query[i].x);
      tmp[++tot] = query[i].x;
    }
    if (ch[0] == 'd') {
      query[i].opt = 2;
      scanf("%d", &query[i].x);
    }
    if (ch[0] == 's') {
      query[i].opt = 3;
    }
  }
  sort(tmp + 1, tmp + 1 + tot);
  tot = unique(tmp + 1, tmp + 1 + tot) - tmp - 1;
  for (int i = 1; i <= tot; i++) mp[tmp[i]] = i;
  build(1, 1, tot);
  for (int i = 1; i <= n; i++) {
    if (query[i].opt == 1) {
      add(1, mp[query[i].x], query[i].x);
    }
    if (query[i].opt == 2) {
      del(1, mp[query[i].x], query[i].x);
    }
    if (query[i].opt == 3) {
      printf("%I64d\n", t[1].a[3]);
    }
  }
  return 0;
}
