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