#include <bits/stdc++.h>
using namespace std;
template <class T, class IT>
inline void PRINT(IT i1, IT i2) {
  cout << '[';
  copy(i1, i2, ostream_iterator<T>(cout, ", "));
  cout << "]\n";
}
template <class KeyT, class DataT, class RefreshT>
struct treap {
  int priority;
  KeyT key;
  DataT data;
  treap<KeyT, DataT, RefreshT>* left;
  treap<KeyT, DataT, RefreshT>* right;
  inline DataT getdata() const { return this == 0 ? RefreshT::empty() : data; }
  inline void refresh() {
    if (this)
      data = RefreshT::refresh(left->getdata(), key, data, right->getdata());
  }
  treap(int pr, KeyT k, const DataT& d, treap<KeyT, DataT, RefreshT>* l,
        treap<KeyT, DataT, RefreshT>* r)
      : priority(pr), key(k), data(d), left(l), right(r) {}
};
template <class treap<KeyT, DataT, RefreshT> >
treap<KeyT, DataT, RefreshT>* merge(treap<KeyT, DataT, RefreshT>* l,
                                    treap<KeyT, DataT, RefreshT>* r) {
  if (l == 0) return r;
  if (r == 0) return l;
  if (l->priority > r->priority) {
    l->right = merge(l->right, r);
    l->refresh();
    return l;
  } else {
    r->left = merge(l, r->left);
    r->refresh();
    return r;
  }
} template <class treap<KeyT, DataT, RefreshT> >
void split(treap<KeyT, DataT, RefreshT>* root,
           const typename treap<KeyT, DataT, RefreshT>::KeyT& key,
           treap<KeyT, DataT, RefreshT>*& l, treap<KeyT, DataT, RefreshT>*& r) {
  if (root == 0) {
    l = r = 0;
    return;
  }
  treap<KeyT, DataT, RefreshT>*nl, *nr;
  if (root->key <= key) {
    split(root->right, key, nl, nr);
    root->right = nl;
    l = root;
    r = nr;
  } else {
    split(root->left, key, nl, nr);
    root->left = nr;
    l = nl;
    r = root;
  }
  l->refresh();
  r->refresh();
} template <class treap<KeyT, DataT, RefreshT> >
void add(treap<KeyT, DataT, RefreshT>*& root,
         const typename treap<KeyT, DataT, RefreshT>::KeyT& key,
         const typename treap<KeyT, DataT, RefreshT>::DataT& data) {
  treap<KeyT, DataT, RefreshT>*l, *r,
      *element = new treap<KeyT, DataT, RefreshT>(rand(), key, data, 0, 0);
  element->refresh();
  split(root, key, l, r);
  root = merge(merge(l, element), r);
} template <class treap<KeyT, DataT, RefreshT> >
void print(treap<KeyT, DataT, RefreshT>* root) {
  if (root == 0) return;
  cout << "(";
  print(root->left);
  cout << root->key << '[' << root->data << ']' << "";
  print(root->right);
  cout << ")";
} template <class treap<KeyT, DataT, RefreshT> >
void del(treap<KeyT, DataT, RefreshT>*& root,
         const typename treap<KeyT, DataT, RefreshT>::KeyT& key) {
  treap<KeyT, DataT, RefreshT>*l, *r, *rr, *d;
  split(root, key - 1, l, r);
  split(r, key, d, rr);
  root = merge(l, rr);
} struct NodeData {
  int count;
  int sum[5];
  NodeData() {
    for (int i = 0; i < (int)(5); ++i) sum[i] = 0;
    count = 0;
  }
};
ostream& operator<<(ostream& os, const NodeData& nd) {
  return os << nd.count << '{' << nd.sum[0] << ',' << nd.sum[1] << ','
            << nd.sum[2] << ',' << nd.sum[3] << ',' << nd.sum[4] << '}';
}
struct task_sz {
  inline static NodeData empty() { return NodeData(); }
  inline static NodeData refresh(const NodeData& l, int key, const NodeData& c,
                                 const NodeData& r) {
    NodeData result;
    result.count = l.count + r.count + 1;
    for (int i = 0; i < (int)(5); ++i) {
      result.sum[i] = l.sum[i] + (l.count % 5 == i ? key : 0) +
                      r.sum[(i + (5 - (l.count + 1) % 5)) % 5];
    }
    return result;
  }
};
int main() {
  int n;
  cin >> n;
  treap<int, NodeData, task_sz>* tree = 0;
  char command[20];
  for (int cmd = 0; cmd < (int)(n); ++cmd) {
    cin >> command;
    switch (command[0]) {
      case 'a': {
        int value;
        cin >> value;
        add(tree, value, NodeData());
        ;
        break;
      }
      case 'd': {
        int value;
        cin >> value;
        del(tree, value);
        ;
        break;
      }
      case 's': {
        if (tree == 0) {
          cout << 0 << '\n';
        } else {
          cout << tree->data.sum[2] << '\n';
        }
        break;
      }
      default:
        assert(false);
    }
  }
  return 0;
}
