#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  char s[32];
  vector<int> v;
  for (int i = 0, x; i < n && cin >> s; ++i)
    if ('s' == *s) {
      long long t = 0;
      for (int i = 2; i < v.size(); i += 5) t += v[i];
      cout << t << endl;
    } else if (cin >> x) {
      vector<int>::iterator it = lower_bound(v.begin(), v.end(), x);
      if ('a' == *s)
        v.insert(it, x);
      else
        v.erase(it);
    }
  return 0;
}
