#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 9;
int n, sq, cnt[320];
bool freq[MAX];
long long sum[320][5], temp[5];
vector<pair<int, int> > q;
vector<int> v;
map<int, int> decode;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    if (s[0] == 's') {
      q.push_back({2, -1});
    } else {
      int x;
      cin >> x;
      int type = (s[0] == 'a' ? 0 : 1);
      q.push_back({type, x});
      v.push_back(x);
    }
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  for (int i = 0; i < v.size(); ++i) {
    decode[i] = v[i];
  }
  sq = (int)sqrt(n + .0) + 1;
  int lst = v.size() / sq;
  for (int i = 0; i < n; ++i) {
    int type = q[i].first;
    if (type == 2) {
      long long ans = 0;
      for (int j = 0; j <= lst; ++j) {
        ans += sum[j][2];
      }
      cout << ans << "\n";
    } else if (type == 0) {
      int cntPrv = 0, x = q[i].second,
          pos = lower_bound(v.begin(), v.end(), x) - v.begin(),
          bucket = pos / sq;
      for (int j = 0; j < bucket; ++j) {
        cntPrv += cnt[j];
      }
      for (int j = 0; j < 5; ++j) {
        sum[bucket][j] = 0;
      }
      ++cnt[bucket];
      freq[pos] = 1;
      int index = cntPrv % 5;
      for (int j = bucket * sq, en = (bucket + 1) * sq - 1; j <= en; ++j) {
        if (freq[j]) {
          sum[bucket][index] += v[j];
          ++index;
          index %= 5;
        }
      }
      for (int j = bucket + 1; j <= lst; ++j) {
        for (int k = 0; k < 5; ++k) {
          temp[k] = sum[j][k];
        }
        for (int k = 0; k < 5; ++k) {
          sum[j][k] = temp[(k - 1 + 5) % 5];
        }
      }
    } else {
      int cntPrv = 0, x = q[i].second,
          pos = lower_bound(v.begin(), v.end(), x) - v.begin(),
          bucket = pos / sq;
      for (int j = 0; j < bucket; ++j) {
        cntPrv += cnt[j];
      }
      for (int j = 0; j < 5; ++j) {
        sum[bucket][j] = 0;
      }
      --cnt[bucket];
      freq[pos] = 0;
      int index = cntPrv % 5;
      for (int j = bucket * sq, en = (bucket + 1) * sq - 1; j <= en; ++j) {
        if (freq[j]) {
          sum[bucket][index] += v[j];
          ++index;
          index %= 5;
        }
      }
      for (int j = bucket + 1; j <= lst; ++j) {
        for (int k = 0; k < 5; ++k) {
          temp[k] = sum[j][k];
        }
        for (int k = 0; k < 5; ++k) {
          sum[j][k] = temp[(k + 1) % 5];
        }
      }
    }
  }
  return 0;
}
