#include <cstdio>
#include <algorithm>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define maxn 100005
#define ll __int64
struct node{
    ll sum[5];
    int cnt,numpos;
}setree[maxn<<2];
struct {
    ll num;
    char s[5];
}mes[maxn];
ll sorted[maxn];
void build(int l,int r,int rt)
{
    for(int i=0;i<5;i++)
    setree[rt].sum[i]=0;
    setree[rt].cnt=0;
    setree[rt].numpos=0;
    if(l==r)
    return;
    int m=(l+r)>>1;
    build(lson);
    build(rson);
}
void pushup(int rt)
{
    for(int i=0;i<5;i++)
    setree[rt].sum[i]=setree[rt<<1].sum[i]+setree[rt<<1|1].sum[i];
    setree[rt].numpos=setree[rt<<1].numpos+setree[rt<<1|1].numpos;
}
int binsearch(int l,int r,ll num)
{
    int m=(l+r)>>1;
    if(sorted[m]==num)
    return m;
    if(num<sorted[m])
    return binsearch(l,m-1,num);
    return binsearch(m+1,r,num);
}
void pushdown(int rt)
{
    ll tmp[5];
    if(setree[rt].cnt!=0){
        int c=setree[rt].cnt;
        if(setree[rt<<1].numpos!=0){
            setree[rt<<1].cnt+=c;
            for(int i=0;i<5;i++)
            tmp[i]=setree[rt<<1].sum[i];
            for(int i=0;i<5;i++)
            setree[rt<<1].sum[i]=tmp[(i+c+5)%5];
        }
        if(setree[rt<<1|1].numpos!=0){
            setree[rt<<1|1].cnt+=c;
            for(int i=0;i<5;i++)
            tmp[i]=setree[rt<<1|1].sum[i];
            for(int i=0;i<5;i++)
            setree[rt<<1|1].sum[i]=tmp[(i+c+5)%5];
        }
        setree[rt].cnt=0;
    }
}
void update1(int l,int r,int rt,int num,int pos)
{
    if(l==r){
        setree[rt].sum[pos%5]=sorted[num];
        setree[rt].numpos=1;
        return;
    }
    pushdown(rt);
    int m=(l+r)>>1;
    if(num<=m)
    update1(lson,num,pos);
    else
    update1(rson,num,pos);
    pushup(rt);
}
int query(int l,int r,int rt,int L,int R)
{
    if(L>R)
    return 0;
    if(L<=l&&r<=R)
    return setree[rt].numpos;
    int m=(l+r)>>1;
    int ans=0;
    if(L<=m)
    ans+=query(lson,L,R);
    if(R>m)
    ans+=query(rson,L,R);
    return ans;
}
void update2(int l,int r,int rt,int num)
{
    if(l==r){
        for(int i=0;i<5;i++)
        setree[rt].sum[i]=0;
        setree[rt].numpos=0;
        setree[rt].cnt=0;
        return;
    }
    pushdown(rt);
    int m=(l+r)>>1;
    if(num<=m)
    update2(lson,num);
    else
    update2(rson,num);
    pushup(rt);
}
void update3(int l,int r,int rt,int L,int R,int c)
{
    if(L<=l&&r<=R){
        ll tmp[5];
        setree[rt].cnt+=c;
        for(int i=0;i<5;i++)
            tmp[i]=setree[rt].sum[i];
        for(int i=0;i<5;i++)
        setree[rt].sum[i]=tmp[(i+c+5)%5];
        return;
    }
    pushdown(rt);
    int m=(l+r)>>1;
    if(L<=m)
    update3(lson,L,R,c);
    if(R>m)
    update3(rson,L,R,c);
    pushup(rt);
}
void print()
{
    for(int i=1;i<14;i++){
        printf("i=%d ",i);
        for(int j=0;j<5;j++)
        printf("sum[%d]=%d ",j,setree[i].sum[j]);
        printf("numpos=%d cnt=%d\n",setree[i].numpos,setree[i].cnt);
    }
}
int main()
{
    int m;
    while(~scanf("%d",&m)){
        int n=0;
        for(int i=1;i<=m;i++){
            scanf("%s",&mes[i].s);
            if(mes[i].s[0]=='a'||mes[i].s[0]=='d'){
            scanf("%I64d",&mes[i].num);
            sorted[++n]=mes[i].num;
            }
        }
        sort(sorted+1,sorted+n+1);
        int k=1;
        for(int i=2;i<=n;i++)
        if(sorted[i]!=sorted[i-1])
        sorted[++k]=sorted[i];
        build(1,k,1);
        for(int i=1;i<=m;i++){
            if(mes[i].s[0]=='a'){
                int pos=binsearch(1,k,mes[i].num);
                int c=query(1,k,1,1,pos-1);
                int cc=query(1,k,1,pos+1,k);
                update1(1,k,1,pos,c+1);
                if(cc!=0)
                update3(1,k,1,pos+1,k,-1);
            }
            else if(mes[i].s[0]=='d'){
                int pos=binsearch(1,k,mes[i].num);
                update2(1,k,1,pos);
                int cc=query(1,k,1,pos+1,k);
                if(cc!=0)
                update3(1,k,1,pos+1,k,1);
            }
            else
            printf("%I64d\n",setree[1].sum[3]);
        }
    }
    return 0;
}
