#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int MAXN = 100000 + 100;
const long long INF = 1e18;
const int inf = 522133279;
const int mod = 1000000009;
int n;
vector<int> lis;
int main() {
  cin >> n;
  while (n--) {
    string op;
    int x;
    cin >> op;
    if (op == "add") {
      cin >> x;
      vector<int>::iterator it = lower_bound(lis.begin(), lis.end(), x);
      lis.insert(it, x);
    } else if (op == "del") {
      cin >> x;
      vector<int>::iterator it = lower_bound(lis.begin(), lis.end(), x);
      lis.erase(it);
    } else {
      long long sum = 0;
      for (int i = 2; i < lis.size(); i += 5) sum += lis[i];
      cout << sum << endl;
    }
  }
  return 0;
}
