#include <bits/stdc++.h>
using namespace std;
vector<int> val;
int main() {
  int t;
  char ch[10];
  scanf("%d", &t);
  while (t--) {
    scanf("%s", ch);
    if (ch[0] == 'a') {
      int tmp;
      scanf("%d", &tmp);
      val.insert(lower_bound(val.begin(), val.end(), tmp), tmp);
    } else if (ch[0] == 'd') {
      int tmp;
      scanf("%d", &tmp);
      val.erase(lower_bound(val.begin(), val.end(), tmp));
    } else {
      long long res = 0;
      for (int i = 2; i < val.size(); i += 5) {
        res += val[i];
      }
      cout << res << endl;
    }
  }
  return 0;
}
