#include <bits/stdc++.h>
using namespace std;
struct node {
  int query;
  int val;
};
struct tree {
  int sum;
  int val[8];
};
node nodes[100100];
int a[100100], n, c;
char s[20];
tree m[3 * 100100 + 4];
map<int, int> num, num1;
void update1(int node, int b, int e, int ind, int val);
void update(int node, int b, int c, int ind, int val);
void init(int node, int b, int e);
int main() {
  int i, j, k, l, test, t = 1;
  scanf("%d", &n);
  c = 0;
  for (i = 1; i <= n; i++) {
    scanf("%s", s);
    if (strcmp(s, "sum") == 0) {
      nodes[i].query = 3;
      continue;
    }
    if (strcmp(s, "add") == 0) {
      nodes[i].query = 1;
      scanf("%d", &k);
      a[c++] = k;
      nodes[i].val = k;
      continue;
    }
    if (strcmp(s, "del") == 0) {
      nodes[i].query = 2;
      scanf("%d", &k);
      a[c++] = k;
      nodes[i].val = k;
      continue;
    }
  }
  sort(a, a + c);
  num[a[0]] = 0;
  j = 1;
  num1[0] = a[0];
  for (i = 1; i < c; i++) {
    if (a[i] == a[i - 1]) continue;
    num1[j] = a[i];
    num[a[i]] = j++;
  }
  init(1, 0, n - 1);
  for (i = 1; i <= n; i++) {
    j = nodes[i].query;
    k = nodes[i].val;
    if (j == 3) {
      printf("%d\n", m[1].val[3]);
    } else if (j == 2) {
      update1(1, 0, n - 1, num[k], k);
    } else
      update(1, 0, n - 1, num[k], k);
  }
  return 0;
}
void update(int node, int b, int e, int ind, int val) {
  if (b == e) {
    m[node].sum += 1;
    m[node].val[1] = num1[b];
    return;
  }
  int left, right, mid, i, k, l, j;
  left = node << 1;
  right = left + 1;
  mid = b + e;
  mid /= 2;
  if (ind <= mid)
    update(left, b, mid, ind, val);
  else
    update(right, mid + 1, e, ind, val);
  m[node].sum = m[left].sum + m[right].sum;
  k = m[left].sum % 5;
  for (i = 0; i < 5; i++) {
    m[node].val[i] = m[left].val[i];
  }
  for (i = 0; i < 5; i++) {
    l = k + i;
    l %= 5;
    m[node].val[l] += m[right].val[i];
  }
}
void update1(int node, int b, int e, int ind, int val) {
  if (b == e) {
    m[node].sum -= 1;
    m[node].val[1] = 0;
    return;
  }
  int left, right, mid, i, k, l, j;
  left = node << 1;
  right = left + 1;
  mid = b + e;
  mid /= 2;
  if (ind <= mid)
    update1(left, b, mid, ind, val);
  else
    update1(right, mid + 1, e, ind, val);
  m[node].sum = m[left].sum + m[right].sum;
  k = m[left].sum % 5;
  for (i = 0; i < 5; i++) {
    m[node].val[i] = m[left].val[i];
  }
  for (i = 0; i < 5; i++) {
    l = k + i;
    l %= 5;
    m[node].val[l] += m[right].val[i];
  }
}
void init(int node, int b, int e) {
  int i;
  if (b == e) {
    m[node].sum = 0;
    for (i = 0; i <= 5; i++) m[node].val[i] = 0;
    return;
  }
  init(node * 2, b, (b + e) / 2);
  init(node * 2 + 1, (b + e) / 2 + 1, e);
  m[node].sum = 0;
  for (i = 0; i <= 5; i++) m[node].val[i] = 0;
}
