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