#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void smn(T &a, const T &b) {
  if (b < a) a = b;
}
template <class T>
inline void smx(T &a, const T &b) {
  if (b > a) a = b;
}
template <class T>
inline T rev(const T &a) {
  T _ = a;
  reverse(_.begin(), _.end());
  return _;
}
const double eps = 1e-9;
const long double leps = 1e-14;
struct node {
  long long s[6];
  int t;
  node() { s[0] = s[1] = s[2] = s[3] = s[4] = s[5] = t = 0; }
};
const int MN = 1000 * 100 + 100;
node seg[(1 << 18) + 100];
map<int, int> mp;
set<int> mark;
set<int>::iterator it;
vector<pair<int, int> > op;
int n;
void add(int s, int e, int n, const int &k, const int &v, const int &u) {
  if (s == e) {
    seg[n].t = u;
    seg[n].s[0] = v;
    for (int i = 1; i < 5; i++) seg[n].s[i] = 0;
    return;
  }
  int m = (s + e) / 2;
  if (k <= m)
    add(s, m, 2 * n, k, v, u);
  else
    add(m + 1, e, 2 * n + 1, k, v, u);
  seg[n].t = seg[2 * n].t + seg[2 * n + 1].t;
  for (int i = 0; i < 5; i++) {
    long long now = seg[2 * n].s[i];
    int t = (i - seg[2 * n].t) % 5;
    if (t < 0) t += 5;
    now += seg[2 * n + 1].s[t];
    seg[n].s[i] = now;
  }
}
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s == "sum") {
      op.push_back(pair<int, int>(2, -1));
      continue;
    }
    int a;
    cin >> a;
    mark.insert(a);
    if (s == "add")
      op.push_back(pair<int, int>(0, a));
    else
      op.push_back(pair<int, int>(1, a));
  }
  it = mark.begin();
  for (int i = 0; it != mark.end(); it++, i++) mp[*it] = i;
  for (int i = 0; i < n; i++) {
    if (op[i].first == 2) {
      cout << seg[1].s[2] << '\n';
      continue;
    }
    if (op[i].first == 0)
      add(0, n + 10, 1, mp[op[i].second], op[i].second, 1);
    else
      add(0, n + 10, 1, mp[op[i].second], 0, 0);
  }
  return 0;
}
