#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
const long long N = 200017;
vector<int> v;
long long get_sum() {
  long long sum = 0;
  for (int i = 2; i < v.size(); i += 5) sum += (v[i] * 1ll);
  return sum;
}
void solve() {
  int q;
  cin >> q;
  while (q--) {
    string type;
    cin >> type;
    if (type == "add") {
      int x;
      cin >> x;
      v.insert(lower_bound(v.begin(), v.end(), x), x);
    } else if (type == "del") {
      int x;
      cin >> x;
      v.erase(lower_bound(v.begin(), v.end(), x));
    } else {
      cout << get_sum() << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t24 = 1;
  while (t24--) {
    solve();
    cout << "\n";
  }
}
