#include <bits/stdc++.h>
using namespace std;
int N, X;
char C[15];
struct Node {
  int value, priority, weight;
  long long sum[5];
  Node *left, *right;
  Node(int val = -1, Node *T = NULL) {
    memset(sum, 0, sizeof sum);
    if (val != -1) sum[0] = val;
    priority = rand();
    value = val;
    if (val == -1)
      weight = 0;
    else
      weight = 1;
    left = right = T;
  }
} * NIL;
typedef Node *Treap;
typedef pair<Node *, Node *> Group;
int GetKey(Treap T, int val) {
  if (T == NIL) return 0;
  int pos = 0;
  if (T->value < val)
    pos += 1 + T->right->weight + GetKey(T->left, val);
  else if (T->value == val) {
    pos = T->right->weight + 1;
    if (T->right->value == val) pos = GetKey(T->right, val);
  } else
    pos += GetKey(T->right, val);
  return pos;
}
void regen(Treap T) {
  T->weight = 1 + T->left->weight + T->right->weight;
  memcpy(T->sum, T->right->sum, sizeof T->sum);
  T->sum[T->right->weight % 5] += T->value;
  for (int i = 0; i < 5; i++)
    T->sum[(i + T->right->weight + 1) % 5] += T->left->sum[i];
}
Treap join(Treap T1, Treap T2) {
  if (T1 == NIL) return T2;
  if (T2 == NIL) return T1;
  if (T1->priority >= T2->priority) {
    T1->left = join(T1->left, T2);
    regen(T1);
    return T1;
  } else {
    T2->right = join(T1, T2->right);
    regen(T2);
    return T2;
  }
}
Group split(Treap T, int key) {
  if (T == NIL) return {NIL, NIL};
  if (T->right->weight >= key) {
    Group Temp = split(T->right, key);
    T->right = Temp.second;
    regen(T);
    return {Temp.first, T};
  } else if (T->right->weight + 1 == key) {
    Group Temp = {T, T->left};
    T->left = NIL;
    regen(T);
    return Temp;
  } else {
    Group Temp = split(T->left, key - 1 - T->right->weight);
    T->left = Temp.first;
    regen(T);
    return {T, Temp.second};
  }
}
void Delete(Treap &T, int val) {
  int key = GetKey(T, val);
  Group Temp = split(T, key - 1);
  Group Temp2 = split(Temp.second, 1);
  T = join(Temp.first, Temp2.second);
}
void Insert(Treap &T, int val) {
  Treap Added = new Node(val, NIL);
  int key = GetKey(T, val);
  Group Temp = split(T, key);
  T = join(Temp.first, join(Added, Temp.second));
}
int main() {
  NIL = new Node();
  Treap Root = NIL;
  scanf("%d", &N);
  srand(time(NULL));
  for (int i = 1; i <= N; i++) {
    scanf("%s", C);
    if (C[0] == 'a') {
      scanf(" %d", &X);
      Insert(Root, X);
    }
    if (C[0] == 's') {
      printf("%d\n", Root->sum[2]);
    }
    if (C[0] == 'd') {
      scanf(" %d", &X);
      Delete(Root, X);
    }
  }
  return 0;
}
