#include <bits/stdc++.h>
using namespace std;
int n;
long long d[100001];
int m;
typedef struct Q {
  char str[3];
  long long a;
} Q;
Q ope[100001];
long long sum[100001 << 2][5];
long long cnt[100001 << 2];
int Count[100001 << 2];
int win;
long long num;
void Do(int t, long long a) {
  a = a % 5;
  if (a < 0) a = (a + 5) % 5;
  for (int i = 1; i <= a; i++) {
    int k = sum[t][4];
    sum[t][4] = sum[t][3];
    sum[t][3] = sum[t][2];
    sum[t][2] = sum[t][1];
    sum[t][1] = sum[t][0];
    sum[t][0] = k;
  }
  return;
}
void Doing(int t, int c) {
  if (c == 1) {
    int k = sum[t][4];
    sum[t][4] = sum[t][3];
    sum[t][3] = sum[t][2];
    sum[t][2] = sum[t][1];
    sum[t][1] = sum[t][0];
    sum[t][0] = k;
  } else {
    int k = sum[t][0];
    sum[t][0] = sum[t][1];
    sum[t][1] = sum[t][2];
    sum[t][2] = sum[t][3];
    sum[t][3] = sum[t][4];
    sum[t][4] = k;
  }
}
void Buildtree(int l, int r, int t) {
  cnt[t] = 0;
  Count[t] = 0;
  sum[t][0] = sum[t][1] = sum[t][2] = sum[t][3] = sum[t][4] = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  Buildtree(l, mid, t << 1);
  Buildtree(mid + 1, r, t << 1 | 1);
  return;
}
void PushDown(int t) {
  cnt[t << 1] += cnt[t];
  cnt[t << 1 | 1] += cnt[t];
  Do(t << 1, cnt[t]);
  Do(t << 1 | 1, cnt[t]);
  cnt[t] = 0;
  return;
}
void PushUp(int t) {
  sum[t][0] = sum[t << 1][0] + sum[t << 1 | 1][0];
  sum[t][1] = sum[t << 1][1] + sum[t << 1 | 1][1];
  sum[t][2] = sum[t << 1][2] + sum[t << 1 | 1][2];
  sum[t][3] = sum[t << 1][3] + sum[t << 1 | 1][3];
  sum[t][4] = sum[t << 1][4] + sum[t << 1 | 1][4];
  Count[t] = Count[t << 1] + Count[t << 1 | 1];
  return;
}
void Update(int l, int r, int t, int a, int b, int c) {
  if (a <= l && b >= r) {
    if (c) {
      cnt[t] += c;
      Doing(t, c);
    } else {
      sum[t][win % 5] = num;
      Count[t] = 1;
    }
    return;
  }
  if (cnt[t]) PushDown(t);
  int mid = (l + r) >> 1;
  if (a <= mid) Update(l, mid, t << 1, a, b, c);
  if (b > mid) Update(mid + 1, r, t << 1 | 1, a, b, c);
  PushUp(t);
  return;
}
int Query(int l, int r, int t, int a, int b) {
  int s = 0;
  if (a <= l && b >= r) {
    return s = Count[t];
  }
  int mid = (l + r) >> 1;
  if (a <= mid) s += Query(l, mid, t << 1, a, b);
  if (b > mid) s += Query(mid + 1, r, t << 1 | 1, a, b);
  return s;
}
void Del(int l, int r, int t, int a) {
  if (l == r) {
    sum[t][0] = sum[t][1] = sum[t][2] = sum[t][3] = sum[t][4] = 0;
    Count[t] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  if (cnt[t]) PushDown(t);
  if (a <= mid)
    Del(l, mid, t << 1, a);
  else
    Del(mid + 1, r, t << 1 | 1, a);
  PushUp(t);
  return;
}
int Binary(long long x) {
  int l = 1;
  int r = m;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (d[mid] == x) return mid;
    if (d[mid] > x)
      r = mid - 1;
    else
      l = mid + 1;
  }
}
void debug(int l, int r, int t) {
  printf(
      "%d %d %d %d cnt[t]=:%d  0:%I64d  1:%I64d  2:%I64d  3:%I64d  4:%I64d\n",
      l, r, t, Count[t], cnt[t], sum[t][0], sum[t][1], sum[t][2], sum[t][3],
      sum[t][4]);
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (cnt[t]) PushDown(t);
  debug(l, mid, t << 1);
  debug(mid + 1, r, t << 1 | 1);
  PushUp(t);
  return;
}
int main() {
  int i, j, k;
  while (scanf("%d", &n) != EOF) {
    m = 0;
    for (i = 1; i <= n; i++) {
      scanf("%s", ope[i].str);
      if (ope[i].str[0] == 's') continue;
      scanf("%I64d", &ope[i].a);
      d[++m] = ope[i].a;
    }
    sort(d + 1, d + 1 + m);
    k = 0;
    for (i = 1; i <= m; i++) {
      while (d[i] == d[i + 1]) i++;
      d[++k] = d[i];
    }
    m = k;
    if (m) Buildtree(1, m, 1);
    for (i = 1; i <= n; i++) {
      if (ope[i].str[0] == 's') {
        printf("%I64d\n", sum[1][3]);
      } else if (ope[i].str[0] == 'a') {
        int index = Binary(ope[i].a);
        if (index < m) Update(1, m, 1, index + 1, m, 1);
        num = ope[i].a;
        if (index > 1) {
          win = Query(1, m, 1, 1, index - 1) + 1;
        } else
          win = 1;
        Update(1, m, 1, index, index, 0);
      } else {
        int index = Binary(ope[i].a);
        if (index < m) Update(1, m, 1, index + 1, m, -1);
        Del(1, m, 1, index);
      }
    }
  }
  return 0;
}
