#include <bits/stdc++.h>
using namespace std;
long long gen, n, m, i, j, x, y, cnt = 1;
string st;
struct treap {
  long long rnd, zhi, ls, rs, sz, sum[5];
} tr[100005];
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 split(long long t, long long &x, long long &y, long long zhi) {
  if (!t) {
    x = 0;
    y = 0;
    return;
  }
  if (zhi < tr[t].zhi) {
    split(tr[t].ls, x, tr[t].ls, zhi);
    y = t;
  } else {
    split(tr[t].rs, tr[t].rs, y, zhi);
    x = t;
  }
  getsum(t);
}
void make(long long x, long long y, long long &z) {
  if (!x || !y) {
    z = 0;
    if (x) z = x;
    if (y) z = y;
    return;
  }
  if (tr[x].rnd > tr[y].rnd) {
    make(tr[x].rs, y, tr[x].rs);
    z = x;
  } else {
    make(x, tr[y].ls, tr[y].ls);
    z = y;
  }
  getsum(z);
}
void insert(long long &k, long long zhi) {
  long long x, y, z;
  split(k, x, y, zhi);
  tr[cnt].zhi = zhi;
  tr[cnt].rnd = rand();
  z = cnt;
  cnt++;
  getsum(z);
  make(x, z, k);
  make(k, y, k);
}
void erase(long long &k, long long x) {
  if (!k) return;
  if (tr[k].zhi == x) {
    make(tr[k].ls, tr[k].rs, k);
  } 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;
}
