#include <bits/stdc++.h>
using namespace std;
int q, n, type[100100], opr[100100], nu;
vector<int> val;
char str[10];
long long dat[401100][5];
int cnt[401100];
void merge(int a, int b, int c) {
  cnt[a] = cnt[b] + cnt[c];
  for (int i = 0; i < 5; i++) dat[a][i] = dat[b][i];
  for (int i = 0; i < 5; i++) dat[a][(i + cnt[b]) % 5] += dat[c][i];
}
void add_val(int num) {
  int idx = num + nu;
  cnt[idx] = 1;
  dat[idx][0] = val[num];
  for (; idx >>= 1; idx) merge(idx, ((idx << 1) | 0), ((idx << 1) | 1));
}
void del_val(int num) {
  int idx = num + nu;
  cnt[idx] = 0;
  dat[idx][0] = 0;
  for (; idx >>= 1; idx) merge(idx, ((idx << 1) | 0), ((idx << 1) | 1));
}
int main() {
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%s", str);
    if (str[0] == 'a') {
      type[i] = 0;
      scanf("%d", opr + i);
      val.push_back(opr[i]);
    }
    if (str[0] == 'd') {
      type[i] = 1;
      scanf("%d", opr + i);
    }
    if (str[0] == 's') type[i] = 2;
  }
  sort(val.begin(), val.end());
  val.erase(unique(val.begin(), val.end()), val.end());
  int n = val.size();
  nu = 1;
  while (nu < (n + 5)) nu *= 2;
  for (int i = 1; i <= q; i++) {
    if (type[i] == 2) continue;
    opr[i] = lower_bound(val.begin(), val.end(), opr[i]) - val.begin();
  }
  for (int i = 1; i <= q; i++) {
    if (type[i] == 0) add_val(opr[i]);
    if (type[i] == 1) del_val(opr[i]);
    if (type[i] == 2) printf("%lld\n", dat[1][2]);
  }
  return 0;
}
