#include <bits/stdc++.h>
using namespace std;
struct info {
  long long a[5];
  int len;
  info() {
    len = 0;
    memset(a, 0, sizeof a);
  }
  info(int x) {
    len = 1;
    memset(a, 0, sizeof a);
    a[2] = x;
  }
};
info operator+(const info &a, const info &b) {
  info ans;
  ans.len = a.len + b.len;
  for (int i = 0; i < 5; i++) {
    ans.a[i] = a.a[i] + b.a[(i + a.len) % 5];
  }
  return ans;
}
struct node {
  node *l, *r;
  int x, y;
  info my, all;
  node() {
    l = r = NULL;
    y = (rand() << 16) + rand();
    x = -1;
  };
  node(int x) : x(x) {
    l = r = NULL;
    y = (rand() << 16) + rand();
    all = my = info(x);
  }
};
typedef node *pnode;
void up(pnode root) {
  root->all = root->my;
  if (root->l) {
    root->all = root->l->all + root->all;
  }
  if (root->r) {
    root->all = root->all + root->r->all;
  }
}
pnode merge(pnode l, pnode r) {
  if (!l) return r;
  if (!r) return l;
  if (l->y > r->y) {
    l->r = merge(l->r, r);
    up(l);
    return l;
  } else {
    r->l = merge(l, r->l);
    up(r);
    return r;
  }
}
void split(pnode root, pnode &l, pnode &r, int x) {
  if (!root) {
    l = r = NULL;
    return;
  }
  if (root->x > x) {
    split(root->l, l, root->l, x);
    up(root);
    r = root;
  } else {
    split(root->r, root->r, r, x);
    up(root);
    l = root;
  }
}
void dfs(pnode root) {
  if (!root) return;
  dfs(root->l);
  cout << root->all.len << " ";
  dfs(root->r);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  pnode root = NULL;
  for (int i = 0; i < n; i++) {
    string t;
    cin >> t;
    if (t == "add") {
      int x;
      cin >> x;
      pnode l, r;
      split(root, l, r, x);
      root = merge(merge(l, new node(x)), r);
    }
    if (t == "del") {
      int x;
      cin >> x;
      pnode first, second, th;
      split(root, first, th, x);
      split(first, first, second, x - 1);
      root = merge(first, th);
    }
    if (t == "sum") {
      if (root)
        cout << root->all.a[0] << "\n";
      else
        cout << 0 << '\n';
    }
  }
  return 0;
}
