#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  int n, value;
  char str[200];
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> str;
    if (strcmp(str, "add") == 0) {
      cin >> value;
      v.insert(lower_bound(v.begin(), v.end(), value), value);
    } else if (strcmp(str, "del") == 0) {
      cin >> value;
      v.erase(lower_bound(v.begin(), v.end(), value));
    } else if (strcmp(str, "sum") == 0) {
      long long sum = 0;
      for (int j = 2; j < v.size(); j += 5) {
        sum += v[j];
      }
      cout << sum << endl;
    }
  }
  return 0;
}
