#include <bits/stdc++.h>
using namespace std;
struct treap {
  treap *l, *r;
  int val;
  long long sum[5];
  int fix, wei, siz;
  int lsiz() {
    if (l)
      return l->siz;
    else
      return 0;
  }
  int rsiz() {
    if (r)
      return r->siz;
    else
      return 0;
  }
} * rt;
void lrot(treap *&a) {
  treap *b = a->r;
  a->r = b->l;
  b->l = a;
  a = b;
  b = a->l;
  b->siz = b->lsiz() + b->rsiz() + b->wei;
  a->siz = a->lsiz() + a->rsiz() + a->wei;
}
void rrot(treap *&a) {
  treap *b = a->l;
  a->l = b->r;
  b->r = a;
  a = b;
  b = a->r;
  b->siz = b->lsiz() + b->rsiz() + b->wei;
  a->siz = a->lsiz() + a->rsiz() + a->wei;
}
void gtsum(treap *&a) {
  if (!a) return;
  int j = (a->lsiz() % 5);
  for (int i = 0; i < 5; i++) a->sum[i] = 0;
  for (int i = 0; i < 5; i++) {
    if (a->l) a->sum[i] = a->l->sum[i];
  }
  for (int i = 0; i < 5; i++) {
    if (a->r) a->sum[(i + j + 1) % 5] += a->r->sum[i];
  }
  a->sum[j] += a->val;
}
void ins(treap *&a, int v) {
  if (!a) {
    a = new treap;
    a->val = v;
    a->wei = 1;
    a->siz = 1;
    a->l = NULL;
    a->r = NULL;
    a->fix = rand();
  } else if (v == a->val)
    a->wei++;
  else if (v < a->val) {
    ins(a->l, v);
    a->siz = a->lsiz() + a->rsiz() + a->wei;
    if (a->l->fix < a->fix) rrot(a);
  } else {
    ins(a->r, v);
    a->siz = a->lsiz() + a->rsiz() + a->wei;
    if (a->r->fix < a->fix) lrot(a);
  }
  gtsum(a);
}
void del(treap *&a, int v) {
  a->siz--;
  if (v == a->val) {
    if (a->wei > 0) a->wei--;
    if (a->wei > 0) return;
    if (!a->l || !a->r) {
      treap *t = a;
      if (!a->r)
        a = a->l;
      else if (!a->l)
        a = a->r;
      delete t;
    } else {
      if (a->l->fix < a->r->fix) {
        rrot(a);
        del(a->r, v);
      } else {
        lrot(a);
        del(a->l, v);
      }
    }
  } else if (v < a->val)
    del(a->l, v);
  else
    del(a->r, v);
  gtsum(a);
}
int FindKth(treap *&a, int k) {
  if (k < a->lsiz() + 1)
    return FindKth(a->l, k);
  else if (k > a->lsiz() + a->wei)
    return FindKth(a->r, k - a->lsiz() - a->wei);
  return a->val;
}
int n;
int main() {
  srand(time(0));
  cin >> n;
  while (n--) {
    string typ;
    cin >> typ;
    int x;
    if (typ == "add") {
      cin >> x;
      ins(rt, x);
    } else if (typ == "del") {
      cin >> x;
      del(rt, x);
    } else {
      long long ans = 0LL;
      if (rt) ans = rt->sum[2];
      printf("%lld\n", ans);
    }
  }
  return 0;
}
