#include <bits/stdc++.h>
#pragma GCC target("sse4.2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long MAXN = 1000 * 1000 + 7, MOD = 1000 * 1000 * 1000 + 7;
long long n, q, qu[MAXN], ans[MAXN], a[MAXN];
vector<long long> vec;
map<long long, long long> pos;
struct node {
  long long sum[5], cnt;
} seg[MAXN << 2];
node merge(node a, node b) {
  node res;
  res.cnt = (a.cnt + b.cnt) % 5;
  res.cnt += 5;
  res.cnt %= 5;
  for (long long i = 0; i < 5; i++) {
    res.sum[i] = a.sum[i] + b.sum[(i + 5 - a.cnt) % 5];
  }
  return res;
}
void upd(long long val, long long x, long long b = 0, long long e = n,
         long long ind = 1) {
  long long mid = (b + e) / 2;
  if (b + 1 == e) {
    seg[ind].cnt = (val > 0);
    seg[ind].sum[0] += val;
    return;
  }
  if (x < mid)
    upd(val, x, b, mid, ind << 1);
  else
    upd(val, x, mid, e, ind << 1 | 1);
  seg[ind] = merge(seg[ind << 1], seg[ind << 1 | 1]);
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  cin >> q;
  string s;
  for (long long i = 0; i < q; i++) {
    cin >> s;
    if (s == "sum") continue;
    cin >> qu[i];
    vec.push_back(qu[i]);
    if (s == "del") qu[i] *= -1;
  }
  sort(vec.begin(), vec.end());
  vec.resize(distance(vec.begin(), unique(vec.begin(), vec.end())));
  n = vec.size();
  for (long long i = 0; i < n; i++) {
    pos[vec[i]] = i;
  }
  for (long long i = 0; i < q; i++) {
    if (qu[i] == 0) {
      cout << seg[1].sum[2] << '\n';
    } else {
      upd(qu[i], pos[abs(qu[i])]);
    }
  }
  return 0;
}
