#include <bits/stdc++.h>
using namespace std;
long long d[300015], q, n, x[100005], y[100005], u[100005], a[300005],
    p[6][300005], w[300005];
map<long long, long long> m;
int main() {
  for (long long i = 1; i <= 300003; i += 5)
    d[i] = 1, d[i + 1] = 2, d[i + 2] = 3, d[i + 3] = 4, d[i + 5] = 5;
  scanf("%I64d", &q);
  for (long long i = 1; i <= q; i++) {
    char c[10];
    scanf("%s", c);
    if (c[0] == 's') continue;
    x[i] = (c[0] == 'a' ? 1 : 2);
    scanf("%I64d", y + i), u[i] = y[i];
  }
  sort(u + 1, u + q + 1);
  for (long long i = 1; i <= q; i++)
    if (u[i] != u[i - 1] && u[i]) m[u[i]] = ++n, a[n + 131071] = u[i];
  for (long long i = 1; i <= q; i++) {
    if (x[i]) {
      long long t = m[y[i]] + 131071;
      w[t] ^= 1;
      p[1][t] = (x[i] & 1) ? y[i] : 0;
      for (long long j = t >> 1; j >= 1; j >>= 1) {
        long long l = j << 1, r = l ^ 1;
        w[j] = w[l] + w[r];
        for (long long z = 1; z <= 5; z++)
          p[z][j] = p[z][l] + p[d[z + 10 - d[w[l]]]][r];
      }
    } else
      printf("%I64d\n", p[3][1]);
  }
  return 0;
}
