#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
struct node {
  int num;
  long long sum[5];
  node operator+(const node &a) {
    node c;
    c.num = num + a.num;
    for (int i = 0; i < 5; i++) {
      c.sum[i] = sum[i] + a.sum[((i - num) % 5 + 5) % 5];
    }
    return c;
  }
} tree[maxn * 4];
char op[maxn][5];
long long a[maxn], data[maxn];
void build(int root, int l, int r) {
  memset(tree[root].sum, 0, sizeof(tree[root].sum));
  tree[root].num = 0;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(root << 1, l, mid);
  build(root << 1 | 1, mid + 1, r);
}
void updata(int root, int l, int r, int p, long long v, int flag) {
  if (l == r) {
    tree[root].num += flag;
    tree[root].sum[0] = v;
    return;
  }
  int mid = (l + r) / 2;
  if (p <= mid) {
    updata(root << 1, l, mid, p, v, flag);
  } else
    updata(root << 1 | 1, mid + 1, r, p, v, flag);
  tree[root] = tree[root << 1] + tree[root << 1 | 1];
}
int main() {
  int n, cnt = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", op[i]);
    if (strcmp(op[i], "sum")) {
      scanf("%lld", &a[i]);
      data[cnt++] = a[i];
    }
  }
  if (cnt == 0) {
    for (int i = 0; i < n; i++) {
      if (op[i][0] == 's') printf("0\n");
    }
    return 0;
  }
  sort(data, data + cnt);
  cnt = unique(data, data + cnt) - data;
  build(1, 1, cnt);
  for (int i = 0; i < n; i++) {
    if (!strcmp(op[i], "sum")) {
      printf("%lld\n", tree[1].sum[2]);
      continue;
    }
    int pos = lower_bound(data, data + cnt, a[i]) - data;
    if (!strcmp(op[i], "add")) {
      updata(1, 1, cnt, pos, a[i], 1);
    } else {
      updata(1, 1, cnt, pos, 0, -1);
    }
  }
}
