#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 17;
int T;
int n;
string s;
vector<pair<int, int>> query;
map<int, int> mp;
int a[N];
int cnt[N << 1];
long long sum[N << 1][5];
int pm[100005];
void pushup(int root) {
  int l = 2 * root;
  int r = 2 * root + 1;
  cnt[root] = cnt[l] + cnt[r];
  for (int i = 0; i < 5; i++) {
    sum[root][i] = sum[l][i] + sum[r][(i - cnt[l] % 5 + 5) % 5];
  }
}
int main() {
  int tmp;
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s[0] == 's') {
      query.push_back(make_pair(2, 0));
    } else {
      scanf("%d\n", &tmp);
      if (s[0] == 'a')
        query.push_back(make_pair(0, tmp));
      else
        query.push_back(make_pair(1, tmp));
      mp[tmp] = 0;
    }
  }
  for (__typeof((mp).begin()) itr = ((mp).begin()); itr != (mp).end(); itr++) {
    (itr->second) = T;
    pm[T] = (itr->first);
    T++;
  }
  for (int i = 0; i < n; i++) {
    int type = query[i].first, x = query[i].second;
    if (type == 2) {
      printf("%I64d\n", sum[1][2]);
    } else {
      int id = N + mp[x];
      cnt[id] = 1 - type;
      sum[id][0] = (1 - type) * x;
      for (int j = id / 2; j >= 1; j /= 2) pushup(j);
    }
  }
  return 0;
}
