#include <bits/stdc++.h>
using namespace std;
long long st[4 * 100000][5];
struct strc {
  int x1, x2;
} stt[100000];
int ar[100000], bt[4 * 100000];
char s[3];
map<int, int> m;
map<int, int>::iterator it;
void ud(int n, int l, int r, int x, int in) {
  if (in)
    ++bt[n];
  else
    --bt[n];
  if (l == r) {
    if (in)
      st[n][1] = x;
    else
      st[n][1] = 0;
    return;
  }
  int mid = l + r >> 1;
  if (x > mid)
    ud(n + 1 << 1, mid + 1, r, x, in);
  else
    ud(n << 1 | 1, l, mid, x, in);
  for (int i = 0; i < 5; ++i) {
    int tmp = (bt[n << 1 | 1] + i) % 5;
    st[n][tmp] = st[n << 1 | 1][tmp] + st[n + 1 << 1][i];
  }
}
int main() {
  int q, x, ii;
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    scanf("%s", &s);
    if (s[0] == 's')
      ar[i] = 0;
    else {
      scanf("%d", &x);
      m[x];
      if (s[0] == 'a')
        ar[i] = x;
      else
        ar[i] = -x;
    }
  }
  ii = 0;
  for (it = m.begin(); it != m.end(); ++it) it->second = ++ii;
  for (int i = 0; i < q; ++i) {
    if (!ar[i])
      printf("%I64d\n", st[0][3]);
    else if (ar[i] > 0) {
      it = m.find(ar[i]);
      ud(0, 1, 100000, it->second, 1);
    } else {
      it = m.find(-ar[i]);
      ud(0, 1, 100000, it->second, 0);
    }
  }
}
