#include <bits/stdc++.h>
using namespace std;
const unsigned long long BIGEST = 1000000000000000000 + 1000000000000000000;
const long long BIGER = 1000000000000000000;
const int BIG = 1000000000;
const int MOD = 19260817;
long long n;
long long a[1000001];
vector<long long> vt[100001];
vector<long long> s[100001];
long long sz;
long long SZ = 1;
long long reorg() {
  vector<long long> vec;
  for (long long i = 0; i < SZ; i++) {
    while (vt[i].size() != 00) {
      vec.push_back(vt[i][vt[i].size() - 1]);
      vt[i].pop_back();
      s[i].pop_back();
    }
  }
  sort(vec.begin(), vec.end());
  long long k = 0;
  SZ = 0;
  for (long long i = 0; k < vec.size(); i++) {
    for (long long j = 0; j < sqrt(vec.size()); j++) {
      vt[i].push_back(vec[k]);
      s[i].push_back(0);
      k++;
      if (k == vec.size()) break;
    }
    SZ++;
  }
  return 0;
}
long long fnd(long long k) {
  long long i = 0;
  if (vt[0].size() == 0) return 0;
  for (i = 0; i < SZ; i++) {
    if (vt[i][0] > k) break;
  }
  i--;
  if (i < 0) i = 0;
  if (i >= SZ) i = SZ - 1;
  return i;
}
long long update(long long k) {
  if (vt[k].size() == 0) return 0;
  for (long long i = vt[k].size() - 1; i >= 0; i--) {
    s[k][i] = vt[k][i];
    if (i + 5 < vt[k].size()) {
      s[k][i] += s[k][i + 5];
    }
  }
  return 0;
}
int main() {
  scanf("%I64d", &n);
  sz = 0;
  string st;
  long long t;
  for (long long i = 1; i <= n; i++) {
    cin >> st;
    if (st == "add") {
      scanf("%I64d", &t);
      long long aim;
      aim = fnd(t);
      vt[aim].push_back(t);
      s[aim].push_back(0);
      for (long long j = vt[aim].size() - 1;
           j > 0 && vt[aim][j] < vt[aim][j - 1]; j--)
        swap(vt[aim][j], vt[aim][j - 1]);
      update(aim);
    } else if (st == "del") {
      scanf("%I64d", &t);
      long long aim;
      aim = fnd(t);
      long long j = 0;
      for (j = 0; j < vt[aim].size() && vt[aim][j] != t; j++)
        ;
      if (j < vt[aim].size()) {
        for (; j < vt[aim].size(); j++)
          if (j < vt[aim].size() - 1) {
            vt[aim][j] = vt[aim][j + 1];
          }
      }
      vt[aim].pop_back();
      s[aim].pop_back();
      update(aim);
    } else if (st == "sum") {
      long long ss = 0;
      t = 2;
      for (long long i = 0; i < SZ; i++) {
        if (s[i].size() > (t) % 5) ss += s[i][(t) % 5];
        t += (5 - s[i].size() % 5) % 5;
        t %= 5;
      }
      cout << ss << endl;
    }
    if (i % ((long long)sqrt(n)) == 0) {
      reorg();
      for (long long i = 0; i < SZ; i++) {
        update(i);
      }
    }
  }
  return 0;
}
