#include <bits/stdc++.h>
using namespace std;
int q, n;
int type[100100];
long long num[100100];
string s;
vector<long long> v;
long long sum[400100][5];
int cnt[400100];
int nu;
void merge(int a, int b, int c) {
  cnt[a] = cnt[b] + cnt[c];
  for (int i = 0; i < 5; i++) sum[a][i] = sum[b][i];
  int g = cnt[b] % 5;
  for (int i = 0; i < 5; i++) sum[a][(i + g) % 5] += sum[c][i];
}
void add(int id) {
  id += nu;
  cnt[id] = 1;
  sum[id][0] = v[id - nu];
  for (; id >>= 1;) merge(id, (id << 1) | 0, (id << 1) | 1);
}
void del(int id) {
  id += nu;
  cnt[id] = 0;
  sum[id][0] = 0;
  for (; id >>= 1;) merge(id, (id << 1) | 0, (id << 1) | 1);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> s;
    if (s == "add")
      type[i] = 0, cin >> num[i], v.push_back(num[i]);
    else if (s == "del")
      type[i] = 1, cin >> num[i];
    else
      type[i] = 2;
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  n = v.size();
  nu = 1;
  while (nu < n + 5) nu *= 2;
  for (int i = 0; i < q; i++)
    if (num[i]) num[i] = lower_bound(v.begin(), v.end(), num[i]) - v.begin();
  for (int i = 0; i < q; i++) {
    if (type[i] == 0)
      add(num[i]);
    else if (type[i] == 1)
      del(num[i]);
    else
      cout << sum[1][2] << endl;
  }
  return 0;
}
