#include <bits/stdc++.h>
const long long MOD = 1e9 + 7, INF = 1e18;
using namespace std;
long long n;
vector<long long> sorted;
struct query {
  char s[10];
  long long x;
} a[1000000];
struct SegTree {
  long long t[5][400000], cnt[400000], start;
  void build(long long n) {
    start = 1;
    while (start < n) start <<= 1;
  }
  void update(long long x, long long d) {
    x += start;
    t[0][x] = d;
    cnt[x] = (d != 0);
    x /= 2;
    while (x) {
      cnt[x] = cnt[2 * x] + cnt[2 * x + 1];
      for (long long i = 0; i < 5; i++) {
        long long r = (cnt[2 * x] - i - 1) % 5;
        if (cnt[2 * x] <= i) {
          r = cnt[2 * x];
          t[i][x] = t[i - cnt[2 * x]][2 * x + 1];
        } else
          t[i][x] = t[i][2 * x] + t[4 - r][2 * x + 1];
      }
      x /= 2;
    }
  }
} t;
int main() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    scanf("%s", a[i].s);
    if (a[i].s[0] != 's') {
      scanf("%lld", &a[i].x);
      if (a[i].s[0] == 'a') sorted.push_back(a[i].x);
    }
  }
  sort(sorted.begin(), sorted.end());
  t.build(sorted.size());
  for (long long i = 0; i < n; i++) {
    if (a[i].s[0] == 's') {
      printf("%lld\n", t.t[2][1]);
    } else if (a[i].s[0] == 'a') {
      long long x =
          lower_bound(sorted.begin(), sorted.end(), a[i].x) - sorted.begin();
      t.update(x, a[i].x);
    } else {
      long long x =
          lower_bound(sorted.begin(), sorted.end(), a[i].x) - sorted.begin();
      t.update(x, 0);
    }
  }
}
