#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, fu = 0;
  char ch = getchar();
  for (; ch < 48 || ch > 57; ch = getchar()) fu |= (ch == '-');
  for (; ch > 47 && ch < 58; ch = getchar()) x = x * 10 + ch - '0';
  return fu ? -x : x;
}
struct seg_tree {
  long long sum[5];
  int siz;
} s[400005];
void update(int id) {
  s[id].siz = s[id << 1].siz + s[id << 1 | 1].siz;
  for (int i = 0; i < 5; i++)
    s[id].sum[i] =
        s[id << 1].sum[i] + s[id << 1 | 1].sum[(i - s[id << 1].siz + 5) % 5];
}
void modify(int id, int l, int r, int po, int val) {
  if (l == r) {
    s[id].sum[0] += val, s[id].siz ^= 1;
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= po)
    modify(id << 1, l, mid, po, val);
  else
    modify(id << 1 | 1, mid + 1, r, po, val);
  update(id);
}
int m, lsh[100005], lxs, op[100005];
int main() {
  m = read();
  char S[10];
  for (int i = 1; i <= m; i++) {
    scanf("%s", S);
    if (S[0] == 'd') op[i] = -read();
    if (S[0] == 'a') op[i] = read(), lsh[++lxs] = op[i];
  }
  sort(lsh + 1, lsh + 1 + lxs), lxs = unique(lsh + 1, lsh + 1 + lxs) - lsh - 1;
  for (int i = 1; i <= m; i++) {
    if (op[i] == 0)
      printf("%I64d\n", s[1].sum[2]);
    else if (op[i] > 0)
      modify(1, 1, lxs, lower_bound(lsh + 1, lsh + 1 + lxs, op[i]) - lsh,
             op[i]);
    else
      modify(1, 1, lxs, lower_bound(lsh + 1, lsh + 1 + lxs, -op[i]) - lsh,
             op[i]);
  }
  return 0;
}
