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