#include <bits/stdc++.h>
using namespace std;
int n, u[100005], b[100005], op[100005], T, o[100005], t;
struct node {
  int l, r, val;
  long long c[5];
} a[100005 << 2];
void build(int x, int l, int r) {
  a[x].l = l;
  a[x].r = r;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build((x << 1), l, mid);
  build(((x << 1) | 1), mid + 1, r);
}
void updata(int x) {
  a[x].val = a[(x << 1)].val + a[((x << 1) | 1)].val;
  for (int k = 0; k <= 4; k++) a[x].c[k] = a[(x << 1)].c[k];
  for (int k = 0; k <= 4; k++)
    a[x].c[(k + a[(x << 1)].val) % 5] += a[((x << 1) | 1)].c[k];
}
void change(int x, int pos, int op) {
  if (a[x].l == a[x].r) {
    if (op)
      a[x].val++, a[x].c[1] += b[pos];
    else
      a[x].val--, a[x].c[1] -= b[pos];
    return;
  }
  int mid = (a[x].l + a[x].r) >> 1;
  if (mid >= pos)
    change((x << 1), pos, op);
  else
    change(((x << 1) | 1), pos, op);
  updata(x);
}
int main() {
  scanf("%d", &n);
  char s[4];
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    if (s[0] == 'a')
      op[i] = 0, scanf("%d", &u[i]), o[++t] = u[i];
    else if (s[0] == 'd')
      op[i] = 1, scanf("%d", &u[i]);
    else
      op[i] = 2;
  }
  sort(o + 1, o + t + 1);
  for (int i = 1; i <= t; i++)
    if (o[i] != o[i - 1]) b[++T] = o[i];
  for (int i = 1; i <= n; i++)
    if (op[i] < 2) u[i] = lower_bound(b + 1, b + T + 1, u[i]) - b;
  build(1, 1, T + 1);
  for (int i = 1; i <= n; i++) {
    if (!op[i])
      change(1, u[i], 1);
    else if (op[i] == 1)
      change(1, u[i], 0);
    else
      printf("%lld\n", a[1].c[3]);
  }
  return 0;
}
