#include <bits\stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define pf(n) printf("%d\n",n)
#define pfcs(cs) printf("Case %d:\n",cs);
#define enl cout<<endl
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define xx first
#define yy second
typedef long long ll;
typedef pair<int,int>PI;
typedef pair<pair<int,int>,int>PII;

typedef struct node
{
    int val,prior,sz;
    struct node *l,*r;
} node;

typedef node* pnode;

inline int siz(pnode t){return t?t->sz:0;}

inline void upd_sz(pnode t){if(t) t->sz = siz(t->l)+1+siz(t->r);}

void split(pnode t,pnode &l,pnode &r,int key)
{
    if(!t) l=r=NULL;
    else if(t->val<=key) split(t->r,t->r,r,key),l=t;
    else split(t->l,l,t->l,key),r=t;
    upd_sz(t);
}
void merge(pnode &t,pnode l,pnode r)
{
    if(!l || !r) t=l?l:r;
    else if(l->prior > r->prior)merge(l->r,l->r,r),t=l;
    else merge(r->l,l,r->l),t=r;
    upd_sz(t);
}
void insert(pnode &t,pnode it){
    if(!t) t=it;
    else if(it->prior>t->prior) split(t,it->l,it->r,it->val),t=it;
    else insert(t->val<=it->val?t->r:t->l,it);
    upd_sz(t);
}

void erase(pnode &t,int key)
{
    if(!t)return;
    else if(t->val==key)
    {
        pnode temp=t;
        merge(t,t->l,t->r);
        free(temp);
    }
    else erase(t->val<key?t->r:t->l,key);
    upd_sz(t);
}
pnode init(int val)
{
    pnode ret = (pnode)malloc(sizeof(node));
    ret->val=val;
    ret->sz=1;
    ret->prior=rand();
    ret->l=ret->r=NULL;
    return ret;
}
int idx;
ll ans=0;
void qr(pnode t)
{
    if(!t)return;
    qr(t->l);
    //cout<<idx<<" "<< t->val <<endl;
    if((idx-2)%5==0)ans+=t->val;
    //cout<<ans<<endl;
    idx++;
    qr(t->r);
}

void inorder(pnode t)
{
    if(!t)return;
    inorder(t->l);
   // cout<< t->val <<endl;
    inorder(t->r);
}
int main()
{
    pnode root=NULL;
    int q;
    isc(q);
    printf("%d",q);
    char a[5];
    //getchar();
    while(q--)
    {
        int b;
        getchar();
        scanf("%s",&a);
        if(a[0]=='a')
        {
            scanf("%d",&b);
            insert(root,init(b));
           // inorder(root);
           // enl;
        }
        else if(a[0]=='d')
        {
            scanf("%d",&b);
            erase(root,b);
        }
        else
        {
            idx=0;
            ans=0;
            qr(root);
            printf("%lld\n",ans);
        }

    }
    return 0;
}

  	  	    							   	 	  						