#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, mod = 1000000007;
const double pi = 3.1415926535897932, eps = 1e-6;
void chmax(int &x, int y) {
  if (x < y) x = y;
}
void chmin(int &x, int y) {
  if (x > y) x = y;
}
int n, cnt[262200], ccnt;
long long sum[262200][5];
void upd(int x) {
  cnt[x] = cnt[(x << 1)] + cnt[(x << 1) + 1];
  for (int(i) = (0); (i) <= (4); (i)++)
    sum[x][i] =
        sum[(x << 1)][i] + sum[(x << 1) + 1][(i - cnt[x << 1] % 5 + 5) % 5];
}
vector<pair<int, int> > que;
map<int, int> m;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int(i) = (1); (i) <= (n); (i)++) {
    string s;
    int g = 0;
    cin >> s;
    if (s[0] != 's') {
      cin >> g;
      m[g] = 0;
    }
    if (s[0] == 's')
      que.push_back(make_pair(2, 0));
    else
      que.push_back(make_pair(s[0] == 'a' ? 1 : 0, g));
  }
  for (map<int, int>::iterator it = m.begin(); it != m.end(); it++)
    it->second = ++ccnt;
  for (int(i) = (0); (i) < (n); (i)++) {
    if (que[i].first == 2) {
      cout << sum[1][2] << endl;
    } else {
      int id = m[que[i].second], t = que[i].first;
      id += 1 << 17;
      cnt[id] = t;
      sum[id][0] = t * que[i].second;
      while (id != 1) {
        id >>= 1;
        upd(id);
      }
    }
  }
  return 0;
}
