#include <bits/stdc++.h>
using namespace std;
const int oo = 1 << 30;
const double PI = M_PI;
const double EPS = 1e-15;
const int MaxN = 100005;
int n;
string op[MaxN];
int a[MaxN];
int b[MaxN], size;
struct tree {
  tree* L;
  tree* R;
  int lo, hi;
  long long sum[5];
  int cnt;
  tree(int __lo, int __hi) {
    lo = __lo;
    hi = __hi;
    L = NULL;
    R = NULL;
    cnt = 0;
    for (int i = 0; i < 5; i++) sum[i] = 0;
    if (lo != hi) {
      int mid = (lo + hi) / 2;
      L = new tree(lo, mid);
      R = new tree(mid + 1, hi);
    }
  }
  void update(int x, int value) {
    if (x < lo || x > hi) return;
    cnt = cnt + value;
    if (lo == hi) {
      sum[0] += value * b[x - 1];
      return;
    }
    L->update(x, value);
    R->update(x, value);
    for (int i = 0; i < 5; i++)
      sum[i] = L->sum[i] + R->sum[(i - L->cnt % 5 + 5) % 5];
  }
};
int main() {
  cin.sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> op[i];
    if (op[i] != "sum") {
      cin >> a[i];
      b[size++] = a[i];
    }
  }
  sort(b, b + size);
  size = unique(b, b + size) - b;
  tree* root = new tree(1, max(1, size));
  for (int i = 0; i < n; i++) {
    if (op[i] == "sum")
      cout << root->sum[2] << endl;
    else {
      int x = lower_bound(b, b + size, a[i]) - b + 1;
      if (op[i] == "add") root->update(x, +1);
      if (op[i] == "del") root->update(x, -1);
    }
  }
  return 0;
}
