#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int INF = 0x3f3f3f3f;
const int iinf = 1 << 30;
const long long linf = 2e18;
const int MOD = 1000000007;
const double eps = 1e-7;
void douout(double x) { printf("%lf\n", x + 0.0000000001); }
template <class T>
void print(T a) {
  cout << a << endl;
  exit(0);
}
template <class T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
void upd(T &a, T b) {
  (a += b) %= MOD;
}
template <class T>
void mul(T &a, T b) {
  a = (long long)a * b % MOD;
}
int Q;
long long ans;
vector<int> v;
signed main() {
  scanf("%d", &Q);
  while (Q--) {
    string op;
    int x;
    cin >> op;
    if (op[0] == 'a') {
      scanf("%d", &x);
      v.insert(lower_bound(v.begin(), v.end(), x), x);
    } else if (op[0] == 'd') {
      scanf("%d", &x);
      v.erase(lower_bound(v.begin(), v.end(), x));
    } else {
      int i = 2;
      ans = 0;
      while (i < ((int)v.size())) {
        ans += v[i];
        i += 5;
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}
