#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, tot;
int b[N], add[N << 2];
long long sum[N << 2][5];
struct number {
  int x, f;
} num[N];
char str[10];
void change(int k, int l, int r, int v1, int v2, int pos) {
  if (l == r) {
    sum[k][1] += (long long)v1;
    add[k] += v2;
    return;
  }
  int mid = l + r >> 1;
  if (pos <= mid)
    change(k << 1, l, mid, v1, v2, pos);
  else
    change(k << 1 | 1, mid + 1, r, v1, v2, pos);
  add[k] = add[k << 1] + add[k << 1 | 1];
  for (register int i = 0; i <= 4; ++i) {
    int now = (i - add[k << 1] % 5 + 5) % 5;
    sum[k][i] = sum[k << 1][i] + sum[k << 1 | 1][now];
  }
}
int main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; ++i) {
    scanf("%s", str + 1);
    if (str[1] == 'a') {
      scanf("%d", &num[i].x);
      num[i].f = 1;
      b[++tot] = num[i].x;
    } else if (str[1] == 'd') {
      scanf("%d", &num[i].x);
      num[i].f = -1;
    } else {
      num[i].f = 0;
    }
  }
  sort(b + 1, b + tot + 1);
  tot = unique(b + 1, b + tot + 1) - b - 1;
  for (register int i = 1; i <= n; ++i) {
    if (!num[i].f)
      printf("%lld\n", sum[1][3]);
    else {
      int v1 = num[i].x;
      int v2 = num[i].f;
      int pos = lower_bound(b + 1, b + tot + 1, num[i].x) - b;
      change(1, 1, n, v1, v2, pos);
    }
  }
  return 0;
}
