#include <bits/stdc++.h>
using namespace std;
long long gen, n, m, i, j, x, y, cnt;
string st;
struct treap {
  long long rnd, zhi, ls, rs, sz, sum[5];
} tr[100010];
void lzhuan(long long &k) {
  long long p = tr[k].rs;
  tr[k].rs = tr[p].ls;
  tr[p].ls = k;
  tr[p].sz = tr[k].sz;
  k = p;
}
void rzhuan(long long &k) {
  long long p = tr[k].ls;
  tr[k].ls = tr[p].rs;
  tr[p].rs = k;
  tr[p].sz = tr[k].sz;
  k = p;
}
void getsum(long long k) {
  if (!k) return;
  tr[k].sz = tr[tr[k].ls].sz + tr[tr[k].rs].sz + 1;
  long long i, j = tr[tr[k].ls].sz;
  j %= 5;
  for (i = 0; i <= 4; i++) tr[k].sum[i] = tr[tr[k].ls].sum[i];
  for (i = 0; i <= 4; i++) {
    j = (j + 1) % 5;
    tr[k].sum[j] += tr[tr[k].rs].sum[i];
  }
  tr[k].sum[j] += tr[k].zhi;
}
void insert(long long &k, long long x) {
  if (tr[k].zhi == x) return;
  if (!k) {
    tr[++cnt].zhi = x;
    tr[cnt].ls = tr[cnt].rs = 0;
    tr[cnt].rnd = rand();
    long long i;
    for (i = 0; i <= 4; i++) tr[cnt].sum[i] = 0;
    tr[cnt].sum[0] = x;
    tr[cnt].sz = 1;
    k = cnt;
    return;
  }
  if (x < tr[k].zhi) {
    insert(tr[k].ls, x);
    if (tr[tr[k].ls].rnd > tr[k].rnd) {
      rzhuan(k);
      getsum(tr[k].rs);
    }
  } else {
    insert(tr[k].rs, x);
    if (tr[tr[k].rs].rnd > tr[k].rnd) {
      lzhuan(k);
      getsum(tr[k].ls);
    }
  }
  getsum(k);
}
void erase(long long &k, long long x) {
  if (!k) return;
  if (tr[k].zhi == x) {
    if (!tr[k].ls || !tr[k].rs)
      k = tr[k].ls + tr[k].rs;
    else if (tr[tr[k].ls].rnd < tr[tr[k].rs].rnd) {
      rzhuan(k);
      erase(k, x);
    } else {
      lzhuan(k);
      erase(k, x);
    }
  } else if (tr[k].zhi < x)
    erase(tr[k].rs, x);
  else
    erase(tr[k].ls, x);
  getsum(k);
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> st;
    if (st == "add") {
      cin >> x;
      insert(gen, x);
    }
    if (st == "del") {
      cin >> x;
      erase(gen, x);
    }
    if (st == "sum") cout << tr[gen].sum[2] << endl;
  }
  return 0;
}
