#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
vector<int> ver;
struct tnode {
  int cnt;
  long long sum[5];
  tnode *lson, *rson;
  tnode() {
    cnt = 0, sum[0] = sum[1] = sum[2] = sum[3] = sum[4] = 0;
    lson = rson = nullptr;
  }
  void maintain() {
    cnt = lson->cnt + rson->cnt;
    for (int i = 0; i < (int)(5); ++i) sum[i] = lson->sum[i];
    for (int i = 0; i < (int)(5); ++i) sum[(lson->cnt + i) % 5] += rson->sum[i];
  }
};
tnode* tre;
tnode* newt(int l, int r) {
  if (l == r) return new tnode();
  tnode* ret = new tnode();
  int mid = (l + r) >> 1;
  ret->lson = newt(l, mid), ret->rson = newt(mid + 1, r);
  ret->maintain();
  return ret;
}
void insert(tnode* cur, int l, int r, int val) {
  if (l == r) {
    cur->cnt = 1, cur->sum[0] = ver[l];
    return;
  }
  int mid = (l + r) >> 1;
  if (val <= mid)
    insert(cur->lson, l, mid, val);
  else
    insert(cur->rson, mid + 1, r, val);
  cur->maintain();
}
void remove(tnode* cur, int l, int r, int val) {
  if (l == r) {
    cur->cnt = 0, cur->sum[0] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  if (val <= mid)
    remove(cur->lson, l, mid, val);
  else
    remove(cur->rson, mid + 1, r, val);
  cur->maintain();
}
int N, x[MAXN];
string cmd[MAXN];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < (int)(N); ++i) {
    cin >> cmd[i];
    if (cmd[i][0] != 's') {
      scanf("%d", &x[i]), ver.push_back(x[i]);
    }
  }
  sort(ver.begin(), ver.end());
  ver.erase(unique(ver.begin(), ver.end()), ver.end());
  for (int i = 0; i < (int)(N); ++i)
    if (x[i]) {
      x[i] = lower_bound(ver.begin(), ver.end(), x[i]) - ver.begin();
    }
  int siz = ver.size();
  tre = newt(0, max(0, siz - 1));
  for (int i = 0; i < (int)(N); ++i) {
    if (cmd[i][0] == 'a') insert(tre, 0, siz - 1, x[i]);
    if (cmd[i][0] == 'd') remove(tre, 0, siz - 1, x[i]);
    if (cmd[i][0] == 's') printf("%lld\n", tre->sum[2]);
  }
  return 0;
}
