#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, k;
char s[N];
std::vector<int> v;
int main() {
  while (~scanf("%d", &n)) {
    v.clear();
    for (int i = 0; i < n; i++) {
      scanf("%s", s);
      if (s[0] == 's') {
        int ans = 0;
        for (int i = 2; i < n; i += 5) ans += v[i];
        printf("%d\n", ans);
        continue;
      }
      scanf("%d", &k);
      if (s[0] == 'a')
        v.insert(lower_bound(v.begin(), v.end(), k), k);
      else if (s[0] == 'd')
        v.erase(lower_bound(v.begin(), v.end(), k));
    }
  }
  return 0;
}
