#include <bits/stdc++.h>
using namespace std;
void sort(int a[], int size) {
  for (int i = 0; i < size - 1; i++)
    if (a[i] > a[i + 1]) {
      int t;
      t = a[i];
      a[i] = a[i + 1];
      a[i + 1] = t;
      i = -1;
    }
}
void out(int a[], int size) {
  for (int i = 0; i < size + 2; i++) cout << a[i];
  cout << endl;
}
int main() {
  int numOfActions = 0;
  char t[15];
  int size = 0;
  int arr[100000];
  int element;
  cin >> numOfActions;
  for (int i = 0; i < 100000; i++) arr[i] = 0;
  for (int i = 0; i < numOfActions; i++) {
    scanf("%s", t);
    if (t[0] == 'a') {
      scanf("%d", &element);
      arr[size] = element;
      size++;
    }
    if (t[0] == 'd') {
      scanf("%d", &element);
      for (int j = 0; j < size; j++) {
        if (arr[j] == element) {
          for (int curr = j; curr < size - 1; curr++) arr[curr] = arr[curr + 1];
          arr[size - 1] = 0;
          break;
        }
      }
      size--;
    }
    if (t[0] == 's') {
      int sum = 0;
      sort(arr, size);
      for (int t = 0; t < size; t = t + 5) {
        sum += arr[t + 2];
      }
      cout << sum << endl;
    }
  }
  return 0;
}
