#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
template <typename T>
void DBG(const char* name, T&& H) {
  cerr << name << " = " << H << ')' << '\n';
}
template <typename T, typename... Args>
void DBG(const char* names, T&& H, Args&&... args) {
  const char* NEXT = strchr(names + 1, ',');
  cerr.write(names, NEXT - names) << " = " << H << " |";
  DBG(NEXT + 1, args...);
}
using ll = long long;
using ld = long double;
const long long mod = 1e9 + 7;
const long double PI = acos(-1.0);
const long long INF = 1e18;
const int maxN = 4e5 + 1;
int N;
map<int, int> ID;
vector<string> type;
vector<int> val;
template <typename T>
struct node {
  T modulo[5], isPresent;
  node() {
    for (int i = 0; i < 5; i++) modulo[i] = 0;
    isPresent = 0;
  }
};
template <typename T>
struct lazyNode {
  T val;
  lazyNode(T x = 0) : val(x){};
};
struct SGT {
  using second = int;
  using T = long long;
  second size;
  vector<node<T>> data;
  vector<lazyNode<T>> lazy;
  vector<bool> isLazy;
  SGT(second sz = 1e6 + 1) {
    size = 1e6 + 1;
    data.resize(4 * sz);
    lazy.resize(4 * sz);
    isLazy.assign(4 * sz, false);
  }
  void merge(node<T>& pt, node<T>& lc, node<T>& rc) {
    for (int i = 0; i < 5; i++) {
      pt.modulo[i] = lc.modulo[i] + rc.modulo[i];
    }
    pt.isPresent = (lc.isPresent + rc.isPresent);
  }
  void push(second pt, second lc, second rc, second l, second r) {
    if (l != r) {
      isLazy[lc] = 1;
      isLazy[rc] = 1;
      lazy[lc].val += lazy[pt].val;
      lazy[rc].val += lazy[pt].val;
    }
    int shift = lazy[pt].val;
    shift %= 5;
    shift = (shift + 5) % 5;
    int newval[5];
    for (int i = 0; i < 5; i++) {
      newval[(i + shift) % 5] = data[pt].modulo[i];
    }
    for (int i = 0; i < 5; i++) {
      data[pt].modulo[i] = newval[i];
    }
    lazy[pt].val = 0;
    isLazy[pt] = 0;
  }
  T query(second x, second l, second r, second qL, second qR) {
    if (isLazy[x]) {
      push(x, 2 * x, 2 * x + 1, l, r);
    }
    if (qL > qR) return 0;
    if ((l == qL) && (r == qR)) return data[x].isPresent;
    T res = 0;
    second mid = ((l + r) >> 1);
    res += query(2 * x, l, mid, qL, min(mid, qR));
    res += query(2 * x + 1, mid + 1, r, max(mid + 1, qL), qR);
    return res;
  }
  void AddDelete(second x, second l, second r, second qL, second qR, T val,
                 T pos, T step) {
    if (isLazy[x]) {
      push(x, 2 * x, 2 * x + 1, l, r);
    }
    if (qL > qR) {
      return;
    }
    if ((l == qL) && (r == qR)) {
      if (step == 1) {
        data[x].modulo[pos] = val;
        data[x].isPresent = 1;
      } else
        data[x].isPresent = data[x].modulo[pos] = 0;
      return;
    }
    second mid = ((l + r) >> 1);
    AddDelete(2 * x, l, mid, qL, min(mid, qR), val, pos, step);
    AddDelete(2 * x + 1, mid + 1, r, max(mid + 1, qL), qR, val, pos, step);
    merge(data[x], data[2 * x], data[2 * x + 1]);
  }
  void shift(second x, second l, second r, second qL, second qR, T val) {
    if (isLazy[x]) {
      push(x, 2 * x, 2 * x + 1, l, r);
    }
    if (qL > qR) return;
    if ((l == qL) && (r == qR)) {
      isLazy[x] = 1;
      lazy[x].val += val;
      push(x, 2 * x, 2 * x + 1, l, r);
      return;
    }
    second mid = ((l + r) >> 1);
    shift(2 * x, l, mid, qL, min(mid, qR), val);
    shift(2 * x + 1, mid + 1, r, max(mid + 1, qL), qR, val);
    merge(data[x], data[2 * x], data[2 * x + 1]);
  }
};
void Solve() {
  cin >> N;
  set<int> dif;
  for (int i = 0; i < N; i++) {
    string in;
    int value = 0;
    cin >> in;
    type.push_back(in);
    if (in[0] != 's') {
      cin >> value;
    }
    val.push_back(value);
    if (value) dif.insert(value);
  }
  int cur = 0;
  for (auto i : dif) {
    ID[i] = cur;
    cur++;
  }
  SGT sgt(cur + 5);
  for (int i = 0; i < N; i++) {
    if (type[i][0] == 's') {
      cout << sgt.data[1].modulo[2] << '\n';
    } else {
      if (type[i][0] == 'a') {
        int idx = ID[val[i]];
        int rank = sgt.query(1, 0, cur - 1, 0, idx - 1);
        sgt.shift(1, 0, cur - 1, idx + 1, cur - 1, 1);
        sgt.AddDelete(1, 0, cur - 1, idx, idx, val[i], rank % 5, 1);
      } else {
        int idx = ID[val[i]];
        int rank = sgt.query(1, 0, cur - 1, 0, idx - 1);
        sgt.shift(1, 0, cur - 1, idx + 1, cur - 1, -1);
        sgt.AddDelete(1, 0, cur - 1, idx, idx, val[i], rank % 5, -1);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  while (tt--) {
    Solve();
  }
  return 0;
}
