#include <iostream>
#include <vector>
#include <utility>
#include <cstdio>
// #include <algorithm>
using namespace std;

#define X first
#define Y second

typedef long long ll;
typedef vector<ll> Vi;

struct Tree {
  Tree* left;
  Tree* right;
  ll x, y;
  // info
  Vi v;
  ll s;
};
typedef pair<Tree*, Tree*> Ptree;

ll rnd;

inline ll rand() {
  return rnd = (100000007LL*rnd + 17LL)%9990454949LL;
}

int get_s(Tree* T) {
  if (T == 0) return 0;
  return T->s;
}

Vi get_v(Tree* T) {
  if (T == 0) return Vi(5, 0);
  return T->v;
}

void update(Tree* T) {
  ll s1 = get_s(T->left), s2 = get_s(T->right);
  Vi v1 = get_v(T->left), v2 = get_v(T->right);
  T->s = 1 + s1 + s2;
  T->v = v1;
  T->v[s1%5] += T->x;
  for (int i = 0; i < 5; ++i) T->v[(s1 + 1 + i)%5] += v2[i];
}

Tree* new_tree(int x) {
  Tree* T = new Tree;
  T->x = x;
  T->y = rand();
  T->left = T->right = 0;
  update(T);
  return T;
}

Tree* merge(Tree* T1, Tree* T2) {
  if (T1 == 0) return T2;
  if (T2 == 0) return T1;
  if (T1->y >= T2->y) {
    T1->right = merge(T1->right, T2);
    update(T1);
    return T1;
  }
  T2->left = merge(T1, T2->left);
  update(T2);
  return T2;
}

Ptree split(Tree* T, ll x) {
  if (T == 0) return Ptree(0, 0);
  if (T->x <= x) {
    Ptree p = split(T->right, x);
    T->right = p.X;
    update(T);
    return Ptree(T, p.Y);
  }
  Ptree p = split(T->left, x);
  T->left = p.Y;
  update(T);
  return Ptree(p.X, T);
}

Tree* insert(Tree* T, ll x) {
  Tree *N = new_tree(x);
  Ptree p = split(T, x);
  return merge(merge(p.X, N), p.Y);
}

void erase(Tree* T) {
  if (T == 0) return;
  erase(T->left);
  erase(T->right);
  delete T;
}

Tree* erase(Tree* T, ll x) {
  Ptree p1 = split(T, x);
  Ptree p2 = split(p1.X, x - 1);
  erase(p2.Y);
  return merge(p2.X, p1.Y);
}

ll query(Tree* T) {
  if (T == 0) return 0;
  return T->v[2];
}

int main() {
  Tree* tree = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    char s[4];
    scanf("%s", s);
    if (s[0] == 'a') {
      int x;
      scanf("%d", &x);
      tree = insert(tree, x);
    }
    else if (s[0] == 'd') {
      int x;
      scanf("%d", &x);
      tree = erase(tree, x);
    }
    else printf("%lld\n", query(tree));
  }
}
