#include <bits/stdc++.h>
using namespace std;
vector<int> q;
vector<int>::iterator it;
int n;
int main() {
  char op[5];
  int a;
  while (scanf("%d", &n) != EOF) {
    q.clear();
    for (int i = 0; i < n; i++) {
      scanf("%s", op);
      if (op[0] == 'a') {
        scanf("%d", &a);
        it = lower_bound(q.begin(), q.end(), a);
        q.insert(it, a);
      } else if (op[0] == 'd') {
        scanf("%d", &a);
        it = lower_bound(q.begin(), q.end(), a);
        q.erase(it);
      } else {
        long long ans = 0;
        for (it = q.begin() + 2; it < q.end(); it += 5) {
          ans += *it;
        }
        printf("%I64d\n", ans);
      }
    }
  }
  return 0;
}
