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