#include <bits/stdc++.h>
using namespace std;
long long oper[262222 >> 1][2];
char op[5];
typedef struct segt {
  long long p[5];
  int len;
} segmenttree;
segmenttree tree[262222];
vector<int> arr;
vector<int> discrete;
void update(int pos, int l, int r, int index, long long value);
int main(int argc, char *argv[]) {
  int m;
  int i;
  long long val;
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    scanf("%s", op);
    if (op[0] == 'a') {
      scanf("%lld", &val);
      oper[i][0] = 1;
      oper[i][1] = val;
      arr.push_back(val);
    } else if (op[0] == 'd') {
      scanf("%lld", &val);
      oper[i][0] = 2;
      oper[i][1] = val;
      arr.push_back(val);
    } else {
      oper[i][0] = 3;
    }
  }
  sort(arr.begin(), arr.end());
  for (i = 0; i < (int)arr.size(); i++) {
    if (i == 0) {
      discrete.push_back(arr[i]);
    } else {
      if (arr[i] != arr[i - 1]) {
        discrete.push_back(arr[i]);
      }
    }
  }
  int n = (int)discrete.size();
  for (i = 0; i < m; i++) {
    if (oper[i][0] == 1) {
      val = lower_bound(discrete.begin(), discrete.end(), oper[i][1]) -
            discrete.begin();
      update(val, 0, n - 1, 1, oper[i][1]);
    } else if (oper[i][0] == 2) {
      val = lower_bound(discrete.begin(), discrete.end(), oper[i][1]) -
            discrete.begin();
      update(val, 0, n - 1, 1, 0);
    } else {
      printf("%lld\n", tree[1].p[2]);
    }
  }
  return 0;
}
segmenttree merge_interval(segmenttree t1, segmenttree t2) {
  segmenttree t;
  t.len = t1.len + t2.len;
  int i;
  for (i = 0; i < 5; i++) {
    t.p[i] = t1.p[i] + t2.p[(i - t1.len + 5) % 5];
  }
  return t;
}
void update(int pos, int l, int r, int index, long long value) {
  if (l > r) return;
  if (l == r && l == pos) {
    if (value != 0) {
      tree[index].len = 1;
    } else {
      tree[index].len = 0;
    }
    tree[index].p[0] = value;
    tree[index].p[1] = tree[index].p[2] = tree[index].p[3] = tree[index].p[4] =
        0;
    return;
  }
  int mid = l + (r - l) / 2;
  if (pos <= mid) {
    update(pos, l, mid, index * 2, value);
  } else {
    update(pos, mid + 1, r, index * 2 + 1, value);
  }
  tree[index] = merge_interval(tree[index * 2], tree[index * 2 + 1]);
}
