#include <bits/stdc++.h>
using namespace std;
struct tree {
  int tl, tr, cnt, add;
  long long key[5];
  tree *l, *r;
  tree(){};
  tree(int _tl, int _tr) : tl(_tl), tr(_tr), cnt(0), l(0), r(0), add(0) {
    key[0] = key[1] = key[2] = key[3] = key[4] = 0;
    if (tl != tr) {
      l = new tree(tl, (tl + tr) / 2);
      r = new tree((tl + tr) / 2 + 1, tr);
    }
  };
} * T;
typedef tree *node;
void push(node &t) {
  if (t->add) {
    long long safe[5];
    for (int i = 0; i < 5; i++) safe[i] = t->key[i];
    if (t->l) t->l->add += t->add;
    if (t->r) t->r->add += t->add;
    for (int i = 0; i < 5; i++) t->key[i] = safe[(i - t->add + 500000) % 5];
    t->add = 0;
  };
};
void add(node &t, int pos, long long value, int left_cnt) {
  push(t);
  if (t->tl == t->tr && t->tl == pos) {
    t->cnt = 1;
    t->key[left_cnt % 5] = value;
  } else {
    int mid = (t->tl + t->tr) / 2;
    if (pos > mid)
      add(t->r, pos, value, left_cnt + t->l->cnt);
    else {
      t->r->add++;
      add(t->l, pos, value, left_cnt);
    };
    push(t->l);
    push(t->r);
    for (int i = 0; i < 5; i++) t->key[i] = t->l->key[i] + t->r->key[i];
    t->cnt = t->l->cnt + t->r->cnt;
  };
};
void del(node &t, int pos) {
  push(t);
  if (t->tl == t->tr && t->tl == pos) {
    t->cnt = 0;
    t->key[0] = t->key[1] = t->key[2] = t->key[3] = t->key[4] = 0;
  } else {
    int mid = (t->tl + t->tr) / 2;
    if (pos > mid)
      del(t->r, pos);
    else {
      t->r->add--;
      del(t->l, pos);
    };
    push(t->l);
    push(t->r);
    for (int i = 0; i < 5; i++) t->key[i] = t->l->key[i] + t->r->key[i];
    t->cnt = t->l->cnt + t->r->cnt;
  };
};
int N, I, query[200000], val[200000];
string s;
set<int> st;
map<int, int> M;
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    cin >> s;
    if (s != "sum") {
      if (s == "add")
        query[i] = 1;
      else
        query[i] = 2;
      scanf("%I64d", &val[i]);
      st.insert(val[i]);
    };
  };
  st.insert(0);
  for (set<int>::iterator it = st.begin(); it != st.end(); it++) M[*it] = ++I;
  T = new tree(1, I);
  add(T, 1, 0, 0);
  for (int i = 0; i < N; i++) {
    if (query[i] == 0) printf("%I64d\n", T->key[3]);
    if (query[i] == 1) add(T, M[val[i]], val[i], 0);
    if (query[i] == 2) del(T, M[val[i]]);
  };
  return 0;
};
