#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long a = 0, b = getchar(), c = 1;
  while (!isdigit(b)) c = b == '-' ? -1 : 1, b = getchar();
  while (isdigit(b)) a = a * 10 + b - '0', b = getchar();
  return a * c;
}
int n, x;
vector<int> v;
string s;
int main() {
  n = read();
  while (n--) {
    cin >> s;
    if (s[0] == 's') {
      long long r = 0;
      for (int i = 2; i < v.size(); i += 5) r += v[i];
      printf("%lld\n", r);
    } else {
      x = read();
      if (s[0] == 'a')
        v.insert(lower_bound(v.begin(), v.end(), x), x);
      else
        v.erase(lower_bound(v.begin(), v.end(), x));
    }
  }
  return 0;
}
