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