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