#include <bits/stdc++.h>
using namespace std;
int Num;
char CH[20];
const int inf = 0x3f3f3f3f;
inline long long read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void P(int x) {
  Num = 0;
  if (!x) {
    putchar('0');
    puts("");
    return;
  }
  while (x > 0) CH[++Num] = x % 10, x /= 10;
  while (Num) putchar(CH[Num--] + 48);
  puts("");
}
vector<int> s;
int main() {
  char a[10];
  int b;
  int n = read();
  for (int i = 0; i < n; i++) {
    scanf("%s", a);
    if (a[0] == 'a') {
      scanf("%d", &b);
      s.insert(lower_bound(s.begin(), s.end(), b), b);
    }
    if (a[0] == 'd') {
      scanf("%d", &b);
      s.erase(lower_bound(s.begin(), s.end(), b));
    }
    if (a[0] == 's') {
      long long sum = 0;
      for (int j = 2; j < s.size(); j += 5) sum += s[j];
      printf("%lld\n", sum);
    }
  }
}
