#include <bits/stdc++.h>
using namespace std;
int V[100000], N;
map<int, int> M;
struct Query {
  int type, x;
  void scan() {
    char s[8];
    scanf("%s", s);
    if (s[0] == 'a')
      type = 0;
    else if (s[0] == 'd')
      type = 1;
    else
      type = 2;
    if (type < 2) {
      scanf("%d", &x);
      M[x] = 0;
    }
  }
} q[100000];
bool exist[100000];
long long sum[100000 / 100][5];
int number[100000 / 100];
void print() {
  int i, now = 0;
  long long an = 0;
  for (i = 0; i * 100 < N; i++) {
    an += sum[i][((2 - now) % 5 + 5) % 5];
    now += number[i];
  }
  printf("%I64d\n", an);
}
void del(int x) {
  int i, No = x / 100, start = No * 100, cnt = 0;
  exist[x] = 0;
  for (i = 0; i < 5; i++) sum[No][i] = 0;
  for (i = 0; i < 100; i++) {
    if (exist[start + i]) {
      sum[No][cnt++] += V[start + i];
      if (cnt == 5) cnt = 0;
    }
  }
  number[No]--;
}
void add(int x) {
  int i, No = x / 100, start = No * 100, cnt = 0;
  exist[x] = 1;
  for (i = 0; i < 5; i++) sum[No][i] = 0;
  for (i = 0; i < 100; i++) {
    if (exist[start + i]) {
      sum[No][cnt++] += V[start + i];
      if (cnt == 5) cnt = 0;
    }
  }
  number[No]++;
}
void Start(int n) {
  int i;
  for (i = 0; i < n; i++) {
    if (q[i].type == 2)
      print();
    else if (q[i].type == 1)
      del(q[i].x);
    else
      add(q[i].x);
  }
}
int main() {
  int n, i;
  scanf("%d", &n);
  for (i = 0; i < n; i++) q[i].scan();
  map<int, int>::iterator it;
  for (i = 0, it = M.begin(); it != M.end(); it++, i++) {
    it->second = i;
    V[i] = it->first;
  }
  N = i;
  for (i = 0; i < n; i++)
    if (q[i].type != 2) q[i].x = M[q[i].x];
  Start(n);
}
