#include <bits/stdc++.h>
using namespace std;
int a[100010], num[4 * 100010], n, na;
long long node[4 * 100010][5];
char q[100010], b[100010];
int cmp(const void* x, const void* y) { return *((int*)x) - *((int*)y); }
void rr_hoa() {
  qsort(a, na, sizeof(a[0]), cmp);
  int j = na;
  na = 1;
  for (int i = 0; i < j; i++)
    if (a[na - 1] != a[i]) {
      na++;
      a[na - 1] = a[i];
    }
}
void update(int s, int l, int r, int u, int ok) {
  if (u < l || r < u) return;
  if (l == r) {
    num[s] = ok;
    for (int i = 0; i < 5; i++) node[s][i] = 0;
    node[s][1] = a[u - 1] * ok;
    return;
  }
  int s1, s2, m;
  s1 = s * 2;
  s2 = s1 + 1;
  m = (l + r) / 2;
  update(s1, l, m, u, ok);
  update(s2, m + 1, r, u, ok);
  num[s] = num[s1] + num[s2];
  for (int i = 1; i <= 5; i++)
    node[s][(num[s1] + i) % 5] = node[s1][(num[s1] + i) % 5] + node[s2][i % 5];
}
int find(int x) {
  int l, r, m;
  l = 0;
  r = na - 1;
  while (l <= r) {
    m = (l + r) / 2;
    if (a[m] == x) return m;
    if (a[m] < x)
      l = m + 1;
    else
      r = m - 1;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    char c;
    scanf("%c", &c);
    while (!('a' <= c && c <= 'z')) scanf("%c", &c);
    q[i] = c;
    scanf("%c", &c);
    scanf("%c", &c);
    if (q[i] != 's') scanf("%d", &b[i]);
  }
  cout << b[0];
  na = 0;
  for (int i = 0; i < n; i++)
    if (q[i] != 's') {
      na++;
      a[na - 1] = b[i];
    }
  rr_hoa();
  memset(node, 0, sizeof(node));
  memset(num, 0, sizeof(num));
  for (int it = 0; it < n; it++) {
    if (q[it] == 's')
      printf("%I64d\n", node[1][3]);
    else if (q[it] == 'a') {
      int u = find(b[it]) + 1;
      update(1, 1, na, u, 1);
    } else if (q[it] == 'd') {
      int u = find(b[it]) + 1;
      update(1, 1, na, u, 0);
    }
  }
}
