#include <bits/stdc++.h>
using namespace std;
const int INF = 1061109567;
const int NINF = -1044266559;
const LL LINF = 4557430888798830399;
const ld eps = 1e-15;
inline int Read() {
  int x = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return w ? -x : x;
}
inline void Write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) Write(x / 10);
  putchar(x % 10 + '0');
}
inline LL powmod(LL a, LL b) {
  LL res = 1;
  a %= (1000000007);
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % (1000000007);
    a = a * a % (1000000007);
  }
  return res % (1000000007);
}
inline LL gcdll(LL a, LL b) { return b ? gcdll(b, a % b) : a; }
const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int dy[] = {1, 0, -1, 0, -1, -1, 1, 1};
const int maxn = 100010;
typedef struct node *pnode;
struct node {
  int key, cnt, pri;
  LL sum;
  pnode l, r;
  node(int _key = 0, int _pri = 0) : key(_key), pri(_pri), l(NULL), r(NULL) {
    cnt = 1;
    sum = key;
  }
};
inline int cnt(pnode u) { return u ? u->cnt : 0; }
inline LL sum(pnode u) { return u ? u->sum : 0; }
inline void upd(pnode u) {
  if (u) {
    u->cnt = cnt(u->l) + cnt(u->r) + 1;
    u->sum = sum(u->l) + sum(u->r) + u->key;
  }
}
inline void merge(pnode &u, pnode l, pnode r) {
  if (!l || !r)
    u = l ? l : r;
  else if (l->pri > r->pri) {
    merge(l->r, l->r, r);
    u = l;
  } else {
    merge(r->l, l, r->l);
    u = r;
  }
}
inline void split(pnode u, int key, pnode &l, pnode &r) {
  if (!u)
    l = r = NULL;
  else if (key <= u->key) {
    split(u->l, key, l, u->l);
    r = u;
  } else {
    split(u->r, key, u->r, r);
    l = u;
  }
  upd(u);
}
int n, rands[maxn];
node nodes[maxn];
pnode root[5];
int main() {
  cin >> n;
  for (int i = 0; i < ((int)(n)); i++) rands[i] = i;
  random_shuffle(rands, rands + n);
  for (int step = 0; step < ((int)(n)); step++) {
    string buf;
    int val;
    cin >> buf;
    if (buf == "sum")
      cout << sum(root[2]) << endl;
    else {
      cin >> val;
      pnode ends[5];
      for (int i = 0; i < ((int)(5)); i++)
        split(root[i], val, root[i], ends[i]);
      if (buf == "add") {
        int mn = INF;
        for (int i = 0; i < ((int)(5)); i++) mn = min(mn, cnt(root[i]));
        for (int i = 0; i < ((int)(5)); i++)
          if (cnt(root[i]) == mn) {
            nodes[step] = node(val, rands[step]);
            merge(root[i], root[i], &nodes[step]);
            break;
          }
        for (int i = 0; i < ((int)(5)); i++)
          merge(root[i], root[i], ends[(i + 4) % 5]);
      } else {
        for (int i = 0; i < ((int)(5)); i++) {
          pnode buf;
          split(ends[i], val + 1, buf, ends[i]);
        }
        for (int i = 0; i < ((int)(5)); i++)
          merge(root[i], root[i], ends[(i + 1) % 5]);
      }
    }
  }
  return 0;
}
