#include <bits/stdc++.h>
using namespace std;
vector<int> vec;
int n;
string Coms[] = {"add", "del", "sum"};
bool flag = true;
int main() {
  scanf("%d", &n);
  string com;
  int k;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> com;
    if (com == Coms[0]) {
      scanf("%d", &k);
      flag = false;
      vec.insert(lower_bound(vec.begin(), vec.end(), k), k);
    } else if (com == Coms[1]) {
      scanf("%d", &k);
      flag = false;
      vec.erase(lower_bound(vec.begin(), vec.end(), k));
    } else {
      ans = 0;
      for (int j = 2; j < (int)vec.size(); j += 5) ans += vec[j];
      printf("%lld\n", ans);
    }
  }
  return 0;
}
