#include <bits/stdc++.h>
using namespace std;
vector<int> vec;
int main() {
  int n, t;
  string op;
  cin >> n;
  while (n--) {
    cin >> op;
    if (op == "add") {
      cin >> t;
      vec.push_back(t);
    }
    if (op == "sum") {
      sort(vec.begin(), vec.end());
      int sum = 0;
      for (int i = 0; i < vec.size(); i++) {
        if ((i + 1) % 5 == 3) sum += vec[i];
      }
      printf("%d\n", sum);
    }
    if (op == "del") {
      cin >> t;
      vector<int>::iterator f = find(vec.begin(), vec.end(), t);
      vec.erase(f);
    }
  }
}
