#include <bits/stdc++.h>
using namespace std;
const int MAXQ = 1e5 + 5;
inline int rnd(void) { return (rand() << 15) | rand(); }
struct Treap {
  struct Node {
    int val, siz, fix;
    Node *son[2];
    long long sum[5];
    Node(int val_) : val(val_), siz(1), fix(rnd()), son(), sum() {
      sum[1] = val;
    }
  } * emp, *root;
  Treap(void) : emp(new Node(0)), root(emp) { emp->siz = 0; }
  inline Node *new_Node(int val = 0) {
    Node *res = new Node(val);
    res->son[0] = res->son[1] = emp;
    return res;
  }
  inline void del_Node(Node *&u, Node *to) {
    delete u;
    u = to;
  }
  inline void push_up(Node *u) {
    Node *l = u->son[0], *r = u->son[1];
    u->siz = l->siz + r->siz + 1;
    for (int i = 0; i < 5; ++i) u->sum[i] = l->sum[i];
    for (int i = 0; i < 5; ++i) u->sum[(l->siz + 1 + i) % 5] += r->sum[i];
    u->sum[(l->siz + 1) % 5] += u->val;
  }
  inline void rotate(Node *&u, int k) {
    Node *v = u->son[k];
    u->son[k] = v->son[k ^ 1];
    v->son[k ^ 1] = u;
    push_up(u);
    push_up(v);
    u = v;
  }
  void insert(Node *&u, int val) {
    if (!u->val) {
      u = new_Node(val);
      return;
    }
    int k = val > u->val;
    insert(u->son[k], val);
    if (u->son[k]->fix < u->fix)
      rotate(u, k);
    else
      push_up(u);
  }
  inline void insert(int val) { insert(root, val); }
  void erase(Node *&u, int val) {
    if (u->val == val) {
      if (!u->son[0]->val) {
        del_Node(u, u->son[1]);
        return;
      }
      if (!u->son[1]->val) {
        del_Node(u, u->son[0]);
        return;
      }
      rotate(u, u->son[1]->fix < u->son[0]->fix);
    }
    erase(u->son[val > u->val], val);
    push_up(u);
  }
  inline void erase(int val) { erase(root, val); }
  inline long long query(void) { return root->sum[3]; }
} tree;
int main(void) {
  srand((unsigned long long)new char);
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    static char s[10];
    scanf("%s", s + 1);
    if (s[1] == 's')
      printf("%lld\n", tree.query());
    else {
      int x;
      scanf("%d", &x);
      if (s[1] == 'a')
        tree.insert(x);
      else
        tree.erase(x);
    }
  }
  return 0;
}
