#include <bits/stdc++.h>
using namespace std;
set<int> s;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string ss;
    cin >> ss;
    if (ss == "add") {
      int x;
      cin >> x;
      s.insert(x);
    }
    if (ss == "del") {
      int x;
      cin >> x;
      s.erase(x);
    }
    int ans = 0;
    if (ss == "sum") {
      int i = 0;
      for (auto x : s) {
        i++;
        if (i % 5 == 3) ans += x;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
