#include <bits/stdc++.h>
using namespace std;
struct NodeData {
  NodeData() : key(0), prior(0), cnt(0), sum(0), l(0), r(0) {}
  NodeData(int key, int prior)
      : key(key), prior(prior), cnt(1), sum(key), l(0), r(0) {}
  int key, prior, cnt;
  long long sum;
  NodeData *l, *r;
};
typedef NodeData* Node;
int cnt(Node t) { return t ? t->cnt : 0; }
long long sum(Node t) { return t ? t->sum : 0; }
void updateNode(Node t) {
  if (t) {
    t->cnt = 1 + cnt(t->l) + cnt(t->r);
    t->sum = t->key + sum(t->l) + sum(t->r);
  }
}
void split(Node t, int key, Node& l, Node& 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;
  updateNode(l);
  updateNode(r);
}
void merge(Node l, Node r, Node& t) {
  if (!l)
    t = r;
  else if (!r)
    t = l;
  else if (l->prior > r->prior)
    merge(l->r, r, l->r), t = l;
  else
    merge(l, r->l, r->l), t = r;
  updateNode(t);
}
void insert(Node& t, Node el) {
  if (!t)
    t = el;
  else if (el->prior > t->prior)
    split(t, el->key, el->l, el->r), t = el;
  else if (el->key < t->key)
    insert(t->l, el);
  else
    insert(t->r, el);
}
void erase(Node& t, int key) {
  if (t) {
    if (key < t->key)
      erase(t->l, key);
    else if (key > t->key)
      erase(t->r, key);
    else
      merge(t->l, t->r, t);
  }
}
char buf[102];
const int maxn = 200007;
NodeData memPool[maxn];
int next_free = 0;
int main() {
  Node ans[5] = {0, 0, 0, 0, 0};
  int n;
  scanf("%d", &n);
  for (int iter = 0; iter < (n); ++iter) {
    scanf("%s", buf);
    if (strcmp(buf, "sum") == 0) {
      printf("%I64d\n", sum(ans[2]));
    } else {
      bool isAdd = (strcmp(buf, "add") == 0);
      int val;
      scanf("%d", &val);
      if (isAdd) {
        Node l[5], r[5];
        for (int i = 0; i < (5); ++i) split(ans[i], val, l[i], r[i]);
        int ind = 0;
        for (int i = 0; i < (5); ++i) ind += cnt(l[i]);
        for (int i = 0; i < (5); ++i) merge(l[i], r[(i + 4) % 5], ans[i]);
        NodeData& newEl = memPool[next_free++];
        newEl = NodeData(val, (int)long long(rand()) * rand());
        insert(ans[ind % 5], &newEl);
      } else {
        Node l[5], r[5];
        for (int i = 0; i < (5); ++i) split(ans[i], val, l[i], r[i]);
        int ind = 0;
        for (int i = 0; i < (5); ++i) ind += cnt(l[i]);
        erase(r[ind % 5], val);
        for (int i = 0; i < (5); ++i) merge(l[i], r[(i + 1) % 5], ans[i]);
      }
    }
  }
  return 0;
}
