#include <bits/stdc++.h>
struct mlist {
  struct node_t {
    node_t *pre, *nxt;
    long long key;
    node_t(long long k = 0) : key(0) { clear(); }
    inline void clear() { pre = nxt = NULL; }
  };
  typedef node_t *iterator;
  typedef node_t &reference;
  int cnt;
  node_t node[500000];
  iterator new_node(long long key) {
    node[cnt].clear();
    node[cnt].key = key;
    return node + cnt++;
  }
  struct block_t {
    static int const SIZE = 500;
    int _size;
    long long sum[5];
    node_t head, tail;
    int const &size() const { return _size; }
    int &size() { return _size; }
    void clear() {
      head.clear();
      tail.clear();
      _size = 0;
      head.nxt = &tail;
      head.key = (1LL << 60);
      tail.pre = &head;
      tail.key = -(1LL << 60);
      init();
    }
    void init() { memset(sum, 0, sizeof(sum)); }
    block_t() { clear(); }
    long long min() const { return head.nxt->key; }
    long long max() const { return tail.pre->key; }
    bool flowup() const { return size() > SIZE; }
    bool is_flow() const { return size() == SIZE; }
    void modify(void) {
      sum[4] -= tail.pre->key;
      long long tmp = sum[4];
      for (int i = 4; i > 1; --i) sum[i] = sum[i - 1];
      sum[0] = tmp + head.nxt->key;
    }
    void modify(int _) {
      sum[0] -= head.nxt->key;
      long long tmp = sum[0];
      for (int i = 0; i < 3; ++i) sum[i] = sum[i + 1];
      sum[4] = tmp + tail.pre->key;
    }
    void deal() {
      init();
      iterator it = head.nxt;
      for (int i = 0; i < _size; ++i) {
        sum[i % 5] += it->key;
        it = it->nxt;
      }
    }
    void out() const {
      iterator begin = head.nxt;
      for (int i = 0; i < size(); ++i, begin = begin->nxt) {
        fprintf(stderr, "%lld ", begin->key);
      }
      fputc('\n', stderr);
    }
  };
  static int const BSIZE = 250;
  block_t block[BSIZE];
  int len;
  inline bool in_block(long long key, block_t const &b) const {
    return b.min() <= key && key <= b.max();
  }
  inline iterator up_bound(long long key, block_t const &b) const {
    iterator it = NULL;
    if (in_block(key, b) || b.size() < block_t::SIZE) {
      for (it = b.head.nxt; it != &b.tail && it->key < key; it = it->nxt)
        ;
      return it;
    }
    return NULL;
  }
  inline iterator find(long long key, block_t const &b) const {
    iterator it = NULL;
    if (in_block(key, b) && b.size() > 0) {
      for (it = b.head.nxt; it && it->key != key; it = it->nxt)
        ;
      return it;
    }
    return NULL;
  }
  inline void add_key(long long key, block_t &b) {
    iterator it = up_bound(key, b);
    iterator in = new_node(key);
    in->pre = it->pre;
    in->nxt = it;
    it->pre->nxt = in;
    it->pre = in;
    ++b.size();
  }
  inline void add_it(iterator it, block_t &b) { add_key(it->key, b); }
  inline iterator remove_it(iterator it) {
    it->pre->nxt = it->nxt;
    it->nxt->pre = it->pre;
    it->clear();
    return it;
  }
  inline void remove_key(long long key, block_t &b) {
    remove_it(find(key, b));
    --b.size();
  }
  inline void add_it_before_x(iterator it, iterator x) {
    it->pre = x->pre;
    it->nxt = x;
    x->pre->nxt = it;
    x->pre = it;
  }
  void add(long long key) {
    for (int i = 0; i < len; ++i) {
      if (in_block(key, block[i]) || !block[i].is_flow()) {
        add_key(key, block[i]);
        for (int j = i; j < len; ++j)
          if (block[j].flowup()) {
            block[j].modify();
            add_it_before_x(remove_it(block[j].tail.pre),
                            block[j + 1].head.nxt);
            --block[j].size();
            ++block[j + 1].size();
          }
        block[i].deal();
        block[len - 1].deal();
        if (block[len].size() != 0) {
          block[len].deal();
          ++len;
        }
        if (block[len - 1].is_flow()) ++len;
        break;
      }
    }
  }
  void del(long long key) {
    for (int i = 0; i < len; ++i) {
      if (in_block(key, block[i]) && block[i].size() > 0) {
        remove_key(key, block[i]);
        for (int j = len - 1; j > i; --j) {
          add_it_before_x(remove_it(block[j].head.nxt), &block[j - 1].tail);
          --block[j].size();
          ++block[j - 1].size();
          if (j != i && block[j - 1].flowup()) block[j - 1].modify(0);
        }
        block[i].deal();
        if (block[len - 1].size() == 0) {
          block[len - 1].clear();
          --len;
        } else
          block[len - 1].deal();
        if (len <= 0) len = 1;
        break;
      }
    }
  }
  long long sum() {
    long long s = 0;
    for (int i = 0; i < len; ++i) s += block[i].sum[2];
    return s;
  }
  void clear() {
    cnt = 0;
    len = 1;
    for (int i = 0; i < BSIZE; ++i) block[i].clear();
  }
  mlist() : cnt(0), len(1) { clear(); }
};
mlist mlt;
int main(void) {
  int n;
  long long x;
  char op[10];
  while (scanf("%d", &n) == 1) {
    mlt.clear();
    while (n--) {
      scanf("%s", op);
      switch (*op) {
        case 'a':
          scanf("%I64d", &x);
          mlt.add(x);
          break;
        case 'd':
          scanf("%I64d", &x);
          mlt.del(x);
          break;
        case 's':
          printf(
              "%I64d"
              "\n",
              mlt.sum());
          break;
      }
    }
  }
}
