#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int tree[4 * N][10], n, k, a[N], i, j, bef, ind[N], cnt[4 * N];
pair<int, int> b[N];
string x[N];
void update(int u, int ind, int l, int r, int val, int c) {
  if (ind < l || ind > r) return;
  if (l == r) {
    tree[u][1] += c;
    cnt[u] = val;
    return;
  }
  int mid = (l + r) / 2;
  update(2 * u, ind, l, mid, val, c);
  update(2 * u + 1, ind, mid + 1, r, val, c);
  for (int i = 0; i <= 4; i++) {
    tree[u][i] =
        tree[2 * u][i] + tree[2 * u + 1][(i + 5 - (cnt[2 * u]) % 5) % 5];
  }
  cnt[u] = cnt[2 * u] + cnt[2 * u + 1];
}
int main() {
  cin >> n;
  for (k = 1; k <= n; k++) {
    cin >> x[k];
    if (x[k][0] != 's') cin >> a[k], i++, b[i].first = a[k], b[i].second = k;
  }
  sort(b + 1, b + i + 1);
  for (k = 1; k <= i; k++) {
    if (b[k].first != bef) {
      j++;
      bef = b[k].first;
    }
    ind[b[k].second] = j;
  }
  for (k = 1; k <= n; k++) {
    if (x[k][0] == 'a') {
      update(1, ind[k], 1, n, 1, a[k]);
    } else if (x[k][0] == 'd') {
      update(1, ind[k], 1, n, 0, -a[k]);
    } else {
      cout << tree[1][3] << endl;
    }
  }
}
