#include <bits/stdc++.h>
using namespace std;
string i_s(int x) {
  if (x == 0) return "0";
  string ret = "";
  while (x) {
    ret = ret + (char)(x % 10 + '0');
    x /= 10;
  }
  reverse(ret.begin(), ret.end());
  return ret;
}
string add(string a, string b) {
  if (a == "") a = "0";
  if (b == "") b = "0";
  if (a.length() < b.length()) swap(a, b);
  while (b.length() < a.length()) {
    b = '0' + b;
  }
  for (int i = 0; i < a.length(); i++) {
    a[i] = a[i] + (b[i] - '0');
  }
  bool big = false;
  for (int i = a.length() - 1; i >= 0; i--) {
    if (big) {
      a[i]++;
    }
    big = false;
    if (a[i] > '9') {
      a[i] = a[i] - 10;
      big = true;
    }
  }
  if (big) a = '1' + a;
  return a;
}
string mul(string a, string b) {
  vector<int> va, vb;
  if (a == "0" || b == "0") return "0";
  string ans;
  for (int i = 0; i < a.length(); i++) {
    va.push_back(a[i] - '0');
  }
  for (int i = 0; i < b.length(); i++) {
    vb.push_back(b[i] - '0');
  }
  reverse(va.begin(), va.end());
  reverse(vb.begin(), vb.end());
  vector<int> res;
  res.clear();
  res.resize(1005);
  for (int i = 0; i < a.length(); i++) {
    for (int j = 0; j < b.length(); j++) {
      res[i + j] += (va[i] * vb[j]);
    }
  }
  for (int i = 0; i < 1005; i++) {
    if (res[i] > 9) {
      res[i + 1] += (res[i] / 10);
      res[i] %= 10;
    }
  }
  for (int i = 0; i < 1005; i++) {
    ans += (res[i] + '0');
  }
  reverse(ans.begin(), ans.end());
  int k = 0;
  while (ans[k] == '0') {
    k++;
  }
  ans = ans.substr(k);
  return ans;
}
bool is_prime(int n) {
  if (n < 2) return false;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
const int len = 333;
int m, o, n;
int t[100005], x[100005], z[100005];
pair<int, int> y[100005];
long long sum[100005 / len + 2][6];
int cnt[100005 / len + 2];
int w[100005 / len + 2][len];
inline long long calc() {
  long long rt = 0;
  int cur = 0;
  for (int i = 0; i < o; i++) {
    rt += ::sum[i][(7 - cur) % 5];
    cur = (cur + ::cnt[i]) % 5;
  }
  return rt;
}
inline int add(int x, int y) {
  int j;
  j = x / len;
  for (int i = cnt[j]; i >= 0; i--) {
    if (i > 0 && w[j][i - 1] > y)
      w[j][i] = w[j][i - 1];
    else {
      w[j][i] = y;
      break;
    }
  }
  for (int i = 0; i < 5; i++) sum[j][i] = 0;
  cnt[j]++;
  for (int i = 0, k = 0; i < cnt[j]; i++, k = (k == 4 ? 0 : k + 1))
    sum[j][k] += w[j][i];
  return 0;
}
inline int del(int x, int y) {
  int j = x / len;
  for (int i = 0; i < cnt[j]; i++)
    if (w[j][i] == y) {
      for (int k = i; k + 1 < cnt[j]; k++) w[j][k] = w[j][k + 1];
      break;
    }
  for (int i = 0; i < 5; i++) sum[j][i] = 0;
  cnt[j]--;
  for (int i = 0, k = 0; i < cnt[j]; i++, k = (k == 4 ? 0 : k + 1))
    sum[j][k] += w[j][i];
  return 0;
}
string s;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s[0] == 'a')
      t[i] = 0;
    else if (s[0] == 'd')
      t[i] = 1;
    else
      t[i] = 2;
    if (t[i] != 2) cin >> x[i];
    y[i] = make_pair(x[i], i);
  }
  sort(y, y + n);
  int r = 0;
  for (int i = 0; i < n; i++) {
    if (i > 0 && y[i - 1].first != y[i].first) r++;
    z[y[i].second] = r;
  }
  o = (n + len - 1) / len;
  for (int i = 0; i < n; i++) {
    if (t[i] == 2)
      cout << calc() << endl;
    else if (t[i] == 0)
      add(z[i], x[i]);
    else
      del(z[i], x[i]);
    del(z[i], x[i]);
    del(z[i], x[i]);
  }
  return 0;
}
