#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
template <class _T>
inline string tostr(const _T& a) {
  ostringstream os("");
  os << a;
  return os.str();
}
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 1e-9;
typedef struct item* pitem;
struct item {
  int prior, cnt;
  long long value, f;
  pitem l, r;
};
int cnt(pitem it) { return it ? it->cnt : 0; }
long long f(pitem it) { return it ? it->f : 0; }
void upd_cnt(pitem it) {
  if (it) {
    it->cnt = cnt(it->l) + cnt(it->r) + 1;
    it->f = f(it->l) + f(it->r) + it->value;
  }
}
void merge(pitem& t, pitem l, pitem r) {
  if (!l || !r)
    t = l ? l : 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);
}
void split1(pitem t, pitem& l, pitem& r, int key, int add = 0) {
  if (!t) return void(l = r = 0);
  int cur_key = t->value;
  if (key <= cur_key)
    split1(t->l, l, t->l, key, add), r = t;
  else
    split1(t->r, t->r, r, key, add + 1 + cnt(t->l)), l = t;
  upd_cnt(t);
}
void split(pitem t, pitem& l, pitem& r, int key, int add = 0) {
  if (!t) return void(l = r = 0);
  int cur_key = add + cnt(t->l);
  if (key <= cur_key)
    split(t->l, l, t->l, key, add), r = t;
  else
    split(t->r, t->r, r, key, add + 1 + cnt(t->l)), l = t;
  upd_cnt(t);
}
void output(pitem t) {
  if (!t) return;
  output(t->l);
  printf("%d ", t->value);
  output(t->r);
}
pitem T[5], T1[5], T2[5], T3[5];
int n, x;
char C[120];
int main() {
  cout.flags(ios::fixed);
  cout.precision(2);
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%s", C);
    if (C[0] == 's') {
      long long ret = 0;
      if (T[2]) ret = T[2]->f;
      printf("%I64d\n", ret);
    }
    if (C[0] == 'a') {
      scanf("%d", &x);
      long long ind = 0, bst = 1000000000;
      for (int j = 0; j < 5; j++) {
        split1(T[j], T1[j], T3[j], x);
        split(T1[j], T1[j], T2[j], 0);
        if (T2[j]) {
          if (abs(x - T2[j]->value) < bst) {
            bst = abs(x - T2[j]->value);
            ind = j + 1;
            if (ind == 5) ind = 0;
          }
        }
      }
      pitem q = new item;
      q->prior = (rand() % 10000) * 10000 + rand() % 10000;
      q->l = NULL;
      q->r = NULL;
      q->cnt = 1;
      q->value = x;
      q->f = x;
      merge(T2[ind], T2[ind], q);
      for (int j = 0; j < 5; j++) {
        merge(T[j], T1[j], T2[j]);
      }
      for (int j = 0; j < 5; j++) {
        merge(T[j], T[j], T3[(j + 4) % 5]);
      }
    }
    if (C[0] == 'd') {
      scanf("%d", &x);
      long long ind = 0, bst = 1000000000;
      for (int j = 0; j < 5; j++) {
        split1(T[j], T1[j], T3[j], x + 1);
        split(T1[j], T1[j], T2[j], 0);
        if (T2[j]) {
          if (abs(x - T2[j]->value) < bst) {
            bst = abs(x - T2[j]->value);
            ind = j;
          }
        }
      }
      T2[ind] = NULL;
      for (int j = 0; j < 5; j++) {
        merge(T[j], T1[j], T2[j]);
      }
      for (int j = 0; j < 5; j++) {
        merge(T[j], T[j], T3[(j + 1) % 5]);
      }
    }
  }
  return 0;
}
