#include <bits/stdc++.h>
using namespace std;
struct node {
  int size = 1, key, prior;
  long long sum[5] = {0, 0, 0, 0, 0};
  node *left = NULL, *right = NULL;
  node() {
    memset(this, 0, sizeof *this);
    size = 1;
  }
  node(const int& k, const int& p) {
    memset(this, 0, sizeof *this);
    size = 1;
    key = k;
    prior = p;
  }
  void update() {
    int cur = 0;
    memset(sum, 0, sizeof sum);
    if (left) {
      cur = left->size;
      for (int i = 0; i < 5; i++) sum[i] = left->sum[i];
    }
    sum[cur++ % 5] += key;
    if (right) {
      for (int i = 0; i < 5; i++) sum[(i + cur) % 5] += right->sum[i];
      cur += right->size;
    }
    size = cur;
  }
};
node* root;
void merge(node*& root, node* left, node* right) {
  if (!left || !right) {
    root = left ? left : right;
  } else if (left->prior < right->prior) {
    merge(right->left, left, right->left);
    root = right;
  } else {
    merge(left->right, left->right, right);
    root = left;
  }
  root->update();
}
void split(node* root, node*& left, node*& right, const int& key) {
  if (!root) return void(left = right = NULL);
  if (key < root->key) {
    split(root->left, left, root->left, key);
    right = root;
  } else {
    split(root->right, root->right, right, key);
    left = root;
  }
}
void add(const int& key, const int& p) {
  node *l, *r, *m = new node(key, p);
  split(root, l, r, key);
  merge(root, l, m);
  merge(root, root, r);
}
node* find(node*& cur, const int& key) {
  if (!cur) return NULL;
  if (cur->key == key) return cur;
  if (cur->key < key) return find(cur->left, key);
  return find(cur->right, key);
}
void del(const int& key, node*& cur = root) {
  if (cur->key == key)
    merge(cur, cur->left, cur->right);
  else if (cur->key < key)
    del(key, cur->right);
  else
    del(key, cur->left);
  cur->update();
}
namespace _Orz_Everybody_Except_Me_ {
int main() {
  srand(1731624);
  int n, x;
  char str[5];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", str);
    if (str[0] == 'a') {
      scanf("%d", &x);
      add(x, rand());
    } else if (str[0] == 'd') {
      scanf("%d", &x);
      del(x);
    } else {
      printf("%d\n", root->sum[2]);
    }
  }
  return 0;
}
}  // namespace _Orz_Everybody_Except_Me_
int main() { return _Orz_Everybody_Except_Me_::main(); }
