#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int x = 0, f = 0;
  register char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
  return f ? -x : x;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const int N = 1e5 + 10;
string op;
int n, x;
long long sum;
vector<int> ans;
bool flag;
signed main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (register int i = 1; i <= n; ++i) {
    cin >> op;
    if (op[0] == 'a')
      cin >> x, ans.insert(lower_bound(ans.begin(), ans.end(), x), x);
    else if (op[0] == 'd')
      cin >> x, ans.erase(lower_bound(ans.begin(), ans.end(), x));
    else {
      if (flag) {
        cout << sum << '\n';
        continue;
      }
      sum = 0;
      for (register int i = 2; i < ans.size(); i += 5) sum += ans[i];
      cout << sum << '\n';
      flag = 1;
      continue;
    }
    flag = 0;
  }
  return 0;
}
