#include <bits/stdc++.h>
using namespace std;
int n, pos[100005], pio[5005], p[100005], len, _n;
long long Sum[5005][5], b[100005], Tot[5005], All[100005];
struct Node {
  int opt;
  long long num;
} a[100005];
void Add(long long A) {
  int t = lower_bound(b + 1, b + 1 + _n, A) - b;
  int w = pos[t];
  Tot[w]++;
  All[t] = A;
  memset(Sum[w], 0, sizeof(Sum[w]));
  if (pio[w] == -1 || t < pio[w]) p[t] = pio[w], pio[w] = t;
  register int cnt = 3;
  for (register int i = pio[w];;) {
    if (i == -1) return;
    cnt = cnt == 0 ? 4 : cnt - 1;
    Sum[w][cnt] += All[i];
    if (i < t && (p[i] == -1 || t < p[i])) p[t] = p[i], p[i] = t;
    i = p[i];
  }
  return;
}
void Del(long long A) {
  int t = lower_bound(b + 1, b + 1 + _n, A) - b;
  int w = pos[t];
  Tot[w]--;
  All[t] = 0;
  memset(Sum[w], 0, sizeof(Sum[w]));
  if (t == pio[w]) p[t] = -1, pio[w] = p[t];
  register int cnt = 3;
  for (register int i = pio[w];;) {
    if (i == -1) return;
    cnt = cnt == 0 ? 4 : cnt - 1;
    Sum[w][cnt] += All[i];
    if (i < t && (p[i] == -1 || t < p[i])) p[t] = p[i], p[i] = t;
    i = p[i];
  }
}
long long Ask() {
  int cnt = 0;
  long long Ans = 0;
  for (register int i = 1; i <= pos[_n]; i++)
    Ans += Sum[i][cnt], cnt = (cnt + Tot[i]) % 5;
  return Ans;
}
signed main() {
  string S;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(p, -1, sizeof(p));
  memset(pio, -1, sizeof(pio));
  cin >> n;
  for (register int i = 1; i <= n; i++) {
    cin >> S;
    if (S[0] == 's') a[i].opt = 3;
    if (S[0] == 'a') a[i].opt = 1, cin >> a[i].num, b[++len] = a[i].num;
    if (S[0] == 'd') a[i].opt = 2, cin >> a[i].num;
  }
  sort(b + 1, b + 1 + len);
  _n = unique(b + 1, b + 1 + len) - b - 1;
  register int block = sqrt(_n);
  for (register int i = 1; i <= _n; i++) pos[i] = (i - 1) / block + 1;
  for (register int i = 1; i <= n; i++) {
    if (a[i].opt == 3) cout << Ask() << endl;
    if (a[i].opt == 1) Add(a[i].num);
    if (a[i].opt == 2) Del(a[i].num);
  }
  return 0;
}
