#include <bits/stdc++.h>
using namespace std;
struct node {
  int cnt;
  long long sum[6];
};
node seg[4 * 100000];
struct info {
  string str;
  int num;
};
info data[100000 + 20];
map<int, int> m;
vector<int> v;
string s;
void insert(int idx, int st, int ed, int pos, int val) {
  if (st == ed) {
    if (val < 0)
      seg[idx].cnt = 0;
    else
      seg[idx].cnt = 1;
    seg[idx].sum[1] += val;
    return;
  }
  int lft, rgt, mid, var, i;
  mid = (st + ed) / 2;
  lft = 2 * idx;
  rgt = lft + 1;
  if (pos <= mid)
    insert(lft, st, mid, pos, val);
  else if (pos > mid)
    insert(rgt, mid + 1, ed, pos, val);
  seg[idx].cnt = seg[lft].cnt + seg[rgt].cnt;
  for (i = 1; i <= 5; i++) seg[idx].sum[i] = 0;
  for (i = 1; i <= 5; i++) {
    var = i % 5;
    if (var == 0) var = 5;
    seg[idx].sum[var] += seg[lft].sum[i];
  }
  for (i = 1; i <= 5; i++) {
    var = (seg[lft].cnt + i) % 5;
    if (var == 0) var = 5;
    seg[idx].sum[var] += seg[rgt].sum[i];
  }
}
int main() {
  int t, k, i, val, pos, sz;
  cin >> t;
  m.clear();
  v.clear();
  for (k = 1; k <= t; k++) {
    s.clear();
    cin >> s;
    data[k].str = s;
    if (s == "sum") {
      data[k].num = 0;
      continue;
    }
    cin >> val;
    if (s == "add") v.push_back(val);
    data[k].num = val;
  }
  sort(v.begin(), v.end());
  sz = v.size();
  for (i = 0; i < sz; i++) m[v[i]] = i + 1;
  for (i = 1; i <= t; i++) {
    s.clear();
    s = data[i].str;
    val = data[i].num;
    pos = m[val];
    if (s == "add")
      insert(1, 1, sz, pos, val);
    else if (s == "del")
      insert(1, 1, sz, pos, -val);
    else if (s == "sum")
      cout << seg[1].sum[3] << endl;
  }
}
