#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1024 * 1024;
long long n;
char op[128];
long long nums[maxn];
long long cnt = 0;
char Op[maxn] = {};
long long data_[maxn] = {};
struct node {
  long long move;
  long long mods[5];
  long long l, r;
  node *L, *R;
} pool[maxn << 1], *g[maxn];
node *root = &pool[++cnt];
void add_(long long l, long long r, long long pos, node *&p, long long num,
          long long add) {
  if (!p) {
    p = &pool[++cnt];
    p->l = l;
    p->r = r;
  }
  if (l == r) {
    p->mods[1] += num * add;
    p->move += add;
    return;
  }
  if (pos <= (l + r) >> 1)
    add_(l, (l + r) >> 1, pos, p->L, num, add);
  else
    add_(1 + (l + r) >> 1, r, pos, p->R, num, add);
  if (!p->L) {
    p->L = &pool[++cnt];
    p->L->l = l;
    p->L->r = (l + r) >> 1;
  }
  if (!p->R) {
    p->R = &pool[++cnt];
    p->R->l = 1 + (l + r) >> 1;
    p->R->r = r;
  }
  p->move = p->L->move + p->R->move;
  for (long long i = 0; i < 5; i++)
    p->mods[i] = p->L->mods[i] + p->R->mods[((i - p->L->move) % 5 + 5) % 5];
}
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> op;
    Op[i] = op[0];
    if (op[0] != 's') {
      cin >> nums[i];
      data_[i] = nums[i];
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (Op[i] == 's') {
      cout << root->mods[3] << endl;
    } else {
      if (Op[i] == 'a')
        add_(1, n, data_[i], root, data_[i], 1);
      else
        add_(1, n, data_[i], root, data_[i], -1);
    }
  }
  return 0;
}
