#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 233;
struct cdd {
  long long sum[5];
  int num;
} ch[maxn * 4];
int op[maxn], a[maxn], b[maxn];
void update(int l, int r, int cur, int x) {
  if (l == r) {
    if (ch[cur].num == 1) {
      ch[cur].num = 0;
      ch[cur].sum[0] = 0;
    } else {
      ch[cur].num = 1;
      ch[cur].sum[0] = b[l];
    }
    return;
  }
  int lc = cur << 1, rc = lc | 1, mid = (l + r >> 1);
  if (x <= mid)
    update(l, mid, lc, x);
  else
    update(mid + 1, r, rc, x);
  for (int i = 0; i < 5; i++)
    ch[cur].sum[i] = ch[lc].sum[i] + ch[rc].sum[(i + ch[lc].num) % 5];
  ch[cur].num = ch[lc].num + ch[rc].num;
  return;
}
int main() {
  int n, cnt = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    if (s[0] == 'a') {
      op[i] = 1;
      cin >> a[i];
      b[++cnt] = a[i];
    } else if (s[0] == 'd') {
      op[i] = 2;
      cin >> a[i];
    } else
      op[i] = 3;
  }
  sort(b + 1, b + 1 + cnt);
  for (int i = 1; i < 4 * maxn; i++) {
    for (int j = 0; j < 5; j++) ch[i].sum[j] = 0;
    ch[i].num = 0;
  }
  for (int i = 1; i <= n; i++) {
    if (op[i] == 1) {
      int k = lower_bound(b + 1, b + 1 + cnt, a[i]) - b;
      update(1, cnt, 1, k);
    } else if (op[i] == 2) {
      int k = lower_bound(b + 1, b + 1 + cnt, a[i]) - b;
      update(1, cnt, 1, k);
    } else
      printf("%I64d\n", ch[1].sum[3]);
  }
}
