#include <bits/stdc++.h>
using namespace std;
struct seg {
  seg *lc, *rc;
  long long sum[5];
  int fi, se, num;
  seg(int fi_, int se_) {
    fi = fi_;
    se = se_;
    sum[0] = sum[1] = sum[2] = sum[3] = sum[4] = num = 0;
    rc = lc = NULL;
  }
  inline void fix() {
    num = 0;
    if (lc != NULL) num = lc->num;
    if (rc != NULL) num += rc->num;
    for (int i = 0; i < 5; i++) {
      int pre = 0;
      if (lc != NULL) {
        sum[i] = lc->sum[i];
        pre = lc->num;
      }
      if (rc != NULL) sum[i] += rc->sum[(i + pre) % 5];
    }
  }
  inline void add(int x) {
    if (fi == se) {
      sum[0] = x;
      num = 1;
      sum[1] = sum[2] = sum[3] = sum[4] = 0;
      return;
    }
    int mid = (fi + se) / 2;
    if (x <= mid) {
      if (lc == NULL) lc = new seg(fi, mid);
      lc->add(x);
    } else {
      if (rc == NULL) rc = new seg(mid + 1, se);
      rc->add(x);
    }
    fix();
  }
  inline void del(int x) {
    if (fi == se) {
      num = 0;
      sum[0] = sum[1] = sum[2] = sum[3] = sum[4] = 0;
      return;
    }
    int mid = (fi + se) / 2;
    if (x <= mid)
      lc->del(x);
    else
      rc->del(x);
    fix();
  }
};
seg *mom = new seg(1, 1000000000);
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  while (n--) {
    string s;
    int x;
    cin >> s;
    if (s == "sum")
      cout << mom->sum[3] << "\n";
    else {
      cin >> x;
      if (s == "add")
        mom->add(x);
      else
        mom->del(x);
    }
  }
  return 0;
}
