#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:16000000")
#pragma warning(disable : 4996)
const int inf = 1 << 25;
const double eps = 1e-9;
struct Bucket {
  const static int SIZE = 512;
  int elems[SIZE];
  long long ps[5];
  int size;
  Bucket() {
    memset((elems), (0), sizeof(elems));
    memset((ps), (0), sizeof(ps));
    size = 0, offset = 0;
  }
  int offset;
  void shft(int x) {
    offset += x;
    if (offset < 0) offset = 4;
    if (offset > 4) offset = 0;
  }
  void add(int id, int x) {
    elems[id] = x;
    recalc();
  }
  void del(int id) {
    elems[id] = 0;
    recalc();
  }
  int Size() const { return size; }
  void recalc() {
    size = 0;
    memset((ps), (0), sizeof(ps));
    for (int i = 0, j = 0; i < SIZE; ++i)
      if (elems[i]) {
        ++size;
        ps[(offset + j) % 5] += elems[i];
        ++j;
      }
  }
  long long Sum() const { return ps[2]; }
};
vector<Bucket> buckets;
long long sum() {
  long long ret = 0;
  for (int i = (0); i < ((int)buckets.size()); ++i) ret += buckets[i].Sum();
  return ret;
}
vector<int> elems;
vector<pair<string, int> > queries;
int main() {
  int q;
  cin >> q;
  for (int i = (0); i < (q); ++i) {
    string cmd;
    cin >> cmd;
    if (cmd == "sum")
      queries.push_back(make_pair("sum", 0));
    else {
      int x;
      cin >> x;
      queries.push_back(make_pair(cmd, x));
      elems.push_back(x);
    }
  }
  sort(elems.begin(), elems.end());
  elems.resize(unique(elems.begin(), elems.end()) - elems.begin());
  buckets.resize(elems.size() / Bucket::SIZE + 2);
  for (int i = (0); i < (q); ++i) {
    string cmd = queries[i].first;
    int x = queries[i].second;
    if (cmd == "sum")
      cout << sum() << endl;
    else {
      int id = lower_bound(elems.begin(), elems.end(), x) - elems.begin();
      int bid = id / Bucket::SIZE;
      if (cmd == "add") {
        buckets[bid].add(id % Bucket::SIZE, x);
        for (int i = (bid + 1); i < ((int)buckets.size()); ++i)
          buckets[i].shft(1);
      } else {
        buckets[bid].del(id % Bucket::SIZE);
        for (int i = (bid + 1); i < ((int)buckets.size()); ++i)
          buckets[i].shft(-1);
      }
    }
  }
  return 0;
}
