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