#include <bits/stdc++.h>
using namespace std;
int n;
struct query {
  string type;
  long long val;
} q[100005];
long long a[100005];
int cnt;
struct Tree {
  int cnt;
  long long sum[10];
} tree[400005];
int get(int x) {
  int left = 0;
  int right = cnt;
  while (left <= right) {
    int mid = (left + right) >> 1;
    if (a[mid] == x) {
      return mid;
    }
    if (a[mid] > x) {
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
}
void push_up(int node) {
  tree[node].cnt = tree[node * 2].cnt + tree[node * 2 + 1].cnt;
  for (int i = 0; i < 5; i++) {
    tree[node].sum[i] = tree[node * 2].sum[i];
  }
  for (int i = 0; i < 5; i++) {
    tree[node].sum[(i + tree[node * 2].cnt) % 5] += tree[node * 2 + 1].sum[i];
  }
}
void Add(int x, int l, int r, int node) {
  if (l == r) {
    tree[node].cnt = 1;
    memset(tree[node].sum, 0, sizeof(tree[node].sum));
    tree[node].sum[1] = a[x - 1];
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= x) {
    Add(x, l, mid, node * 2);
  } else {
    Add(x, mid + 1, r, node * 2 + 1);
  }
  push_up(node);
}
void Minu(int x, int l, int r, int node) {
  if (l == r) {
    tree[node].cnt = 0;
    memset(tree[node].sum, 0, sizeof(tree[node].sum));
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= x) {
    Minu(x, l, mid, node * 2);
  } else {
    Minu(x, mid + 1, r, node * 2 + 1);
  }
  push_up(node);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> q[i].type;
    if (q[i].type == "add" || q[i].type == "del") {
      cin >> q[i].val;
      a[cnt] = q[i].val;
      cnt++;
    }
  }
  cnt--;
  sort(a, a + cnt + 1);
  cnt = unique(a, a + cnt + 1) - a;
  for (int i = 1; i <= n; i++) {
    if (q[i].type == "add") {
      Add(get(q[i].val) + 1, 1, n, 1);
    } else if (q[i].type == "del") {
      Minu(get(q[i].val) + 1, 1, n, 1);
    } else {
      cout << tree[1].sum[3] << endl;
    }
  }
  return 0;
}
