#include <bits/stdc++.h>
using namespace std;
template <class Tp>
class Treap_Node {
 public:
  Tp value;
  int time, fix;
  Treap_Node *left, *right;
  Treap_Node() { puts("you forget something!"); }
  Treap_Node(Tp v, int f) {
    left = right = NULL;
    value = v;
    fix = f;
    time = 1;
  }
};
template <class Tp>
class Treap {
 private:
  Treap_Node<Tp> *Root;
  void Left_Rotate(Treap_Node<Tp> *&H) {
    Treap_Node<Tp> *temp = H->right;
    H->right = temp->left;
    temp->left = H;
    H = temp;
  }
  void Right_Rotate(Treap_Node<Tp> *&H) {
    Treap_Node<Tp> *temp = H->left;
    H->left = temp->right;
    temp->right = H;
    H = temp;
  }
  void insert(Treap_Node<Tp> *&H, Tp v) {
    if (H == NULL)
      H = new Treap_Node<Tp>(v, rand());
    else if (v < H->value) {
      insert(H->left, v);
      if (H->left->fix < H->fix) Right_Rotate(H);
    } else if (v > H->value) {
      insert(H->right, v);
      if (H->right->fix < H->fix) Left_Rotate(H);
    } else
      H->time++;
  }
  bool del(Treap_Node<Tp> *&H, Tp v) {
    if (H == NULL) return false;
    if (v == H->value) {
      if (--H->time) return true;
      if (H->left == NULL || H->right == NULL) {
        Treap_Node<Tp> *t = H;
        H = (H->right == NULL) ? H->left : H->right;
        delete t;
        return true;
      } else {
        if (H->left->fix < H->right->fix) {
          Right_Rotate(H);
          return del(H->right, v);
        } else {
          Left_Rotate(H);
          return del(H->left, v);
        }
      }
    } else if (v < H->value)
      return del(H->left, v);
    else
      return del(H->right, v);
  }
  Treap_Node<Tp> *find(Treap_Node<Tp> *H, Tp v) {
    if (H == NULL || v == H->value) return H;
    if (v < H->value)
      return find(H->left, v);
    else
      return find(H->right, v);
  }
  void Destroy(Treap_Node<Tp> *H) {
    if (H == NULL) return;
    Destroy(H->left);
    Destroy(H->right);
    delete H;
  }
  void out(Treap_Node<Tp> *H, vector<int> &V) {
    if (H == NULL) return;
    out(H->left, V);
    V.push_back(H->value);
    out(H->right, V);
  }
  Treap_Node<Tp> *L(Treap_Node<Tp> *&H) {
    if (H == NULL) return H;
    return H->left != NULL ? L(H->left) : H;
  }
  Treap_Node<Tp> *R(Treap_Node<Tp> *&H) {
    if (H == NULL) return H;
    return H->right != NULL ? R(H->right) : H;
  }

 public:
  Treap() { Root = NULL; }
  ~Treap() { Destroy(Root); }
  void Insert(Tp v) { insert(Root, v); }
  void Delete(Tp v) { del(Root, v); }
  Treap_Node<Tp> *Find(Tp v) { return find(Root, v); }
  Treap_Node<Tp> *Min(void) { return L(Root); }
  Treap_Node<Tp> *Max(void) { return R(Root); }
  void print(vector<int> &V) { out(Root, V); }
};
int main(void) {
  int n, i, a;
  string name;
  while (cin >> n) {
    Treap<int> T;
    while (n--) {
      cin >> name;
      if (name == "add") {
        cin >> a;
        if (T.Find(a) == NULL) T.Insert(a);
      } else if (name == "del") {
        cin >> a;
        T.Delete(a);
      } else {
        int sum = 0;
        vector<int> V;
        T.print(V);
        for (i = 2; i < V.size(); i += 5) sum += V[i];
        cout << sum << endl;
      }
    }
  }
  return 0;
}
