#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, num[maxn << 2];
long long sum[maxn << 2][5];
void pushUp(int rt) {
  num[rt] = num[rt << 1] + num[rt << 1 | 1];
  for (int i = 0; i < 5; ++i) {
    sum[rt][i] =
        sum[rt << 1][i] + sum[rt << 1 | 1][((i - num[rt << 1]) % 5 + 5) % 5];
  }
}
void update(int p, int c, int l, int r, int rt) {
  if (l == r) {
    num[rt] ^= 1;
    if (num[rt])
      sum[rt][1] += c;
    else
      sum[rt][1] -= c;
    return;
  }
  int m = (l + r) >> 1;
  if (p <= m)
    update(p, c, l, m, rt << 1);
  else
    update(p, c, m + 1, r, rt << 1 | 1);
  pushUp(rt);
}
char op[maxn][4];
int oop[maxn], san[maxn], tot;
int main() {
  while (~scanf("%d", &n)) {
    tot = 0;
    for (int i = 0; i < n; ++i) {
      scanf("%s", op[i]);
      if (op[i][0] != 's') {
        scanf("%d", &oop[i]);
        san[tot++] = oop[i];
      }
    }
    sort(san, san + tot);
    tot = unique(san, san + tot) - san;
    memset(num, 0, sizeof(num));
    memset(sum, 0, sizeof(sum));
    int pos;
    for (int i = 0; i < n; ++i) {
      if (op[i][0] != 's') {
        pos = lower_bound(san, san + tot, oop[i]) - san + 1;
        update(pos, oop[i], 1, tot, 1);
      } else {
        printf("%I64d\n", sum[1][3]);
      }
    }
  }
  return 0;
}
