#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::string;
constexpr int MAXN = 1e5 + 5;
struct Node {
  int l, r;
  int fa;
  int siz;
  int ch[2];
  long long val;
  long long sum[6];
};
enum child { left = 0, right = 1 };
Node t[MAXN << 1 | 1];
int cnt;
int root;
int n;
inline int newNode(long long val = 0, int fa = 0) {
  ++cnt;
  t[cnt].val = val;
  t[cnt].sum[1] = val;
  t[cnt].fa = fa;
  t[cnt].siz = 1;
  return cnt;
}
inline void connect(int rt, int fa, int ch) {
  t[rt].fa = fa;
  t[fa].ch[ch] = rt;
}
inline int identify(int rt) { return t[t[rt].fa].ch[1] == rt; }
inline void pushUp(int rt) {
  t[rt].siz = t[t[rt].ch[0]].siz + t[t[rt].ch[1]].siz + 1;
  for (int i = 0; i < 5; ++i) {
    t[rt].sum[i] =
        t[t[rt].ch[0]].sum[i] +
        t[t[rt].ch[1]].sum[(i + 5 - ((t[t[rt].ch[0]].siz + 1) % 5)) % 5];
  }
  t[rt].sum[(t[t[rt].ch[0]].siz + 1) % 5] += t[rt].val;
}
inline void rotate(int x) {
  int y = t[x].fa;
  int z = t[y].fa;
  int chk = identify(x);
  connect(t[x].ch[chk ^ 1], y, chk);
  connect(y, x, chk ^ 1);
  t[x].fa = z;
  if (z) {
    t[z].ch[t[z].ch[1] == y] = x;
  }
  pushUp(y);
  pushUp(x);
}
inline void splay(int x, int to = root) {
  to = t[to].fa;
  while (t[x].fa != to) {
    int f = t[x].fa;
    if (t[f].fa == to) {
      rotate(x);
      break;
    } else if (identify(x) == identify(f)) {
      rotate(f);
      rotate(x);
    } else {
      rotate(x);
      rotate(x);
    }
  }
  if (!to) {
    root = x;
  }
}
inline int pre() {
  int rt = t[root].ch[0];
  while (t[rt].ch[1]) {
    rt = t[rt].ch[1];
  }
  return rt;
}
inline int nxt() {
  int rt = t[root].ch[1];
  while (t[rt].ch[0]) {
    rt = t[rt].ch[0];
  }
  return rt;
}
inline void insert(long long x) {
  if (!root) {
    root = newNode(x);
    return;
  }
  int rt = root;
  while (rt) {
    ++t[rt].siz;
    int nxt = t[rt].val < x;
    if (!t[rt].ch[nxt]) {
      t[rt].ch[nxt] = newNode(x, rt);
      pushUp(rt);
      splay(t[rt].ch[nxt]);
      return;
    } else {
      rt = t[rt].ch[nxt];
    }
  }
}
inline int rank(long long x) {
  int rt = root;
  int ans = 1;
  while (rt) {
    if (x < t[rt].val) {
      rt = t[rt].ch[0];
    } else {
      ans += t[t[rt].ch[0]].siz;
      if (t[rt].val == x) {
        splay(rt);
        return ans;
      }
      rt = t[rt].ch[1];
    }
  }
  return 0;
}
inline void del(long long k) {
  rank(k);
  if (!t[root].ch[0] && !t[root].ch[1]) {
    root = 0;
    return;
  }
  if (t[root].ch[0] && !t[root].ch[1]) {
    root = t[root].ch[0];
    t[root].fa = 0;
    return;
  }
  if (!t[root].ch[0] && t[root].ch[1]) {
    root = t[root].ch[1];
    t[root].fa = 0;
    return;
  }
  int x = pre();
  int rt = root;
  splay(x);
  connect(t[rt].ch[1], root, child::right);
  pushUp(root);
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    string opt;
    long long x;
    cin >> opt;
    if (opt[0] == 'a') {
      cin >> x;
      insert(x);
    } else if (opt[0] == 'd') {
      cin >> x;
      del(x);
    } else if (opt[0] == 's') {
      cout << t[root].sum[3] << endl;
    }
  }
  return 0;
}
