#include <bits/stdc++.h>
using namespace std;
struct pok {
  long long cnt[5];
};
long long const N = 1e5 + 20, SQ = 333;
long long n;
vector<vector<long long>> vec;
vector<pok> C;
inline void recalc(long long i) {
  C[i] = {0, 0, 0, 0, 0};
  for (long long j = 0; j < (long long)vec[i].size(); j++)
    C[i].cnt[(j + 1) % 5] += vec[i][j];
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    if (s == "add") {
      long long x;
      cin >> x;
      for (long long i = 0; i < (long long)vec.size(); i++) {
        if ((!i || vec[i][0] < x) &&
            (i == (long long)vec.size() - 1 || vec[i + 1][0] > x)) {
          vector<long long> tmp;
          while (vec[i].size() && vec[i].back() > x) {
            tmp.push_back(vec[i].back());
            vec[i].pop_back();
          }
          vec[i].push_back(x);
          while (tmp.size()) {
            vec[i].push_back(tmp.back());
            tmp.pop_back();
          }
          if ((long long)vec[i].size() == 2 * SQ) {
            for (long long t = 0; t < SQ; t++) {
              tmp.push_back(vec[i].back());
              vec[i].pop_back();
            }
            C.insert(C.begin() + i + 1, {0, 0, 0, 0, 0});
            reverse(tmp.begin(), tmp.end());
            vec.insert(vec.begin() + i + 1, tmp);
            recalc(i + 1);
          }
          recalc(i);
          break;
        }
      }
      if (!(long long)vec.size()) {
        vec.push_back({x});
        C.push_back({0, x, 0, 0, 0});
      }
    } else if (s == "del") {
      long long x;
      cin >> x;
      for (long long i = 0; i < (long long)vec.size(); i++)
        if ((!i || vec[i][0] < x) &&
            (i == (long long)vec.size() - 1 || vec[i + 1][0] > x)) {
          for (long long j = 0; j < (long long)vec[i].size(); j++)
            if (vec[i][j] == x) vec[i].erase(vec[i].begin() + j);
          recalc(i);
        }
    } else {
      long long st = 0, res = 0;
      for (long long i = 0; i < (long long)vec.size(); i++) {
        res += C[i].cnt[(5 - st + 3) % 5];
        (st += (long long)vec[i].size()) %= 5;
      }
      cout << res << '\n';
    }
  }
}
