#include <bits/stdc++.h>
using namespace std;
struct treap {
  struct tnode {
    tnode *l, *r;
    int x, size;
    const int h;
    long long sum[5];
    tnode(int a) : l(NULL), r(NULL), x(a), h(rand()), size(0) {
      fill(sum, sum + 5, 0);
    }
    ~tnode() {
      delete l;
      delete r;
    }
    void upd() {
      int i;
      size = 1;
      fill(sum, sum + 5, 0);
      if (l) {
        size += l->size;
        for (i = 0; i < 5; i++) sum[i] += l->sum[i];
      }
      sum[(size - 1) % 5] += x;
      if (r) {
        for (i = 0; i < 5; i++) sum[(size + i) % 5] += r->sum[i];
        size += r->size;
      }
    }
  } * root;
  treap() : root(NULL) {}
  static tnode* zig(tnode* p) {
    tnode* t = p->l;
    p->l = t->r;
    t->r = p;
    p->upd();
    t->upd();
    return t;
  }
  static tnode* zag(tnode* p) {
    tnode* t = p->r;
    p->r = t->l;
    t->l = p;
    p->upd();
    t->upd();
    return t;
  }
  static tnode* merge(tnode* l, tnode* r) {
    if (l == NULL) {
      return r;
    } else if (r == NULL) {
      return l;
    } else if (l->h < r->h) {
      l->r = merge(l->r, r);
      l->upd();
      return l;
    } else {
      r->l = merge(l, r->l);
      r->upd();
      return r;
    }
  }
  static tnode* insert(tnode* p, int a) {
    if (p == NULL)
      p = new tnode(a);
    else if (a < p->x) {
      p->l = insert(p->l, a);
      if (p->l->h < p->h) {
        p = zig(p);
      }
    } else {
      p->r = insert(p->r, a);
      if (p->r->h < p->h) {
        p = zag(p);
      }
    }
    p->upd();
    return p;
  }
  void insert(int a) { root = insert(root, a); }
  static tnode* remove(tnode* p, int a) {
    if (p == NULL)
      return NULL;
    else if (a < p->x) {
      p->l = remove(p->l, a);
      p->upd();
    } else if (a > p->x) {
      p->r = remove(p->r, a);
      p->upd();
    } else {
      tnode* t = p;
      p = merge(p->l, p->r);
      t->l = t->r = NULL;
      delete t;
    }
    return p;
  }
  void remove(int a) { root = remove(root, a); }
};
int main() {
  int n, x, i;
  char op[80];
  treap gao;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s", op);
    if (op[0] == 'a') {
      scanf("%d", &x);
      gao.insert(x);
    } else if (op[0] == 'd') {
      scanf("%d", &x);
      gao.remove(x);
    } else
      printf("%Ld\n", gao.root == NULL ? 0LL : gao.root->sum[2]);
  }
  return 0;
}
