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