#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 5;
vector<pair<char, int> > query;
int a[N];
long long t[4 * N][5];
int cnt[4 * N];
int sz = 0;
int n;
char buf[3];
void upd(int idx, int lf, int rg, int pos, int c, int val) {
  if (lf == rg) {
    cnt[idx] += c;
    t[idx][0] += val;
    return;
  }
  int mid = (lf + rg) >> 1;
  if (pos <= mid)
    upd(idx * 2 + 1, lf, mid, pos, c, val);
  else
    upd(idx * 2 + 2, mid + 1, rg, pos, c, val);
  cnt[idx] = cnt[idx * 2 + 1] + cnt[idx * 2 + 2];
  int cntLf = cnt[idx * 2 + 1] % 5;
  int i;
  for (int i = 0; i < 5; i++)
    t[idx][i] = t[idx * 2 + 1][i] + t[idx * 2 + 2][(i - cntLf + 5) % 5];
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", &buf);
    if (buf[0] == 's')
      query.push_back(make_pair(buf[0], -1));
    else {
      int x;
      scanf("%d", &x);
      query.push_back(make_pair(buf[0], x));
      a[sz++] = x;
    }
  }
  sort(a, a + sz);
  sz = (unique(a, a + sz) - a);
  for (int i = 0; i < n; i++) {
    char c = query[i].first;
    int val = query[i].second;
    if (c == 's')
      printf("%I64d\n", t[0][2]);
    else {
      int pos = lower_bound(a, a + sz, val) - a;
      if (c == 'a')
        upd(0, 0, sz - 1, pos, 1, val);
      else
        upd(0, 0, sz - 1, pos, -1, -val);
    }
  }
  return 0;
}
