#include <bits/stdc++.h>
using namespace std;
vector<int> v;
char s[10];
int main() {
  int n;
  cin >> n;
  while (n--) {
    scanf("%s", s);
    int x;
    if (s[0] == 'a' || s[0] == 'd') scanf("%d", &x);
    if (s[0] == 'a')
      v.insert(lower_bound(v.begin(), v.end(), x), x);
    else if (s[0] == 'd')
      v.erase(lower_bound(v.begin(), v.end(), x));
    else {
      int i = 2;
      long long int sum = 0;
      while (i < v.size()) {
        sum += v[i];
        i += 5;
      }
      printf("%lld\n", sum);
    }
  }
}
