#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long n, sum[500][5], sz[500], t = 500, st[500], ed[500], a[100010], mx;
vector<pair<long long, long long> > que;
vector<long long> v;
int main() {
  cin >> n;
  string s;
  long long x;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s[0] != 's') {
      scanf("%I64d", &x);
      if (s[0] == 'a')
        v.push_back(x), que.push_back(make_pair(0, x));
      else
        que.push_back(make_pair(1, x));
    } else
      que.push_back(make_pair(2, 0));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < 495; i++) st[i] = -1;
  for (int i = 0; i < v.size(); i++) {
    if (st[i / t] == -1) st[i / t] = i;
    ed[i / t] = i;
  }
  mx = ((int)v.size() - 1) / t;
  for (int i = 0; i < n; i++) {
    if (que[i].first == 0) {
      long long pos =
                    lower_bound(v.begin(), v.end(), que[i].second) - v.begin(),
                num = pos / t, cur = 0;
      a[pos] = que[i].second;
      sz[num]++;
      for (int j = 0; j < 5; j++) sum[num][j] = 0;
      for (int j = st[num]; j <= ed[num]; j++) {
        if (a[j] > 0) {
          sum[num][cur] += a[j];
          cur = (cur + 1) % 5;
        }
      }
    } else if (que[i].first == 1) {
      long long pos =
                    lower_bound(v.begin(), v.end(), que[i].second) - v.begin(),
                num = pos / t, cur = 0;
      a[pos] = 0;
      sz[num]--;
      for (int j = 0; j < 5; j++) sum[num][j] = 0;
      for (int j = st[num]; j <= ed[num]; j++) {
        if (a[j] > 0) {
          sum[num][cur] += a[j];
          cur = (cur + 1) % 5;
        }
      }
    } else {
      long long cur = 0, ans = 0;
      for (int i = 0; i < mx + 1; i++) {
        ans += sum[i][(2 - cur % 5 + 5) % 5];
        cur += sz[i];
      }
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
