#include <bits/stdc++.h>
using namespace std;
long long sum[(1 << 20) * 2][5];
long long num[(1 << 20) * 2];
void order(long long pos) {
  do {
    pos /= 2;
    num[pos] = num[pos * 2] + num[pos * 2 + 1];
    long long tmp = num[pos * 2] % 5;
    for (long long i = 0; i < ((long long)5); i++)
      sum[pos][i] = sum[pos * 2][i] + sum[pos * 2 + 1][(i + 5 - tmp) % 5];
  } while (pos > 1);
}
int main() {
  for (long long i = 0; i < ((long long)(1 << 20) * 2); i++)
    for (long long j = 0; j < ((long long)5); j++) sum[i][j] = num[i] = 0;
  set<long long> s;
  vector<pair<long long, long long> > vec;
  long long n;
  cin >> n;
  for (long long i = 0; i < ((long long)n); i++) {
    string str;
    cin >> str;
    if (str == "sum") {
      vec.push_back(make_pair(2, 0));
    } else {
      long long tmp;
      cin >> tmp;
      s.insert(tmp);
      vec.push_back(make_pair((str == "del"), tmp));
    }
  }
  long long cnt = 0;
  map<long long, long long> con;
  for (set<long long>::iterator it = s.begin(); it != s.end(); it++)
    con[*it] = cnt++;
  for (long long i = 0; i < ((long long)n); i++) {
    long long pos = con[vec[i].second] + (1 << 20);
    if (vec[i].first == 0) {
      num[pos] = 1;
      sum[pos][1] = vec[i].second;
      order(pos);
    } else if (vec[i].first == 1) {
      num[pos] = sum[pos][1] = 0;
      order(pos);
    } else {
      cout << sum[1][3] << endl;
    }
  }
}
