#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
const int L = 330;
struct bucket {
  long long s5k3;
  vector<long long> val;
  bucket *nex, *prev;
  bucket() {
    nex = prev = NULL;
    s5k3 = 0;
  }
  void add(const long long &x) {
    vector<long long>::iterator ite = lower_bound(val.begin(), val.end(), x);
    val.insert(ite, x);
    upd();
  }
  void del(const long long &x) {
    vector<long long>::iterator ite = lower_bound(val.begin(), val.end(), x);
    val.erase(ite);
    upd();
  }
  void upd() {
    s5k3 = 0;
    for (int i = 2; i < (int)val.size(); i += 5) s5k3 += val[i];
  }
  void split() {
    bucket *x = new bucket();
    int mid = (int)val.size() >> 1;
    for (int i = mid; i < (int)val.size(); i++) x->val.push_back(val[i]);
    while ((int)val.size() > mid) val.pop_back();
    x->upd();
    upd();
    x->nex = nex;
    x->prev = this;
    if (nex != NULL) nex->prev = x;
    nex = x;
  }
  void combine() {
    if (prev != NULL) {
      for (int i = 0; i < (int)val.size(); i++) prev->val.push_back(val[i]);
      prev->upd();
      prev->nex = nex;
      if (nex != NULL) nex->prev = prev;
      val.clear();
      s5k3 = 0;
    } else if (nex != NULL) {
      int sz = (int)val.size();
      for (int i = 0; i < (int)nex->val.size(); i++) val.push_back(nex->val[i]);
      upd();
      if (nex->nex != NULL) nex->nex->prev = this;
      nex->s5k3 = 0;
      nex = nex->nex;
    }
  }
};
bucket *r = new bucket(), *pos;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  long long x;
  string cmd;
  cin >> n;
  while (n--) {
    cin >> cmd;
    if (cmd == "add") {
      cin >> x;
      pos = r;
      if (pos->val.size() == 0) {
        pos->add(x);
        continue;
      }
      while (pos != NULL) {
        if (((int)pos->val.size() > 0 && x <= pos->val.back()) ||
            pos->nex == NULL) {
          pos->add(x);
          if ((int)pos->val.size() > 2 * L) pos->split();
          break;
        }
        pos = pos->nex;
      }
    } else if (cmd == "del") {
      cin >> x;
      pos = r;
      while (pos != NULL) {
        if ((int)pos->val.size() > 0 && x <= pos->val.back()) {
          pos->del(x);
          if ((int)pos->val.size() < L / 2) pos->combine();
          break;
        }
        pos = pos->nex;
      }
    } else {
      long long ans = 0;
      pos = r;
      while (pos != NULL) {
        ans += pos->s5k3;
        pos = pos->nex;
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
