#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 15;
int type[N], x[N];
long long tree[N * 4][5];
int lazy[N * 4];
int cc[N];
void pupdate(int ind, int add) {
  while (ind < N) cc[ind] += add, ind += ind & (-ind);
}
int pquery(int ind) {
  int ret = 0;
  while (ind) ret += cc[ind], ind = ind & (ind - 1);
  return ret;
}
void push(int pos, int l, int r) {
  lazy[pos] %= 5;
  if (lazy[pos] != 0) {
    long long temp[5];
    for (int i = 0; i < 5; ++i) {
      int nind = (i + lazy[pos] + 5) % 5;
      temp[nind] = tree[pos][i];
    }
    for (int i = 0; i < 5; ++i) tree[pos][i] = temp[i];
    if (l != r) {
      lazy[pos * 2] += lazy[pos], lazy[pos * 2 + 1] += lazy[pos];
    }
    lazy[pos] = 0;
  }
}
void update(int pos, int l, int r, int ql, int qr, int d) {
  push(pos, l, r);
  if (r < ql || qr < l) return;
  if (ql <= l && r <= qr) {
    lazy[pos] = d;
    push(pos, l, r);
    return;
  }
  int mid = (l + r) / 2;
  update(pos * 2, l, mid, ql, qr, d);
  update(pos * 2 + 1, mid + 1, r, ql, qr, d);
  for (int i = 0; i < 5; ++i)
    tree[pos][i] = tree[pos * 2][i] + tree[pos * 2 + 1][i];
}
void add(int pos, int l, int r, int ind, int b, int val) {
  push(pos, l, r);
  if (l == r) {
    tree[pos][b] += val;
    return;
  }
  int mid = (l + r) / 2;
  if (ind <= mid) {
    add(pos * 2, l, mid, ind, b, val);
  } else {
    add(pos * 2 + 1, mid + 1, r, ind, b, val);
  }
  for (int i = 0; i < 5; ++i)
    tree[pos][i] = tree[pos * 2 + 1][i] + tree[pos * 2][i];
}
int main() {
  char s[50];
  int n;
  cin >> n;
  map<int, int> Hash;
  int pos = 1;
  for (int i = 0; i < n; ++i) {
    scanf("%s", s);
    if (s[0] == 'a') {
      type[i] = 0;
      scanf("%d", &x[i]);
      Hash[x[i]];
    } else if (s[0] == 'd') {
      type[i] = 1;
      scanf("%d", &x[i]);
      Hash[x[i]];
    } else {
      type[i] = 2;
    }
  }
  for (auto it = Hash.begin(); it != Hash.end(); ++it) {
    it->second = pos++;
  }
  for (int i = 0; i < n; ++i) {
    if (type[i] == 0) {
      int ind = Hash[x[i]];
      pupdate(ind, 1);
      int num = pquery(ind);
      add(1, 1, n, ind, num % 5, x[i]);
      if (ind + 1 <= n) update(1, 1, n, ind + 1, n, 1);
    } else if (type[i] == 1) {
      int ind = Hash[x[i]];
      int num = pquery(ind);
      add(1, 1, n, ind, num % 5, -x[i]);
      if (ind + 1 <= n) update(1, 1, n, ind + 1, n, -1);
      pupdate(ind, -1);
    } else {
      printf("%lld\n", tree[1][3]);
    }
  }
  return 0;
}
