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