#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
char s[10];
int main() {
  int n, i;
  long long x, all;
  while (~scanf("%d", &n)) {
    while (n--) {
      scanf("%s", s);
      if (s[0] == 'a') {
        scanf("%lld", &x);
        v.insert(lower_bound(v.begin(), v.end(), x), x);
      } else if (s[0] == 'd') {
        scanf("%lld", &x);
        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;
}
