#include <bits/stdc++.h>
using namespace std;
long long n, ret = 0;
long long add[100010];
struct node {
  long long mask, num;
} ask[100010];
map<long long, long long> licent_num, num_licent;
long long tr[400010][5];
long long flag[400010];
void Update(long long c, long long l, long long r, long long x, long long val) {
  if (l == r) {
    tr[c][1] += val;
    flag[c]++;
    return;
  }
  if (x <= (l + r) / 2) {
    Update(c * 2, l, (l + r) / 2, x, val);
  } else {
    Update(c * 2 + 1, (l + r) / 2 + 1, r, x, val);
  }
  flag[c] = flag[c * 2] + flag[c * 2 + 1];
  for (long long i = 0; i <= 4; i++) {
    tr[c][i] = tr[c * 2][i] + tr[c * 2 + 1][((i - flag[c * 2]) % 5 + 5) % 5];
  }
}
void Del(long long c, long long l, long long r, long long x, long long val) {
  if (l == r) {
    tr[c][1] -= val;
    flag[c]--;
    return;
  }
  if (x <= (l + r) / 2) {
    Del(c * 2, l, (l + r) / 2, x, val);
  } else {
    Del(c * 2 + 1, (l + r) / 2 + 1, r, x, val);
  }
  flag[c] = flag[c * 2] + flag[c * 2 + 1];
  for (long long i = 0; i <= 4; i++) {
    tr[c][i] = tr[c * 2][i] + tr[c * 2 + 1][((i - flag[c * 2]) % 5 + 5) % 5];
  }
}
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    char a[10];
    cin >> a;
    if (a[0] == 'a') {
      long long x;
      cin >> x;
      add[++ret] = x;
      ask[i].mask = 0;
      ask[i].num = x;
    } else if (a[0] == 'd') {
      long long x;
      cin >> x;
      ask[i].mask = 1;
      ask[i].num = x;
    } else {
      ask[i].mask = 2;
    }
  }
  sort(add + 1, add + ret + 1);
  long long sum = 0;
  for (long long i = 1; i <= ret; i++) {
    if (!num_licent.count(add[i])) {
      num_licent[add[i]] = ++sum;
      licent_num[sum] = add[i];
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (ask[i].mask == 2) {
      cout << tr[1][3] << endl;
    } else if (ask[i].mask == 0) {
      Update(1, 1, sum, num_licent[ask[i].num], ask[i].num);
    } else {
      Del(1, 1, sum, num_licent[ask[i].num], ask[i].num);
    }
  }
  return 0;
}
