#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
using namespace std;
#define MAXN 100006
int array[MAXN];
map < int , int > M;
struct ss
{
    int sz;
    long long sum[5];
    ss()
    {
        sz = 0;
        memset(sum,0,sizeof(sum));
    }
};
ss TREE[4*MAXN];
struct qq
{
    int tp;
    int x;
    qq(int t, int val = -1) {tp = t, x = val;}
};
vector < qq > Q;
void update(int node, int left, int right, int idx, bool tp)
{
    if (idx < left || right < idx) return;
    if (left == right)
    {
        if (tp)
        {
            TREE[node].sz = 1;
            TREE[node].sum[0] = array[idx];
        }
        else TREE[node].sz = TREE[node].sum[0] = 0;
        return;
    }
    int mid = (left + right) / 2;
    update(2*node, left, mid, idx, tp);
    update(2*node+1, mid+1, right, idx, tp);
    TREE[node].sz = TREE[2*node].sz + TREE[2*node+1].sz;
    int i, s = TREE[2*node].sz;
    for (i=0; i<5; ++i) TREE[node].sum[i] = TREE[2*node].sum[i] + TREE[2*node+1].sum[(i-s+5)%5];
    //printf("%d : %d %d : ", node, left, right);
    //for (i=0; i<5; ++i) printf(" %I64d", TREE[node].sum[i]); puts("");
}
int main()
{
    int N,x,i;
    char str[6];
    map < int , int > :: iterator im;
    while (scanf("%d", &N) != EOF)
    {
        memset(TREE, 0, sizeof(TREE));
        M.clear();
        Q.clear();
        while (N--)
        {
            scanf("%s", str);
            if (str[0] == 's') Q.push_back(qq(0));
            else
            {
                scanf("%d", &x);
                M[x] = -1;
                if (str[0] == 'a') Q.push_back(qq(1,x));
                else Q.push_back(qq(2,x));
            }
        }
        for (i=1, im = M.begin(); im != M.end(); ++im, ++i)
        {
            im->second = i;
            array[i] = im->first;
        }
        N = i-1;
        //for (i=1; i<=N; ++i) printf("%d %d\n", M[array[i]], array[i]);
        for (i=0; i<Q.size(); ++i)
        {
            if (Q[i].tp == 0) printf("%I64d\n", TREE[1].sum[2]);
            else
            {
                x = Q[i].x;
                if (Q[i].tp == 1) update(1,1,N,M[x],1);
                else update(1,1,N,M[x],0);
            }
            //puts("");
        }
    }
    return 0;
}
