#include <bits/stdc++.h>
using namespace std;
long long n;
string cmd[110000], buf;
vector<long long> V;
long long v[110000];
long long getid(long long x) {
  return lower_bound(V.begin(), V.end(), x) - V.begin() + 1;
}
struct A {
  long long lazy, val[5];
} tr[440000];
void update(long long p, long long add, long long l, long long r,
            long long rt) {
  if (l == r) {
    tr[rt].lazy += add;
    for (long long i = 0; i < 5; i++) tr[rt].val[i] = 0;
    if (tr[rt].lazy) tr[rt].val[0] = V[p - 1];
    return;
  }
  long long m = (l + r) / 2;
  if (p <= m)
    update(p, add, l, m, rt << 1);
  else
    update(p, add, m + 1, r, rt << 1 | 1);
  tr[rt].lazy = tr[rt << 1].lazy + tr[rt << 1 | 1].lazy;
  for (long long i = 0; i < 5; i++)
    tr[rt].val[i] = tr[rt << 1].val[i] +
                    tr[rt << 1 | 1].val[(5 - tr[rt << 1].lazy % 5 + i) % 5];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> cmd[i];
    if (cmd[i] == "sum") continue;
    cin >> v[i];
    if (cmd[i] == "add") V.push_back(v[i]);
  }
  sort(V.begin(), V.end());
  for (long long i = 0; i < n; i++) {
    if (cmd[i] == "add") {
      update(getid(v[i]), 1, 1, V.size() * 2, 1);
    } else if (cmd[i] == "del") {
      update(getid(v[i]), -1, 1, V.size() * 2, 1);
    } else {
      cout << tr[1].val[2] << '\n';
    }
  }
  return 0;
}
