#include <bits/stdc++.h>
using namespace std;
const int MN = 101234, SQ = 333;
pair<string, int> qw[MN];
vector<int> vect[SQ];
int sum[SQ][5], sz[SQ];
int main() {
  int q;
  cin >> q;
  vector<int> vec;
  for (int i = 0; i < q; i++) {
    string type;
    cin >> type;
    int x = 0;
    if (type == "add" || type == "del") cin >> x;
    qw[i] = {type, x};
    vec.push_back(x);
  }
  sort(vec.begin(), vec.end());
  vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
  for (int i = 0; i < q; i++)
    qw[i] = {qw[i].first,
             lower_bound(vec.begin(), vec.end(), qw[i].second) - vec.begin()};
  for (int i = 0; i < q; i++) {
    int num = qw[i].second;
    string str = qw[i].first;
    if (str == "sum") {
      int now = 2, res = 0;
      for (int i = 0; i < SQ; i++) {
        res += sum[i][now];
        now = (now + sz[i]) % 5;
      }
      cout << res << '\n';
    } else {
      int cn = num / SQ;
      if (str == "del") {
        vector<int> q = vect[cn];
        vect[cn].clear();
        for (int u : q)
          if (u != num) vect[cn].push_back(u);
      } else {
        vect[cn].push_back(num);
        sort(vect[cn].begin(), vect[cn].end());
      }
      for (int i = 0; i < 5; i++) sum[cn][i] = 0;
      sz[cn] = vect[cn].size();
      for (int i = 0; i < vect[cn].size(); i++)
        sum[cn][i % 5] += vec[vect[cn][i]];
    }
  }
}
