#include <bits/stdc++.h>
using namespace std;
struct BNode {
  int _arr[316];
  long long _sum[5];
  int _cnt;
  BNode *_prev, *_next;
  BNode() : _cnt(0), _prev(0), _next(0) { update(); }
  void update() {
    memset(_sum, 0, sizeof(_sum));
    for (int i = 0; i < _cnt; ++i) _sum[i % 5] += _arr[i];
  }
  void insert(int p, const int &x) {
    for (int i = _cnt++; i > p; --i) _arr[i] = _arr[i - 1];
    _arr[p] = x;
    update();
  }
  void insert2(int p, const int &x) {
    for (int i = 0; i < p; ++i) _arr[i] = _arr[i + 1];
    _arr[p] = x;
    update();
  }
  void erase(int p) {
    --_cnt;
    for (int i = p; i < _cnt; ++i) _arr[i] = _arr[i + 1];
    update();
  }
};
struct Rope {
  BNode *_head, *_tail;
  Rope() {
    _head = new BNode;
    _tail = new BNode;
    _head->_next = _tail;
    _tail->_prev = _head;
    _head->_cnt = _tail->_cnt = 316;
  }
  ~Rope() {
    delete _head;
    delete _tail;
  }
  void clear() {}
  bool empty() const { return _head->_next == _tail; }
  void insert(const int &x) {
    if (empty()) {
      BNode *nd = new BNode;
      nd->insert(0, x);
      nd->_next = _tail;
      nd->_prev = _head;
      _tail->_prev = nd;
      _head->_next = nd;
      return;
    }
    BNode *it;
    for (it = _head->_next; it != _tail; it = it->_next)
      if (x <= it->_arr[it->_cnt - 1]) break;
    if (it == _tail) it = it->_prev;
    int p = lower_bound(it->_arr, it->_arr + it->_cnt, x) - it->_arr;
    if (it->_cnt < 316) {
      it->insert(p, x);
    } else {
      if (it->_prev->_cnt < 316) {
        it->_prev->insert(it->_prev->_cnt, it->_arr[0]);
        it->insert2(p, x);
      } else if (it->_next->_cnt < 316) {
        it->_next->insert(0, it->_arr[it->_cnt - 1]);
        --it->_cnt;
        it->insert(p, x);
      } else {
        BNode *nd = new BNode;
        nd->insert(0, it->_arr[316 - 1]);
        --it->_cnt;
        it->insert(p, x);
        nd->_next = it->_next;
        nd->_prev = it;
        it->_next = nd;
        nd->_next->_prev = nd;
      }
    }
  }
  void erase(const int &x) {
    BNode *it;
    for (it = _head->_next; it != _tail; it = it->_next)
      if (x <= it->_arr[it->_cnt - 1]) break;
    if (it == _tail) return;
    int p = lower_bound(it->_arr, it->_arr + it->_cnt, x) - it->_arr;
    if (p == it->_cnt || it->_arr[p] != x) return;
    for (int i = p; i < it->_cnt - 1; ++i) it->_arr[i] = it->_arr[i + 1];
    --it->_cnt;
    if (it->_cnt + it->_prev->_cnt <= 316) {
      copy(it->_arr, it->_arr + it->_cnt, it->_prev->_arr + it->_prev->_cnt);
      it = it->_prev;
      it->_cnt += it->_next->_cnt;
      BNode *t = it->_next;
      it->_next = it->_next->_next;
      it->_next->_prev = it;
      delete t;
    } else if (it->_cnt + it->_next->_cnt <= 316) {
      copy(it->_next->_arr, it->_next->_arr + it->_next->_cnt,
           it->_arr + it->_cnt);
      it->_cnt += it->_next->_cnt;
      BNode *t = it->_next;
      it->_next = it->_next->_next;
      it->_next->_prev = it;
      delete t;
    }
    it->update();
  }
  long long query() {
    BNode *it;
    long long ans = 0;
    int cnt = 0;
    for (it = _head->_next; it != _tail; it = it->_next) {
      ans += it->_sum[((2 - cnt) % 5 + 5) % 5];
      cnt += it->_cnt;
    }
    return ans;
  }
} rope;
int main() {
  int n, x;
  char opt[15];
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", opt);
    if (opt[0] == 'a') {
      scanf("%d", &x);
      rope.insert(x);
    } else if (opt[0] == 'd') {
      scanf("%d", &x);
      rope.erase(x);
    } else {
      printf("%I64d\n", rope.query());
    }
  }
  return 0;
}
