#include<cstdio>
#include<cstring>
#include<iostream>
#include <map>
#include <numeric>
#include <sstream>
#include <cmath>
#include <stack>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
#include <queue>
#include <string>
#include<utility>
using namespace std;
//typedef long  long ll;
typedef __int64 ll;
///////////////////////////////////////////////
#define mems(a,b) memset((a),b,sizeof((a)))
#define rll(a,b) scanf("%lld%lld", &(a),&(b))
#define rl(a) scanf("%lld", &(a))
#define ri(i) scanf("%d", &(i) )
#define rii(a,b) scanf("%d%d",&(a), &(b))
#define rs(s) scanf("%s", s)
#define ps(s)  printf("%s\n", s)
#define pi(i) printf("%d\n", (i))
#define pl(i) printf("%lld\n",(i))
#define pll(a,b) printf("%lld %lld\n", (a),(b))
#define pii(a,b) printf("%d %d\n",(a),(b));
#define pki(i)  printf(" %d", (i))
#define all(a)  a.begin(), a.end()
#define SZ(a)  ((int)(a).size())
#define fir  first
#define sec second
#define rep(i, n ) for( int i=1;i<=n;i++)
#define rep1( i,a,b )for(int i=a;i<=b;i++)
#define rep2( i,a,b)  for( i=a; i>=b;i--)
#define mp(a,b) make_pair(a,b)
#define pb(v) push_back(v)
#define ENDL cout<<endl
#define fr(a) freopen(a, "r", stdin) ;
#define fw(a) freopen(a, "w", stdout);
#define FUCK cout<<"fuck"<<endl
const int MAXN = (int)1e5+20;
const int INF =(int) 1e9+20;
struct SMT
{
  int l,r,sum,v;
  ll mod[5];
}a[MAXN<<2];
struct NODE
{
  int so,v,id,pos;
}b[MAXN];
int ord[MAXN];
 
void build(int p,int l,int r) 
{
  a[p].l=l, a[p].r=r;
  if(l==r) 
    a[p].sum=0;
  else 
  {
    int mid=l+r>>1;
    int lc=p*2+1, rc=p*2+2;
    build(lc,l,mid);
    build(rc,mid+1,r);
    a[p].sum=a[lc].sum+a[rc].sum;
  } 
} 
void add(int p,int l,int r,int v,int id) 
{
  if(l==r) 
  {
    a[p].v=v;
    a[p].sum=1;
  } else { 
    int mid=l+r>>1;
    int lc=p*2+1,rc=p*2+2;
    if(id < mid ) add(lc,l,mid,v,id);
    else add(rc,mid+1,r,v,id);
    a[p].sum = a[lc].sum+a[rc].sum;
  }
}
void update(int p,int l,int r,int v,int id) 
{
  if(l==r) 
  {
    memset(a[p].mod,0,sizeof(a[p].mod));
    a[p].mod[1]=v;
    a[p].sum=1;
  } else { 
    int mid=l+r>>1;
    int lc=p*2+1, rc=p*2+2;
    if( id < mid ) update(lc,l,mid,v,id);
    else update(rc,mid+1,r,v,id);
    a[p].sum = a[lc].sum+a[rc].sum;
    int len = a[lc].sum;
    for(int i=0;i<5;i++) a[p].mod[(len+i)%5] = a[lc].mod[(len+i)%5] + a[rc].mod[i];
  }
} 

ll cal(int p,int l,int r, int cnt) 
{
  if( l==r ) 
  {
    if((cnt+a[p].sum)%5==3) return a[p].v;
    else return 0;
  } else { 
    int mid=l+r>>1;
    int lc=p*2+1,rc=p*2+2;
    return cal(lc,l,mid,cnt)+cal(rc,mid+1,r,cnt+a[lc].sum);
  }  
}  
void del(int p,int l,int r,int id) 
{
  if(l==r) 
  { 
    a[p].v=0;
    a[p].sum=0;
    //printf("%d %d %d\n", l,r,id);
  }  else { 
    int mid=l+r>>1;
    int lc=p*2+1,rc=p*2+2;
    if( id <mid ) del(lc,l,mid,id);
    else del(rc,mid+1,r,id);
    a[p].sum = a[lc].sum+a[rc].sum;
    int len = a[lc].sum;
    for(int i=0;i<5;i++) a[p].mod[(len+i)%5]= a[lc].mod[(len+i)%5] + a[rc].mod[i];
  } 
}
bool cmp(int x,int y) 
{
  return b[x].v < b[y].v;
}
int main() 
{
  int n,i,j;
  char s[10];
  
 map<int , int >ma;

  scanf("%d",&n);
  for(i=1;i<=n;i++) ord[i]=i;
  for(i=1;i<=n;i++) 
  {
    scanf("%s",s);
    if(s[0]=='a' )
    {
      b[i].so=1;
      scanf("%d",&b[i].v);
    }
    else if(s[0]=='d') 
    {
      b[i].so=2;
      scanf("%d",&b[i].v);
    } 
    else 
    {
      b[i].so=3;
      b[i].v=INF;
    } 
  } 
  sort(ord+1,ord+n+1,cmp);
  int cnt=0;
  for(i=1;i<=n;i++) 
  {
    int tmp = b[ord[i]].v;
    if(!ma.count(tmp)) ma[tmp] = ++cnt;
    b[ord[i]].id=ma[tmp];
  } 
  build(0,1,cnt);
//  for(i=1;i<=n;i++) 
//  {
//    printf("%d %d\n", i,b[ord[i]].v);
//  } 
  for(i=1;i<=n;i++) 
   if( b[i].so==1) {update(0,1,cnt,b[i].v,b[i].id); }
   else if( b[i].so==2) { del(0,1,cnt,b[i].id); }
   else printf("%lld\n", a[0].mod[3]); 
}

    
      
