#include <bits/stdc++.h>
using namespace std;
long long n, tot, t[400010][5], a[400010], num[400010], kind[400010],
    cnt[400010];
char s[5];
map<long long, long long> m;
long long read() {
  long long s = 0, f = 0;
  char c = getchar();
  while (!(c >= '0' && c <= '9')) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while ((c >= '0' && c <= '9')) {
    s = (s << 3) + (s << 1) + (c ^ 48);
    c = getchar();
  }
  return f ? -s : s;
}
void pushup(int x) {
  cnt[x] = cnt[(x << 1)] + cnt[(x << 1 | 1)];
  for (int i = 0; i <= 4; i++)
    t[x][i] = t[(x << 1)][i] + t[(x << 1 | 1)][(i - cnt[(x << 1)] + 5) % 5];
  return;
}
void modify(int l, int r, int x, int id, long long p, int sum) {
  if (l == r) {
    t[x][1] += p;
    cnt[x] += sum;
  } else {
    int mid = (l + r) >> 1;
    if (id <= mid)
      modify(l, mid, (x << 1), id, p, sum);
    else
      modify(mid + 1, r, (x << 1 | 1), id, p, sum);
    pushup(x);
  }
  return;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    if (s[0] == 'a') {
      long long x = read();
      a[++tot] = x;
      num[i] = x;
      kind[i] = 1;
    } else if (s[0] == 'd') {
      long long x = read();
      num[i] = x;
      kind[i] = -1;
    }
  }
  sort(a + 1, a + tot + 1);
  long long sum = 0;
  for (int i = 1; i <= tot; i++)
    if (m[a[i]] == 0) m[a[i]] = ++sum;
  for (int i = 1; i <= n; i++) {
    if (kind[i] == 0)
      printf("%lld\n", t[1][3]);
    else
      modify(1, n, 1, m[num[i]], num[i] * kind[i], kind[i]);
  }
  return 0;
}
