#include <bits/stdc++.h>
using namespace std;
int a[101000], cnt, b[101000];
char s[101000][5];
struct Node {
  int l, r, cnt;
  long long sum[5];
  int mid() { return (l + r) >> 1; }
} f[101000 * 4];
void build(int l, int r, int k) {
  f[k].l = l;
  f[k].r = r;
  f[k].cnt = 0;
  for (int i = 0; i < 5; i++) f[k].sum[i] = 0;
  if (l == r) return;
  int mid = f[k].mid();
  build(l, mid, (k << 1));
  build(mid + 1, r, (k << 1 | 1));
}
int Binary(int n) {
  int l = 1, r = cnt - 1, mid;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (b[mid] == n) return mid;
    if (b[mid] < n)
      l = mid + 1;
    else
      r = mid - 1;
  }
  return mid;
}
void PushUp(int k) {
  for (int i = 0; i < 5; i++) {
    f[k].sum[i] =
        f[(k << 1)].sum[i] + f[(k << 1 | 1)].sum[(i + 5 - f[(k << 1)].cnt) % 5];
  }
}
void update(int idx, int val, int flag, int k) {
  f[k].cnt += flag;
  if (f[k].l == f[k].r) {
    f[k].sum[0] += (long long)val;
    return;
  }
  int mid = f[k].mid();
  if (idx <= mid)
    update(idx, val, flag, (k << 1));
  else
    update(idx, val, flag, (k << 1 | 1));
  PushUp(k);
}
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    cnt = 1;
    for (int i = 1; i <= n; i++) {
      scanf("%s", s[i]);
      if (s[i][0] != 's') {
        scanf("%d", &a[i]);
        if (s[i][0] == 'a') b[cnt++] = a[i];
      }
    }
    sort(b + 1, b + cnt);
    build(1, n, 1);
    for (int i = 1; i <= n; i++) {
      if (s[i][0] == 'a') {
        int idx = Binary(a[i]);
        update(idx, a[i], 1, 1);
      } else if (s[i][0] == 'd') {
        int idx = Binary(a[i]);
        update(idx, -a[i], -1, 1);
      } else {
        cout << f[1].sum[2] << endl;
      }
    }
  }
  return 0;
}
