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