#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 233;
struct treap {
  int val, fix, siz;
  long long sum[5];
  treap *lc, *rc;
} * tot, *I;
void update(treap *&x) {
  if (!x) return;
  treap *lc = x->lc ? x->lc : I;
  treap *rc = x->rc ? x->rc : I;
  x->siz = lc->siz + rc->siz + 1;
  int j = lc->siz;
  j %= 5;
  for (int i = 0; i < 5; i++) x->sum[i] = lc->sum[i];
  for (int i = 0; i < 5; i++) {
    j++;
    if (j == 5) j = 0;
    x->sum[j] += rc->sum[i];
  }
  x->sum[j] += x->val;
  return;
}
void right_rotate(treap *&x) {
  treap *y = x->lc;
  x->lc = y->rc;
  y->rc = x;
  x = y;
  return;
}
void left_rotate(treap *&x) {
  treap *y = x->rc;
  x->rc = y->lc;
  y->lc = x;
  x = y;
  return;
}
void add(int val, treap *&x) {
  if (!x) {
    x = new treap;
    x->val = val;
    x->fix = rand() + rand() ^ rand();
    x->lc = x->rc = NULL;
    x->sum[0] = val;
    x->siz = 1;
    for (int i = 1; i < 5; i++) x->sum[i] = 0;
    return;
  }
  if (val <= x->val) {
    add(val, x->lc);
    if (x->lc->fix > x->fix) right_rotate(x), update(x->rc);
  } else {
    add(val, x->rc);
    if (x->rc->fix > x->fix) left_rotate(x), update(x->lc);
  }
  update(x);
  return;
}
void del(int val, treap *&x) {
  if (x->val == val) {
    if (!(x->lc) || !(x->rc)) {
      if (!x->lc)
        x = x->rc;
      else
        x = x->lc;
      update(x);
      return;
    }
    if (x->lc->fix > x->rc->fix) {
      right_rotate(x);
      del(val, x->rc);
    } else {
      left_rotate(x);
      del(val, x->lc);
    }
  } else if (val < x->val)
    del(val, x->lc);
  else
    del(val, x->rc);
  update(x);
  return;
}
void go_over(treap *x) {
  if (!x) return;
  go_over(x->lc);
  cout << x->val << ": ";
  for (int i = 0; i < 5; i++) cout << x->sum[i] << " ";
  cout << endl;
  go_over(x->rc);
  return;
}
char op[100];
int main() {
  srand(20010204);
  I = new treap;
  I->val = I->fix = I->siz = 0;
  for (int i = 0; i < 5; i++) I->sum[i] = 0;
  int m;
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int x;
    scanf("%s", op);
    if (op[0] == 's') {
      if (tot)
        printf("%I64d\n", tot->sum[2]);
      else
        printf("0\n");
    } else {
      int x;
      scanf("%d", &x);
      if (op[0] == 'd')
        del(x, tot);
      else
        add(x, tot);
    }
  }
  return 0;
}
