#include <bits/stdc++.h>
using namespace std;
vector<int> vec;
int main(int argc, char *argv[]) {
  int N;
  scanf("%d", &N);
  for (int i = 0, _i = N; i < _i; ++i) {
    char s[10];
    scanf("%s", s);
    if (*s == 's') {
      long long ans = 0;
      for (int i = 2; i < vec.size(); i += 5) ans += vec[i];
      cout << ans << "\n";
    } else {
      int x;
      scanf("%d", &x);
      vector<int>::iterator it = lower_bound(vec.begin(), vec.end(), x);
      if (*s == 'a') {
        vec.insert(it, x);
      } else {
        vec.erase(it);
      }
    }
  }
  return 0;
}
