#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const long long LINF = 1000000000000000000LL;
void prepare() {}
struct item {
  int key, prior, cnt;
  long long sum[5];
  item *l, *r;
  item() {}
  item(int key, int prior) : key(key), prior(prior), l(0), r(0) {}
};
typedef item *pitem;
inline int cnt(pitem t) {
  if (t)
    return t->cnt;
  else
    return 0;
}
void upd_cnt(pitem t) {
  if (t) t->cnt = 1 + cnt(t->l) + cnt(t->r);
}
void upd_sum(pitem t) {
  if (t) {
    memset(t->sum, 0, sizeof(t->sum));
    int mv = 0;
    if (t->l) {
      mv = t->l->cnt;
      for (int i = 0; i < 5; i++) t->sum[i] = t->l->sum[i];
    }
    mv %= 5;
    t->sum[mv] += t->key;
    mv = (mv + 1) % 5;
    if (t->r) {
      for (int i = 0; i < 5; i++) t->sum[(mv + i) % 5] += t->r->sum[i];
    }
  }
}
void split(pitem t, int key, pitem &l, pitem &r) {
  if (!t) {
    l = r = 0;
  } else if (key < t->key) {
    split(t->l, key, l, t->l);
    r = t;
  } else {
    split(t->r, key, t->r, r);
    l = t;
  }
  upd_cnt(l);
  upd_cnt(r);
  upd_sum(l);
  upd_sum(r);
}
void insert(pitem &t, pitem it) {
  if (!t) {
    t = it;
  } else if (it->prior > t->prior) {
    split(t, it->key, it->l, it->r);
    t = it;
  } else {
    if (it->key < t->key)
      insert(t->l, it);
    else
      insert(t->r, it);
  }
  upd_cnt(t);
  upd_sum(t);
}
void merge(pitem &t, pitem l, pitem r) {
  if (!l || !r) {
    if (l)
      t = l;
    else
      t = r;
  } else if (l->prior > r->prior) {
    merge(l->r, l->r, r);
    t = l;
  } else {
    merge(r->l, l, r->l);
    t = r;
  }
  upd_cnt(t);
  upd_sum(t);
}
void erase(pitem &t, int key) {
  if (t->key == key) {
    merge(t, t->l, t->r);
  } else {
    if (key < t->key)
      erase(t->l, key);
    else
      erase(t->r, key);
  }
  upd_cnt(t);
  upd_sum(t);
}
pitem tree = 0;
char tmp[100];
bool solve() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", tmp);
    if (tmp[0] == 'a') {
      int p;
      scanf("%d", &p);
      insert(tree, new item(p, rand()));
    } else if (tmp[0] == 'd') {
      int p;
      scanf("%d", &p);
      erase(tree, p);
    } else {
      if (!tree)
        printf("0\n");
      else
        printf("%I64d\n", tree->sum[2]);
    }
  }
  return false;
}
int main() {
  prepare();
  while (solve())
    ;
  return 0;
}
