#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;
int n, m;
int seg[MAXN * 8];
long long modSum[5][MAXN * 8];
set<int> ord;
set<int>::iterator it;
unordered_map<int, int> comp;
int discomp[MAXN];
long long sum;
queue<pair<char, int> > fila;
void update(int pos, int ini, int fim, int id, int val);
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    char type[5];
    int aux = 0;
    scanf(" %s", type);
    if (type[0] != 's') scanf("%d", &aux);
    if (aux != 0) ord.insert(aux);
    fila.push(make_pair(type[0], aux));
  }
  for (it = ord.begin(); it != ord.end(); it++) {
    comp[*it] = ++m;
    discomp[m] = *it;
  }
  for (int i = 0; i < n; i++) {
    char type = fila.front().first;
    int aux = comp[fila.front().second];
    fila.pop();
    if (type == 'a') update(1, 1, m, aux, 1);
    if (type == 'd') update(1, 1, m, aux, -1);
    if (type == 's') printf("%lld\n", modSum[3][1]);
  }
}
void update(int pos, int ini, int fim, int id, int val) {
  if (ini > id || fim < id) return;
  if (ini == fim) {
    seg[pos] += val;
    modSum[1][pos] += val * discomp[ini];
    return;
  }
  int mid = ini + ((fim - ini) >> 1), e = (pos << 1), d = e | 1;
  update(e, ini, mid, id, val);
  update(d, mid + 1, fim, id, val);
  seg[pos] = seg[e] + seg[d];
  for (int i = 5; i < 10; i++)
    modSum[i - 5][pos] = modSum[i - 5][e] + modSum[(i - (seg[e]) % 5) % 5][d];
  return;
}
