#include <bits/stdc++.h>
using namespace std;
int n, x;
string s;
set<int> S;
set<int>::iterator it;
int main() {
  cin >> n;
  while (n--) {
    cin >> s;
    if (s[0] == 's') {
      long long r = 0;
      for (it = S.begin(), it++, it++; it != S.end();
           it++, it++, it++, it++, it++)
        r += *it;
      cout << r << endl;
    } else if (s[0] == 'a') {
      cin >> x;
      S.insert(x);
    } else {
      cin >> x;
      S.erase(x);
    }
  }
}
