#include <bits/stdc++.h>
using namespace std;
long long ans;
int a[100000 + 5], p[100000 + 5];
struct Tree {
  int l, r;
  long long val[5], siz;
} T[800000 + 5];
void update(int pos) {
  T[pos].siz = T[pos * 2].siz + T[pos * 2 + 1].siz;
  for (int i = 0; i < 5; i++)
    T[pos].val[i] = T[pos * 2].val[i] +
                    T[pos * 2 + 1].val[(i - T[pos * 2].siz % 5 + 5) % 5];
}
void Build(int Left, int Right, int pos) {
  T[pos].l = Left;
  T[pos].r = Right;
  if (Left == Right) return;
  int mid = (T[pos].l + T[pos].r) / 2;
  Build(Left, mid, pos * 2);
  Build(mid + 1, Right, pos * 2 + 1);
}
void modify(int id, int pos, int opt) {
  if (T[pos].l >= id && T[pos].r <= id) {
    if (opt == 0)
      T[pos].val[++T[pos].siz] += p[id];
    else
      T[pos].val[T[pos].siz--] -= p[id];
    return;
  }
  int mid = (T[pos].l + T[pos].r) / 2;
  if (mid >= id)
    modify(id, pos * 2, opt);
  else
    modify(id, pos * 2 + 1, opt);
  update(pos);
}
char op[100000 + 5][10];
int main() {
  int n, m = 0, i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%s", op[i]);
    if (op[i][0] != 's') scanf("%d", &a[i]), p[++m] = a[i];
  }
  sort(p + 1, p + m + 1);
  m = unique(p + 1, p + m + 1) - p - 1;
  for (i = 1; i <= n; i++) a[i] = lower_bound(p + 1, p + m + 1, a[i]) - p;
  if (m != 0) Build(1, m, 1);
  for (i = 1; i <= n; i++) {
    if (op[i][0] == 'a') modify(a[i], 1, 0);
    if (op[i][0] == 'd') modify(a[i], 1, 1);
    if (op[i][0] == 's') printf("%lld\n", T[1].val[3]);
  }
}
