#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
struct node {
  node *l, *r;
  int cnt[6];
  int p;
} res[6 * MAXN + 10], *nil;
int tmp[MAXN + 10], xb;
node *Build(int n, int l, int r) {
  res[n].l = res[n].r = nil;
  res[n].p = -1;
  memset(res[n].cnt, 0, sizeof res[n].cnt);
  if (l == r) return &res[n];
  int m = (l + r) >> 1;
  res[n].l = Build(n * 2, l, m);
  res[n].r = Build(n * 2 + 1, m + 1, r);
  return &res[n];
}
int od[MAXN + 10], sv[MAXN + 10];
void Insert(node *now, int l, int r, int id, int val, int le) {
  if (now->l == nil && now->r == nil) {
    now->p = (now->p + le + 5) % 5;
    now->cnt[now->p] += val * le;
  } else {
    int md = (l + r) >> 1;
    if (id <= md)
      Insert(now->l, l, md, id, val, le);
    else
      Insert(now->r, md + 1, r, id, val, le);
    now->p = (now->l->p + now->r->p + 6) % 5;
    for (int i = 0; i < 5; i++)
      now->cnt[i] = now->l->cnt[i] + now->r->cnt[(i - now->l->p + 9) % 5];
  }
}
int main() {
  char ord[10];
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", ord);
    if (ord[0] == 's')
      od[i] = 1;
    else if (ord[0] == 'a') {
      od[i] = 2;
      scanf("%d", &sv[i]);
      tmp[xb++] = sv[i];
    } else if (ord[0] == 'd') {
      od[i] = 3;
      scanf("%d", &sv[i]);
      tmp[xb++] = sv[i];
    }
  }
  sort(tmp, tmp + xb);
  int len = unique(tmp, tmp + xb) - tmp;
  Build(1, 0, len);
  for (int i = 0; i < n; i++) {
    if (od[i] == 2)
      Insert(&res[1], 0, len, lower_bound(tmp, tmp + len, sv[i]) - tmp, sv[i],
             1);
    else if (od[i] == 3)
      Insert(&res[1], 0, len, lower_bound(tmp, tmp + len, sv[i]) - tmp, sv[i],
             -1);
    else if (od[i] == 1)
      printf("%d\n", res[1].cnt[2]);
  }
  return 0;
}
