#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 20, SQ = 330;
int n, query[N], sz[SQ], type[N];
long long sum[SQ][5];
bool mark[N];
vector<int> vec;
void compress() {
  for (int i = 0; i < n; i++)
    if (query[i]) vec.push_back(query[i]);
  sort(vec.begin(), vec.end());
  vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
  for (int i = 0; i < n; i++)
    query[i] =
        (query[i] ? lower_bound(vec.begin(), vec.end(), query[i]) - vec.begin()
                  : -1);
}
void update(int idx) {
  mark[idx] = !mark[idx];
  for (int i = 0; i < 5; i++) sum[idx / SQ][i] = 0;
  sz[idx / SQ] = 0;
  for (int i = idx - idx % SQ; i < min(idx - idx % SQ + SQ, N); i++)
    if (mark[i]) {
      sz[idx / SQ]++;
      sum[idx / SQ][(sz[idx / SQ]) % 5] += vec[i];
    }
}
long long get() {
  int _sz = 0;
  long long res = 0;
  for (int i = 0; i < SQ; i++) {
    res += sum[i][(3 - _sz % 5 + 5) % 5];
    _sz += sz[i];
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s != "sum") cin >> query[i];
    type[i] = (s == "sum" ? 2 : (s == "add" ? 1 : 0));
  }
  compress();
  for (int i = 0; i < n; i++) {
    if (type[i] == 2)
      cout << get() << "\n";
    else {
      if (mark[query[i]] != type[i]) update(query[i]);
    }
  }
  return 0;
}
