#include<cstdio>                                                             //*
#include<cstring>                                                            //*
#include<algorithm>                                                          //*
#include<iostream>                                                           //*
#include<vector>                                                             //*
#include<map>                                                                //*
#include<set>                                                                //*
#include<queue>                                                              //*
#include<stack>                                                              //*
#include<cmath>                                                              //*
#include<list>                                                               //*
#define ll long long                                                         //*
#define INT __int64                                                          //*
#define usn unsigned                                                         //*
const int INF = 0x3f3f3f3f;                                                  //*
const ll INF_LL = 9223372036854775807LL;                                     //*
const double E = exp(1.0);                                                   //*
const double PI = acos(-1.0);                                                //*
ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}                            //*
ll lcd(ll a , ll b){return a * b / gcd(a,b);}                                //*
inline ll read(){                                                            //*
    char ch = getchar(); ll x = 0, f = 1;                                    //*
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}      //*
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}   //*
    return x * f;                                                            //*
}                                                                            //*
inline void write(ll x)                                                      //*
{                                                                            //*
    if(x<0) {                                                                //*
        putchar('-');                                                        //*
        x = -x;                                                              //*
    }                                                                        //*
    if(x>9) write(x / 10);                                                   //*
    putchar(x % 10 + '0');                                                   //*
}                                                                            //*
void init_cin(){                                                             //*
  std::ios::sync_with_stdio(false);                                          //*
  std::cin.tie(nullptr);                                                     //*
  std::cout.tie(nullptr);                                                    //*
}                                                                            //*
using namespace std;                                                         //*
//---------------------------------------------------------------------------//*
std::vector<ll> v;
  int main(){
      int n = read();
       init_cin();
       while(n--){
           char s[5];
            scanf("%s", s);
               if(s[0] == 'a'){
                 ll x;
                  scanf("%I64d", &x);
                  v.push_back(x);
               }
               else if(s[0] == 's'){
                  ll sum = 0;
                  if(v.size() == 0){
                     cout <<  0 << endl;
                     continue;
                  }
                  sort(v.begin() , v.end());
                  for(int i = 0 ; i < v.size() ; i+=5){
                    if(i+2 < v.size())  sum += v[i+2];
                  }
                cout << sum << endl;
               }
               else{
                  ll x;
                     scanf("%I64d", &x);
                   int pos = -1;
                   for(int i = 0 ; i < v.size() ; i ++){
                       if(v[i] == x){
                         pos = i;
                         break;
                       }
                   }
                   if(pos >= 0) v.erase(v.begin() + pos);
               }

       }
  }


#include<cstdio>                                                             //*
#include<cstring>                                                            //*
#include<algorithm>                                                          //*
#include<iostream>                                                           //*
#include<vector>                                                             //*
#include<map>                                                                //*
#include<set>                                                                //*
#include<queue>                                                              //*
#include<stack>                                                              //*
#include<cmath>                                                              //*
#include<list>                                                               //*
#define ll long long                                                         //*
#define INT __int64                                                          //*
#define usn unsigned                                                         //*
const int INF = 0x3f3f3f3f;                                                  //*
const ll INF_LL = 9223372036854775807LL;                                     //*
const double E = exp(1.0);                                                   //*
const double PI = acos(-1.0);                                                //*
ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}                            //*
ll lcd(ll a , ll b){return a * b / gcd(a,b);}                                //*
inline ll read(){                                                            //*
    char ch = getchar(); ll x = 0, f = 1;                                    //*
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}      //*
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}   //*
    return x * f;                                                            //*
}                                                                            //*
inline void write(ll x)                                                      //*
{                                                                            //*
    if(x<0) {                                                                //*
        putchar('-');                                                        //*
        x = -x;                                                              //*
    }                                                                        //*
    if(x>9) write(x / 10);                                                   //*
    putchar(x % 10 + '0');                                                   //*
}                                                                            //*
void init_cin(){                                                             //*
  std::ios::sync_with_stdio(false);                                          //*
  std::cin.tie(nullptr);                                                     //*
  std::cout.tie(nullptr);                                                    //*
}                                                                            //*
using namespace std;                                                         //*
//---------------------------------------------------------------------------//*
std::vector<ll> v;
  int main(){
      int n = read();
      char s[5];
       init_cin();
       while(n--){

            scanf("%s", s);

                if(s[0] == 's'){
                  ll sum = 0;
                  for(int i = 2 ; i < v.size() ; i+=5){
                    sum += v[i];
                  }
                printf("%I64d\n", sum);
               }
               else{
                 ll x;
               scanf("%I64d", &x);
                 if(s[0] == 'a'){
                    v.insert(lower_bound(v.begin(),v.end(),x),x);
                 }
                  else{
                      v.erase(lower_bound(v.begin(),v.end(),x));}
               }

       }
  }


#include<bits/stdc++.h>
std::vector<int> v;
  int main(){
      int n;
      char s[5];
      scanf("%d", &n);
       while(n--){
            scanf("%s", s);
                if(s[0] == 's'){
                  ll sum = 0;
                  for(int i = 2 ; i < v.size() ; i+=5){
                    sum += v[i];
                  }
                printf("%I64d\n", sum);
               }
               else{
                 int x;
               scanf("%d", &x);
                 if(s[0] == 'a'){
                    v.insert(lower_bound(v.begin(),v.end(),x),x);
                 }
                  else{
                      v.erase(lower_bound(v.begin(),v.end(),x));}
               }

       }
  }


#include<cstdio>                                                             //*
#include<cstring>                                                            //*
#include<algorithm>                                                          //*
#include<iostream>                                                           //*
#include<vector>                                                             //*
#include<map>                                                                //*
#include<set>                                                                //*
#include<queue>                                                              //*
#include<stack>                                                              //*
#include<cmath>                                                              //*
#include<list>                                                               //*
#define ll long long                                                         //*
#define INT __int64                                                          //*
#define usn unsigned                                                         //*
const int INF = 0x3f3f3f3f;                                                  //*
const ll INF_LL = 9223372036854775807LL;                                     //*
const double E = exp(1.0);                                                   //*
const double PI = acos(-1.0);                                                //*
ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}                            //*
ll lcd(ll a , ll b){return a * b / gcd(a,b);}                                //*
inline ll read(){                                                            //*
    char ch = getchar(); ll x = 0, f = 1;                                    //*
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}      //*
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}   //*
    return x * f;                                                            //*
}                                                                            //*
inline void write(ll x)                                                      //*
{                                                                            //*
    if(x<0) {                                                                //*
        putchar('-');                                                        //*
        x = -x;                                                              //*
    }                                                                        //*
    if(x>9) write(x / 10);                                                   //*
    putchar(x % 10 + '0');                                                   //*
}                                                                            //*
void init_cin(){                                                             //*
  std::ios::sync_with_stdio(false);                                          //*
  std::cin.tie(nullptr);                                                     //*
  std::cout.tie(nullptr);                                                    //*
}                                                                            //*
using namespace std;                                                         //*
//---------------------------------------------------------------------------//*
std::vector<ll> v;
  int main(){
      int n = read();
       init_cin();
       while(n--){
           char s[5];
            scanf("%s", s);
               if(s[0] == 'a'){
                 ll x;
                  scanf("%I64d", &x);
                  v.push_back(x);
               }
               else if(s[0] == 's'){
                  ll sum = 0;
                  if(v.size() == 0){
                     cout << -1 << endl;
                     continue;
                  }
                  sort(v.begin() , v.end());
                  for(int i = 0 ; i < v.size() ; i+=5){
                      sum += v[i+2];
                  }
                cout << sum << endl;
               }
               else{
                  int x;
                     scanf("%I64d", &x);
                   int pos = -1;
                   for(int i = 0 ; i < v.size() ; i ++){
                       if(v[i] == x){
                         pos = i;
                         break;
                       }
                   }
                   if(pos >= 0) v.erase(v.begin() + pos);
               }

       }
  }


#include<cstdio>                                                             //*
#include<cstring>                                                            //*
#include<algorithm>                                                          //*
#include<iostream>                                                           //*
#include<vector>                                                             //*
#include<map>                                                                //*
#include<set>                                                                //*
#include<queue>                                                              //*
#include<stack>                                                              //*
#include<cmath>                                                              //*
#include<list>                                                               //*
#define ll long long                                                         //*
#define INT __int64                                                          //*
#define usn unsigned                                                         //*
const int INF = 0x3f3f3f3f;                                                  //*
const ll INF_LL = 9223372036854775807LL;                                     //*
const double E = exp(1.0);                                                   //*
const double PI = acos(-1.0);                                                //*
ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}                            //*
ll lcd(ll a , ll b){return a * b / gcd(a,b);}                                //*
inline ll read(){                                                            //*
    char ch = getchar(); ll x = 0, f = 1;                                    //*
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}      //*
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}   //*
    return x * f;                                                            //*
}                                                                            //*
inline void write(ll x)                                                      //*
{                                                                            //*
    if(x<0) {                                                                //*
        putchar('-');                                                        //*
        x = -x;                                                              //*
    }                                                                        //*
    if(x>9) write(x / 10);                                                   //*
    putchar(x % 10 + '0');                                                   //*
}                                                                            //*
void init_cin(){                                                             //*
  std::ios::sync_with_stdio(false);                                          //*
  std::cin.tie(nullptr);                                                     //*
  std::cout.tie(nullptr);                                                    //*
}                                                                            //*
using namespace std;                                                         //*
//---------------------------------------------------------------------------//*
std::vector<ll> v;
  int main(){
      int n = read();
       init_cin();
       while(n--){
           char s[5];
             cin >> s;
               if(s[0] == 'a'){
                 int x;
                  cin >> x;
                  v.push_back(x);
               }
               else if(s[0] == 's'){
                  int sum = 0;
                  if(v.size() == 0){
                     cout << -1 << endl;
                     continue;
                  }
                  sort(v.begin() , v.end());
                  for(int i = 0 ; i < v.size() ; i+=5){
                      sum += v[i+2];
                  }
                cout << sum << endl;
               }
               else{
                  int x;
                   cin >> x;
                   int pos = -1;
                   for(int i = 0 ; i < v.size() ; i ++){
                       if(v[i] == x){
                         pos = i;
                         break;
                       }
                   }
                   if(pos >= 0) v.erase(v.begin() + pos);
               }

       }
  }


#include<bits/stdc++.h>
#define ll long long
std::vector<ll> v;
  int main(){
      int n;
      char s[5];
      scanf("%d", &n);
       while(n--){
            scanf("%s", s);
                if(s[0] == 's'){
                  ll sum = 0;
                  for(int i = 2 ; i < v.size() ; i+=5){
                    sum += v[i];
                  }
                printf("%I64d\n", sum);
               }
               else{
                 ll x;
               scanf("%I64d", &x);
                 if(s[0] == 'a'){
                    v.insert(lower_bound(v.begin(),v.end(),x),x);
                 }
                  else{
                      v.erase(lower_bound(v.begin(),v.end(),x));}
               }

       }
  }


#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
//#ifdef ONLINE_JUDGE
#define filename(_ST_); \
		freopen(_ST_".in","r",stdin); \
		freopen(_ST_".out1","w",stdout);
//#else
//#define filename(_ST_);
//#endif
char outp[64];
template<typename T>
inline void read(T &x){
	char ch=0; x=0;
	bool sign=false;
	while(ch<'0'||'9'<ch) sign|=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	x=sign?-x:x;
}
template<typename T>
inline void print(T x){
	if(!x){ putchar('0'); return; }
	if(x<0) putchar('-'),x=-x;
	int tot=0;
	while(x) outp[tot++]=x%10+'0',x/=10;
	while(tot) putchar(outp[--tot]);
}
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rt register int
#define read2(_a,_b) read(_a),read(_b)
#define read3(_a,_b,_c) read(_a),read(_b),read(_c)
#define For1(f,e,item) for(rt item=f;item!=e;++item)
#define Rep1(f,e,item) for(rt item=f;item!=e;--item)
#define For2(f,e,item) for(rt item=f;item<e;++item)
#define Rep2(f,e,item) for(rt item=f;item>e;--item)
#define For3(f,e,item) for(rt item=f;item<=e;++item)
#define Rep3(f,e,item) for(rt item=f;item>=e;--item)
namespace Name1{
	vector<int> Set;
	inline void add(int x){
		Set.insert(lower_bound(Set.begin(),Set.end(),x),x);
	}
	inline void del(int x){
		Set.erase(lower_bound(Set.begin(),Set.end(),x));
	}
	inline ll sum(){
		ll ret=0;
		int lth=Set.size();
		for(rt i=2;i<lth;i+=5){
			ret+=Set[i];
		}
		return ret;
	}
}
const int sqrn=350;
namespace Name2{
	struct Node{
		ll eac[8];
	};
	const int MAXN=1e5+64;
	vector<vector<int> > vec;
	vector<Node> eve;
	inline int search(int x){
		int lth=vec.size();
		int l=0,r=lth,ans=lth-1;
		while(l<r){
			int mid=(l+r)>>1;
			if(x<=vec[mid].back()) r=ans=mid;
			else l=mid+1;
		}
		if(!lth){
			vec.pb(vector<int>(0));
			eve.pb(Node());  ans=0;
		}
		return ans;
	}
	inline void rcount(int wei){
		int lth=vec[wei].size();
		memset(eve[wei].eac,0,sizeof(eve[wei].eac));
		For1(0,lth,i){
			eve[wei].eac[i%5]+=vec[wei][i];
		}
	}
	inline void add(int x){
		int wei=search(x);
		vec[wei].insert(lower_bound(vec[wei].begin(),vec[wei].end(),x),x);
		int lth=vec[wei].size();
		if(lth>sqrn<<1){
			int rsize=lth>>1;
			vector<int> step(0);
			step.insert(step.begin(),vec[wei].begin()+rsize,vec[wei].end());
			vec[wei].resize(rsize);
			vec.insert(vec.begin()+wei+1,step);
			eve.insert(eve.begin()+wei+1,Node());
			rcount(wei),rcount(wei+1);
		}
		else rcount(wei);
	}
	inline void del(int x){
		int wei=search(x);
		vec[wei].erase(lower_bound(vec[wei].begin(),vec[wei].end(),x));
		int tot=vec.size();
		int lth=vec[wei].size();
		if(lth<sqrn>>1){
			if(wei>0&&(int)vec[wei-1].size()<(sqrn>>1)){
				vec[wei-1].insert(vec[wei-1].end(),vec[wei].begin(),vec[wei].end());
				vec.erase(vec.begin()+wei);
				eve.erase(eve.begin()+wei);
				rcount(wei-1);
			}
			else if(wei+1<tot&&(int)vec[wei+1].size()<(sqrn>>1)){
				vec[wei].insert(vec[wei].end(),vec[wei+1].begin(),vec[wei+1].end());
				vec.erase(vec.begin()+wei+1);
				eve.erase(eve.begin()+wei+1);
				rcount(wei);
			}
			else rcount(wei);
		}
		else rcount(wei);
	}
	inline ll sum(){
		unsigned int tot=0;
		int lth=vec.size();
		ll ret(0);
		For1(0,lth,i){
			ret+=eve[i].eac[(7-tot%5)%5];
			tot+=vec[i].size();
		}
		return ret;
	}
}
using namespace Name1;
int main(){
	//filename("input");
	//ios::sync_with_stdio(false);
	int n,ope;
	char s[16];
	read(n);
	For1(0,n,i){
		memset(s,0,sizeof(s));
		scanf("%s",s);
		if(s[0]=='a') read(ope),add(ope);
		else if(s[0]=='d') read(ope),del(ope);
		else if(s[0]=='s') print(sum()),putchar('\n');
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
//#ifdef ONLINE_JUDGE
#define filename(_ST_); \
		freopen(_ST_".in","r",stdin); \
		freopen(_ST_".out2","w",stdout);
//#else
//#define filename(_ST_);
//#endif
char outp[64];
template<typename T>
inline void read(T &x){
	char ch=0; x=0;
	bool sign=false;
	while(ch<'0'||'9'<ch) sign|=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	x=sign?-x:x;
}
template<typename T>
inline void print(T x){
	if(!x){ putchar('0'); return; }
	if(x<0) putchar('-'),x=-x;
	int tot=0;
	while(x) outp[tot++]=x%10+'0',x/=10;
	while(tot) putchar(outp[--tot]);
}
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rt register int
#define read2(_a,_b) read(_a),read(_b)
#define read3(_a,_b,_c) read(_a),read(_b),read(_c)
#define For1(f,e,item) for(rt item=f;item!=e;++item)
#define Rep1(f,e,item) for(rt item=f;item!=e;--item)
#define For2(f,e,item) for(rt item=f;item<e;++item)
#define Rep2(f,e,item) for(rt item=f;item>e;--item)
#define For3(f,e,item) for(rt item=f;item<=e;++item)
#define Rep3(f,e,item) for(rt item=f;item>=e;--item)
namespace Name1{
	vector<int> Set;
	inline void add(int x){
		Set.insert(lower_bound(Set.begin(),Set.end(),x),x);
	}
	inline void del(int x){
		Set.erase(lower_bound(Set.begin(),Set.end(),x));
	}
	inline ll sum(){
		ll ret=0;
		int lth=Set.size();
		for(rt i=2;i<lth;i+=5){
			ret+=Set[i];
		}
		return ret;
	}
}
const int sqrn=350;
namespace Name2{
	struct Node{
		ll eac[8];
	};
	const int MAXN=1e5+64;
	vector<vector<int> > vec;
	vector<Node> eve;
	inline int search(int x){
		int lth=vec.size();
		int l=0,r=lth,ans=lth-1;
		while(l<r){
			int mid=(l+r)>>1;
			if(x<=vec[mid].back()) r=ans=mid;
			else l=mid+1;
		}
		if(!lth){
			vec.pb(vector<int>(0));
			eve.pb(Node());  ans=0;
		}
		//
		if(ans<0||ans>=lth) exit(0);
		//
		return ans;
	}
	inline void rcount(int wei){
		if(wei>=vec.size()||wei>=eve.size()) exit(0);
		int lth=vec[wei].size();
		memset(eve[wei].eac,0,sizeof(eve[wei].eac));
		For1(0,lth,i){
			eve[wei].eac[i%5]+=vec[wei][i];
		}
	}
	inline void add(int x){
		int wei=search(x);
		//
		if(wei>=vec.size()||wei>=eve.size()) exit(0);
		//
		vec[wei].insert(lower_bound(vec[wei].begin(),vec[wei].end(),x),x);
		int lth=vec[wei].size();
		if(lth>sqrn<<1){
			int rsize=lth>>1;
			vector<int> step(0);
			step.insert(step.begin(),vec[wei].begin()+rsize,vec[wei].end());
			vec[wei].resize(rsize);
			vec.insert(vec.begin()+wei+1,step);
			eve.insert(eve.begin()+wei+1,Node());
			rcount(wei),rcount(wei+1);
		}
		else rcount(wei);
	}
	inline void del(int x){
		int wei=search(x);
		//
		if(wei>=vec.size()||wei>=eve.size()) exit(0);
		//
		vec[wei].erase(lower_bound(vec[wei].begin(),vec[wei].end(),x));
		int tot=vec.size();
		int lth=vec[wei].size();
		if(lth<sqrn>>1){
			if(wei>0&&(int)vec[wei-1].size()<(sqrn>>1)){
				vec[wei-1].insert(vec[wei-1].end(),vec[wei].begin(),vec[wei].end());
				vec.erase(vec.begin()+wei);
				eve.erase(eve.begin()+wei);
				rcount(wei-1);
			}
			else if(wei+1<tot&&(int)vec[wei+1].size()<(sqrn>>1)){
				vec[wei].insert(vec[wei].end(),vec[wei+1].begin(),vec[wei+1].end());
				vec.erase(vec.begin()+wei+1);
				eve.erase(eve.begin()+wei+1);
				rcount(wei);
			}
			else rcount(wei);
		}
		else rcount(wei);
	}
	inline ll sum(){
		unsigned int tot=0;
		int lth=vec.size();
		ll ret(0);
		For1(0,lth,i){
			ret+=eve[i].eac[(7-tot%5)%5];
			tot+=vec[i].size();
		}
		return ret;
	}
}
using namespace Name2;
int main(){
	//filename("input");
	//ios::sync_with_stdio(false);
	int n,ope;
	char s[16];
	read(n);
	For1(0,n,i){
		memset(s,0,sizeof(s));
		scanf("%s",s);
		if(s[0]=='a') read(ope),add(ope);
		else if(s[0]=='d') read(ope),del(ope);
		else if(s[0]=='s') print(sum()),putchar('\n');
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MAXN = 1e5 + 20;
vector<int> Rand;
struct Treap {
	struct Node {
		lint val[5];
		int lson, rson;
		int key, prior, sz;
		Node () {
			lson = rson = -1;
		}
	}	tr[MAXN];
	int root, cnt;
	Treap() {
		cnt = 0;
		root = -1;
	}
	inline void update(int u) {
		if (u == -1) return;
		tr[u].sz = 1;
		if (~tr[u].lson) {
			tr[u].sz += tr[tr[u].lson].sz;
			memcpy(tr[u].val, tr[tr[u].lson].val, sizeof(tr[u].val));
		} else {
			memset(tr[u].val, 0, sizeof(tr[u].val));
		}
		tr[u].val[(tr[u].sz - 1) % 5] += tr[u].key;
		if (~tr[u].rson) {
			int M = tr[u].sz % 5;
			for (int i = 0; i != 5; ++i) {
				int pos = i + M;
				if (pos >= 5) pos -= 5;
				tr[u].val[pos] += tr[tr[u].rson].val[i];
			}
			tr[u].sz += tr[tr[u].rson].sz;
		}
	}
	inline void split(int u, int key, int & r1, int & r2) {
		if (u == -1) {
			r1 = r2 = -1;
			return;
		}
		if (tr[u].key < key) {
			split(tr[u].rson, key, r1, r2);
			tr[u].rson = r1; r1 = u;
		} else {
			split(tr[u].lson, key, r1, r2);
			tr[u].lson = r2; r2 = u;
		}
		update(u);
	}
	inline int merge(int r1, int r2) {
		if (r1 == -1) return r2;
		if (r2 == -1) return r1;
		if (tr[r1].prior < tr[r2].prior) {
			tr[r1].rson = merge(tr[r1].rson, r2);
			update(r1); return r1;
		} else {
			tr[r2].lson = merge(r1, tr[r2].lson);
			update(r2); return r2;
		}
	}
	inline void insert(int x) {
		if (root == -1) {
			root = cnt++;
			tr[root].sz = 1;
			tr[root].key = x;
			tr[root].val[0] = x;
			tr[root].prior = Rand[root];
			return;
		}
		int newNode = cnt++;
		tr[newNode].sz = 1;
		tr[newNode].key = x;
		tr[newNode].val[0] = x;
		tr[newNode].prior = Rand[newNode];
		int r1 = -1, r2 = -1;
		split(root, x, r1, r2);
		root = merge(merge(r1, newNode), r2);
	}
	inline void erase(int x) {
		int r1, r2, r3;
		split(root, x, r1, r2);
		split(r2, x + 1, r2, r3);
		root = merge(r1, r3);
	}
	inline lint query() {
		return ~root ? tr[root].val[2] : 0;
	}
}	tr;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n;
	cin >> n;
	rep (i, 0, n - 1) {
		Rand.push_back(i);
	}
	random_shuffle(all(Rand));
	while (n--) {
		string s;
		cin >> s;
		if (s[0] == 'a') {
			int x;
			cin >> x;
			tr.insert(x);
		} else if (s[0] == 'd') {
			int x;
			cin >> x;
			tr.erase(x);
		} else {
			cout << tr.query() << endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
#ifdef ONLINE_JUDGE
#define filename(_ST_); \
		freopen(_ST_".in","r",stdin); \
		freopen(_ST_".out","w",stdout);
#else
#define filename(_ST_);
#endif
char outp[64];
template<typename T>
inline void read(T &x){
	char ch=0; x=0;
	bool sign=false;
	while(ch<'0'||'9'<ch) sign|=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	x=sign?-x:x;
}
template<typename T>
inline void print(T x){
	if(!x){ putchar('0'); return; }
	if(x<0) putchar('-'),x=-x;
	int tot=0;
	while(x) outp[tot++]=x%10+'0',x/=10;
	while(tot) putchar(outp[--tot]);
}
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rt register int
#define read2(_a,_b) read(_a),read(_b)
#define read3(_a,_b,_c) read(_a),read(_b),read(_c)
#define For1(f,e,item) for(rt item=f;item!=e;++item)
#define Rep1(f,e,item) for(rt item=f;item!=e;--item)
#define For2(f,e,item) for(rt item=f;item<e;++item)
#define Rep2(f,e,item) for(rt item=f;item>e;--item)
#define For3(f,e,item) for(rt item=f;item<=e;++item)
#define Rep3(f,e,item) for(rt item=f;item>=e;--item)
namespace Name1{
	vector<int> Set;
	inline void add(int x){
		Set.insert(lower_bound(Set.begin(),Set.end(),x),x);
	}
	inline void del(int x){
		Set.erase(lower_bound(Set.begin(),Set.end(),x));
	}
	inline ll sum(){
		ll ret=0;
		int lth=Set.size();
		for(rt i=2;i<lth;i+=5){
			ret+=Set[i];
		}
		return ret;
	}
}
int sqrn;
namespace Name2{
	struct Node{
		ll eac[6];
		Node(){}
	};
	#define lowbit(x) x&-x
	const int MAXN=1e5+64;
	vector<vector<int> > vec;
	vector<Node> eve;
	inline int search(int x){
		int lth=vec.size();
		int l=0,r=lth,ans=0;
		while(l<r){
			int mid=(l+r)>>1;
			if(x<vec[mid].back()) r=ans=mid;
			else l=mid+1;
		}
		if(!lth){
			vec.pb(vector<int>(0));
			eve.pb(Node());
		}
		return ans;
	}
	inline void rcount(int wei){
		int lth=vec[wei].size();
		memset(eve[wei].eac,0,sizeof(eve[wei].eac));
		For1(0,lth,i){
			eve[wei].eac[i%5]+=vec[wei][i];
		}
	}
	inline void add(int x){
		int wei=search(x);
		vec[wei].insert(lower_bound(vec[wei].begin(),vec[wei].end(),x),x);
		int lth=vec[wei].size();
		if(lth>sqrn<<1){
			int rsize=lth>>1;
			vector<int> step;
			For1(rsize,lth,i){
				step.pb(vec[wei][i]);
			}
			vec[wei].resize(rsize);
			vec.insert(vec.begin()+wei+1,step);
			eve.insert(eve.begin()+wei+1,Node());
			rcount(wei),rcount(wei+1);
		}
		else rcount(wei);
	}
	inline void del(int x){
		int wei=search(x);
		vec[wei].erase(lower_bound(vec[wei].begin(),vec[wei].end(),x));
		int tot=vec.size();
		int lth=vec[wei].size();
		if(lth<sqrn>>1){
			if(wei>0&&(int)vec[wei-1].size()<(sqrn>>1)){
				For1(0,lth,i){
					vec[wei-1].insert(vec[wei-1].end(),vec[wei].begin(),vec[wei].end());
					vec.erase(vec.begin()+wei);
				}
				rcount(wei-1);
			}
			else if(wei+1<tot&&(int)vec[wei+1].size()<(sqrn>>1)){
				For1(0,lth,i){
					vec[wei].insert(vec[wei].end(),vec[wei+1].begin(),vec[wei+1].end());
					vec.erase(vec.begin()+wei+1);
				}
				rcount(wei);
			}
		}
		else rcount(wei);
	}
	inline ll sum(){
		int tot=0;
		int lth=vec.size();
		ll ret(0);
		For1(0,lth,i){
			ret+=eve[i].eac[tot%5+2];
			tot+=vec[i].size();
		}
		return ret;
	}
}
using namespace Name1;
int main(){
	//filename("");
	//ios::sync_with_stdio(false);
	int n,ope;
	char s[8];
	read(n);
	sqrn=sqrt(n)+4;
	For1(0,n,i){
		memset(s,0,sizeof(s));
		scanf("%s",s);
		if(s[0]=='a') read(ope),add(ope);
		else if(s[0]=='d') read(ope),del(ope);
		else if(s[0]=='s') print(sum()),putchar('\n');
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
//#ifdef ONLINE_JUDGE
#define filename(_ST_); \
		freopen(_ST_".in","r",stdin); \
		freopen(_ST_".out2","w",stdout);
//#else
//#define filename(_ST_);
//#endif
char outp[64];
template<typename T>
inline void read(T &x){
	char ch=0; x=0;
	bool sign=false;
	while(ch<'0'||'9'<ch) sign|=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	x=sign?-x:x;
}
template<typename T>
inline void print(T x){
	if(!x){ putchar('0'); return; }
	if(x<0) putchar('-'),x=-x;
	int tot=0;
	while(x) outp[tot++]=x%10+'0',x/=10;
	while(tot) putchar(outp[--tot]);
}
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rt register int
#define read2(_a,_b) read(_a),read(_b)
#define read3(_a,_b,_c) read(_a),read(_b),read(_c)
#define For1(f,e,item) for(rt item=f;item!=e;++item)
#define Rep1(f,e,item) for(rt item=f;item!=e;--item)
#define For2(f,e,item) for(rt item=f;item<e;++item)
#define Rep2(f,e,item) for(rt item=f;item>e;--item)
#define For3(f,e,item) for(rt item=f;item<=e;++item)
#define Rep3(f,e,item) for(rt item=f;item>=e;--item)
namespace Name1{
	vector<int> Set;
	inline void add(int x){
		Set.insert(lower_bound(Set.begin(),Set.end(),x),x);
	}
	inline void del(int x){
		Set.erase(lower_bound(Set.begin(),Set.end(),x));
	}
	inline ll sum(){
		ll ret=0;
		int lth=Set.size();
		for(rt i=2;i<lth;i+=5){
			ret+=Set[i];
		}
		return ret;
	}
}
const int sqrn=350;
namespace Name2{
	struct Node{
		ll eac[8];
	};
	const int MAXN=1e5+64;
	vector<vector<int> > vec;
	vector<Node> eve;
	inline int search(int x){
		int lth=vec.size();
		int l=0,r=lth,ans=lth-1;
		while(l<r){
			int mid=(l+r)>>1;
			if(x<=vec[mid].back()) r=ans=mid;
			else l=mid+1;
		}
		if(!lth){
			vec.pb(vector<int>(0));
			eve.pb(Node());  ans=0;
		}
		//
		//if(ans<0||ans>=lth) exit(0);
		//
		return ans;
	}
	inline void rcount(int wei){
		if(wei>=vec.size()||wei>=eve.size()) exit(0);
		int lth=vec[wei].size();
		memset(eve[wei].eac,0,sizeof(eve[wei].eac));
		For1(0,lth,i){
			eve[wei].eac[i%5]+=vec[wei][i];
		}
	}
	inline void add(int x){
		int wei=search(x);
		//
		//if(wei>=vec.size()||wei>=eve.size()) exit(0);
		//
		vec[wei].insert(lower_bound(vec[wei].begin(),vec[wei].end(),x),x);
		int lth=vec[wei].size();
		if(lth>sqrn<<1){
			int rsize=lth>>1;
			vector<int> step(0);
			step.insert(step.begin(),vec[wei].begin()+rsize,vec[wei].end());
			vec[wei].resize(rsize);
			vec.insert(vec.begin()+wei+1,step);
			eve.insert(eve.begin()+wei+1,Node());
			rcount(wei),rcount(wei+1);
		}
		else rcount(wei);
	}
	inline void del(int x){
		int wei=search(x);
		//
		//if(wei>=vec.size()||wei>=eve.size()) exit(0);
		//
		vec[wei].erase(lower_bound(vec[wei].begin(),vec[wei].end(),x));
		int tot=vec.size();
		int lth=vec[wei].size();
		if(lth<sqrn>>1){
			if(wei>0&&(int)vec[wei-1].size()<(sqrn>>1)){
				vec[wei-1].insert(vec[wei-1].end(),vec[wei].begin(),vec[wei].end());
				vec.erase(vec.begin()+wei);
				eve.erase(eve.begin()+wei);
				rcount(wei-1);
			}
			else if(wei+1<tot&&(int)vec[wei+1].size()<(sqrn>>1)){
				vec[wei].insert(vec[wei].end(),vec[wei+1].begin(),vec[wei+1].end());
				vec.erase(vec.begin()+wei+1);
				eve.erase(eve.begin()+wei+1);
				rcount(wei);
			}
			else rcount(wei);
		}
		else rcount(wei);
	}
	inline ll sum(){
		unsigned int tot=0;
		int lth=vec.size();
		ll ret(0);
		For1(0,lth,i){
			ret+=eve[i].eac[(7-tot%5)%5];
			tot+=vec[i].size();
		}
		return ret;
	}
}
using namespace Name2;
int main(){
	//filename("input");
	//ios::sync_with_stdio(false);
	int n,ope;
	char s[16];
	read(n);
	For1(0,n,i){
		memset(s,0,sizeof(s));
		scanf("%s",s);
		if(s[0]=='a') read(ope),add(ope);
		else if(s[0]=='d') read(ope),del(ope);
		else if(s[0]=='s') print(sum()),putchar('\n');
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
//#ifdef ONLINE_JUDGE
#define filename(_ST_); \
		freopen(_ST_".in","r",stdin); \
		freopen(_ST_".out2","w",stdout);
//#else
//#define filename(_ST_);
//#endif
char outp[64];
template<typename T>
inline void read(T &x){
	char ch=0; x=0;
	bool sign=false;
	while(ch<'0'||'9'<ch) sign|=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	x=sign?-x:x;
//	cerr<<x<<endl;
}
template<typename T>
inline void print(T x){
	if(!x){ putchar('0'); return; }
	if(x<0) putchar('-'),x=-x;
	int tot=0;
	while(x) outp[tot++]=x%10+'0',x/=10;
	while(tot) putchar(outp[--tot]);
}
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rt register int
#define read2(_a,_b) read(_a),read(_b)
#define read3(_a,_b,_c) read(_a),read(_b),read(_c)
#define For1(f,e,item) for(rt item=f;item!=e;++item)
#define Rep1(f,e,item) for(rt item=f;item!=e;--item)
#define For2(f,e,item) for(rt item=f;item<e;++item)
#define Rep2(f,e,item) for(rt item=f;item>e;--item)
#define For3(f,e,item) for(rt item=f;item<=e;++item)
#define Rep3(f,e,item) for(rt item=f;item>=e;--item)
namespace Name1{
	vector<int> Set;
	inline void add(int x){
		Set.insert(lower_bound(Set.begin(),Set.end(),x),x);
	}
	inline void del(int x){
		Set.erase(lower_bound(Set.begin(),Set.end(),x));
	}
	inline ll sum(){
		ll ret=0;
		int lth=Set.size();
		for(rt i=2;i<lth;i+=5){
			ret+=Set[i];
		}
		return ret;
	}
}
const int sqrn=350;
namespace Name2{
	struct Node{
		ll eac[8];
		Node(){}
	};
	const int MAXN=1e5+64;
	vector<pair<vector<int>,int> > vec;
	vector<Node> eve;
	vector<int> fill;
	inline int search(int x){
		if(!vec.size()){
			vec.pb(mp(vector<int>(0),-1));
			eve.pb(Node());
			return 0;
		}
		int ans=0;
		for(rt i=0;i!=-1;i=vec[i].se){
			if(!vec[i].fi.size()) continue;
			if(x<=vec[i].fi.back()) return i;
			else ans=i;
		}
		return ans;
	}
	inline void rcount(int wei){
		int lth=vec[wei].fi.size();
		memset(eve[wei].eac,0,sizeof(eve[wei].eac));
		For1(0,lth,i){
			eve[wei].eac[i%5]+=vec[wei].fi[i];
		}
	}
	inline void add(int x){
		int wei=search(x);
		vec[wei].fi.insert(lower_bound(vec[wei].fi.begin(),vec[wei].fi.end(),x),x);
		int lth=vec[wei].fi.size();
		if(lth>sqrn<<1){
			int rsize=lth>>1;
			vector<int> step(0);
			step.insert(step.begin(),vec[wei].fi.begin()+rsize,vec[wei].fi.end());
			vec[wei].fi.resize(rsize);
			if(fill.size()){
				vec[fill.back()].fi=step;
				eve[fill.back()]=Node();
				vec[fill.back()].se=vec[wei].se;
				vec[wei].se=fill.back();
				rcount(wei),rcount(fill.back());
				fill.pop_back();
			}
			else{
				vec.pb(mp(step,0));
				eve.pb(Node());
				vec[vec.size()-1].se=vec[wei].se;
				vec[wei].se=vec.size()-1;
				rcount(wei),rcount(vec.size()-1);
			}
		}
		else rcount(wei);
	}
	inline void del(int x){
	//	cerr<<'d'<<endl;
		int wei=search(x);
	//	cerr<<wei<<endl;
	//	cerr<<vec[wei].fi.size()<<endl;
		vec[wei].fi.erase(lower_bound(vec[wei].fi.begin(),vec[wei].fi.end(),x));

		int lth=vec[wei].fi.size();
		if(lth<sqrn>>1){
			if(vec[wei].se!=-1&&(int)vec[vec[wei].se].fi.size()<(sqrn>>1)){
				vec[wei].fi.insert(vec[wei].fi.end(),vec[vec[wei].se].fi.begin(),vec[vec[wei].se].fi.end());
				fill.pb(vec[wei].se);
				vec[wei].se=vec[vec[wei].se].se;
				rcount(wei);
			}
			else rcount(wei);
		}
		else rcount(wei);
	}
	inline ll sum(){
		if(!vec.size()) return 0;
		unsigned int tot=0;
		ll ret(0);
		for(rt i=0;i!=-1;i=vec[i].se){
			ret+=eve[i].eac[(7-tot%5)%5];
			tot+=vec[i].fi.size();
		}
		return ret;
	}
}
using namespace Name2;
int main(){
	//filename("input");
	//ios::sync_with_stdio(false);
	int n,ope;
	char s[16];
	read(n);
	For1(0,n,i){
		memset(s,0,sizeof(s));
		scanf("%s",s);
//		cerr<<s;
//		cerr<<endl;
	//	cerr<<i<<' '<<s[0]<<endl;
		if(s[0]=='a') read(ope),add(ope);
		else if(s[0]=='d') read(ope),del(ope);
		else if(s[0]=='s') print(sum()),putchar('\n');
		sum();
	}
	//cerr<<"over2"<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
#ifdef ONLINE_JUDGE
#define filename(_ST_); \
		freopen(_ST_".in","r",stdin); \
		freopen(_ST_".out","w",stdout);
#else
#define filename(_ST_);
#endif
char outp[64];
template<typename T>
inline void read(T &x){
	char ch=0; x=0;
	bool sign=false;
	while(ch<'0'||'9'<ch) sign|=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	x=sign?-x:x;
}
template<typename T>
inline void print(T x){
	if(!x){ putchar('0'); return; }
	if(x<0) putchar('-'),x=-x;
	int tot=0;
	while(x) outp[tot++]=x%10+'0',x/=10;
	while(tot) putchar(outp[--tot]);
}
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rt register int
#define read2(_a,_b) read(_a),read(_b)
#define read3(_a,_b,_c) read(_a),read(_b),read(_c)
#define For1(f,e,item) for(rt item=f;item!=e;++item)
#define Rep1(f,e,item) for(rt item=f;item!=e;--item)
#define For2(f,e,item) for(rt item=f;item<e;++item)
#define Rep2(f,e,item) for(rt item=f;item>e;--item)
#define For3(f,e,item) for(rt item=f;item<=e;++item)
#define Rep3(f,e,item) for(rt item=f;item>=e;--item)
namespace Name1{
	vector<int> Set;
	inline void add(int x){
		Set.insert(lower_bound(Set.begin(),Set.end(),x),x);
	}
	inline void del(int x){
		Set.erase(lower_bound(Set.begin(),Set.end(),x));
	}
	inline ll sum(){
		ll ret=0;
		int lth=Set.size();
		for(rt i=2;i<lth;i+=5){
			ret+=Set[i];
		}
		return ret;
	}
}
int sqrn;
namespace Name2{
	struct Node{
		ll eac[6];
		Node(){}
	};
	#define lowbit(x) x&-x
	const int MAXN=1e5+64;
	vector<vector<int> > vec;
	vector<Node> eve;
	inline int search(int x){
		int lth=vec.size();
		int l=0,r=lth,ans=0;
		while(l<r){
			int mid=(l+r)>>1;
			if(x<vec[mid].back()) r=ans=mid;
			else l=mid+1;
		}
		if(!lth){
			vec.pb(vector<int>(0));
			eve.pb(Node());
		}
		return ans;
	}
	inline void rcount(int wei){
		int lth=vec[wei].size();
		memset(eve[wei].eac,0,sizeof(eve[wei].eac));
		For1(0,lth,i){
			eve[wei].eac[i%5]+=vec[wei][i];
		}
	}
	inline void add(int x){
		int wei=search(x);
		vec[wei].insert(lower_bound(vec[wei].begin(),vec[wei].end(),x),x);
		int lth=vec[wei].size();
		if(lth>sqrn<<1){
			int rsize=lth>>1;
			vector<int> step;
			For1(rsize,lth,i){
				step.pb(vec[wei][i]);
			}
			vec[wei].resize(rsize);
			vec.insert(vec.begin()+wei+1,step);
			eve.insert(eve.begin()+wei+1,Node());
			rcount(wei),rcount(wei+1);
		}
		else rcount(wei);
	}
	inline void del(int x){
		int wei=search(x);
		vec[wei].erase(lower_bound(vec[wei].begin(),vec[wei].end(),x));
		int tot=vec.size();
		int lth=vec[wei].size();
		if(lth<sqrn>>1){
			if(wei>0&&(int)vec[wei-1].size()<(sqrn>>1)){
				For1(0,lth,i){
					vec[wei-1].insert(vec[wei-1].end(),vec[wei].begin(),vec[wei].end());
					vec.erase(vec.begin()+wei);
				}
				rcount(wei-1);
			}
			else if(wei+1<tot&&(int)vec[wei+1].size()<(sqrn>>1)){
				For1(0,lth,i){
					vec[wei].insert(vec[wei].end(),vec[wei+1].begin(),vec[wei+1].end());
					vec.erase(vec.begin()+wei+1);
				}
				rcount(wei);
			}
		}
		else rcount(wei);
	}
	inline ll sum(){
		int tot=0;
		int lth=vec.size();
		ll ret(0);
		For1(0,lth,i){
			ret+=eve[i].eac[tot%5+2];
			tot+=vec[i].size();
		}
		return ret;
	}
}
using namespace Name2;
int main(){
	//filename("");
	//ios::sync_with_stdio(false);
	int n,ope;
	char s[8];
	read(n);
	sqrn=sqrt(n)+4;
	For1(0,n,i){
		memset(s,0,sizeof(s));
		scanf("%s",s);
		if(s[0]=='a') read(ope),add(ope);
		else if(s[0]=='d') read(ope),del(ope);
		else if(s[0]=='s') print(sum()),putchar('\n');
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
//#ifdef ONLINE_JUDGE
#define filename(_ST_); \
		freopen(_ST_".in","r",stdin); \
		freopen(_ST_".out2","w",stdout);
//#else
//#define filename(_ST_);
//#endif
char outp[64];
template<typename T>
inline void read(T &x){
	char ch=0; x=0;
	bool sign=false;
	while(ch<'0'||'9'<ch) sign|=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	x=sign?-x:x;
}
template<typename T>
inline void print(T x){
	if(!x){ putchar('0'); return; }
	if(x<0) putchar('-'),x=-x;
	int tot=0;
	while(x) outp[tot++]=x%10+'0',x/=10;
	while(tot) putchar(outp[--tot]);
}
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rt register int
#define read2(_a,_b) read(_a),read(_b)
#define read3(_a,_b,_c) read(_a),read(_b),read(_c)
#define For1(f,e,item) for(rt item=f;item!=e;++item)
#define Rep1(f,e,item) for(rt item=f;item!=e;--item)
#define For2(f,e,item) for(rt item=f;item<e;++item)
#define Rep2(f,e,item) for(rt item=f;item>e;--item)
#define For3(f,e,item) for(rt item=f;item<=e;++item)
#define Rep3(f,e,item) for(rt item=f;item>=e;--item)
namespace Name1{
	vector<int> Set;
	inline void add(int x){
		Set.insert(lower_bound(Set.begin(),Set.end(),x),x);
	}
	inline void del(int x){
		Set.erase(lower_bound(Set.begin(),Set.end(),x));
	}
	inline ll sum(){
		ll ret=0;
		int lth=Set.size();
		for(rt i=2;i<lth;i+=5){
			ret+=Set[i];
		}
		return ret;
	}
}
const int sqrn=350;
namespace Name2{
	struct Node{
		ll eac[8];
		Node(){}
	};
	const int MAXN=1e5+64;
	vector<pair<vector<int>,int> > vec;
	vector<Node> eve;
	vector<int> fill;
	inline int search(int x){
		if(!vec.size()){
			vec.pb(mp(vector<int>(0),-1));
			eve.pb(Node());
			return 0;
		}
		int ans=0;
		for(rt i=0;i!=-1;i=vec[i].se){
			ans=i;
			if(x<=vec[i].fi.back()) break;
		}
		return ans;
	}
	inline void rcount(int wei){
		int lth=vec[wei].fi.size();
		memset(eve[wei].eac,0,sizeof(eve[wei].eac));
		For1(0,lth,i){
			eve[wei].eac[i%5]+=vec[wei].fi[i];
		}
	}
	inline void add(int x){
		int wei=search(x);
		vec[wei].fi.insert(lower_bound(vec[wei].fi.begin(),vec[wei].fi.end(),x),x);
		int lth=vec[wei].fi.size();
		if(lth>sqrn<<1){
			int rsize=lth>>1;
			vector<int> step(0);
			step.insert(step.begin(),vec[wei].fi.begin()+rsize,vec[wei].fi.end());
			vec[wei].fi.resize(rsize);
			if(fill.size()){
				vec[fill.back()].fi=step;
				eve[fill.back()]=Node();
				vec[fill.back()].se=vec[wei].se;
				vec[wei].se=fill.back();
				rcount(wei),rcount(fill.back());
				fill.pop_back();
			}
			else{
				vec.pb(mp(step,0));
				eve.pb(Node());
				vec[vec.size()-1].se=vec[wei].se;
				vec[wei].se=vec.size()-1;
				rcount(wei),rcount(vec.size()-1);
			}
		}
		else rcount(wei);
	}
	inline void del(int x){
		int wei=search(x);
		vec[wei].fi.erase(lower_bound(vec[wei].fi.begin(),vec[wei].fi.end(),x));
		int lth=vec[wei].fi.size();
		if(lth<sqrn>>1){
			if(vec[wei].se!=-1&&(int)vec[vec[wei].se].fi.size()<(sqrn>>1)){
				vec[wei].fi.insert(vec[wei].fi.end(),vec[vec[wei].se].fi.begin(),vec[vec[wei].se].fi.end());
				fill.pb(vec[wei].se);
				vec[wei].se=vec[vec[wei].se].se;
				rcount(wei);
			}
			else rcount(wei);
		}
		else rcount(wei);
	}
	inline ll sum(){
		if(!vec.size()) return 0;
		unsigned int tot=0;
		ll ret(0);
		for(rt i=0;i!=-1;i=vec[i].se){
			ret+=eve[i].eac[(7-tot%5)%5];
			tot+=vec[i].fi.size();
		}
		return ret;
	}
}
using namespace Name2;
int main(){
	//filename("input");
	//ios::sync_with_stdio(false);
	int n,ope;
	char s[16];
	read(n);
	For1(0,n,i){
		memset(s,0,sizeof(s));
		scanf("%s",s);
		if(s[0]=='a') read(ope),add(ope);
		else if(s[0]=='d') read(ope),del(ope);
		else if(s[0]=='s') print(sum()),putchar('\n');
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
//#ifdef ONLINE_JUDGE
#define filename(_ST_); \
		freopen(_ST_".in","r",stdin); \
		freopen(_ST_".out2","w",stdout);
//#else
//#define filename(_ST_);
//#endif
char outp[64];
template<typename T>
inline void read(T &x){
	char ch=0; x=0;
	bool sign=false;
	while(ch<'0'||'9'<ch) sign|=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	x=sign?-x:x;
}
template<typename T>
inline void print(T x){
	if(!x){ putchar('0'); return; }
	if(x<0) putchar('-'),x=-x;
	int tot=0;
	while(x) outp[tot++]=x%10+'0',x/=10;
	while(tot) putchar(outp[--tot]);
}
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rt register int
#define read2(_a,_b) read(_a),read(_b)
#define read3(_a,_b,_c) read(_a),read(_b),read(_c)
#define For1(f,e,item) for(rt item=f;item!=e;++item)
#define Rep1(f,e,item) for(rt item=f;item!=e;--item)
#define For2(f,e,item) for(rt item=f;item<e;++item)
#define Rep2(f,e,item) for(rt item=f;item>e;--item)
#define For3(f,e,item) for(rt item=f;item<=e;++item)
#define Rep3(f,e,item) for(rt item=f;item>=e;--item)
namespace Name1{
	vector<int> Set;
	inline void add(int x){
		Set.insert(lower_bound(Set.begin(),Set.end(),x),x);
	}
	inline void del(int x){
		Set.erase(lower_bound(Set.begin(),Set.end(),x));
	}
	inline ll sum(){
		ll ret=0;
		int lth=Set.size();
		for(rt i=2;i<lth;i+=5){
			ret+=Set[i];
		}
		return ret;
	}
}
const int sqrn=350;
namespace Name2{
	struct Node{
		ll eac[8];
	};
	const int MAXN=1e5+64;
	vector<vector<int> > vec;
	vector<Node> eve;
	inline int search(int x){
		int lth=vec.size();
		int l=0,r=lth,ans=lth-1;
		while(l<r){
			int mid=(l+r)>>1;
			if(x<=vec[mid].back()) r=ans=mid;
			else l=mid+1;
		}
		if(!lth){
			vec.pb(vector<int>(0));
			eve.pb(Node());
			ans=0;
			lth=1;
		}
		//
		if(ans<0||ans>=lth) exit(0);
		//
		return ans;
	}
	inline void rcount(int wei){
		if(wei>=vec.size()||wei>=eve.size()) exit(0);
		int lth=vec[wei].size();
		memset(eve[wei].eac,0,sizeof(eve[wei].eac));
		For1(0,lth,i){
			eve[wei].eac[i%5]+=vec[wei][i];
		}
	}
	inline void add(int x){
		int wei=search(x);
		//
		if(wei>=vec.size()||wei>=eve.size()) exit(0);
		//
		vec[wei].insert(lower_bound(vec[wei].begin(),vec[wei].end(),x),x);
		int lth=vec[wei].size();
		if(lth>sqrn<<1){
			int rsize=lth>>1;
			vector<int> step(0);
			step.insert(step.begin(),vec[wei].begin()+rsize,vec[wei].end());
			vec[wei].resize(rsize);
			vec.insert(vec.begin()+wei+1,step);
			eve.insert(eve.begin()+wei+1,Node());
			rcount(wei),rcount(wei+1);
		}
		else rcount(wei);
	}
	inline void del(int x){
		int wei=search(x);
		//
		if(wei>=vec.size()||wei>=eve.size()) exit(0);
		//
		vec[wei].erase(lower_bound(vec[wei].begin(),vec[wei].end(),x));
		int tot=vec.size();
		int lth=vec[wei].size();
		if(lth<sqrn>>1){
			if(wei>0&&(int)vec[wei-1].size()<(sqrn>>1)){
				vec[wei-1].insert(vec[wei-1].end(),vec[wei].begin(),vec[wei].end());
				vec.erase(vec.begin()+wei);
				eve.erase(eve.begin()+wei);
				rcount(wei-1);
			}
			else if(wei+1<tot&&(int)vec[wei+1].size()<(sqrn>>1)){
				vec[wei].insert(vec[wei].end(),vec[wei+1].begin(),vec[wei+1].end());
				vec.erase(vec.begin()+wei+1);
				eve.erase(eve.begin()+wei+1);
				rcount(wei);
			}
			else rcount(wei);
		}
		else rcount(wei);
	}
	inline ll sum(){
		unsigned int tot=0;
		int lth=vec.size();
		ll ret(0);
		For1(0,lth,i){
			ret+=eve[i].eac[(7-tot%5)%5];
			tot+=vec[i].size();
		}
		return ret;
	}
}
using namespace Name2;
int main(){
	//filename("input");
	//ios::sync_with_stdio(false);
	int n,ope;
	char s[16];
	read(n);
	For1(0,n,i){
		memset(s,0,sizeof(s));
		scanf("%s",s);
		if(s[0]=='a') read(ope),add(ope);
		else if(s[0]=='d') read(ope),del(ope);
		else if(s[0]=='s') print(sum()),putchar('\n');
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FOD(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define DEBUG(X) cout << #X << " = " << X << endl;
#define PR(A, n) {cout << #A << " = "; FOR(_, 1, n) cout << A[_] << " "; cout << endl;}
#define fs first
#define sc second

template <typename T> void Read(T &n) {
    char c; n = 0;
    while (!isdigit(c = getchar()));
    do {
        n = n * 10 + c - '0';
    } while (isdigit(c = getchar()));
}

template <typename T> void Writeln(T n) {
    char c[10]; int k = 0;
    while (n > 0) c[++k] = n % 10 + '0', n /= 10;
    FOD(i, k, 1) putchar(c[i]);
    if (k == 0) putchar('0');
    putchar('\n');
}

typedef long long LL;
typedef pair <int, int> II;
const int N = 1E5 + 10;

int n;
II q[N];
vector <int> rar;

void Add(int &a, int b) {a += b; if (a > 5) a -= 5;}

struct FenwickTree {
    int ft[N];
    void Update(int pos, int val) {
        for (int i = pos; i <= n; i += i & -i)
            ft[i] += val;
    }
    int Get(int pos) {
        int ret = 0;
        for (int i = pos; i > 0; i -= i & -i)
            ret += ft[i];
        return ret;
    }
} FT;

struct SegmentTree {
    #define mid (l + r) / 2
    int shift[N * 8];
    LL sum[N * 8][5];
    void Down(int id) {
        if (!shift[id]) return;
        Add(shift[id << 1], shift[id]);
        Add(shift[id << 1 | 1], shift[id]);
        LL L[N], R[N];
        REP(x, 0, 5) {
            L[x] = sum[id << 1][x];
            R[x] = sum[id << 1 | 1][x];
        }
        REP(x, 0, 5) {
            sum[id << 1][(x + shift[id]) % 5] = L[x];
            sum[id << 1 | 1][(x + shift[id]) % 5] = R[x];
        }
        shift[id] = 0;
    }
    void Update(int id, int l, int r, int i, int pos, int val) {
        if (i < l || r < i || l > r) return;
        if (l == r) {
            sum[id][pos] += val;
            return;
        }
        Down(id);
        Update(id << 1, l, mid, i, pos, val);
        Update(id << 1 | 1, mid + 1, r, i, pos, val);
        sum[id][pos] = sum[id << 1][pos] + sum[id << 1 | 1][pos];
    }
    void Move(int id, int l, int r, int u, int v, int step) {
        if (v < l || r < u || l > r) return;
        if (u <= l && r <= v) {
            LL tmp[5];
            Add(shift[id], step);
            REP(x, 0, 5) tmp[x] = sum[id][x];
            REP(x, 0, 5) sum[id][(x + step) % 5] = tmp[x];
            return;
        }
        Down(id);
        Move(id << 1, l, mid, u, v, step);
        Move(id << 1 | 1, mid + 1, r, u, v, step);
        REP(x, 0, 5) sum[id][x] = sum[id << 1][x] + sum[id << 1 | 1][x];
    }
    void Update(int i, int pos, int val) {
        Update(1, 1, rar.size(), i, pos, val);
    }
    void Move(int i, int step) {
        Move(1, 1, rar.size(), i, n, step);
    }
    #undef mid
} ST;

void Read_Input() {
    #ifdef LOCAL
    freopen("set.inp", "r", stdin);
    freopen("set.out", "w", stdout);
    #endif // LOCAL
    Read(n);
    FOR(i, 1, n) {
        char c, t;
        int val;
        while (!isalpha(c = getchar()));
        do {t = c;} while (isalpha(c = getchar()));
        if (t == 'm') q[i] = II(0, 0);
            else {
                Read(val);
                if (t == 'l') q[i] = II(2, val);
                    else q[i] = II(1, val), rar.push_back(val);
            }
    }
}

void Solve() {
    sort(rar.begin(), rar.end());
    FOR(i, 1, n) {
        if (q[i].fs == 0) Writeln(ST.sum[1][3]);
        if (q[i].fs == 1) {
            int j = lower_bound(rar.begin(), rar.end(), q[i].sc) - rar.begin() + 1;
            ST.Move(j, 1);
            FT.Update(j, 1);
            int pos = FT.Get(j) % 5;
            ST.Update(j, pos, q[i].sc);
        }
        if (q[i].fs == 2) {
            int j = lower_bound(rar.begin(), rar.end(), q[i].sc) - rar.begin() + 1;
            int pos = FT.Get(j) % 5;
            FT.Update(j, -1);
            ST.Update(j, pos, -q[i].sc);
            ST.Move(j, 5 - 1);
        }
    }
}

int main() {
    Read_Input();
    Solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FOD(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define DEBUG(X) cout << #X << " = " << X << endl;
#define PR(A, n) {cout << #A << " = "; FOR(_, 1, n) cout << A[_] << " "; cout << endl;}
#define fs first
#define sc second

template <typename T> void Read(T &n) {
    char c; n = 0;
    while (!isdigit(c = getchar()));
    do {
        n = n * 10 + c - '0';
    } while (isdigit(c = getchar()));
}

template <typename T> void Writeln(T n) {
    char c[10]; int k = 0;
    while (n > 0) c[++k] = n % 10 + '0', n /= 10;
    FOD(i, k, 1) putchar(c[i]);
    if (k == 0) putchar('0');
    putchar('\n');
}

typedef long long LL;
typedef pair <int, int> II;
const int N = 1E5 + 10;

int n;
II q[N];
vector <int> rar;

void Add(int &a, int b) {a += b; if (a > 5) a -= 5;}

struct FenwickTree {
    int ft[N];
    void Update(int pos, int val) {
        for (int i = pos; i <= n; i += i & -i)
            ft[i] += val;
    }
    int Get(int pos) {
        int ret = 0;
        for (int i = pos; i > 0; i -= i & -i)
            ret += ft[i];
        return ret;
    }
} FT;

struct SegmentTree {
    #define mid (l + r) / 2
    int shift[N * 8];
    LL sum[N * 8][5];
    void Down(int id) {
        if (!shift[id]) return;
        Add(shift[id << 1], shift[id]);
        Add(shift[id << 1 | 1], shift[id]);
        LL L[N], R[N];
        REP(x, 0, 5) {
            L[x] = sum[id << 1][x];
            R[x] = sum[id << 1 | 1][x];
        }
        REP(x, 0, 5) {
            sum[id << 1][(x + shift[id]) % 5] = L[x];
            sum[id << 1 | 1][(x + shift[id]) % 5] = R[x];
        }
        shift[id] = 0;
    }
    void Update(int id, int l, int r, int i, int pos, int val) {
        if (i < l || r < i || l > r) return;
        if (l == r) {
            sum[id][pos] += val;
            return;
        }
        Down(id);
        Update(id << 1, l, mid, i, pos, val);
        Update(id << 1 | 1, mid + 1, r, i, pos, val);
        sum[id][pos] = sum[id << 1][pos] + sum[id << 1 | 1][pos];
    }
    void Move(int id, int l, int r, int u, int v, int step) {
        if (v < l || r < u || l > r) return;
        if (u <= l && r <= v) {
            LL tmp[5];
            Add(shift[id], step);
            REP(x, 0, 5) tmp[x] = sum[id][x];
            REP(x, 0, 5) sum[id][(x + step) % 5] = tmp[x];
            return;
        }
        Down(id);
        Move(id << 1, l, mid, u, v, step);
        Move(id << 1 | 1, mid + 1, r, u, v, step);
        REP(x, 0, 5) sum[id][x] = sum[id << 1][x] + sum[id << 1 | 1][x];
    }
    void Update(int i, int pos, int val) {
        Update(1, 1, rar.size(), i, pos, val);
    }
    void Move(int i, int step) {
        Move(1, 1, rar.size(), i, n, step);
    }
    #undef mid
} ST;

void Read_Input() {
    #ifdef LOCAL
    freopen("set.inp", "r", stdin);
    freopen("set.out", "w", stdout);
    #endif // LOCAL
    Read(n); return;
    FOR(i, 1, n) {
        char c, t;
        int val;
        while (!isalpha(c = getchar()));
        do {t = c;} while (isalpha(c = getchar()));
        if (t == ' m') q[i] = II(0, 0);
            else {
                Read(val);
                if (t == 'l') q[i] = II(2, val);
                    else q[i] = II(1, val), rar.push_back(val);
            }
    }
}

void Solve() {
    sort(rar.begin(), rar.end());
    FOR(i, 1, n) {
        if (q[i].fs == 0) Writeln(ST.sum[1][3]);
        if (q[i].fs == 1) {
            int j = lower_bound(rar.begin(), rar.end(), q[i].sc) - rar.begin() + 1;
            ST.Move(j, 1);
            FT.Update(j, 1);
            int pos = FT.Get(j) % 5;
            ST.Update(j, pos, q[i].sc);
        }
        if (q[i].fs == 2) {
            int j = lower_bound(rar.begin(), rar.end(), q[i].sc) - rar.begin() + 1;
            int pos = FT.Get(j) % 5;
            FT.Update(j, -1);
            ST.Update(j, pos, -q[i].sc);
            ST.Move(j, 5 - 1);
        }
    }
}

int main() {
    Read_Input();
    Solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FOD(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define DEBUG(X) cout << #X << " = " << X << endl;
#define PR(A, n) {cout << #A << " = "; FOR(_, 1, n) cout << A[_] << " "; cout << endl;}
#define fs first
#define sc second

template <typename T> void Read(T &n) {
    char c; n = 0;
    while (!isdigit(c = getchar()));
    do {
        n = n * 10 + c - '0';
    } while (isdigit(c = getchar()));
}

template <typename T> void Writeln(T n) {
    char c[10]; int k = 0;
    while (n > 0) c[++k] = n % 10 + '0', n /= 10;
    FOD(i, k, 1) putchar(c[i]);
    if (k == 0) putchar('0');
    putchar('\n');
}

typedef long long LL;
typedef pair <int, int> II;
const int N = 1E5 + 10;

int n;
II q[N];
vector <int> rar;

void Add(int &a, int b) {a += b; if (a > 5) a -= 5;}

struct FenwickTree {
    int ft[N];
    void Update(int pos, int val) {
        for (int i = pos; i <= n; i += i & -i)
            ft[i] += val;
    }
    int Get(int pos) {
        int ret = 0;
        for (int i = pos; i > 0; i -= i & -i)
            ret += ft[i];
        return ret;
    }
} FT;

struct SegmentTree {
    #define mid (l + r) / 2
    int shift[N * 4];
    LL sum[N * 4][5];
    void Down(int id) {
        if (!shift[id]) return;
        Add(shift[id << 1], shift[id]);
        Add(shift[id << 1 | 1], shift[id]);
        LL L[N], R[N];
        REP(x, 0, 5) {
            L[x] = sum[id << 1][x];
            R[x] = sum[id << 1 | 1][x];
        }
        REP(x, 0, 5) {
            sum[id << 1][(x + shift[id]) % 5] = L[x];
            sum[id << 1 | 1][(x + shift[id]) % 5] = R[x];
        }
        shift[id] = 0;
    }
    void Update(int id, int l, int r, int i, int pos, int val) {
        if (i < l || r < i || l > r) return;
        if (l == r) {
            sum[id][pos] += val;
            return;
        }
        Down(id);
        Update(id << 1, l, mid, i, pos, val);
        Update(id << 1 | 1, mid + 1, r, i, pos, val);
        sum[id][pos] = sum[id << 1][pos] + sum[id << 1 | 1][pos];
    }
    void Move(int id, int l, int r, int u, int v, int step) {
        if (v < l || r < u || l > r) return;
        if (u <= l && r <= v) {
            LL tmp[5];
            Add(shift[id], step);
            REP(x, 0, 5) tmp[x] = sum[id][x];
            REP(x, 0, 5) sum[id][(x + step) % 5] = tmp[x];
            return;
        }
        Down(id);
        Move(id << 1, l, mid, u, v, step);
        Move(id << 1 | 1, mid + 1, r, u, v, step);
        REP(x, 0, 5) sum[id][x] = sum[id << 1][x] + sum[id << 1 | 1][x];
    }
    void Update(int i, int pos, int val) {
        Update(1, 1, n, i, pos, val);
    }
    void Move(int i, int step) {
        Move(1, 1, n, i, n, step);
    }
    #undef mid
} ST;

void Read_Input() {
    #ifdef LOCAL
    freopen("set.inp", "r", stdin);
    freopen("set.out", "w", stdout);
    #endif // LOCAL
    Read(n);
    FOR(i, 1, n) {
        char c, t;
        int val;
        while (!isalpha(c = getchar()));
        do {t = c;} while (isalpha(c = getchar()));
        if (t == 'm') q[i] = II(0, 0);
            else {
                Read(val);
                if (t == 'l') q[i] = II(2, val);
                    else q[i] = II(1, val), rar.push_back(val);
            }
    }
}

void Solve() {
    sort(rar.begin(), rar.end());
    FOR(i, 1, n) {
        if (q[i].fs == 0) Writeln(ST.sum[1][3]);
        if (q[i].fs == 1) {
            int j = lower_bound(rar.begin(), rar.end(), q[i].sc) - rar.begin() + 1;
            ST.Move(j, 1);
            FT.Update(j, 1);
            int pos = FT.Get(j) % 5;
            ST.Update(j, pos, q[i].sc);
        }
        if (q[i].fs == 2) {
            int j = lower_bound(rar.begin(), rar.end(), q[i].sc) - rar.begin() + 1;
            int pos = FT.Get(j) % 5;
            FT.Update(j, -1);
            ST.Update(j, pos, -q[i].sc);
            ST.Move(j, 5 - 1);
        }
    }
}

int main() {
    Read_Input();
    Solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FOD(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define DEBUG(X) cout << #X << " = " << X << endl;
#define PR(A, n) {cout << #A << " = "; FOR(_, 1, n) cout << A[_] << " "; cout << endl;}
#define fs first
#define sc second

typedef long long LL;
typedef pair <int, int> II;
const int N = 1E5 + 10;

int n;
II q[N];
vector <int> rar;

void Add(int &a, int b) {a += b; if (a > 5) a -= 5;}

struct FenwickTree {
    int ft[N];
    void Update(int pos, int val) {
        for (int i = pos; i <= n; i += i & -i)
            ft[i] += val;
    }
    int Get(int pos) {
        int ret = 0;
        for (int i = pos; i > 0; i -= i & -i)
            ret += ft[i];
        return ret;
    }
} FT;

struct SegmentTree {
    #define mid (l + r) / 2
    int shift[N * 4];
    LL sum[N * 4][5];
    void Down(int id) {
        Add(shift[id << 1], shift[id]);
        Add(shift[id << 1 | 1], shift[id]);
        LL L[N], R[N];
        REP(x, 0, 5) L[x] = sum[id << 1][x];
        REP(x, 0, 5) R[x] = sum[id << 1 | 1][x];
        REP(x, 0, 5) sum[id << 1][(x + shift[id]) % 5] = L[x];
        REP(x, 0, 5) sum[id << 1 | 1][(x + shift[id]) % 5] = R[x];
        shift[id] = 0;
    }
    void Update(int id, int l, int r, int i, int pos, int val) {
        if (i < l || r < i || l > r) return;
        if (l == r) {
            sum[id][pos] += val;
            return;
        }
        Down(id);
        Update(id << 1, l, mid, i, pos, val);
        Update(id << 1 | 1, mid + 1, r, i, pos, val);
        sum[id][pos] = sum[id << 1][pos] + sum[id << 1 | 1][pos];
    }
    void Move(int id, int l, int r, int u, int v, int step) {
        if (v < l || r < u || l > r) return;
        if (u <= l && r <= v) {
            LL tmp[5];
            shift[id] += step;
            REP(x, 0, 5) tmp[x] = sum[id][x];
            REP(x, 0, 5) sum[id][(x + step) % 5] = tmp[x];
            return;
        }
        Down(id);
        Move(id << 1, l, mid, u, v, step);
        Move(id << 1 | 1, mid + 1, r, u, v, step);
        REP(x, 0, 5) sum[id][x] = sum[id << 1][x] + sum[id << 1 | 1][x];
    }
    void Update(int i, int pos, int val) {
        Update(1, 1, n, i, pos, val);
    }
    void Move(int i, int step) {
        Move(1, 1, n, i, n, step);
    }
    #undef mid
} ST;

void Read_Input() {
    #ifdef LOCAL
    freopen("set.inp", "r", stdin);
    freopen("set.out", "w", stdout);
    #endif // LOCAL
    scanf("%d\n", &n);
    FOR(i, 1, n) {
        char a[3];
        int val;
        scanf("%s", a);
        if (a[0] == 's') q[i] = II(0, 0);
            else {
                scanf("%d\n", &val);
                if (a[0] == 'd') q[i] = II(2, val);
                    else q[i] = II(1, val), rar.push_back(val);
            }
    }
}

void Solve() {
    sort(rar.begin(), rar.end());
    FOR(i, 1, n) {
        if (q[i].fs == 0) printf("%I64d\n", ST.sum[1][3]);
        if (q[i].fs == 1) {
            int j = lower_bound(rar.begin(), rar.end(), q[i].sc) - rar.begin() + 1;
            ST.Move(j, 1);
            FT.Update(j, 1);
            int pos = FT.Get(j) % 5;
            ST.Update(j, pos, q[i].sc);
        }
        if (q[i].fs == 2) {
            int j = lower_bound(rar.begin(), rar.end(), q[i].sc) - rar.begin() + 1;
            int pos = FT.Get(j) % 5;
            FT.Update(j, -1);
            ST.Update(j, pos, -q[i].sc);
            ST.Move(j, 5 - 1);
        }
    }
}

int main() {
    Read_Input();
    Solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FOD(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define DEBUG(X) cout << #X << " = " << X << endl;
#define PR(A, n) {cout << #A << " = "; FOR(_, 1, n) cout << A[_] << " "; cout << endl;}
#define fs first
#define sc second

template <typename T> void Read(T &n) {
    char c; n = 0;
    while (!isdigit(c = getchar()));
    do {
        n = n * 10 + c - '0';
    } while (isdigit(c = getchar()));
}

template <typename T> void Writeln(T n) {
    char c[10]; int k = 0;
    while (n > 0) c[++k] = n % 10 + '0', n /= 10;
    FOD(i, k, 1) putchar(c[i]);
    if (k == 0) putchar('0');
    putchar('\n');
}

typedef long long LL;
typedef pair <int, int> II;
const int N = 1E5 + 10;

int n;
II q[N];
vector <int> rar;

void Add(int &a, int b) {a += b; if (a > 5) a -= 5;}

struct FenwickTree {
    int ft[N];
    void Update(int pos, int val) {
        for (int i = pos; i <= n; i += i & -i)
            ft[i] += val;
    }
    int Get(int pos) {
        int ret = 0;
        for (int i = pos; i > 0; i -= i & -i)
            ret += ft[i];
        return ret;
    }
} FT;

struct SegmentTree {
    #define mid (l + r) / 2
    int shift[N * 4];
    LL sum[N * 4][5];
    void Down(int id) {
        if (!shift[id]) return;
        Add(shift[id << 1], shift[id]);
        Add(shift[id << 1 | 1], shift[id]);
        LL L[N], R[N];
        REP(x, 0, 5) {
            L[x] = sum[id << 1][x];
            R[x] = sum[id << 1 | 1][x];
        }
        REP(x, 0, 5) {
            sum[id << 1][(x + shift[id]) % 5] = L[x];
            sum[id << 1 | 1][(x + shift[id]) % 5] = R[x];
        }
        shift[id] = 0;
    }
    void Update(int id, int l, int r, int i, int pos, int val) {
        if (i < l || r < i || l > r) return;
        if (l == r) {
            sum[id][pos] += val;
            return;
        }
        Down(id);
        if (i <= mid) Update(id << 1, l, mid, i, pos, val);
            else Update(id << 1 | 1, mid + 1, r, i, pos, val);
        sum[id][pos] = sum[id << 1][pos] + sum[id << 1 | 1][pos];
    }
    void Move(int id, int l, int r, int u, int v, int step) {
        if (v < l || r < u || l > r) return;
        if (u <= l && r <= v) {
            LL tmp[5];
            Add(shift[id], step);
            REP(x, 0, 5) tmp[x] = sum[id][x];
            REP(x, 0, 5) sum[id][(x + step) % 5] = tmp[x];
            return;
        }
        Down(id);
        if (u <= mid) Move(id << 1, l, mid, u, v, step);
        if (mid + 1 <= v) Move(id << 1 | 1, mid + 1, r, u, v, step);
        REP(x, 0, 5) sum[id][x] = sum[id << 1][x] + sum[id << 1 | 1][x];
    }
    void Update(int i, int pos, int val) {
        Update(1, 1, rar.size(), i, pos, val);
    }
    void Move(int i, int step) {
        Move(1, 1, rar.size(), i, n, step);
    }
    #undef mid
} ST;

void Read_Input() {
    #ifdef LOCAL
    freopen("set.inp", "r", stdin);
    freopen("set.out", "w", stdout);
    #endif // LOCAL
    Read(n);
    FOR(i, 1, n) {
        char c, t;
        int val;
        while (!isalpha(c = getchar()));
        do {t = c;} while (isalpha(c = getchar()));
        if (t == 'm') q[i] = II(0, 0);
            else {
                Read(val);
                if (t == 'l') q[i] = II(2, val);
                    else q[i] = II(1, val), rar.push_back(val);
            }
    }
}

void Solve() {
    sort(rar.begin(), rar.end());
    FOR(i, 1, n) {
        if (q[i].fs == 0) Writeln(ST.sum[1][3]);
        if (q[i].fs == 1) {
            int j = lower_bound(rar.begin(), rar.end(), q[i].sc) - rar.begin() + 1;
            ST.Move(j, 1);
            FT.Update(j, 1);
            int pos = FT.Get(j) % 5;
            ST.Update(j, pos, q[i].sc);
        }
        if (q[i].fs == 2) {
            int j = lower_bound(rar.begin(), rar.end(), q[i].sc) - rar.begin() + 1;
            int pos = FT.Get(j) % 5;
            FT.Update(j, -1);
            ST.Update(j, pos, -q[i].sc);
            ST.Move(j, 5 - 1);
        }
    }
}

int main() {
    Read_Input();
    Solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FOD(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define DEBUG(X) cout << #X << " = " << X << endl;
#define PR(A, n) {cout << #A << " = "; FOR(_, 1, n) cout << A[_] << " "; cout << endl;}
#define fs first
#define sc second

template <typename T> void Read(T &n) {
    char c; n = 0;
    while (!isdigit(c = getchar()));
    do {
        n = n * 10 + c - '0';
    } while (isdigit(c = getchar()));
}

template <typename T> void Writeln(T n) {
    char c[10]; int k = 0;
    while (n > 0) c[++k] = n % 10 + '0', n /= 10;
    FOD(i, k, 1) putchar(c[i]);
    if (k == 0) putchar('0');
    putchar('\n');
}

typedef long long LL;
typedef pair <int, int> II;
const int N = 1E5 + 10;

int n;
II q[N];
vector <int> rar;

void Add(int &a, int b) {a += b; if (a > 5) a -= 5;}

struct FenwickTree {
    int ft[N];
    void Update(int pos, int val) {
        for (int i = pos; i <= n; i += i & -i)
            ft[i] += val;
    }
    int Get(int pos) {
        int ret = 0;
        for (int i = pos; i > 0; i -= i & -i)
            ret += ft[i];
        return ret;
    }
} FT;

struct SegmentTree {
    #define mid (l + r) / 2
    int shift[N * 4];
    LL sum[N * 4][5];
    void Down(int id) {
        if (!shift[id]) return;
        Add(shift[id << 1], shift[id]);
        Add(shift[id << 1 | 1], shift[id]);
        LL L[5], R[5];
        REP(x, 0, 5) {
            L[x] = sum[id << 1][x];
            R[x] = sum[id << 1 | 1][x];
        }
        REP(x, 0, 5) {
            sum[id << 1][(x + shift[id]) % 5] = L[x];
            sum[id << 1 | 1][(x + shift[id]) % 5] = R[x];
        }
        shift[id] = 0;
    }
    void Update(int id, int l, int r, int i, int pos, int val) {
        if (i < l || r < i || l > r) return;
        if (l == r) {
            sum[id][pos] += val;
            return;
        }
        Down(id);
        if (i <= mid) Update(id << 1, l, mid, i, pos, val);
            else Update(id << 1 | 1, mid + 1, r, i, pos, val);
        sum[id][pos] = sum[id << 1][pos] + sum[id << 1 | 1][pos];
    }
    void Move(int id, int l, int r, int u, int v, int step) {
        if (v < l || r < u || l > r) return;
        if (u <= l && r <= v) {
            LL tmp[5];
            Add(shift[id], step);
            REP(x, 0, 5) tmp[x] = sum[id][x];
            REP(x, 0, 5) sum[id][(x + step) % 5] = tmp[x];
            return;
        }
        Down(id);
        if (u <= mid) Move(id << 1, l, mid, u, v, step);
        if (mid + 1 <= v) Move(id << 1 | 1, mid + 1, r, u, v, step);
        REP(x, 0, 5) sum[id][x] = sum[id << 1][x] + sum[id << 1 | 1][x];
    }
    void Update(int i, int pos, int val) {
        Update(1, 1, n, i, pos, val);
    }
    void Move(int i, int step) {
        Move(1, 1, n, i, n, step);
    }
    #undef mid
} ST;

void Read_Input() {
    #ifdef LOCAL
    freopen("set.inp", "r", stdin);
    freopen("set.out", "w", stdout);
    #endif // LOCAL
    Read(n);
    FOR(i, 1, n) {
        char c, t;
        int val;
        while (!isalpha(c = getchar()));
        do {t = c;} while (isalpha(c = getchar()));
        if (t == 'm') q[i] = II(0, 0);
            else {
                Read(val);
                if (t == 'l') q[i] = II(2, val);
                    else q[i] = II(1, val), rar.push_back(val);
            }
    }
}

void Solve() {
    sort(rar.begin(), rar.end());
    FOR(i, 1, n) {
        if (q[i].fs == 0) Writeln(ST.sum[1][3]);
        if (q[i].fs == 1) {
            int j = lower_bound(rar.begin(), rar.end(), q[i].sc) - rar.begin() + 1;
            ST.Move(j, 1);
            FT.Update(j, 1);
            int pos = FT.Get(j) % 5;
            ST.Update(j, pos, q[i].sc);
        }
        if (q[i].fs == 2) {
            int j = lower_bound(rar.begin(), rar.end(), q[i].sc) - rar.begin() + 1;
            int pos = FT.Get(j) % 5;
            FT.Update(j, -1);
            ST.Update(j, pos, -q[i].sc);
            ST.Move(j, 5 - 1);
        }
    }
}

int main() {
    Read_Input();
    Solve();
    return 0;
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
//#define mp make_pair
#define int long long
using namespace std;
inline int read(){
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

int n;
vector<int> v;
main() {
 n=read();
	while(n--) {
		string gcd;
		cin >> gcd;
		if(gcd == "add") {
			int x = read();
			v.insert(lower_bound(v.begin(),v.end(),x),x);
		}
		else if(gcd == "del") v.erase(lower_bound(v.begin(),v.end(),read()));
		else if(gcd == "sum"){
			 	 int ans = 0;
			 	 for(int i = 2 ; i < (int)v.size() ; i += 5) ans += v[i];
				 cout << ans << endl;
			}
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define repn(i, n) for (int (i) = 1; (i) <= (int)n; (i)++)
#define rep(i, n) for (int (i) = 0; (i) < (int)n; (i)++)
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
const int BL = 5;
const int N = 100010;
int size = 0;
vector <int> a;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	while (n--) {
		string op; cin >> op;
		if (op == "add") {
			int x;
			cin >> x;
			a.insert(lower_bound(a.begin(), a.end(), x), x);
		}
		else if (op == "del") {
			int x;
			cin >> x;
			a.erase(lower_bound(a.begin(), a.end(), x));
		}
		else if (op == "sum") {
			long long ans = 0;
			for (int i = 2; i < (int)a.size(); i += 5) ans += a[i];
			cout << ans << endl;
		}
	}
	return 0;
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
//#define mp make_pair
#define int long long
using namespace std;
inline int read(){
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

vector <int> a;
 main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	while (n--) {
		string op; cin >> op;
		if (op == "add") {
			int x;
			cin >> x;
			a.insert(lower_bound(a.begin(), a.end(), x), x);
		}
		else if (op == "del") {
			int x;
			cin >> x;
			a.erase(lower_bound(a.begin(), a.end(), x));
		}
		else if (op == "sum") {
			long long ans = 0;
			for (int i = 2; i < (int)a.size(); i += 5) ans += a[i];
			cout << ans << endl;
		}
	}
	return 0;
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
//#define mp make_pair
#define int long long
using namespace std;
inline int read(){
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

int n;
vector<int> v;
main() {
	n = read();
	ios::sync_with_stdio(false);
	cin.tie(0);
	while(n--) {
		string gcd;
		cin >> gcd;
		if(gcd == "add") {
			int x = read();
			v.insert(lower_bound(v.begin(),v.end(),x),x);
		}
		else if(gcd == "del") v.erase(lower_bound(v.begin(),v.end(),read()));
		else if(gcd == "sum"){
			 	 int ans = 0;
			 	 for(int i = 2 ; i < v.size() ; i += 5) ans += v[i];
				 printf("%lld",ans);
			}
	}
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
//#define mp make_pair
#define int long long
using namespace std;
inline int read(){
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

vector <int> a;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	while (n--) {
		string op; cin >> op;
		if (op == "add") {
			int x;
			cin >> x;
			a.insert(lower_bound(a.begin(), a.end(), x), x);
		}
		else if (op == "del") {
			int x;
			cin >> x;
			a.erase(lower_bound(a.begin(), a.end(), x));
		}
		else if (op == "sum") {
			long long ans = 0;
			for (int i = 2; i < (int)a.size(); i += 5) ans += a[i];
			cout << ans << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
//#define mp make_pair
#define int long long
#define panhan using
#define no namespace
#define xm std;
panhan no xm;
inline int read(){
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}
char gcd[5];
int n;
vector<int> v;
main() {
	n = read();
	while(n--) {
		cin >> gcd;
		if(gcd[0] == 'a') {
			int x = read();
			v.insert(lower_bound(v.begin(),v.end(),x),x);
		}
		else
			if(gcd[0] == 'd') v.erase(lower_bound(v.begin(),v.begin(),read()));
			else {
				int ans = 0;
				for(int i = 2 ; i < v.size() ; i += 5) ans += v[i];
				cout << ans << endl;
			}
	}

}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
//#define mp make_pair
#define int long long
using namespace std;
inline int read(){
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

int n;
vector<int> v;
main() {
	n = read();
	ios::sync_with_stdio(false);
	cin.tie(0);
	while(n--) {
		string gcd;
		cin >> gcd;
		if(gcd == "add") {
			int x = read();
			v.insert(lower_bound(v.begin(),v.end(),x),x);
		}
		else if(gcd == "del") v.erase(lower_bound(v.begin(),v.end(),read()));
		else if(gcd == "sum"){
			 	 int ans = 0;
			 	 for(int i = 2 ; i < v.size() ; i += 5) ans += v[i];
				 cout << ans << endl;
			}
	}
}


#include <bits/stdc++.h>
//#define mp make_pair
#define int long long
using namespace std;
inline int read(){
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

int n;
vector<int> v;
main() {
	n = read();
	while(n--) {
		string gcd;
		cin >> gcd;
		if(gcd == "add") {
			int x = read();
			v.insert(lower_bound(v.begin(),v.end(),x),x);
		}
		else if(gcd == "del") v.erase(lower_bound(v.begin(),v.end(),read()));
		else if(gcd == "sum"){
			 	 int ans = 0;
			 	 for(int i = 2 ; i < v.size() ; i += 5) ans += v[i];
				 cout << ans << endl;
			}
	}
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
//#define mp make_pair
#define int long long
using namespace std;
inline int read(){
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

int n;
vector<int> v;
main() {
	n = read();
	while(n--) {
		string gcd;
		cin >> gcd;
		if(gcd == "add") {
			int x = read();
			v.insert(lower_bound(v.begin(),v.end(),x),x);
		}
		else if(gcd == "del") v.erase(lower_bound(v.begin(),v.end(),read()));
		else if(gcd == "sum"){
			 	 int ans = 0;
			 	 for(int i = 2 ; i < v.size() ; i += 5) ans += v[i];
				 cout << ans << endl;
			}
	}
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

using namespace std;

const int maxn=1000100;
const int INF=(1<<29);

typedef long long ll;
int N;
char op[maxn][10];
int Q[maxn];
int X[maxn],Xn;
struct Node
{
    int cnt;
    ll sum[5];
};Node T[maxn<<2];

void push_up(int rt)
{
    T[rt].cnt=T[rt<<1].cnt+T[rt<<1|1].cnt;
    for(int i=0;i<5;i++){
        int p=i-T[rt<<1].cnt;
        //cout<<"        p="<<p<<" "<<p%5<<" "<<(p+5)%5<<" "<<(p%5+5)%5<<endl;
        T[rt].sum[i]=T[rt<<1].sum[i]+T[rt<<1|1].sum[(p+50000000)%5];
    }
}

void build(int l,int r,int rt)
{
    if(l>r) return;
    if(l==r){
        T[rt].cnt=0;
        for(int i=0;i<5;i++) T[rt].sum[i]=0;
        return;
    }
    int m=(l+r)>>1;
    build(lson);
    build(rson);
    push_up(rt);
}

void update(int pos,int val,int op,int l,int r,int rt)
{
    if(l==r){
        if(op==1){
            if(T[rt].cnt==1) return;
        }
        if(op==-1){
            if(T[rt].cnt==0) return;
        }
        T[rt].cnt+=op;
        T[rt].sum[1]+=val;
        return;
    }
    int m=(l+r)>>1;
    if(pos<=m) update(pos,val,op,lson);
    else update(pos,val,op,rson);
    push_up(rt);
}

void get(int l,int r,int rt)
{
    cout<<"rt="<<rt<<" l="<<l<<" r="<<r<<" cnt="<<T[rt].cnt<<endl;
    if(l==r) return;
    int m=(l+r)>>1;
    get(lson);
    get(rson);
    return;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    while(cin>>N){
        Xn=0;
        for(int i=1;i<=N;i++){
            scanf("%s",op[i]);
            if(op[i][0]!='s'){
                scanf("%d",&Q[i]);
                X[++Xn]=Q[i];
            }
        }
        sort(X+1,X+Xn+1);
        Xn=unique(X+1,X+Xn+1)-(X+1);
        //cout<<"Xn"<<Xn<<endl;
        build(1,Xn,1);
        for(int i=1;i<=N;i++){
            int pos=lower_bound(X+1,X+Xn+1,Q[i])-X;
            //cout<<"pos="<<pos<<" "<<Q[i]<<endl;
            if(op[i][0]=='a') update(pos,Q[i],1,1,Xn,1);
            else if(op[i][0]=='d') update(pos,-Q[i],-1,1,Xn,1);
            else printf("%I64d\n",T[1].sum[3]);
            //if(i==1) get(1,Xn,1);//cout<<endl;getchar();
            //cout<<"i="<<i<<" "<<T[6].sum[3]<<" "<<T[25].cnt<<endl;//<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

using namespace std;

const int maxn=1000100;
const int INF=(1<<29);

typedef long long ll;
int N;
char op[maxn][10];
int Q[maxn];
int X[maxn],Xn;
struct Node
{
    int cnt;
    ll sum[5];
};Node T[maxn<<2];

void push_up(int rt)
{
    T[rt].cnt=T[rt<<1].cnt+T[rt<<1|1].cnt;
    for(int i=0;i<5;i++){
        int p=i-T[rt<<1].cnt;
        //cout<<"        p="<<p<<" "<<p%5<<" "<<(p+5)%5<<" "<<(p%5+5)%5<<endl;
        T[rt].sum[i]=T[rt<<1].sum[i]+T[rt<<1|1].sum[(p+200)%5];
    }
}

void build(int l,int r,int rt)
{
    if(l>r) return;
    if(l==r){
        T[rt].cnt=0;
        for(int i=0;i<5;i++) T[rt].sum[i]=0;
        return;
    }
    int m=(l+r)>>1;
    build(lson);
    build(rson);
    push_up(rt);
}

void update(int pos,int val,int op,int l,int r,int rt)
{
    if(l==r){
        if(op==1){
            if(T[rt].cnt==1) return;
        }
        if(op==-1){
            if(T[rt].cnt==0) return;
        }
        T[rt].cnt+=op;
        T[rt].sum[1]+=val;
        return;
    }
    int m=(l+r)>>1;
    if(pos<=m) update(pos,val,op,lson);
    else update(pos,val,op,rson);
    push_up(rt);
}

void get(int l,int r,int rt)
{
    cout<<"rt="<<rt<<" l="<<l<<" r="<<r<<" cnt="<<T[rt].cnt<<endl;
    if(l==r) return;
    int m=(l+r)>>1;
    get(lson);
    get(rson);
    return;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    while(cin>>N){
        Xn=0;
        for(int i=1;i<=N;i++){
            scanf("%s",op[i]);
            if(op[i][0]!='s'){
                scanf("%d",&Q[i]);
                X[++Xn]=Q[i];
            }
        }
        sort(X+1,X+Xn+1);
        Xn=unique(X+1,X+Xn+1)-(X+1);
        //cout<<"Xn"<<Xn<<endl;
        build(1,Xn,1);
        for(int i=1;i<=N;i++){
            int pos=lower_bound(X+1,X+Xn+1,Q[i])-X;
            //cout<<"pos="<<pos<<" "<<Q[i]<<endl;
            if(op[i][0]=='a') update(pos,Q[i],1,1,Xn,1);
            else if(op[i][0]=='d') update(pos,-Q[i],-1,1,Xn,1);
            else printf("%I64d\n",T[1].sum[3]);
            //if(i==1) get(1,Xn,1);//cout<<endl;getchar();
            //cout<<"i="<<i<<" "<<T[6].sum[3]<<" "<<T[25].cnt<<endl;//<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

using namespace std;

const int maxn=1000100;
const int INF=(1<<29);

typedef long long ll;
int N;
char op[maxn][10];
int Q[maxn];
int X[maxn],Xn;
struct Node
{
    int cnt;
    ll sum[5];
};Node T[maxn<<2];

void push_up(int rt)
{
    T[rt].cnt=T[rt<<1].cnt+T[rt<<1|1].cnt;
    for(int i=0;i<5;i++){
        T[rt].sum[i]=T[rt<<1].sum[i]+T[rt<<1|1].sum[(i-T[rt<<1].cnt+5)%5];
    }
}

void build(int l,int r,int rt)
{
    if(l>r) return;
    if(l==r){
        T[rt].cnt=0;
        for(int i=0;i<5;i++) T[rt].sum[i]=0;
        return;
    }
    int m=(l+r)>>1;
    build(lson);
    build(rson);
    push_up(rt);
}

void update(int pos,int val,int op,int l,int r,int rt)
{
    if(l==r){
        if(op==1){
            if(T[rt].cnt==1) return;
        }
        if(op==-1){
            if(T[rt].cnt==0) return;
        }
        T[rt].cnt+=op;
        T[rt].sum[1]+=val;
        return;
    }
    int m=(l+r)>>1;
    if(pos<=m) update(pos,val,op,lson);
    else update(pos,val,op,rson);
    push_up(rt);
}

void get(int l,int r,int rt)
{
    //cout<<"rt="<<rt<<" l="<<l<<" r="<<r<<" cnt="<<T[rt].cnt<<endl;
    if(l==r) return;
    int m=(l+r)>>1;
    get(lson);
    get(rson);
    return;
}

int main()
{
   // freopen("in.txt","r",stdin);
    while(cin>>N){
        Xn=0;
        for(int i=1;i<=N;i++){
            scanf("%s",op[i]);
            if(op[i][0]!='s'){
                scanf("%d",&Q[i]);
                X[++Xn]=Q[i];
            }
        }
        sort(X+1,X+Xn+1);
        Xn=unique(X+1,X+Xn+1)-(X+1);
        //cout<<"Xn"<<Xn<<endl;
        build(1,Xn,1);
        for(int i=1;i<=N;i++){
            int pos=lower_bound(X+1,X+Xn+1,Q[i])-X;
            if(op[i][0]=='a') update(pos,Q[i],1,1,Xn,1);
            else if(op[i][0]=='d') update(pos,-Q[i],-1,1,Xn,1);
            else printf("%I64d\n",T[1].sum[3]);
            //get(1,Xn,1);cout<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

using namespace std;

const int maxn=1000100;
const int INF=(1<<29);

typedef long long ll;
int N;
char op[maxn][10];
int Q[maxn];
int X[maxn],Xn;
struct Node
{
    int cnt;
    ll sum[5];
};Node T[maxn<<2];

void push_up(int rt)
{
    T[rt].cnt=T[rt<<1].cnt+T[rt<<1|1].cnt;
    for(int i=0;i<5;i++){
        int p=i-T[rt<<1].cnt;
        //cout<<"        p="<<p<<" "<<p%5<<" "<<(p+5)%5<<" "<<(p%5+5)%5<<endl;
        T[rt].sum[i]=T[rt<<1].sum[i]+T[rt<<1|1].sum[(p+1000000007)%5];
    }
}

void build(int l,int r,int rt)
{
    if(l>r) return;
    if(l==r){
        T[rt].cnt=0;
        for(int i=0;i<5;i++) T[rt].sum[i]=0;
        return;
    }
    int m=(l+r)>>1;
    build(lson);
    build(rson);
    push_up(rt);
}

void update(int pos,int val,int op,int l,int r,int rt)
{
    if(l==r){
        if(op==1){
            if(T[rt].cnt==1) return;
        }
        if(op==-1){
            if(T[rt].cnt==0) return;
        }
        T[rt].cnt+=op;
        T[rt].sum[1]+=val;
        return;
    }
    int m=(l+r)>>1;
    if(pos<=m) update(pos,val,op,lson);
    else update(pos,val,op,rson);
    push_up(rt);
}

void get(int l,int r,int rt)
{
    cout<<"rt="<<rt<<" l="<<l<<" r="<<r<<" cnt="<<T[rt].cnt<<endl;
    if(l==r) return;
    int m=(l+r)>>1;
    get(lson);
    get(rson);
    return;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    while(cin>>N){
        Xn=0;
        for(int i=1;i<=N;i++){
            scanf("%s",op[i]);
            if(op[i][0]!='s'){
                scanf("%d",&Q[i]);
                X[++Xn]=Q[i];
            }
        }
        sort(X+1,X+Xn+1);
        Xn=unique(X+1,X+Xn+1)-(X+1);
        //cout<<"Xn"<<Xn<<endl;
        build(1,Xn,1);
        for(int i=1;i<=N;i++){
            int pos=lower_bound(X+1,X+Xn+1,Q[i])-X;
            //cout<<"pos="<<pos<<" "<<Q[i]<<endl;
            if(op[i][0]=='a') update(pos,Q[i],1,1,Xn,1);
            else if(op[i][0]=='d') update(pos,-Q[i],-1,1,Xn,1);
            else printf("%I64d\n",T[1].sum[3]);
            //if(i==1) get(1,Xn,1);//cout<<endl;getchar();
            //cout<<"i="<<i<<" "<<T[6].sum[3]<<" "<<T[25].cnt<<endl;//<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

using namespace std;

const int maxn=1000100;
const int INF=(1<<29);

typedef long long ll;
int N;
char op[maxn][10];
int Q[maxn];
int X[maxn],Xn;
struct Node
{
    int cnt;
    ll sum[5];
};Node T[maxn<<2];

void push_up(int rt)
{
    T[rt].cnt=T[rt<<1].cnt+T[rt<<1|1].cnt;
    for(int i=0;i<5;i++){
        T[rt].sum[i]=T[rt<<1].sum[i]+T[rt<<1|1].sum[(i-T[rt<<1].cnt+5)%5];
    }
}

void build(int l,int r,int rt)
{
    if(l==r){
        T[rt].cnt=0;
        for(int i=0;i<5;i++) T[rt].sum[i]=0;
        return;
    }
    int m=(l+r)>>1;
    build(lson);
    build(rson);
    push_up(rt);
}

void update(int pos,int val,int op,int l,int r,int rt)
{
    if(l==r){
        if(op==1){
            if(T[rt].cnt==1) return;
        }
        if(op==-1){
            if(T[rt].cnt==0) return;
        }
        T[rt].cnt+=op;
        T[rt].sum[1]+=val;
        return;
    }
    int m=(l+r)>>1;
    if(pos<=m) update(pos,val,op,lson);
    else update(pos,val,op,rson);
    push_up(rt);
}

void get(int l,int r,int rt)
{
    //cout<<"rt="<<rt<<" l="<<l<<" r="<<r<<" cnt="<<T[rt].cnt<<endl;
    if(l==r) return;
    int m=(l+r)>>1;
    get(lson);
    get(rson);
    return;
}

int main()
{
   // freopen("in.txt","r",stdin);
    while(cin>>N){
        Xn=0;
        for(int i=1;i<=N;i++){
            scanf("%s",op[i]);
            if(op[i][0]!='s'){
                scanf("%d",&Q[i]);
                X[++Xn]=Q[i];
            }
        }
        sort(X+1,X+Xn+1);
        Xn=unique(X+1,X+Xn+1)-(X+1);
        //cout<<"Xn"<<Xn<<endl;
        build(1,Xn,1);
        for(int i=1;i<=N;i++){
            int pos=lower_bound(X+1,X+Xn+1,Q[i])-X;
            if(op[i][0]=='a') update(pos,Q[i],1,1,Xn,1);
            else if(op[i][0]=='d') update(pos,-Q[i],-1,1,Xn,1);
            else printf("%I64d\n",T[1].sum[3]);
            //get(1,Xn,1);cout<<endl;
        }
    }
    return 0;
}


// In the name of ALLAH
#include <bits/stdc++.h>
using namespace std;

#define int ll

#define PB push_back
#define PF push_front
#define MP make_pair
#define FF first
#define SS second
#define _sz(x) (int)x.size()

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

struct pok { int cnt[5]; };

int const N = 1e5 + 20, SQ = 333;
int n;
vector <vector <int>> vec;
vector <pok> C;

inline void recalc (int i){
	C[i] = {0, 0, 0, 0, 0};
	for (int j = 0; j < _sz(vec[i]); j ++)
		C[i].cnt[(j + 1) % 5] += vec[i][j];
}

int32_t main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	while (n --){
		string s;
		cin >> s;

		if (s == "add"){
			int x; cin >> x;

			for (int i = 0; i < _sz(vec); i ++){
				if ((!i || vec[i][0] < x) && (i == _sz(vec) - 1 || vec[i + 1][0] > x)){
					vector <int> tmp;

					while (vec[i].size() && vec[i].back() > x){
						tmp.PB(vec[i].back());
						vec[i].pop_back();
					}

					vec[i].PB(x);

					while (tmp.size()){
						vec[i].PB(tmp.back());
						tmp.pop_back();
					}

					if (_sz(vec[i]) == 2 * SQ){
						for (int t = 0; t < SQ; t ++){
							tmp.PB(vec[i].back());
							vec[i].pop_back();
						}
						C.insert(C.begin() + i + 1, {0, 0, 0, 0, 0});
						vec.insert(vec.begin() + i + 1, tmp);

						recalc(i + 1);
					}

					recalc(i);

				  	break;
				}
			}

			if (!_sz(vec)){
				vec.PB({x});
				C.PB({0, x, 0, 0, 0});
			}

/*			for (int i = 0; i < _sz(vec); i ++){
				for (auto j: vec[i]) cout << j << ' '; cout << ",  ";
				for (int j = 0; j < 5; j ++) cout << C[i].cnt[j] << ' '; cout << endl;
			}*/
		}
		else if (s == "del"){
		  	int x; cin >> x;
			for (int i = 0; i < _sz(vec); i ++)
				if ((!i || vec[i][0] < x) && (i == _sz(vec) - 1 || vec[i + 1][0] > x)){
					for (int j = 0; j < _sz(vec[i]); j ++)
						if (vec[i][j] == x) vec[i].erase(vec[i].begin() + j);
					recalc(i);
				}
		}
		else {
			int st = 0, res = 0;
			for (int i = 0; i < _sz(vec); i ++){
				res += C[i].cnt[(5 - st + 3) % 5];
			  	(st += _sz(vec[i])) %= 5;
			}

			cout << res << '\n';
		}
	}
}


// In the name of ALLAH
#include <bits/stdc++.h>
using namespace std;

#define int ll

#define PB push_back
#define PF push_front
#define MP make_pair
#define FF first
#define SS second
#define _sz(x) (int)x.size()

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

struct pok { int cnt[5]; };

int const N = 1e5 + 20, SQ = 333;
int n;
vector <vector <int>> vec;
vector <pok> C;

inline void recalc (int i){
	C[i] = {0, 0, 0, 0, 0};
	for (int j = 0; j < _sz(vec[i]); j ++)
	  	C[i].cnt[(j + 1) % 5] += vec[i][j];
}

int32_t main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	while (n --){
		string s;
		cin >> s;

		if (s == "add"){
			int x; cin >> x;

			for (int i = 0; i < _sz(vec); i ++){
				if ((!i || vec[i][0] < x) && (i == _sz(vec) - 1 || vec[i + 1][0] > x)){
					vec[i].insert(upper_bound(vec[i].begin(), vec[i].end(), x), x);

					if (_sz(vec[i]) == 2 * SQ){
						vector <int> tmp;

					  	for (int t = 0; t < SQ; t ++){
							tmp.PB(vec[i].back());
							vec[i].pop_back();
						}
						reverse(tmp.begin(), tmp.end());

						C.insert(C.begin() + i + 1, {0, 0, 0, 0, 0});
						vec.insert(vec.begin() + i + 1, tmp);

						recalc(i + 1);
					}

					recalc(i);

				  	break;
				}
			}

			if (!_sz(vec)){
				vec.PB({x});
				C.PB({0, x, 0, 0, 0});
			}

/*		    for (int i = 0; i < _sz(vec); i ++){
				cout << i << ":  "; for (auto x: vec[i]) cout << x << ' ';
				cout << '\t'; for (int j = 0; j < 5; j ++) cout << C[i].cnt[j] << ' ';
				cout << endl;
			}
*/
		}
		else if (s == "del"){
		  	int x; cin >> x;
			for (int i = 0; i < _sz(vec); i ++)
				if (vec[i][0] <= x && vec[i].back() >= x){
					for (int j = 0; j < _sz(vec[i]); j ++)
						if (vec[i][j] == x){
							vec[i].erase(vec[i].begin() + j);
							break;
						}

					if (vec[i].empty()){
						vec.erase(vec.begin() + i);
						C.erase(C.begin() + i);
					}
					else recalc(i);
					break;
				}
		}
		else {
			int st = 0, res = 0;
			for (int i = 0; i < _sz(vec); i ++){
				res += C[i].cnt[(5 - st + 3) % 5];
			  	(st += _sz(vec[i])) %= 5;
			}

			cout << res << '\n';
		}
	}
}