#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 100010;
class Treap {
 public:
  struct Treap_Node {
    Treap_Node *left, *right;
    int value, fix, weight, size, fuck[5];
  } * root, *null;
  void updateFromChildren(Treap_Node *&P) {
    int count = 0;
    for (int i = 0; i < 5; i++) P->fuck[i] = 0;
    if (P->left != null) {
      for (int i = 0; i < 5; i++) P->fuck[i] = P->left->fuck[i];
      count += P->left->size;
    }
    P->fuck[count % 5] += P->value;
    if (P->value) count++;
    if (P->right != null) {
      for (int i = 0; i < 5; i++) P->fuck[(i + count) % 5] += P->right->fuck[i];
      count += P->right->size;
    }
  }
  Treap() {
    null = new struct Treap_Node;
    null->size = 0;
    null->weight = 0;
    null->value = inf;
    null->left = null;
    null->right = null;
    null->fix = inf;
    root = null;
  }
  void Treap_Print(Treap_Node *P) {
    if (P != null) {
      Treap_Print(P->left);
      printf("%d\n", P->value);
      Treap_Print(P->right);
    }
  }
  void Treap_Left_Rotate(Treap_Node *&a) {
    Treap_Node *b = a->right;
    a->right = b->left;
    b->left = a;
    b->size = a->size;
    a->size = a->left->size + a->right->size + a->weight;
    a = b;
  }
  void Treap_Right_Rotate(Treap_Node *&a) {
    Treap_Node *b = a->left;
    a->left = b->right;
    b->right = a;
    b->size = a->size;
    a->size = a->left->size + a->right->size + a->weight;
    a = b;
  }
  int Treap_Find(Treap_Node *P, int value) {
    if (P == null) return 0;
    if (P->value == value)
      return 1;
    else if (value < P->value)
      return Treap_Find(P->left, value);
    else
      return Treap_Find(P->right, value);
  }
  void Treap_Insert(Treap_Node *&P, int value) {
    if (P == null) {
      P = new Treap_Node;
      P->left = P->right = null;
      P->value = value;
      P->fix = rand();
      P->weight = 1;
      P->size = 1;
      for (int i = 0; i < 5; i++) P->fuck[i] = 0;
      P->fuck[0] = value;
    } else if (value == P->value) {
      P->weight++;
    } else if (value < P->value) {
      Treap_Insert(P->left, value);
      updateFromChildren(P);
    } else {
      Treap_Insert(P->right, value);
      updateFromChildren(P);
    }
    P->size = P->left->size + P->right->size + P->weight;
  }
  void Treap_Delete(Treap_Node *&P, int value) {
    if (P == null) return;
    if (value < P->value) {
      Treap_Delete(P->left, value);
      updateFromChildren(P);
    } else if (value > P->value) {
      Treap_Delete(P->right, value);
      updateFromChildren(P);
    } else if ((P->left == NULL) && (P->right == NULL)) {
      delete P;
      P = NULL;
    } else {
      P->value = 0;
      P->weight = 0;
      updateFromChildren(P);
    }
    P->size = P->left->size + P->right->size + P->weight;
  }
  int Treap_pred(Treap_Node *P, int value, Treap_Node *optimal) {
    if (P == null || value == P->value) return optimal->value;
    if (P->value < value)
      return Treap_pred(P->right, value, P);
    else
      return Treap_pred(P->left, value, optimal);
  }
  int Treap_succ(Treap_Node *P, int value, Treap_Node *optimal) {
    if (P == null || value == P->value) return optimal->value;
    if (P->value > value)
      return Treap_succ(P->left, value, P);
    else
      return Treap_succ(P->right, value, optimal);
  }
  int Treap_Findkth(Treap_Node *P, int k) {
    if (P == null) return 0;
    int t = P->left->size;
    if (k < t + 1)
      return Treap_Findkth(P->left, k);
    else if (k > t + P->weight)
      return Treap_Findkth(P->right, k - (t + P->weight));
    else
      return P->value;
  }
  int Treap_Rank(Treap_Node *P, int value, int cur) {
    int t = P->left->size;
    if (value == P->value)
      return t + cur + 1;
    else if (value < P->value)
      return Treap_Rank(P->left, value, cur);
    else
      return Treap_Rank(P->right, value, t + cur + P->weight);
  }
  void Treap_erase(Treap_Node *&P) {
    if (P->left != null) Treap_erase(P->left);
    if (P->right != null) Treap_erase(P->right);
    delete P;
  }
};
int n;
pair<int, int> q[100100];
vector<int> v;
int main() {
  srand(233);
  Treap tree;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    char s[10];
    int a;
    scanf("%s", &s);
    if (s[0] == 'a') {
      scanf("%d", &a);
      tree.Treap_Insert(tree.root, a);
    } else if (s[0] == 'd') {
      scanf("%d", &a);
      tree.Treap_Delete(tree.root, a);
    } else {
      printf("%d\n", tree.root->fuck[2]);
    }
  }
  return 0;
}
