#include <bits/stdc++.h>
using namespace std;
int n, x, newin;
string s;
vector<int> v;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    if (s != "sum") cin >> x;
    if (s == "add") v.insert(lower_bound(v.begin(), v.end(), x), x);
    if (s == "del") v.erase(lower_bound(v.begin(), v.end(), x));
    if (s == "sum") {
      int ans = 0;
      for (int i = 2; i < v.size(); i += 5) ans += v[i];
      cout << ans << endl;
    }
  }
  return 0;
}
