#include <bits/stdc++.h>
using namespace std;
int n, x[100005], y[100005], c[100005 * 4], p, q, m;
long long t[100005 * 4][5];
char o[100005][4];
void upd(int d, int l, int r) {
  c[d] += m * 2 - 1;
  if (l == r) {
    t[d][0] = m * y[q];
    return;
  }
  if ((l + r >> 1) < q)
    upd(((d << 1) | 1), (l + r >> 1) + 1, r);
  else
    upd((d << 1), l, (l + r >> 1));
  for (int i = (0); i < (5); i++)
    t[d][i] = t[(d << 1)][i] + t[((d << 1) | 1)][(i - c[(d << 1)] % 5 + 5) % 5];
}
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); i++) {
    scanf("%s", o[i]);
    if (o[i][0] == 'a' || o[i][0] == 'd') scanf("%d", &x[i]), y[p++] = x[i];
  }
  sort(y, y + p);
  p = unique(y, y + p) - y;
  for (int i = (0); i < (n); i++) {
    q = lower_bound(y, y + p, x[i]) - y;
    if (o[i][0] == 'a')
      m = 1, upd(1, 1, p);
    else if (o[i][0] == 'd')
      m = 0, upd(1, 1, p);
    else
      printf("%I64d\n", t[1][2]);
  }
}
