#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long n, q[100005], p[100005];
vector<long long> v;
const long long N = 1 << 17;
long long sum[N << 1][5], cnt[N << 1];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  long long x;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> s;
    if (s == "sum") {
      p[i] = 2;
    } else if (s == "add") {
      cin >> x;
      p[i] = 0;
      q[i] = x;
      v.emplace_back(x);
    } else {
      cin >> x;
      p[i] = 1;
      q[i] = x;
      v.emplace_back(x);
    }
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  for (long long i = 1; i <= n; i++) {
    if (p[i] != 2) q[i] = lower_bound(v.begin(), v.end(), q[i]) - v.begin();
  }
  for (long long i = 1; i <= n; i++) {
    if (p[i] == 2) {
      cout << sum[1][2] << '\n';
    } else {
      cnt[N + q[i]] = 1 ^ p[i];
      sum[N + q[i]][0] = v[q[i]] * (1 ^ p[i]);
      for (long long j = (N + q[i]) >> 1; j; j >>= 1) {
        cnt[j] = cnt[(j << 1) ^ 1] + cnt[j << 1];
        for (long long k = 0; k < 5; k++)
          sum[j][k] = sum[(j << 1) ^ 1][((k - cnt[j << 1]) % 5 + 5) % 5] +
                      sum[j << 1][k];
      }
    }
  }
  return 0;
}
