#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000100;
const int INF = (1 << 29);
int N;
char op[maxn][10];
int Q[maxn];
int X[maxn], Xn;
struct Node {
  int cnt;
  long long sum[5];
};
Node T[maxn << 2];
void push_up(int rt) {
  T[rt].cnt = T[rt << 1].cnt + T[rt << 1 | 1].cnt;
  for (int i = 0; i < 5; i++) {
    T[rt].sum[i] =
        T[rt << 1].sum[i] + T[rt << 1 | 1].sum[(i - T[rt << 1].cnt + 5) % 5];
  }
}
void build(int l, int r, int rt) {
  if (l > r) return;
  if (l == r) {
    T[rt].cnt = 0;
    for (int i = 0; i < 5; i++) T[rt].sum[i] = 0;
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
  push_up(rt);
}
void update(int pos, int val, int op, int l, int r, int rt) {
  if (l == r) {
    if (op == 1) {
      if (T[rt].cnt == 1) return;
    }
    if (op == -1) {
      if (T[rt].cnt == 0) return;
    }
    T[rt].cnt += op;
    T[rt].sum[1] += val;
    return;
  }
  int m = (l + r) >> 1;
  if (pos <= m)
    update(pos, val, op, l, m, rt << 1);
  else
    update(pos, val, op, m + 1, r, rt << 1 | 1);
  push_up(rt);
}
void get(int l, int r, int rt) {
  if (l == r) return;
  int m = (l + r) >> 1;
  get(l, m, rt << 1);
  get(m + 1, r, rt << 1 | 1);
  return;
}
int main() {
  while (cin >> N) {
    Xn = 0;
    for (int i = 1; i <= N; i++) {
      scanf("%s", op[i]);
      if (op[i][0] != 's') {
        scanf("%d", &Q[i]);
        X[++Xn] = Q[i];
      }
    }
    sort(X + 1, X + Xn + 1);
    Xn = unique(X + 1, X + Xn + 1) - (X + 1);
    build(1, Xn, 1);
    for (int i = 1; i <= N; i++) {
      int pos = lower_bound(X + 1, X + Xn + 1, Q[i]) - X;
      if (op[i][0] == 'a')
        update(pos, Q[i], 1, 1, Xn, 1);
      else if (op[i][0] == 'd')
        update(pos, -Q[i], -1, 1, Xn, 1);
      else
        printf("%I64d\n", T[1].sum[3]);
    }
  }
  return 0;
}
