#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const int DIM = 110 * 1000;
int q;
char s[10];
vector<pair<string, int> > zap;
int xx[DIM], cx, n;
long long sum[4 * DIM][5];
int tr[4 * DIM];
void push(int pos, int d, int v = 1, int vl = 0, int vr = cx - 1) {
  if (vl == vr) {
    if (d == 1)
      sum[v][0] = xx[vl];
    else
      sum[v][0] = 0;
    tr[v] += d;
    return;
  }
  int vs = (vl + vr) / 2;
  if (pos <= vs)
    push(pos, d, v * 2, vl, vs);
  else
    push(pos, d, v * 2 + 1, vs + 1, vr);
  tr[v] = tr[v * 2] + tr[v * 2 + 1];
  int nn = tr[v * 2] % 5;
  nn = 5 - nn;
  for (int i = (0); i < (5); i++) {
    if (nn == 5) nn = 0;
    sum[v][i] = sum[v * 2][i] + sum[v * 2 + 1][nn];
    nn++;
  }
}
int getx(int x) { return lower_bound(xx, xx + cx, x) - xx; }
void solve() {
  sort(xx, xx + cx);
  for (int i = (0); i < (q); i++) {
    char c = zap[i].first[0];
    if (c == 'a') {
      int pos = getx(zap[i].second);
      push(pos, 1);
    } else if (c == 'd') {
      int pos = getx(zap[i].second);
      push(pos, -1);
    } else {
      printf("%I64d\n", sum[1][2]);
    }
  }
}
int main() {
  scanf("%d", &q);
  for (int i = (0); i < (q); i++) {
    int n;
    scanf("%s%d", s, &n);
    zap.push_back(make_pair(s, n));
    if (s[0] == 'a') {
      xx[cx++] = n;
    }
  }
  solve();
  return 0;
}
