#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5 + 7;
const int sq = 317;
const string ANS = "sum";
const string DEL = "del";
const string ADD = "add";
int FF[] = {2, 1, 0, 4, 3};
vector<int> V;
string s[Maxn];
bool mark[Maxn];
int x[Maxn], n, q;
int ted[sq + 10];
long long ans = 0, sum[10][sq + 10];
void add(int re, bool vis) {
  int p = lower_bound(V.begin(), V.end(), re) - V.begin();
  mark[p] = vis;
  int id = p / sq, t = -1;
  int st = id * sq;
  int en = st + sq;
  for (int i = 0; i < 5; i++) sum[i][id] = 0;
  ted[id] += vis;
  for (int i = st; i < en; i++)
    if (mark[i]) sum[++t][id] += V[i], t %= 5;
}
void solve() {
  int tt = 0;
  for (int rr = 0; rr <= n; rr++) ans += sum[FF[tt]][rr], (tt += ted[rr]) %= 5;
}
int main() {
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> s[i];
    if (s[i][0] != 's') cin >> x[i], V.push_back(x[i]);
  }
  sort(V.begin(), V.end());
  V.resize(unique(V.begin(), V.end()) - V.begin());
  int n = V.size() - 1;
  n /= sq;
  for (int i = 0; i < q; i++) {
    if (s[i] == ADD) add(x[i], true);
    if (s[i] == DEL) add(x[i], false);
    if (s[i] == ANS) solve(), cout << ans << endl, ans = 0;
  }
  return 0;
}
