#include <bits/stdc++.h>
using namespace std;
const int maxn = 320 * 320;
int n, sz[maxn], a[maxn];
long long int sum[320][5];
struct as {
  char s[5];
  int x;
} ask[maxn];
map<int, int> p;
int main() {
  while (scanf("%d", &n) == 1 && n) {
    int block = 0, k = 0, i;
    while (block * block < n) block++;
    p.clear();
    for (i = 0; i < n; ++i) {
      scanf("%s", ask[i].s);
      if (ask[i].s[0] != 's') scanf("%d", &ask[i].x), a[k++] = ask[i].x;
    }
    sort(a, a + k);
    k = unique(a, a + k) - a;
    for (i = 0; i < k; ++i) p[a[i]] = i;
    memset(a, 0, sizeof(a));
    memset(sz, 0, sizeof(sz));
    memset(sum, 0, sizeof(sum));
    for (i = 0; i < n; ++i) {
      if (ask[i].s[0] != 's') {
        int pos = p[ask[i].x], rt = pos / block, l = rt * block, r = l + block,
            k = 0;
        a[pos] = ask[i].s[0] == 'a' ? ask[i].x : 0;
        memset(sum[rt], 0, sizeof(sum[rt]));
        for (; l < r; ++l)
          if (a[l]) sum[rt][k++ % 5] += a[l];
        sz[rt] = k;
      } else {
        long long int ans = 0;
        k = 2;
        for (int i = 0; i < block; ++i)
          ans += sum[i][k], k = (k - sz[i] + 50000) % 5;
        printf("%I64d\n", ans);
      }
    }
  }
  return 0;
}
