#include <bits/stdc++.h>
using namespace std;
template <class T>
T s2t(string s) {
  istringstream i(s);
  T x;
  i >> x;
  return x;
}
template <class T>
string t2s(T x) {
  ostringstream o;
  o << x;
  return o.str();
}
vector<string> split(string s, string del = " ") {
  vector<string> res;
  int ss = s.size(), sdel = del.size();
  for (int p = 0, q; p < ss; p = q + sdel) {
    if ((q = s.find(del, p)) == (signed)string::npos) q = ss;
    if (q - p > 0) res.push_back(s.substr(p, q - p));
  }
  return res;
}
int ile[1 << 18];
long long sum[1 << 18][5];
int N;
int E;
char op[100001];
pair<int, int> val[100001];
int num[100001];
int unq[100001];
void insert(int pos, int mn) {
  int cur = (1 << 17) + pos;
  ile[cur] += mn;
  sum[cur][0] += mn * unq[pos];
  while (cur > 1) {
    cur >>= 1;
    ile[cur] = ile[2 * cur] + ile[2 * cur + 1];
    for (int a = 0; a < (signed)(5); ++a) {
      sum[cur][a] =
          sum[2 * cur][a] + sum[2 * cur + 1][(a + 5 - ile[2 * cur] % 5) % 5];
    }
  }
}
int main(int argc, char *argv[]) {
  cerr.precision(15);
  cout.precision(15);
  char buf[5];
  E = 0;
  scanf("%d", &N);
  for (int a = 0; a < (signed)(N); ++a) {
    scanf("%s", buf);
    op[a] = buf[0];
    if (buf[0] == 's') continue;
    scanf("%d", &val[E].first);
    val[E].second = a;
    E++;
  }
  sort(val, val + E);
  int xx = 0;
  for (int a = 0; a < (signed)(E); ++a) {
    if (!xx || val[a].first != unq[xx - 1]) {
      unq[xx] = val[a].first;
    }
    num[val[a].second] = xx++;
  }
  for (int a = 0; a < (signed)(N); ++a) {
    if (op[a] == 's') {
      cout << sum[1][2] << '\n';
    } else {
      insert(num[a], (op[a] == 'a') ? 1 : -1);
    }
  }
  return 0;
}
