#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[5];
  set<int> a;
  long long sum;
  int n, del;
  scanf("%d", &n);
  while (n--) {
    scanf("%s", s);
    if (s[0] == 's') {
      sum = 0;
      set<int>::iterator it = a.begin();
      int b = 0;
      while (it != a.end() && b <= 2) {
        it++;
        b++;
      }
      while (it != a.end()) {
        sum += *it;
        b = 0;
        while (it != a.end() && b <= 5) {
          it++;
          b++;
        }
      }
      printf("%I64d\n", sum);
      continue;
    }
    scanf("%d", &del);
    if (s[0] == 'a') {
      a.insert(del);
      continue;
    }
    if (s[0] == 'd') {
      a.erase(del);
      continue;
    }
  }
  return 0;
}
