#include <bits/stdc++.h>
using namespace std;
long long sum[2 * (1 << 17)][6];
int cnt[2 * (1 << 17)];
map<int, int> m;
vector<pair<int, int> > opt;
int N;
string op;
int val;
int siz = 0;
void update(int id) {
  int i;
  int l = id * 2, r = id * 2 + 1;
  cnt[id] = cnt[l] + cnt[r];
  for ((i) = 0; (i) < (int)(5); (i)++)
    sum[id][i] = sum[l][i] + sum[r][(i + 5 - cnt[l] % 5) % 5];
}
int main() {
  int i, j, k;
  scanf("%d", &N);
  for ((i) = 0; (i) < (int)(N); (i)++) {
    scanf("%s", op.c_str());
    if (op[0] == 'a' || op[0] == 'd') {
      scanf("%d", &val);
      opt.push_back(make_pair(!(op[0] == 'a'), val));
      m[val] = 0;
    } else
      opt.push_back(make_pair(2, -1));
  }
  for (__typeof((m).begin()) it = (m).begin(); it != (m).end(); it++) {
    it->second = siz;
    siz++;
  }
  for ((i) = 0; (i) < (int)(N); (i)++) {
    int type = opt[i].first;
    val = opt[i].second;
    if (type == 2) {
      printf("%I64d\n", sum[1][2]);
    } else {
      int id = m[val] + (1 << 17);
      cnt[id] = 1 ^ type;
      sum[id][0] = (1 ^ type) * val;
      for (int x = id / 2; x > 0; x >>= 1) update(x);
    }
  }
  return 0;
}
