#include <bits/stdc++.h>
using namespace std;
int c[111111 << 2];
long long s[111111 << 2][5];
int n, k;
char ch[111], tt[111];
int tp[111111];
int nm[111111];
int d[111111];
inline void update(int v) {
  for (int(i) = 0; (i) < (5); ++(i))
    s[v][i] = s[2 * v + 1][i] + s[2 * v + 2][(i + 5 - c[2 * v + 1] % 5) % 5];
  c[v] = c[2 * v + 1] + c[2 * v + 2];
}
void add(int v, int l, int r, int pos, int how) {
  if (l + 1 == r) {
    c[v] = 1 * how;
    for (int(i) = 0; (i) < (5); ++(i)) s[v][i] = 0;
    s[v][0] = d[pos] * how;
    return;
  }
  int mid = (l + r + 1) / 2;
  if (pos < mid)
    add(2 * v + 1, l, mid, pos, how);
  else
    add(2 * v + 2, mid, r, pos, how);
  update(v);
}
int main() {
  gets(ch);
  sscanf(ch, "%d", &n);
  for (int(i) = 0; (i) < (n); ++(i)) {
    gets(ch);
    sscanf(ch, "%s %d", tt, &nm[i]);
    if (tt[0] == 'a')
      tp[i] = 0;
    else if (tt[0] == 'd')
      tp[i] = 1;
    else
      tp[i] = 2;
    d[i] = nm[i];
  }
  sort(d, d + n);
  k = unique(d, d + n) - d;
  for (int(i) = 0; (i) < (n); ++(i))
    if (tp[i] == 0)
      add(0, 0, k, lower_bound(d, d + k, nm[i]) - d, 1);
    else if (tp[i] == 1)
      add(0, 0, k, lower_bound(d, d + k, nm[i]) - d, 0);
    else
      printf("%I64d\n", s[0][2]);
}
