#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, mod = 1000000007;
const double pi = 3.1415926535897932, eps = 1e-6;
int cnt[262200];
long long sum[262200][5];
void chan(int x) {
  int i, l = x << 1, r = (x << 1) + 1;
  cnt[x] = cnt[l] + cnt[r];
  for (int(i) = (0); (i) <= (4); (i)++)
    sum[x][i] = sum[l][i] + sum[r][(i - cnt[l] % 5 + 5) % 5];
}
int n, a[100005];
vector<pair<int, int> > v;
vector<int> num;
int main() {
  cin >> n;
  for (int(i) = (1); (i) <= (n); (i)++) {
    string com;
    int g;
    cin >> com;
    if (com[0] != 's') {
      cin >> g;
    }
    v.push_back(make_pair(com[0] == 's' ? inf : g, com[0]));
    if (com[0] != 's') num.push_back(g);
  }
  sort(num.begin(), num.end());
  int s = unique(num.begin(), num.end()) - num.begin();
  for (int(i) = (1); (i) <= (n); (i)++) {
    pair<int, int> now = v[i - 1];
    if (now.second == 's')
      cout << sum[1][2] << endl;
    else {
      int typ = now.second == 'a' ? 0 : 1,
          id = (1 << 17) +
               (lower_bound(num.begin(), num.begin() + s, now.first) -
                num.begin());
      cnt[id] = 1 - typ;
      sum[id][0] = (1 - typ) * now.first;
      for (int j = id >> 1; j; j >>= 1) chan(j);
    }
  }
  return 0;
}
