#include <bits/stdc++.h>
using namespace std;
char str[1 << 8];
int main() {
  int n, x;
  long long sum = 0;
  scanf("%d", &n);
  vector<int> vec;
  while (n--) {
    scanf("%s", str);
    if (str[0] == 'a') {
      scanf("%d", &x);
      vec.insert(lower_bound(vec.begin(), vec.end(), x), x);
    } else if (str[0] == 'd') {
      scanf("%d", &x);
      vec.erase(lower_bound(vec.begin(), vec.end(), x));
    } else {
      int cur = 2;
      sum = 0;
      while (cur < vec.size()) {
        sum += vec[cur];
        cur += 5;
      }
      printf("%lld\n", sum);
    }
  }
  return 0;
}
