#include <bits/stdc++.h>
using namespace std;
int a[100001], ans[100001], c, d;
string s;
int main() {
  int n, i, j, k, kb;
  cin >> n;
  a[++c] = n;
  while (1) {
    cin >> s >> i;
    if (s[0] == 'a') {
      a[++c] = i;
    }
    if (s[0] == 'd') {
      for (j = 1; j <= c; j++) {
        if (a[j] == i) a[j] = -1;
      }
    }
    if (s[0] == 's') {
      sort(a, a + c);
      for (j = 1; j <= c; j++) {
        if (a[j] != -1) break;
      }
      d++;
      for (k = j + 3; k <= c; k += 5) {
        ans[d] += a[k];
      }
    } else
      break;
  }
  for (i = 1; i <= n; i++) cout << ans[i] << endl;
  return 0;
}
