#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 100 * 1000 + 13;
struct T {
  T *left, *right;
  long long f;
  int val;
  int rnd;
  int size;
};
T pool[maxn];
int tCur = 0;
T* tVertex(int val) {
  T* root = &pool[tCur++];
  root->left = root->right = NULL;
  root->rnd = rand();
  root->val = val;
  root->f = val;
  root->size = 1;
  return root;
}
T* tRecalc(T* root) {
  if (!root) return root;
  long long f = 0;
  int size = 0;
  f = f + root->val;
  size++;
  if (root->left) f = f + root->left->f, size += root->left->size;
  if (root->right) f = f + root->right->f, size += root->right->size;
  root->f = f;
  root->size = size;
  return root;
}
void tSplit(T* root, int val, T*& l, T*& r) {
  if (!root) return void(l = r = NULL);
  if (val < root->val) {
    tSplit(root->left, val, l, root->left);
    r = tRecalc(root);
  } else {
    tSplit(root->right, val, root->right, r);
    l = tRecalc(root);
  }
}
T* tMerge(T* left, T* right) {
  if (!left) return right;
  if (!right) return left;
  if (left->rnd > right->rnd) {
    left->right = tMerge(left->right, right);
    return tRecalc(left);
  } else {
    right->left = tMerge(left, right->left);
    return tRecalc(right);
  }
}
T* root[5];
int main() {
  srand(time(NULL));
  int k;
  scanf("%d", &k);
  char str[10];
  T* troot[5];
  T* t1;
  for (int i = 0; i < (k); i++) {
    scanf("%s", str);
    if (str[0] == 's') {
      long long res = root[2] ? root[2]->f : 0;
      printf("%I64d\n", res);
    } else {
      int val;
      scanf("%d", &val);
      if (str[0] == 'a') {
        int pos = 0;
        for (int i = 0; i < 5; i++)
          tSplit(root[i], val, root[i], troot[i]),
              pos += root[i] ? root[i]->size : 0;
        pos %= 5;
        root[pos] = tMerge(root[pos], tVertex(val));
        for (int i = 0; i < 5; i++)
          root[i] = tMerge(root[i], troot[(i + 4) % 5]);
      } else {
        int pos = 0;
        for (int i = 0; i < 5; i++)
          tSplit(root[i], val, root[i], troot[i]),
              pos += root[i] ? root[i]->size : 0;
        pos = (pos + 1) % 5;
        tSplit(troot[pos], val + 1, t1, troot[pos]);
        for (int i = 0; i < 5; i++)
          root[i] = tMerge(root[i], troot[(i + 1) % 5]);
      }
    }
  }
  return 0;
}
