#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, inv2 = (MOD + 1) / 2;
long double eps = 1e-6;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
long double pi = acos(-1.0L);
struct node {
  int s;
  long long a[5];
} t[100000 + 10 << 2];
struct Q {
  int op, x;
} q[100000 + 10];
int c[100000 + 10], n, m, n1;
char s[100000 + 10];
int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
long long readll() {
  long long v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
void pushup(int p) {
  t[p].s = t[p << 1].s + t[p << 1 | 1].s;
  for (int i = (int)0; i <= (int)4; i++)
    t[p].a[i] = t[p << 1].a[i] + t[p << 1 | 1].a[(i - t[p << 1].s + 5) % 5];
}
void update(int l, int r, int x, int v, int op, int p) {
  if (l == r) {
    t[p].s += op;
    t[p].a[0] += v;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(l, mid, x, v, op, p << 1);
  else
    update(mid + 1, r, x, v, op, p << 1 | 1);
  pushup(p);
}
void init() {
  m = read();
  n1 = 0;
  for (int i = (int)1; i <= (int)m; i++) {
    scanf("%s", s + 1);
    if (s[1] == 'a') {
      int x = read();
      c[++n1] = x;
      q[i].op = 1;
      q[i].x = x;
    }
    if (s[1] == 'd') {
      int x = read();
      c[++n1] = x;
      q[i].op = -1;
      q[i].x = x;
    }
    if (s[1] == 's') q[i].op = 0;
  }
}
void solve() {
  sort(c + 1, c + n1 + 1);
  int n = unique(c + 1, c + n1 + 1) - c;
  for (int i = (int)1; i <= (int)m; i++) {
    if (q[i].op) {
      int x = lower_bound(c + 1, c + n + 1, q[i].x) - c;
      update(1, n, x, q[i].x * q[i].op, q[i].op, 1);
    } else
      printf("%I64d\n", t[1].a[2]);
  }
}
int main() {
  init();
  solve();
  return 0;
}
