#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
vector<int> vec;
vector<pair<int, int> > query;
struct node {
  long long sum[5], sz;
  node() {
    memset(sum, 0, sizeof sum);
    sz = 0;
  }
} seg[N << 2];
node merge(node x, node y) {
  node ret;
  ret.sz = (x.sz + y.sz) % 5;
  for (int i = 0; i < 5; i++) {
    int cur = (i - (x.sz % 5)) % 5;
    cur = (cur + 5) % 5;
    ret.sum[i] = x.sum[i] + y.sum[cur];
  }
  return ret;
}
void modify(int pos, int val, int id = 1, int b = 0, int e = n) {
  if (e - b == 1) {
    int type = ((val > 0) ? 1 : -1);
    seg[id].sum[seg[id].sz] += val * type;
    seg[id].sz += type;
    seg[id].sz = (seg[id].sz + 5) % 5;
    return;
  }
  int mid = (b + e) >> 1, lc = id * 2, rc = lc | 1;
  if (pos < mid)
    modify(pos, val, lc, b, mid);
  else
    modify(pos, val, rc, mid, e);
  seg[id] = merge(seg[lc], seg[rc]);
  return;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int x;
    if (s != "sum") {
      cin >> x;
      vec.push_back(x);
      if (s == "add")
        query.push_back({0, x});
      else
        query.push_back({1, x});
    } else
      query.push_back({2, -1});
  }
  sort(vec.begin(), vec.end());
  vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
  for (int t = 0; t < n; t++) {
    int type = query[t].first;
    if (type == 2) {
      cout << seg[1].sum[2] << "\n";
      continue;
    }
    int val = query[t].second,
        pos = lower_bound(vec.begin(), vec.end(), val) - vec.begin();
    if (!type)
      modify(pos, val);
    else if (type == 1)
      modify(pos, -val);
    else
      cout << seg[1].sum[2] << "\n";
  }
}
