#include <bits/stdc++.h>
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int mod = 199999;
const double eps = 1e-6;
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  long long f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f *= -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  x *= f;
}
template <typename T, typename... Args>
void read(T &first, Args &...args) {
  read(first);
  read(args...);
}
using namespace std;
const int maxn = 1e5 + 10;
int val[maxn * 40][5], lc[maxn * 40], rc[maxn * 40], cnt[maxn * 40], tot;
void pushup(int root) {
  for (int i = 0; i < 5; ++i) val[root][i] = val[lc[root]][i];
  for (int i = 0; i < 5; ++i)
    val[root][(i + cnt[lc[root]]) % 5] += val[rc[root]][i];
  cnt[root] = cnt[lc[root]] + cnt[rc[root]];
}
void insert(int &root, int l, int r, int k, int v) {
  if (!root) {
    root = ++tot;
  }
  if (l == r) {
    cnt[root] += v;
    val[root][1] += 1ll * k * v;
    return;
  }
  int mid = l + r >> 1;
  if (k <= mid)
    insert(lc[root], l, mid, k, v);
  else
    insert(rc[root], mid + 1, r, k, v);
  pushup(root);
}
int main() {
  char op[10];
  int n;
  int rt = 0, x;
  read(n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", op);
    if (strcmp(op, "sum") == 0)
      printf("%lld\n", val[rt][3]);
    else if (strcmp(op, "del") == 0) {
      read(x);
      insert(rt, 1, 1e9, x, -1);
    } else {
      read(x);
      insert(rt, 1, 1e9, x, 1);
    }
  }
}
