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