#include <bits/stdc++.h>
using namespace std;
set<int> num;
int n, m, i, j, x, sum;
string st;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> st;
    if (st == "add") {
      cin >> x;
      num.insert(x);
    }
    if (st == "del") {
      cin >> x;
      num.erase(x);
    }
    if (st == "sum") {
      sum = 0;
      j = 0;
      for (set<int>::iterator it = num.begin(); it != num.end(); it++) {
        j++;
        if (j % 5 == 3) sum += *it;
      }
      cout << sum << endl;
    }
  }
  return 0;
}
