#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int n, x;
char s[9];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (*s == 's') {
      long long z = 0;
      for (long long j = 2; j < a.size(); j += 5) z += a[j];
      cout << z << endl;
    } else {
      cin >> x;
      if (*s == 'a') {
        a.insert(lower_bound(a.begin(), a.end(), x), x);
      } else {
        a.erase(lower_bound(a.begin(), a.end(), x));
      }
    }
  }
  return 0;
}
