#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 17, D = 2 * N + 10;
int n, a[N], b[N], c[N], s[D], te[N];
long long t[D][5];
void update(int i, int x) {
  i += N - 1;
  if (x)
    s[i] = 1, t[i][0] = x;
  else
    s[i] = t[i][0] = 0;
  for (i >>= 1; i; i >>= 1) {
    s[i] = s[i << 1] + s[i << 1 | 1];
    for (int j = 0; j < 5; j++) {
      int k = (s[i << 1] + j) % 5;
      t[i][k] = t[i << 1][k] + t[i << 1 | 1][j];
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    char es[10];
    scanf("%s", es);
    if (es[0] != 's') {
      scanf("%d", &a[i]);
      b[i] = a[i];
      if (es[0] == 'd') te[i] = 1;
    } else
      te[i] = 2;
  }
  sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; i++) c[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;
  for (int i = 1; i <= n; i++)
    if (!te[i])
      update(c[i], a[i]);
    else if (te[i] == 1)
      update(c[i], 0);
    else
      printf("%lld\n", t[1][2]);
  return 0;
}
