#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 28;
const double INF = 1e12, EPS = 1e-9;
const int SZ = 300;
int n, nums[100000];
long long sum[400][5];
vector<vector<int> > bucket;
void run() {
  scanf("%d", &n);
  bucket.resize(1);
  for (int i = 0; i < n; i++) {
    char inst[9];
    scanf("%s", inst);
    if (inst[0] == 's') {
      long long ans = 0;
      for (int j = 0; j < bucket.size(); j++) ans += sum[j][2];
      cout << ans << endl;
    } else if (inst[0] == 'a') {
      int x, p = 0, pos = 0;
      scanf("%d", &x);
      for (; p < bucket.size() - 1; p++) {
        if (!bucket[p].empty() && bucket[p].back() > x) break;
        pos += bucket[p].size();
      }
      bucket[p].insert(lower_bound((bucket[p]).begin(), (bucket[p]).end(), x),
                       x);
      for (int j = 0; j < 5; j++) sum[p][j] = 0;
      for (int j = 0; j < bucket[p].size(); j++)
        sum[p][(j + pos) % 5] += bucket[p][j];
      for (p++; p < bucket.size(); p++) {
        long long t = sum[p][4];
        for (int j = 0; j < 4; j++) sum[p][j + 1] = sum[p][j];
        sum[p][0] = t;
      }
    } else if (inst[0] == 'd') {
      int x, p = 0, pos = 0;
      scanf("%d", &x);
      for (; p < bucket.size() - 1; p++) {
        if (!bucket.empty() && bucket[p].back() > x) break;
        pos += bucket[p].size();
      }
      bucket[p].erase(lower_bound((bucket[p]).begin(), (bucket[p]).end(), x));
      for (int j = 0; j < 5; j++) sum[p][j] = 0;
      for (int j = 0; j < bucket[p].size(); j++)
        sum[p][(j + pos) % 5] += bucket[p][j];
      for (p++; p < bucket.size(); p++) {
        long long t = sum[p][0];
        for (int j = 0; j < 4; j++) sum[p][j] = sum[p][j + 1];
        sum[p][4] = t;
      }
    }
    if (i % 1000 == 999) {
      int s = 0;
      for (int j = 0; j < bucket.size(); j++)
        for (int k = 0; k < bucket[j].size(); k++) nums[s++] = bucket[j][k];
      bucket.clear();
      bucket.resize(max(1, (s + SZ - 1) / SZ));
      for (int j = 0; j < s; j++) bucket[j / SZ].push_back(nums[j]);
      s = 0;
      for (int j = 0; j < bucket.size(); j++) {
        for (int k = 0; k < 5; k++) sum[j][k] = 0;
        for (int k = 0; k < bucket[j].size(); k++)
          sum[j][(s + k) % 5] += bucket[j][k];
        s += bucket[j].size();
      }
    }
  }
}
int main() { run(); }
