#include <bits/stdc++.h>
using namespace std;
struct ii {
  long long id, num;
  string zl;
} zl[100005];
bool cmp(ii x, ii y) { return x.num < y.num; }
bool cmp2(ii x, ii y) { return x.id < y.id; }
map<long long, long long> mp, zhi;
long long n, m, i, j, cnt, sum[100005][15], sz[100005];
void update(long long id, long long le, long long ri, long long pos) {
  sz[id]++;
  if (le == pos && ri == pos) {
    sum[id][1] += zhi[pos];
    return;
  }
  if (pos > (le + ri) / 2)
    update(id * 2 + 1, (le + ri) / 2 + 1, ri, pos);
  else
    update(id * 2, le, (le + ri) / 2, pos);
  long long i;
  for (i = 0; i < 5; i++) {
    sum[id][i] =
        sum[id * 2][i] + sum[id * 2 + 1][((i - sz[id * 2] % 5) + 5) % 5];
  }
}
void erase(long long id, long long le, long long ri, long long pos) {
  sz[id]--;
  if (le == pos && ri == pos) {
    sum[id][1] -= zhi[pos];
    return;
  }
  if (pos > (le + ri) / 2)
    erase(id * 2 + 1, (le + ri) / 2 + 1, ri, pos);
  else
    erase(id * 2, le, (le + ri) / 2, pos);
  long long i;
  for (i = 0; i < 5; i++) {
    sum[id][i] =
        sum[id * 2][i] + sum[id * 2 + 1][((i - sz[id * 2] % 5) + 5) % 5];
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (i = 1; i <= n; i++) {
    zl[i].id = i;
    cin >> zl[i].zl;
    if (zl[i].zl != "sum") cin >> zl[i].num;
  }
  sort(zl + 1, zl + n + 1, cmp);
  cnt = 0;
  for (i = 1; i <= n; i++) {
    if (zl[i].zl == "sum") continue;
    if (!mp[zl[i].num]) {
      mp[zl[i].num] = ++cnt;
      zhi[cnt] = zl[i].num;
    }
    zl[i].num = mp[zl[i].num];
  }
  sort(zl + 1, zl + n + 1, cmp2);
  for (i = 1; i <= n; i++) {
    if (zl[i].zl == "add") {
      update(1, 1, cnt, zl[i].num);
    }
    if (zl[i].zl == "del") {
      erase(1, 1, cnt, zl[i].num);
    }
    if (zl[i].zl == "sum") {
      cout << sum[1][3] << endl;
    }
  }
  return 0;
}
