#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > q;
vector<int> X;
vector<int>::iterator it;
int Q, s[100100 * 5];
long long f[100100 * 5][5];
void Update(int nd, int l, int r, int x) {
  if (l == r) {
    if (s[nd])
      s[nd] = f[nd][0] = 0;
    else
      s[nd] = 1, f[nd][0] = X[x];
  } else {
    int i, m = (l + r) / 2;
    if (x <= m)
      Update(nd * 2, l, m, x);
    else
      Update(nd * 2 + 1, m + 1, r, x);
    for (i = 0; i <= 4; i++)
      f[nd][i] = f[nd * 2][i] + f[nd * 2 + 1][(i + 5 - s[nd * 2]) % 5];
    s[nd] = (s[nd * 2] + s[nd * 2 + 1]) % 5;
  }
}
int main() {
  freopen("d.in", "r", stdin);
  int i, x;
  char s[11];
  cin >> Q;
  for (i = 0; i <= Q - 1; i++) {
    scanf("%s", &s);
    if (s[0] == 's')
      q.push_back(make_pair(0, 0));
    else {
      scanf("%d", &x);
      if (s[0] == 'a')
        q.push_back(make_pair(1, x));
      else
        q.push_back(make_pair(-1, x));
      X.push_back(x);
    }
  }
  sort(X.begin(), X.end());
  it = unique(X.begin(), X.end());
  X.resize(it - X.begin());
  for (i = 0; i <= Q - 1; i++)
    if (q[i].first) {
      x = lower_bound(X.begin(), X.end(), q[i].second) - X.begin();
      Update(1, 0, int(X.size()) - 1, x);
    } else
      printf("%lld\n", f[1][2]);
  return 0;
}
