#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
int n;
struct node {
  int v, w, sz;
  node *l, *r;
  long long sum[5];
  void maintain() {
    int pre = 0, s = 1;
    if (l != NULL) s += l->sz;
    pre = s;
    if (r != NULL) s += r->sz;
    sz = s;
    memset((sum), 0, sizeof(sum));
    sum[(pre % 5)] = v;
    for (int i = 0; i < 5; i++) {
      if (l != NULL) sum[i] += l->sum[i];
      if (r != NULL) sum[(pre + i) % 5] += r->sum[i];
    }
  }
  node(int x) {
    this->v = x;
    this->w = rand();
    this->sz = 1;
    this->l = this->r = NULL;
    memset((sum), 0, sizeof(sum));
    this->sum[1] = x;
  }
};
node *rt;
void Split(node *x, node **l, node **r, int v) {
  if (x == NULL)
    (*l) = (*r) = NULL;
  else if (x->v < v) {
    *l = x;
    Split(x->r, &x->r, r, v);
  } else {
    *r = x;
    Split(x->l, l, &x->l, v);
  }
  if ((*l) != NULL) (*l)->maintain();
  if ((*r) != NULL) (*r)->maintain();
}
void Merge(node **x, node *l, node *r) {
  if (l == NULL || r == NULL) {
    *x = (l == NULL) ? r : l;
    return;
  }
  if (l->w < r->w) {
    *x = l;
    Merge(&(*x)->r, (*x)->r, r);
  } else {
    *x = r;
    Merge(&(*x)->l, l, (*x)->l);
  }
  if ((*x) != NULL) (*x)->maintain();
}
void add(node **x, int v) {
  node *l, *r, *m;
  Split(*x, &l, &r, v);
  Merge(&m, l, new node(v));
  Merge(x, m, r);
}
void del(node **x, int v) {
  node *l, *m, *r, *tmp;
  Split(*x, &l, &tmp, v);
  Split(tmp, &m, &r, v + 1);
  Merge(x, l, r);
}
int main() {
  srand((unsigned)time(NULL));
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  rt = new node(0x3f3f3f3f);
  node *Null = rt;
  while (n--) {
    string opt;
    cin >> opt;
    if (opt[0] == 's') {
      if (rt == Null || rt->sum[3] == 0x3f3f3f3f)
        cout << "0\n";
      else
        cout << (rt->sum[3]) << endl;
    } else {
      int x;
      cin >> x;
      if (opt[0] == 'a')
        add(&rt, x);
      else
        del(&rt, x);
    }
  }
  return 0;
}
