#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;
const int MAXA = 1e9;
int n;
vector<int> seg, e, d;
long long sum;
int create();
int bb(int pos, int ini, int fim, int val);
void update(int pos, int ini, int fim, int id, int val);
void defining(int pos, int ini, int fim, int p, int q, int aux, int id);
int main() {
  create();
  create();
  scanf("%d", &n);
  int m = 0;
  for (int i = 0; i < n; i++) {
    char type[5];
    int aux;
    scanf(" %s", type);
    if (type[0] != 's') scanf("%d", &aux);
    if (type[0] == 'a') {
      update(1, 1, MAXA, aux, 1);
      defining(1, 1, MAXA, 1, seg[1], 1, aux);
    }
    if (type[0] == 'd') {
      update(1, 1, MAXA, aux, -1);
      defining(1, aux, MAXA, 1, seg[1], -1, aux);
    }
    if (type[0] == 's') {
      printf("%lld\n", sum);
    }
  }
}
void defining(int pos, int ini, int fim, int p, int q, int aux, int id) {
  if (pos == 0) return;
  if (seg[pos] == 0) return;
  if (q - p < 0) return;
  if (ini == fim) {
    if (p % 5 == 3 + aux) sum -= ini;
    if (p % 5 == 3) sum += ini;
    return;
  }
  int mid = ini + ((fim - ini) >> 1);
  if (id <= mid) defining(e[pos], ini, mid, p, p + seg[e[pos]] - 1, aux, id);
  defining(d[pos], mid + 1, fim, q - seg[d[pos]] + 1, q, aux, id);
  return;
}
int bb(int pos, int ini, int fim, int val) {
  if (ini == fim) return ini;
  int mid = ini + ((fim - ini) >> 1);
  if (seg[e[pos]] >= val)
    return bb(e[pos], ini, mid, val);
  else
    return bb(d[pos], mid + 1, fim, val - seg[e[pos]]);
}
void update(int pos, int ini, int fim, int id, int val) {
  if (ini > id || fim < id) return;
  if (ini == fim) {
    seg[pos] += val;
    return;
  }
  int mid = ini + ((fim - ini) >> 1);
  if (id <= mid) {
    if (e[pos] == 0) {
      int aux = create();
      e[pos] = aux;
    }
    update(e[pos], ini, mid, id, val);
  }
  if (id > mid) {
    if (d[pos] == 0) {
      int aux = create();
      d[pos] = aux;
    }
    update(d[pos], mid + 1, fim, id, val);
  }
  seg[pos] = seg[e[pos]] + seg[d[pos]];
  return;
}
int create() {
  seg.push_back(0);
  e.push_back(0);
  d.push_back(0);
  return seg.size() - 1;
}
