#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, l, cnt, at;
int op[200002], oper[200002];
int a[200002];
char s[200002];
int v[200000];
long long sums[5][10000], ans;
int mod5[10000];
void recalc(int at) {
  int i, j;
  for (i = 0; i < 5; i++) sums[i][at] = 0;
  j = 0;
  for (i = k * at; i < k * (at + 1); i++)
    if (v[i]) {
      sums[j][at] += v[i];
      j++;
      if (j >= 5) j -= 5;
    }
}
int main() {
  scanf("%d\n", &m);
  for (i = 0; i < m; i++) {
    scanf("%s", s);
    if (s[0] == 'a') {
      op[i] = 1;
      scanf("%d\n", &oper[i]);
      a[n++] = oper[i];
    }
    if (s[0] == 'd') {
      op[i] = 2;
      scanf("%d\n", &oper[i]);
    }
    if (s[0] == 's') {
      op[i] = 3;
      scanf("\n");
    }
  }
  sort(a, a + n);
  n = unique(a, a + n) - a;
  k = (int)sqrt(1.0 * n) + 5;
  cnt = (n + k - 1) / k;
  for (l = 0; l < m; l++)
    if (op[l] == 1) {
      i = lower_bound(a, a + n, oper[l]) - a;
      int at = i / k;
      v[i] = oper[l];
      for (j = at + 1; j < cnt; j++) {
        mod5[j]++;
        if (mod5[j] >= 5) mod5[j] -= 5;
      }
      recalc(at);
    } else if (op[l] == 2) {
      i = lower_bound(a, a + n, oper[l]) - a;
      int at = i / k;
      v[i] = 0;
      for (j = at + 1; j < cnt; j++) {
        mod5[j]--;
        if (mod5[j] < 0) mod5[j] += 5;
      }
      recalc(at);
    } else {
      ans = 0;
      for (j = 0; j < cnt; j++) ans += sums[(7 - mod5[j]) % 5][j];
      cout << ans << endl;
    }
  return 0;
}
