#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, lazy[N << 2], val;
long long seg[N << 2][6];
vector<pair<string, int> > q;
vector<int> vec;
int get(int id, int mod) { return seg[id][((mod - lazy[id]) % 5 + 5) % 5]; }
void relax(int id, int lc, int rc) {
  lazy[lc] = (lazy[lc] + lazy[id]) % 5, lazy[rc] = (lazy[rc] + lazy[id]) % 5;
  lazy[id] = 0;
  return;
}
void add1(int p, int id = 1, int s = 0, int e = n) {
  if (e - s == 1) {
    seg[id][0] += val;
    return;
  }
  int mid = (s + e) / 2, lc = id * 2, rc = lc + 1;
  relax(id, lc, rc);
  if (p < mid)
    add1(p, lc, s, mid);
  else
    add1(p, rc, mid, e);
  for (int i = 0; i < 5; i++) seg[id][i] = get(lc, i) + get(rc, i);
  return;
}
void add2(int l, int r, int id = 1, int s = 0, int e = n) {
  if (e <= l || r <= s) return;
  if (l <= s && e <= r) {
    lazy[id] = (lazy[id] + val) % 5;
    return;
  }
  int mid = (s + e) / 2, lc = id * 2, rc = lc + 1;
  relax(id, lc, rc);
  add2(l, r, lc, s, mid);
  add2(l, r, rc, mid, e);
  for (int i = 0; i < 5; i++) seg[id][i] = get(lc, i) + get(rc, i);
  return;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s[0] == 's')
      q.push_back({s, -1});
    else {
      int x;
      cin >> x;
      vec.push_back(x);
      q.push_back({s, x});
    }
  }
  sort(vec.begin(), vec.end());
  vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
  for (auto p : q) {
    string s = p.first;
    int x = p.second;
    if (s[0] == 's') {
      cout << get(1, 2) << "\n";
      continue;
    }
    x = lower_bound(vec.begin(), vec.end(), x) - vec.begin();
    if (s[0] == 'a') {
      val = 1;
      add2(x + 1, n);
      val = vec[x];
      add1(x);
    } else {
      val = -1, val += 5;
      add2(x + 1, n);
      val = -vec[x];
      add1(x);
    }
  }
  return 0;
}
