#include <bits/stdc++.h>
using namespace std;
struct luv {
  luv *l = NULL, *r = NULL;
  int rr = 0;
  long long sn[5] = {0, 0, 0, 0, 0};
  void pp() {
    if (l == NULL) l = new luv;
    if (r == NULL) r = new luv;
    for (int i = 0; i < 5; ++i)
      sn[(i + l->rr) % 5] = l->sn[(i + l->rr) % 5] + r->sn[i];
    rr = l->rr + r->rr;
  }
} * rt;
int gsi, gvl;
void gnkk(int l, int r, luv *&t) {
  if (t == NULL) t = new luv;
  if (l == r) {
    t->sn[1] = gvl;
    t->rr = (gvl ? 1 : 0);
    return;
  }
  if ((l + r) / 2 >= gsi)
    gnkk(l, (l + r) / 2, t->l);
  else
    gnkk((l + r) / 2 + 1, r, t->r);
  t->pp();
}
long long ap() { return (rt == NULL ? 0ll : rt->sn[3]); }
void gnk(int, int);
const int X = 1e9;
string s;
int n, x;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> s;
    if (s == "sum") {
      printf("%I64d\n", ap());
    } else {
      cin >> x;
      if (s == "add") {
        gnk(x, x);
      } else {
        gnk(x, 0);
      }
    }
  }
  cout << endl;
  return 0;
}
void gnk(int si, int vl) {
  gsi = si;
  gvl = vl;
  gnkk(1, X, rt);
}
