#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y, k;
  long long s;
  node *l, *r;
  long long sum() const { return this ? s : 0; }
  int count() const { return this ? k : 0; }
  void add(const node *t) {
    s += t->sum();
    k += t->count();
  }
  void sub(const node *t) {
    s -= t->sum();
    k -= t->count();
  }
} T[100500], *F = T, *f[5];
node *unite(node *, node *);
pair<node *, node *> split(node *z, int x) {
  if (z == 0) return {0, 0};
  if (z->x < x) {
    auto t = split(z->r, x);
    z->sub(z->r);
    z->r = 0;
    return make_pair(unite(z, t.first), t.second);
  } else {
    auto t = split(z->l, x);
    z->sub(z->l);
    z->l = 0;
    return make_pair(t.first, unite(t.second, z));
  }
}
node *unite(node *l, node *r) {
  if (l == 0) return r;
  if (r == 0) return l;
  if (l->y > r->y) {
    l->sub(l->r);
    l->r = unite(l->r, r);
    l->add(l->r);
    return l;
  } else {
    r->sub(r->l);
    r->l = unite(l, r->l);
    r->add(r->l);
    return r;
  }
}
node *tree(int x) {
  F->x = x;
  F->y = (rand() << 15) ^ rand();
  F->s = x;
  F->k = 1;
  return F++;
}
void print(node *t) {
  if (t == 0) return;
  print(t->l);
  printf("%d ", t->x);
  print(t->r);
}
int main() {
  int n;
  cin >> n;
  for (int i(0); i < n; ++i) {
    char q[6];
    scanf("%s", q);
    if (q[0] == 'a') {
      int x;
      scanf("%d", &x);
      pair<node *, node *> z[5];
      int pos = 1;
      for (int i(0); i < 5; ++i) {
        z[i] = split(f[i], x);
        pos += z[i].first->count();
      }
      pos %= 5;
      z[pos].first = unite(z[pos].first, tree(x));
      for (int i(0); i < 5; ++i)
        f[i] = unite(z[i].first, z[(i + 4) % 5].second);
    } else if (q[0] == 'd') {
      int x;
      scanf("%d", &x);
      pair<node *, node *> z[5];
      for (int i(0); i < 5; ++i) {
        z[i] = split(f[i], x);
        z[i].second = split(z[i].second, x + 1).second;
      }
      for (int i(0); i < 5; ++i)
        f[i] = unite(z[i].first, z[(i + 1) % 5].second);
    } else
      cout << f[3]->sum() << endl;
  }
  return 0;
}
