#include <bits/stdc++.h>
using namespace std;
inline void sc(int &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c<48 | c> 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
const int N = 200005;
struct dta {
  int op;
  int val;
};
dta d[N];
char cc[6];
vector<int> v;
int a[N];
int sqN[320][6];
int size[320];
int block;
void updt(int pos, int val) {
  if (val)
    a[pos] = 1;
  else
    a[pos] = 0;
  int id = pos / block;
  int cnt = 0;
  memset(sqN[id], 0, sizeof(sqN[id]));
  for (int i = (pos / block) * block, j = 0; j < block; j++, i++) {
    if (a[i]) {
      sqN[id][cnt % 5] += v[i];
      cnt++;
    }
  }
  size[id] = cnt;
}
long long Query(int sz) {
  long long sum = 0;
  int cnt = 0;
  for (int i = 0; i * block <= sz; i++) {
    sum += sqN[i][(2 - cnt + 5) % 5];
    cnt = (cnt + size[i]) % 5;
  }
  return sum;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", cc);
    if (cc[0] == 'a') {
      int a;
      scanf("%d", &a);
      d[i] = {1, a};
      v.push_back((a));
    } else if (cc[0] == 'd') {
      int a;
      scanf("%d", &a);
      d[i] = {2, a};
      v.push_back((a));
    } else
      d[i] = {3, 0};
  }
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  block = sqrt(v.size()) + 1;
  long long np = v.size() - 1;
  for (int i = 0; i < n; i++) {
    int op = d[i].op;
    int val = d[i].val;
    if (op == 3) {
      printf("%lld\n", Query(np - 1));
    } else if (op == 1) {
      long long pos = lower_bound(v.begin(), v.end(), val) - v.begin();
      updt(pos, 1);
    } else {
      long long pos = lower_bound(v.begin(), v.end(), val) - v.begin();
      updt(pos, 0);
    }
  }
}
