#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int flag;
char op[MAXN][10];
long long mod[MAXN << 2][5], sum[MAXN << 2];
int a[MAXN], b[MAXN];
void push_up(int rt) {
  sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
  for (int i = 0; i < 5; i++)
    mod[rt][i] =
        mod[rt << 1][i] + mod[rt << 1 | 1][((i - sum[rt << 1]) % 5 + 5) % 5];
}
void update(int pos, int add, int l, int r, int rt) {
  if (l == r) {
    sum[rt] = flag;
    mod[rt][1] = flag * add;
    return;
  }
  int m = (l + r) >> 1;
  if (pos <= m)
    update(pos, add, l, m, rt << 1);
  else
    update(pos, add, m + 1, r, rt << 1 | 1);
  push_up(rt);
}
int main() {
  int n, m = 0;
  cin >> n;
  memset(mod, 0, sizeof(mod));
  memset(sum, 0, sizeof(sum));
  for (int i = 0; i < n; i++) {
    scanf("%s", op[i]);
    if (op[i][0] != 's') {
      scanf("%d", &a[i]);
      b[m++] = a[i];
    }
  }
  sort(b, b + m);
  m = unique(b, b + m) - b;
  for (int i = 0; i < n; i++) {
    if (op[i][0] == 's') {
      cout << mod[1][3] << endl;
      continue;
    }
    if (op[i][0] == 'a')
      flag = 1;
    else
      flag = 0;
    int pos = lower_bound(b, b + m, a[i]) - b + 1;
    update(pos, a[i], 1, n, 1);
  }
  return 0;
}
