#include <bits/stdc++.h>
const int maxn = 1e5 + 10;
using namespace std;
long long s[maxn * 4][5];
long long resp[maxn * 4];
int lazy[maxn * 4];
int indice[maxn * 4];
int m(int l, int r) { return (l + r) / 2; }
void refresh(int pos, int l, int r) {
  if (l > r) return;
  int k = -lazy[pos];
  lazy[pos] = 0;
  int aux[5];
  for (int i = 0; i < 5; i++) aux[i] = s[pos][i];
  for (int i = 0; i < 5; i++) s[pos][i] = aux[(i + k + 5) % 5];
  resp[pos] = s[pos][3];
  if (l == r) {
    indice[pos] = (indice[pos] - k + 5) % 5;
    return;
  }
  lazy[pos * 2] -= k;
  lazy[pos * 2 + 1] -= k;
}
void merge(int pos) {
  for (int i = 0; i < 5; i++) s[pos][i] = s[pos * 2][i] + s[pos * 2 + 1][i];
  resp[pos] = resp[pos * 2] + resp[pos * 2 + 1];
}
void upd1(int pos, int l, int r, int beg, int en, int val) {
  refresh(pos, l, r);
  if (l > en || r < beg) return;
  if (l >= beg && r <= en) {
    refresh(pos * 2, l, m(l, r));
    refresh(pos * 2 + 1, m(l, r) + 1, r);
    lazy[pos] = val;
    refresh(pos, l, r);
    return;
  }
  upd1(pos * 2, l, m(l, r), beg, en, val);
  upd1(pos * 2 + 1, m(l, r) + 1, r, beg, en, val);
  merge(pos);
}
void upd2(int pos, int l, int r, int x, int index, long long val, bool ok) {
  refresh(pos, l, r);
  if (l == r) {
    if (!ok) {
      s[pos][indice[pos]] = 0;
      indice[pos] = 0;
      resp[pos] = 0;
      return;
    }
    indice[pos] = index;
    s[pos][index] = val;
    resp[pos] = s[pos][3];
    return;
  }
  if (x <= m(l, r))
    upd2(pos * 2, l, m(l, r), x, index, val, ok);
  else
    upd2(pos * 2 + 1, m(l, r) + 1, r, x, index, val, ok);
  merge(pos);
}
int query(int pos, int l, int r, int x) {
  refresh(pos, l, r);
  if (l == r) return indice[pos];
  if (x <= m(l, r)) return query(pos * 2, l, m(l, r), x);
  return query(pos * 2 + 1, m(l, r) + 1, r, x);
}
int n;
int numb[maxn];
pair<string, int> op[maxn];
void print(int pos, int l, int r) {
  refresh(pos, l, r);
  if (l == r) return;
  print(pos * 2, l, m(l, r));
  print(pos * 2 + 1, m(l, r) + 1, r);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  vector<int> compression;
  for (int i = 0; i < n; i++) {
    op[i].second = -1;
    cin >> op[i].first;
    if (op[i].first == "sum") continue;
    cin >> op[i].second;
    compression.push_back(op[i].second);
  }
  sort(compression.begin(), compression.end());
  map<int, int> mapa;
  int chave = 0;
  for (int i = 0; i < compression.size(); i++)
    if (mapa.find(compression[i]) == mapa.end())
      mapa.insert(make_pair(compression[i], ++chave));
  set<int> ativo;
  for (int i = 0; i < n; i++) {
    if (op[i].first == "add") {
      if (ativo.size() == 0) {
        upd2(1, 1, maxn, mapa.find(op[i].second)->second, 1, op[i].second, 1);
        ativo.insert(op[i].second);
        continue;
      }
      set<int>::iterator it = ativo.upper_bound(op[i].second);
      int k = mapa.find(op[i].second)->second;
      if (it == ativo.begin()) {
        upd1(1, 1, maxn, k + 1, maxn, 1);
        upd2(1, 1, maxn, k, 1, op[i].second, 1);
        ativo.insert(op[i].second);
        continue;
      }
      int q = query(1, 1, maxn, mapa.find(*(--it))->second);
      upd2(1, 1, maxn, k, (q + 1) % 5, op[i].second, 1);
      upd1(1, 1, maxn, k + 1, maxn, 1);
      ativo.insert(op[i].second);
      continue;
    }
    if (op[i].first == "sum") {
      refresh(1, 1, maxn);
      printf("%I64d\n", resp[1]);
      continue;
    }
    int k = mapa.find(op[i].second)->second;
    int q = query(1, 1, maxn, k);
    upd2(1, 1, maxn, k, q, -op[i].second, 0);
    upd1(1, 1, maxn, k + 1, maxn, -1);
    ativo.erase(ativo.find(op[i].second));
  }
}
