#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300;
long long sum[1000][10];
vector<long long> vec, v[1000];
int n, ind;
void ok(int x) {
  for (int i = 0; i < 5; i++) sum[x][i] = 0;
  for (int i = 0; i < v[x].size(); i++) sum[x][i % 5] += v[x][i];
}
void relax() {
  vec.clear();
  for (int i = 0; i < ind; i++) {
    for (int j = 0; j < v[i].size(); j++) vec.push_back(v[i][j]);
    v[i].clear();
  }
  ind = 0;
  for (int i = 0; i < vec.size(); i++) {
    v[ind].push_back(vec[i]);
    if (v[ind].size() >= MAXN) ind++;
  }
  for (int i = 0; i < ind; i++) ok(i);
}
int main() {
  cin >> n;
  ind = 1;
  for (int q = 0; q < n; q++) {
    string s;
    cin >> s;
    int x;
    if (s == "add") {
      cin >> x;
      int i = 0;
      while (i < ind - 1 && v[i].back() < x) i++;
      v[i].push_back(x);
      int j = v[i].size() - 1;
      while (j > 0 && v[i][j] < v[i][j - 1]) {
        swap(v[i][j], v[i][j - 1]);
        j--;
      }
      if (v[i].size() >= 2 * MAXN)
        relax();
      else
        ok(i);
    } else if (s == "del") {
      cin >> x;
      int i = 0;
      while (v[i].back() < x) i++;
      for (int j = 0; j < v[i].size() - 1; j++)
        if (v[i][j] >= x) v[i][j] = v[i][j + 1];
      v[i].pop_back();
      if (v[i].size() == 0)
        relax();
      else
        ok(i);
    } else {
      long long ans = 0, t = 2;
      for (int i = 0; i < ind; i++) {
        ans += sum[i][t];
        t = (t - (v[i].size() % 5) + 5) % 5;
      }
      cout << ans << endl;
    }
  }
}
