#include <bits/stdc++.h>
using namespace std;
char Str[100005][5];
struct node {
  int cnt;
  long long sum[5];
} Tree[100005 * 4];
int key[100005];
int Rec[100005];
void build(int r, int ll, int rr) {
  Tree[r].cnt = 0;
  memset(Tree[r].sum, 0, sizeof(Tree[r].sum));
  if (ll == rr) {
    return;
  }
  int mid = (ll + rr) >> 1;
  build(r << 1, ll, mid);
  build(r << 1 | 1, mid + 1, rr);
}
void update(int r, int ll, int rr, int pos, int f) {
  if (ll == rr) {
    if (f == -1) {
      Tree[r].cnt = 0;
      Tree[r].sum[1] = 0;
    } else {
      Tree[r].cnt = 1;
      Tree[r].sum[1] = key[pos - 1];
    }
    return;
  }
  int mid = (ll + rr) >> 1;
  if (pos <= mid)
    update(r << 1, ll, mid, pos, f);
  else
    update(r << 1 | 1, mid + 1, rr, pos, f);
  int offset = Tree[r << 1].cnt;
  for (int i = 0; i < 5; ++i) {
    Tree[r].sum[i] =
        Tree[r << 1].sum[i] + Tree[r << 1 | 1].sum[((i - offset) % 5 + 5) % 5];
  }
  Tree[r].cnt = Tree[r << 1].cnt + Tree[r << 1 | 1].cnt;
}
int main() {
  int n;
  scanf("%d", &n);
  int tot = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%s", Str[i]);
    if (Str[i][0] != 's') {
      int x;
      scanf("%d", &x);
      key[tot++] = x;
      Rec[i] = x;
    }
  }
  sort(key, key + tot);
  tot = unique(key, key + tot) - key;
  if (tot) build(1, 1, tot);
  for (int i = 0; i < n; ++i) {
    if (Str[i][0] == 's') {
      printf("%I64d\n", Tree[1].sum[3]);
    } else {
      int pos = lower_bound(key, key + tot, Rec[i]) - key;
      pos++;
      if (Str[i][0] == 'a') {
        update(1, 1, tot, pos, 1);
      } else {
        update(1, 1, tot, pos, -1);
      }
    }
  }
  return 0;
}
