#include <bits/stdc++.h>
using namespace std;
long long sum[100010 << 3][5];
int c[100010 << 3];
int n, m;
long long d[100010];
int p1, p2;
typedef struct {
  int a;
  long long b;
} Q;
Q q[100010];
void PushUp(int t) {
  c[t] = c[t << 1] + c[t << 1 | 1];
  for (p1 = 0; p1 < 5; p1++) {
    sum[t][p1] = sum[t << 1][p1];
  }
  for (p1 = 0; p1 < 5; p1++) {
    sum[t][(c[t << 1] + p1) % 5] += sum[t << 1 | 1][p1];
  }
  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 Buildtree(int l, int r, int t) {
  for (p1 = 0; p1 < 5; p1++) sum[t][p1] = 0;
  c[t] = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  Buildtree(l, mid, t << 1);
  Buildtree(mid + 1, r, t << 1 | 1);
  return;
}
void update(int l, int r, int t, int a, long long b) {
  if (l == r) {
    if (b >= 0)
      c[t] = 1;
    else
      c[t] = 0;
    sum[t][1] += b;
    return;
  }
  int mid = (l + r) >> 1;
  if (a <= mid) {
    update(l, mid, t << 1, a, b);
  } else {
    update(mid + 1, r, t << 1 | 1, a, b);
  }
  PushUp(t);
  return;
}
void debug(int l, int r, int t) {
  printf("%d %d %d %d\n", l, r, t, c[t]);
  for (p1 = 0; p1 < 5; p1++) printf("%lld ", sum[t][p1]);
  puts("");
  if (l == r) return;
  int mid = (l + r) >> 1;
  debug(l, mid, t << 1);
  debug(mid + 1, r, t << 1 | 1);
  return;
}
int main() {
  int i, j, k;
  char str[10];
  int zz;
  while (scanf("%d", &n) != EOF) {
    zz = 0;
    int a;
    long long b;
    m = 0;
    for (i = 1; i <= n; i++) {
      scanf("%s", str);
      if (str[0] == 'a') {
        scanf("%I64d", &b);
        d[i] = b;
        q[i].a = 0;
        q[i].b = b;
      } else if (str[0] == 'd') {
        scanf("%I64d", &b);
        d[i] = b;
        q[i].a = 1;
        q[i].b = b;
      } else {
        q[i].a = 2;
      }
    }
    sort(d + 1, d + 1 + n);
    m = unique(d + 1, d + 1 + n) - (d + 1);
    Buildtree(1, m, 1);
    for (i = 1; i <= n; i++) {
      a = q[i].a;
      b = q[i].b;
      int idx;
      if (a == 0 || a == 1) idx = Binary(b);
      if (a == 0) {
        update(1, m, 1, idx, b);
        zz++;
      } else if (a == 1) {
        update(1, m, 1, idx, -b);
        zz--;
      } else {
        if (zz == 0)
          printf("0\n");
        else
          printf("%I64d\n", sum[1][3]);
      }
    }
  }
  return 0;
}
