#include <bits/stdc++.h>
using namespace std;
const int N = 8 * 102400;
int LEFT(int id) { return 2 * id + 1; }
int RIGHT(int id) { return 2 * id + 2; }
int cnt[N];
long long sum[N][5];
void build(int id, int x, int y) {
  for (int i = 0; i < 5; i++) sum[id][i] = 0;
  if (y - x == 1) return;
  int mid = (x + y) >> 1;
  build(LEFT(id), x, mid);
  build(RIGHT(id), mid, y);
}
void update(int id, int x, int y) {
  if (y - x == 1) return;
  int left = LEFT(id), right = RIGHT(id);
  cnt[id] = cnt[left] + cnt[right];
  int cc = cnt[left] % 5;
  for (int i = 0; i < 5; i++) {
    sum[id][i] = sum[left][i] + sum[right][(i - cc + 5) % 5];
  }
}
void insert(int id, int x, int y, int px, int pv) {
  if (y - x == 1) {
    cnt[id]++;
    sum[id][0] += pv;
    return;
  }
  int mid = (y + x) >> 1;
  if (px < mid)
    insert(LEFT(id), x, mid, px, pv);
  else
    insert(RIGHT(id), mid, y, px, pv);
  update(id, x, y);
}
void remove(int id, int x, int y, int px, int pv) {
  if (y - x == 1) {
    cnt[id]--;
    sum[id][0] -= pv;
    return;
  }
  int mid = (y + x) >> 1;
  if (px < mid)
    remove(LEFT(id), x, mid, px, pv);
  else
    remove(RIGHT(id), mid, y, px, pv);
  update(id, x, y);
}
int tp[N], num[N];
int x[N], xn;
int main() {
  int n;
  scanf("%d", &n);
  xn = 0;
  for (int i = 0; i < n; i++) {
    char str[5];
    scanf("%s", str);
    if (str[0] == 'a') {
      tp[i] = 0;
      scanf("%d", num + i);
      x[xn++] = num[i];
    } else if (str[0] == 'd') {
      tp[i] = 1;
      scanf("%d", num + i);
      x[xn++] = num[i];
    } else {
      tp[i] = 2;
    }
  }
  if (xn == 0) {
    for (int i = 0; i < n; i++) printf("0\n");
    return 0;
  }
  sort(x, x + xn);
  xn = unique(x, x + xn) - x;
  build(0, 0, xn);
  for (int i = 0; i < n; i++) {
    if (tp[i] == 0) {
      int id = lower_bound(x, x + xn, num[i]) - x;
      insert(0, 0, xn, id, num[i]);
    } else if (tp[i] == 1) {
      int id = lower_bound(x, x + xn, num[i]) - x;
      remove(0, 0, xn, id, num[i]);
    } else {
      printf("%I64d\n", sum[0][2]);
    }
  }
  return 0;
}
