#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
string s;
int main() {
  long long x, all, i, n;
  while (cin >> n) {
    while (n--) {
      cin >> s;
      if (s == "add") {
        cin >> x;
        getchar();
        v.insert(lower_bound(v.begin(), v.end(), x), x);
      } else if (s == "del") {
        cin >> x;
        getchar();
        v.erase(lower_bound(v.begin(), v.end(), x));
      } else {
        all = 0;
        for (i = 2; i < v.size(); i += 5) all += v[i];
        printf("%lld\n", all);
      }
    }
  }
  return 0;
}
