#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 1e5 + 10;
const int maxv = 1e3 + 10;
const double eps = 1e-9;
struct Question {
  char s[5];
  long long num;
  void read() {
    scanf("%s", s);
    if (s[0] != 's') {
      scanf("%lld", &num);
    }
  }
} q[maxn];
vector<long long> xs;
long long sum[maxn << 2][5];
long long cnt[maxn << 2];
int n;
int tot;
void up(int rt) {
  cnt[rt] = cnt[rt << 1] + cnt[rt << 1 | 1];
  int offset = cnt[rt << 1];
  for (int i = 0; i < 5; i++) sum[rt][i] = sum[rt << 1][i];
  for (int i = 0; i < 5; i++) sum[rt][(i + offset) % 5] += sum[rt << 1 | 1][i];
}
void updata(int rt, int l, int r, int id, long long val) {
  if (l == r) {
    sum[rt][0] = val * xs[id];
    cnt[rt] = val;
    return;
  }
  int mid = l + r >> 1;
  if (id <= mid)
    updata(rt << 1, l, mid, id, val);
  else
    updata(rt << 1 | 1, mid + 1, r, id, val);
  up(rt);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    q[i].read();
    if (q[i].s[0] != 's') {
      xs.push_back(q[i].num);
    }
  }
  sort(xs.begin(), xs.end());
  xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
  tot = xs.size() - 1;
  for (int i = 0; i < n; i++) {
    if (q[i].s[0] == 's') {
      printf("%lld\n", sum[1][2]);
    } else if (q[i].s[0] == 'a') {
      int id = lower_bound(xs.begin(), xs.end(), q[i].num) - xs.begin();
      updata(1, 0, tot, id, 1);
    } else {
      int id = lower_bound(xs.begin(), xs.end(), q[i].num) - xs.begin();
      updata(1, 0, tot, id, 0);
    }
  }
  return 0;
}
