#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
vector<int> vec;
string type;
int n, num;
long long res;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  while (n--) {
    cin >> type;
    if (type[0] == 'a') {
      cin >> num;
      vec.insert(lower_bound(vec.begin(), vec.end(), num), num);
    }
    if (type[0] == 'd') {
      cin >> num;
      vec.erase(lower_bound(vec.begin(), vec.end(), num));
    }
    if (type[0] == 's') {
      res = 0;
      for (int i = 2; i < vec.size(); i += 5) res += vec[i];
      cout << res << endl;
    }
  }
  return 0;
}
