#include <bits/stdc++.h>
using namespace std;
set<long long> st;
int main() {
  int i, j, n, x;
  char c[5];
  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    scanf("%s", c);
    if (c[0] == 'a')
      scanf("%d", &x), st.insert(x);
    else if (c[0] == 'd')
      scanf("%d", &x), st.erase(x);
    else {
      long long ans = 0, pt = 0;
      for (set<long long>::iterator it = st.begin(); it != st.end(); it++) {
        ++pt;
        if (pt % 5 == 3) ans += *it;
      }
      printf("%d\n", ans);
    }
  }
  return 00;
}
