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