//In the name of ALLAH
//Sum of Medians - 85D

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long llint;
#define err(x) cout << #x << " : " << x << '\n';

const int N = 100010, L = 320;

llint sum[L<<1][5];
int m, ndel = 0;
vector<int> vec[L<<1];

inline void upd(int& t){
	for (int i=0;i<5;i++) sum[t][i] = 0;
	for (int i=0;i<(int)vec[t].size();i++)
		sum[t][i % 5] += (llint)vec[t][i];
}

vector<int> tmp;
inline void relax(void){
	ndel = 0;
	tmp.resize(0);
	for (int i=0;i<m;i++){
		for (int j=0;j<(int)vec[i].size();j++)
			tmp.push_back(vec[i][j]);
		vec[i].resize(0);
	}
	m = 0;
	for (int i=0;i<(int)tmp.size();i++){
		vec[m].push_back(tmp[i]);
		if ((int)vec[m].size() >= L)
			++m;
	}
	m++;
	for (int i=0;i<m;i++)
		upd(i);
}

int main(){
	int n;
	scanf("%d",&n);

	char cmd[20];
	int x, idx, sz;
	llint ans;

	while (n--){
		scanf("%s",cmd);

		if (*cmd == 's'){
			sz = 0;
			ans = 0;
			for (int i=0;i<m;i++){
				ans += sum[i][(2 - (sz % 5) + 5)%5];
				sz += (int)vec[i].size();
			}
			printf("%I64d\n", ans);
		}
		else if (*cmd == 'a'){
			scanf("%d",&x);
			idx = 0;
			while (idx < m - 1 && vec[idx].back() < x)
				idx++;
			vec[idx].push_back(x);
			m = max(m, idx + 1);
			int j = (int)vec[idx].size() - 1;
			while (j && vec[idx][j] < vec[idx][j-1]){
				swap(vec[idx][j], vec[idx][j-1]);
				j--;
			}
			if ((int)vec[idx].size() >= 2 * L)
				relax();
			upd(idx);
		}
		else{
			++ndel;
			scanf("%d",&x);
			int i = 0;
			while (vec[i].back() < x)
				i++;
			vec[i].erase(find(vec[i].begin(), vec[i].end(), x));
			upd(i);
			if (ndel >= 2 * L)
				relax();
		}
	}

	return 0;
}


//In the name of ALLAH
//Sum of Medians - 85D

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long llint;
#define err(x) cout << #x << " : " << x << '\n';

const int N = 100010, L = 320;

llint sum[L<<3][5];
int m, ndel;
vector<int> vec[L<<3];

inline void upd(int& t){
	for (int i=0;i<5;i++) sum[t][i] = 0;
	for (int i=0;i<(int)vec[t].size();i++)
		sum[t][i % 5] += (llint)vec[t][i];
}

vector<int> tmp;
inline void relax(void){
	ndel = 0;
	tmp.resize(0);
	for (int i=0;i<m;i++)
		for (int j=0;j<(int)vec[i].size();j++)
			tmp.push_back(vec[i][j]);
	m = 0;
	for (int i=0;i<(int)tmp.size();i++){
		vec[m].push_back(tmp[i]);
		if ((int)vec[m].size() >= L)
			++m;
	}
	m++;
	for (int i=0;i<m;i++)
		upd(i);
}

int main(){
	int n;
	scanf("%d",&n);

	char cmd[20];
	int x, idx, sz;
	llint ans;

	while (n--){
		scanf("%s",cmd);

		if (*cmd == 's'){
			sz = 0;
			ans = 0;
			for (int i=0;i<m;i++){
				ans += sum[i][(2 - (sz % 5) + 5)%5];
				sz += (int)vec[i].size();
			}
			printf("%I64d\n", ans);
		}
		else if (*cmd == 'a'){
			scanf("%d",&x);
			idx = 0;
			while (idx < m - 1 && vec[idx].back() < x)
				idx++;
			vec[idx].push_back(x);
			m = max(m, idx + 1);
			int j = (int)vec[idx].size() - 1;
			while (j && vec[idx][j] < vec[idx][j-1]){
				swap(vec[idx][j], vec[idx][j-1]);
				j--;
			}
			if ((int)vec[idx].size() >= 2 * L)
				relax();
			upd(idx);
		}
		else{
			++ndel;
			scanf("%d",&x);
			int i = 0;
			while ((int)vec[i].size() == 0 || vec[i].back() < x)
				++i;
			vec[i].erase(find(vec[i].begin(), vec[i].end(), x));
			upd(i);
			if (ndel >= 2 * L)
				relax();
		}
	}

	return 0;
}


//In the name of ALLAH
//Sum of Medians - 85D

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long llint;
#define err(x) cout << #x << " : " << x << '\n';

const int N = 100010, L = 320;

llint sum[L<<3][5];
int m, ndel;
vector<int> vec[L<<3];

inline void upd(int& t){
	for (int i=0;i<5;i++) sum[t][i] = 0;
	for (int i=0;i<(int)vec[t].size();i++)
		sum[t][i % 5] += (llint)vec[t][i];
}

vector<int> tmp;
inline void relax(void){
	ndel = 0;
	tmp.resize(0);
	for (int i=0;i<m;i++)
		for (int j=0;j<(int)vec[i].size();j++)
			tmp.push_back(vec[i][j]);
	m = 0;
	for (int i=0;i<(int)tmp.size();i++){
		vec[m].push_back(tmp[i]);
		if ((int)vec[m].size() >= L)
			++m;
	}
	m++;
	for (int i=0;i<m;i++)
		upd(i);
}

int main(){
	int n;
	scanf("%d",&n);

	char cmd[20];
	int x, idx, sz;
	llint ans;

	while (n--){
		scanf("%s",cmd);

		if (*cmd == 's'){
			sz = 0;
			ans = 0;
			for (int i=0;i<m;i++){
				ans += sum[i][(2 - (sz % 5) + 5)%5];
				sz += (int)vec[i].size();
			}
			printf("%I64d\n", ans);
		}
		else if (*cmd == 'a'){
			scanf("%d",&x);
			idx = 0;
			while (idx < m - 1 && vec[idx].back() < x)
				idx++;
			vec[idx].push_back(x);
			m = max(m, idx + 1);
			int j = (int)vec[idx].size() - 1;
			while (j && vec[idx][j] < vec[idx][j-1]){
				swap(vec[idx][j], vec[idx][j-1]);
				j--;
			}
			if ((int)vec[idx].size() >= 2 * L)
				relax();
			upd(idx);
		}
		else{
			++ndel;
			scanf("%d",&x);
			int i = 0;
			while (vec[i].back() < x)
				++i;
			vec[i].erase(find(vec[i].begin(), vec[i].end(), x));
			if (vec[i].size() == 0 && i < m-1)
				relax();
		}
	}

	return 0;
}


//In the name of ALLAH
//Sum of Medians - 85D

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long llint;
#define err(x) cout << #x << " : " << x << '\n';

const int N = 100010, L = 320;

llint sum[L<<2][5];
int m, ndel;
vector<int> vec[L<<2];

inline void upd(int& t){
	for (int i=0;i<5;i++) sum[t][i] = 0;
	for (int i=0;i<(int)vec[t].size();i++)
		sum[t][i % 5] += (llint)vec[t][i];
}

vector<int> tmp;
inline void relax(void){
	ndel = 0;
	tmp.resize(0);
	for (int i=0;i<m;i++)
		for (int j=0;j<(int)vec[i].size();j++)
			tmp.push_back(vec[i][j]);
	m = 0;
	for (int i=0;i<(int)tmp.size();i++){
		vec[m].push_back(tmp[i]);
		if ((int)vec[m].size() >= L)
			++m;
	}
	m++;
	for (int i=0;i<m;i++)
		upd(i);
}

int main(){
	int n;
	scanf("%d",&n);

	char cmd[20];
	int x, idx, sz;
	llint ans;

	while (n--){
		scanf("%s",cmd);

		if (*cmd == 's'){
			sz = 0;
			ans = 0;
			for (int i=0;i<m;i++){
				ans += sum[i][(2 - (sz % 5) + 5)%5];
				sz += (int)vec[i].size();
			}
			printf("%I64d\n", ans);
		}
		else if (*cmd == 'a'){
			scanf("%d",&x);
			idx = 0;
			while (idx < m - 1 && vec[idx].back() < x)
				idx++;
			vec[idx].push_back(x);
			m= max(m, idx + 1);
			int j = (int)vec[idx].size() - 1;
			while (j && vec[idx][j] < vec[idx][j-1]){
				swap(vec[idx][j], vec[idx][j-1]);
				j--;
			}
			if ((int)vec[idx].size() >= 2 * L)
				relax();
			upd(idx);
		}
		else{
			++ndel;
			scanf("%d",&x);
			int i = 0;
			while (vec[i].back() < x)
				i++;
			//err(i);
			vec[i].erase(find(vec[i].begin(), vec[i].end(), x));
			upd(i);
			if (ndel >= 2 * L)
				relax();
		}
	}

	return 0;
}


//In the name of ALLAH
//Sum of Medians - 85D

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long llint;
#define err(x) cout << #x << " : " << x << '\n';

const int N = 100010, L = 320;

llint sum[L<<3][5];
int m, ndel;
vector<int> vec[L<<3];

inline void upd(int& t){
	for (int i=0;i<5;i++) sum[t][i] = 0;
	for (int i=0;i<(int)vec[t].size();i++)
		sum[t][i % 5] += (llint)vec[t][i];
}

vector<int> tmp;
inline void relax(void){
	ndel = 0;
	tmp.resize(0);
	for (int i=0;i<m;i++)
		for (int j=0;j<(int)vec[i].size();j++)
			tmp.push_back(vec[i][j]);
	m = 0;
	for (int i=0;i<(int)tmp.size();i++){
		vec[m].push_back(tmp[i]);
		if ((int)vec[m].size() >= L)
			++m;
	}
	m++;
	for (int i=0;i<m;i++)
		upd(i);
}

int main(){
	int n;
	scanf("%d",&n);

	char cmd[20];
	int x, idx, sz;
	llint ans;

	while (n--){
		scanf("%s",cmd);

		if (*cmd == 's'){
			sz = 0;
			ans = 0;
			for (int i=0;i<m;i++){
				ans += sum[i][(2 - (sz % 5) + 5)%5];
				sz += (int)vec[i].size();
			}
			printf("%I64d\n", ans);
		}
		else if (*cmd == 'a'){
			scanf("%d",&x);
			idx = 0;
			while (idx < m - 1 && vec[idx].back() < x)
				idx++;
			vec[idx].push_back(x);
			m = max(m, idx + 1);
			int j = (int)vec[idx].size() - 1;
			while (j && vec[idx][j] < vec[idx][j-1]){
				swap(vec[idx][j], vec[idx][j-1]);
				j--;
			}
			if ((int)vec[idx].size() >= 2 * L)
				relax();
			upd(idx);
		}
		else{
			++ndel;
			scanf("%d",&x);
			int i = 0;
			while (vec[i].back() < x)
				++i;
			vec[i].erase(find(vec[i].begin(), vec[i].end(), x));
			if (vec[i].size() == 0 && i < m-1)
				relax();
			else upd(i);
		}
	}

	return 0;
}


//In the name of ALLAH
//Sum of Medians - 85D

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long llint;
#define err(x) cout << #x << " : " << x << '\n';

const int N = 100010, L = 320;

llint sum[L<<3][5];
int m, ndel;
vector<int> vec[L<<3];

inline void upd(int& t){
	for (int i=0;i<5;i++) sum[t][i] = 0;
	for (int i=0;i<(int)vec[t].size();i++)
		sum[t][i % 5] += (llint)vec[t][i];
}

vector<int> tmp;
inline void relax(void){
	ndel = 0;
	tmp.resize(0);
	for (int i=0;i<m;i++)
		for (int j=0;j<(int)vec[i].size();j++)
			tmp.push_back(vec[i][j]);
	m = 0;
	for (int i=0;i<(int)tmp.size();i++){
		vec[m].push_back(tmp[i]);
		if ((int)vec[m].size() >= L)
			++m;
	}
	m++;
	for (int i=0;i<m;i++)
		upd(i);
}

int main(){
	int n;
	scanf("%d",&n);

	char cmd[20];
	int x, idx, sz;
	llint ans;

	while (n--){
		scanf("%s",cmd);

		if (*cmd == 's'){
			sz = 0;
			ans = 0;
			for (int i=0;i<m;i++){
				ans += sum[i][(2 - (sz % 5) + 5)%5];
				sz += (int)vec[i].size();
			}
			printf("%I64d\n", ans);
		}
		else if (*cmd == 'a'){
			scanf("%d",&x);
			idx = 0;
			while (idx < m - 1 && vec[idx].back() < x)
				idx++;
			vec[idx].push_back(x);
			int j = (int)vec[idx].size() - 1;
			while (j && vec[idx][j] < vec[idx][j-1]){
				swap(vec[idx][j], vec[idx][j-1]);
				j--;
			}
			if ((int)vec[idx].size() >= 2 * L)
				relax();
			upd(idx);
		}
		else{
			++ndel;
			scanf("%d",&x);
			int i = 0;
			while (true){
				if ((int)vec[i].size() == 0) i++;
				else if (vec[i].back() >= x) break;
				else i++;
			}
			vec[i].erase(find(vec[i].begin(), vec[i].end(), x));
			upd(i);
			if (ndel >= 2 * L)
				relax();
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

const int MAXN=100010;
struct tree{
	int cnt;
	ll w[6];
	int l,r,tag;
}t[4*MAXN];
struct commen{
	string typ;
	ll k;
} cm[MAXN];
int N;
int room[MAXN]={0};
int numcnt=0;

void build_tree(int p,int l,int r){
	t[p].l=l;t[p].r=r;
	t[p].cnt=0;t[p].tag=0;
	for(int i=1;i<=5;i++) t[p].w[i]=0;
	if(l==r){
		return;
	}
	int mid=(l+r)>>1;
	build_tree(p*2,l,mid);build_tree(p*2+1,mid+1,r);
}

int mov(int x,ll k){
	k=(k%5+5)%5;
    x=(x+k-1)%5+1;
    return x;
}

void download(int p){
	t[p*2].tag+=t[p].tag;
	t[p*2+1].tag+=t[p].tag;
	ll tmp[2][6];
	for(int i=1;i<=5;i++){
		tmp[0][mov(i,t[p].tag)]=t[p*2].w[i];
		tmp[1][mov(i,t[p].tag)]=t[p*2+1].w[i];
	}
	for(int i=1;i<=5;i++){
		t[p*2].w[i]=tmp[0][i];
		t[p*2+1].w[i]=tmp[1][i];
	}
	t[p].tag=0;
}

void move(int p,int l,int r,int s){
	if(l<=t[p].l&&t[p].r<=r){
	    t[p].tag+=s;
	    ll tmp[6];
	    for(int i=1;i<=5;i++) tmp[mov(i,s)]=t[p].w[i];
	    for(int i=1;i<=5;i++) t[p].w[i]=tmp[i];
	    return;
	}
	download(p);
	int mid=(t[p].l+t[p].r)>>1;
	if(l<=mid) move(p*2,l,r,s);
	if(r>=mid+1) move(p*2+1,l,r,s);
}

void add(int p,int id,int pnt,ll k){
	if(t[p].l==t[p].r){
	    t[p].w[id]+=k;
	    t[p].cnt++;
	    return;
	}
    download(p);
    int mid=(t[p].l+t[p].r)>>1;
    if(pnt<=mid) add(p*2,id,pnt,k);
    if(pnt>=mid+1) add(p*2+1,id,pnt,k);
    for(int i=1;i<=5;i++) t[p].w[i]=t[p*2].w[i]+t[p*2+1].w[i];
    t[p].cnt=t[p*2].cnt+t[p*2+1].cnt;
}

void del(int p,int id,int pnt,ll k){
	if(t[p].l==t[p].r){
	    t[p].w[id]-=k;
	    t[p].cnt--;
	    return;
	}
    download(p);
    int mid=(t[p].l+t[p].r)>>1;
    if(pnt<=mid) del(p*2,id,pnt,k);
    if(pnt>=mid+1) del(p*2+1,id,pnt,k);
    for(int i=1;i<=5;i++) t[p].w[i]=t[p*2].w[i]+t[p*2+1].w[i];
    t[p].cnt=t[p*2].cnt+t[p*2+1].cnt;
}

ll ask(int p,int l,int r){
	if(l<=t[p].l&&t[p].r<=r){
		return t[p].cnt;
	}
	ll ans=0;
	int mid=(t[p].l+t[p].r)>>1;
	if(l<=mid) ans+=ask(p*2,l,r);
	if(r>=mid+1) ans+=ask(p*2+1,l,r);
	return ans;
}

bool cmp(int a,int b){
	return a<b;
}

int found(int k){
	int l=1,r=N,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(room[mid]==k){
			return mid;
		}
		if(room[mid]>k){
			r=mid-1;
		}
		if(room[mid]<k){
			l=mid+1;
		}
	}
}

void prepare(){
	cin>>N;
	string tmp;
	for(int i=1;i<=N;i++){
		cin>>cm[i].typ;
		if(cm[i].typ=="add"){
			scanf("%d",&cm[i].k);
			room[++numcnt]=cm[i].k;
		}
		if(cm[i].typ=="del"){
			scanf("%d",&cm[i].k);
		}
	}
	sort(room+1,room+1+numcnt,cmp);
	build_tree(1,1,numcnt);
}

void solve(){
	int pnt,id,k;
	for(int i=1;i<=N;i++){
		if(cm[i].typ=="sum"){
			printf("%lld\n",t[1].w[3]);
		}
		if(cm[i].typ=="add"){
			k=cm[i].k;
			pnt=found(k);
			move(1,pnt+1,numcnt,1);
			id=ask(1,1,pnt-1)%5+1;
			add(1,id,pnt,k);
		}
		if(cm[i].typ=="del"){
			k=cm[i].k;
			pnt=found(k);
			move(1,pnt+1,numcnt,-1);
			id=ask(1,1,pnt-1)%5+1;
			del(1,id,pnt,k);
		}
	}
}

int main(){
	prepare();
	solve();
}


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
vector <int> v;
int n;
void solve(){
    scanf("%d",&n);
    while(n--){
        int x;
        char op[3];
        scanf("%s",op);
        if(op[0]=='a'){
            scanf("%d",&x);
            v.insert(lower_bound(v.begin(),v.end(),x),x);
        }
        if(op[0]=='d'){
            int x;
            scanf("%d",&x);
            v.erase(lower_bound(v.begin(),v.end(),x));
        }
        if(op[0]=='s'){
            long long ans=0;//一定要开long long，否则会卡在90分
            for(int i=2;i<v.size();i+=5)
                    ans+=v[i];
            printf("%lld\n",ans);
        }
    }
}
int main(){
    solve();
    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#define ll long long

using namespace std;

vector<int > V;

int n;
int q;
ll ans;
string s;

int main(){
    cin >> n;
    for(int qwq = 1; qwq <= n; qwq ++){
        cin >> s;
        if(s == "add"){
            cin >> q;
            V.insert(lower_bound(V.begin() , V.end() , q) , q);
        }
        else if(s == "del"){
            cin >> q;
            V.erase(lower_bound(V.begin() , V.end() , q));
        }
        else{
           for(int i = 2; i < V.size(); i = i + 5){
               ans = ans + V[i];
           }
           cout << ans << endl;
           ans = 0;
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
const int N=1e5+10;
char s[10];
ll tmp[N];
struct tree
{
	int left,right;
	int cnt; ll val[7];
}t[4*N];
struct query
{
	int type; ll num;
}q[N];
inline void build(int p,int l,int r)
{
	t[p].left=l,t[p].right=r;
	if(l==r) return;
	int mid=(t[p].left+t[p].right)/2;
	build(p*2,l,mid);
	build(p*2+1,mid+1,r);
}
inline void pushup(int p)
{
	for(int i=0;i<=4;i++)
		t[p].val[i]=t[p*2].val[i]+t[p*2+1].val[((i-t[p*2].cnt)%5+5)%5];
	t[p].cnt=(t[p*2].cnt+t[p*2+1].cnt)%5;
}
inline void change(int p,int pos,ll num)
{
	if(t[p].left==t[p].right)
	{
		t[p].val[1]=num;
		t[p].cnt=(t[p].val[1]>0);
		return;
	}
	int mid=(t[p].left+t[p].right)/2;
	if(pos<=mid) change(p*2,pos,num);
	else change(p*2+1,pos,num);
	pushup(p);
}
int main()
{
	int n,m=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s);
		if(s[0]=='a')
		{
			scanf("%lld",&q[i].num);
			q[i].type=1,tmp[++m]=q[i].num;
		}
		if(s[0]=='d')
		{
			scanf("%lld",&q[i].num);
			q[i].type=2,tmp[++m]=q[i].num;
		}
		if(s[0]=='s') q[i].type=3;
	}
	sort(tmp+1,tmp+m+1);
	m=unique(tmp+1,tmp+m+1)-(tmp+1);
	build(1,1,m);
	for(int i=1;i<=n;i++)
	{
		if(q[i].type<3)
		{
			int pos=lower_bound(tmp+1,tmp+m+1,q[i].num)-tmp;
			if(q[i].type==1) change(1,pos,q[i].num);
			else change(1,pos,0);
		}
		else printf("%lld\n",t[1].val[3]);
	}
	return 0;
}


#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
using namespace std;

int n;
vector<long long> ji;

int main() {
	cin >> n;
	ji.push_back(-1);
	for (int i = 1;i <= n;i ++) {
		string a;
		long long b;
		cin >> a;
		if (a[0] == 'a') {
			cin >> b;
			ji.push_back(b);
		}
		if (a[0] == 's') {
			sort(ji.begin(), ji.end());
			long long sum = 0;
			for (int j = 3;j < ji.size();j += 5) {
				sum += ji[j];
			}
			cout << sum << endl;
		}
		if (a[0] == 'd') {
			cin >> b;
			sort(ji.begin(), ji.end());
			ji.erase(lower_bound(ji.begin(), ji.end(), b));
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;

typedef long long ll;

struct Node{
	int v, size, fix;
	ll sum[5];
	Node *left, *right;
	Node(){}
	Node(int _v, Node *l = NULL, Node *r = NULL){
		v = _v, fix = rand(), left = l, right = r;
	}
	int lsize(){return left == NULL ? 0 : left->size;}
	int rsize(){return right == NULL ? 0 : right->size;}
	void Push_up(){
		memset(sum, 0, sizeof(sum));
		size = 0;
		if (left != NULL){
			for (int i = 0; i < 5; i++){
				sum[i] = left->sum[i];
			}
		}
		size = lsize(), sum[size % 5] += v, size++;
		if (right != NULL){
			for (int i = 0; i < 5; i++){
				sum[(size + i) % 5] += right->sum[i];
			}
		}
		size += rsize();
	}
}*T = NULL;

typedef pair <Node*, Node*> pnn;

Node *merge(Node *l, Node *r){
	if (l == NULL || r == NULL){
		return l == NULL ? r : l;
	}
	if (l->fix < r->fix){
		l->right = merge(l->right, r);
		l->Push_up();
		return l;
	}
	r->left = merge(l, r->left);
	r->Push_up();
	return r;
}

pnn split(Node *T, int v){
	if (T == NULL) return mp<Node*, Node*>(NULL, NULL);
	if (v > T->v){
		pnn t = split(T->right, v);
		Node *l = T, *r = t.se;
		l->right = t.fi, l->Push_up();
		return mp(l, r);
	}
	pnn t = split(T->left, v);
	Node *l = t.fi, *r = T;
	r->left = t.se, r->Push_up();
	return mp(l, r);
}

void add(int x){
	pnn t = split(T, x);
	T = merge(t.fi, merge(new Node(x), t.se));
}

void del(int x){
	pnn t1 = split(T, x);
	pnn t2 = split(t1.se, x + 1);
	if (t2.fi != NULL) delete t2.fi;
	T = merge(t1.fi, t2.se);
}

ll sum(){
	return T == NULL ? 0 : T->sum[2];
}

char buf[10];

string read(){
	scanf("%s", buf);
	return buf;
}

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		string op = read();
		int x;
		if (op == "add"){
			scanf("%d", &x);
			add(x);
		}
		if (op == "del"){
			scanf("%d", &x);
			del(x);
		}
		if (op== "sum"){
			printf("%I64d\n", sum());
		}
	}
	return 0;
}


#include <iostream>
#include <string.h>
#include <algorithm>
#define ll long long
using namespace std;
ll n,x;
ll tree[800005][5],add[400005],pan[400005],shu[400005],haha[400005],id[400005];
ll num[800005];
char a[10];
inline ll read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int ls(int k)
{
	return k<<1;
}
int rs(int k)
{
	return k<<1|1;
}
void push_up(int i)
{
	num[i]=num[ls(i)]+num[rs(i)];
	for(int j=0;j<=4;j++)
	{
		tree[i][j]=tree[ls(i)][j]+tree[rs(i)][((j-num[ls(i)])%5+5)%5];
	}
 }
void in(int left,int right,int i,int wei,int wor,int sum)
{
	if(left==right)
	{
		tree[i][1]+=wor;
		num[i]+=sum;
		return;
	}
	else
	{
		int mid=(left+right)/2;
		if(wei<=mid) in(left,mid,ls(i),wei,wor,sum);
		else in(mid+1,right,rs(i),wei,wor,sum);
		push_up(i);
	}
}
int main()
{
	ll cnt=0;
	n=read();
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		if(a[0]=='a')
		{
			x=read();
			add[++cnt]=x;
			shu[i]=x;
			pan[i]=1;
		}
		if(a[0]=='d')
		{
			x=read();
			shu[i]=x;
			pan[i]=-1;
		}
		if(a[0]=='s')
		{
			haha[i]=1;
		}
	 } //离线
	 sort(add+1,add+cnt+1);
	 ll sum=1;
	 for(int i=1;i<=cnt;i++)
	 {
	 	id[add[i]]=sum;
	 	sum++;
	 }//离散化
	 for(int i=1;i<=n;i++)
	 {
	 	if(haha[i]==1) cout<<tree[1][3]<<endl;
	 	else
	 	{
	 		in(1,n,1,id[shu[i]],pan[i]*shu[i],pan[i]);
		 }
	 }
	 return 0;
}


#pragma region Header
#include <cmath>
#include <bitset>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <ctime>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;
#define INF 0x3F3F3F3F
#define FINF 0xC0C0C0C0
#define llINF 0x3F3F3F3F3F3F3F3FLL
#define llFINF 0xC0C0C0C0C0C0C0C0LL
#define RG register
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int UINT;
#define Clear(x) memset(x,0,sizeof(x));
#ifdef _DEBUG
#define DEBUG(str,...) fprintf(stderr,str,__VA_ARGS__)
#define DEBUGX(exp) exp
#else
#define _ASSERTE(...) (void)(0)
#define DEBUG(str,...)(int)(0)
#define DEBUGX(exp)
//#define freopen(...)(void)(0)
#endif
int linecnt;
inline int read() {
	int re = 0, fh = 1;
	char c = getchar();
	while (c > '9' || c < '0') {
		if (c == '\n')++linecnt;
		if (c == -1)return -1;
		if (c == '-')fh = -1; c = getchar();
	}
	while (c >= '0' && c <= '9') {
		re = re * 10 + c - '0'; c = getchar();
	}
	if (c == '\n')++linecnt;
	return re * fh;
}
//struct OutPutS {
//#define putchar(c) (*(_out.p++)=(c))
//	char buf[10000000];
//	char* p;
//	OutPutS() { p = buf; }
//	~OutPutS() { fwrite(buf, 1, p - buf, stdout); }
//}_out;
template<class T>
inline void write(T x) {
	if (x == 0)return (void)putchar('0');
	if (x < 0)putchar('-'), x = -x;
	static char buf[30];
	char* p = buf;
	while (x) {
		*(p++) = x % 10 + '0';
		x /= 10;
	}
	while (p > buf)putchar(*(--p));
}
inline void writestr(const char* s) { while (*s != 0)putchar(*(s++)); }
inline char readstr(char* s) {
	char c = getchar();
	while (c < 33 || c>126)c = getchar();
	while (c > 32 && c < 127) {
		*(s++) = c;
		c = getchar();
	}
	*s = 0;
	return c;
}
#pragma endregion

#define N 100100
#define LP (p<<1)
#define RP (p<<1|1)
#define LT LP,l,mid
#define RT RP,mid+1,r
constexpr LL HASH(const char* s) {
	LL ret = 0;
	while (*s != 0)
		ret = ret * 1331 + *(s++);
	return ret;
}
int sum[N][5];
int cnt[N];
int tag_mov[N];
int n;
inline void MOV(int p, int x) {
	if (x == 0)return;
	static int tmp[5];
	int* now = sum[p]; x = (x + 5) % 5;
	tag_mov[p] = (tag_mov[p] + x) % 5;
	for (int i = 0; i < 5; i++)tmp[i] = now[i];
	for (int i = 0; i < 5; i++)now[(i + x) % 5] = tmp[i];
}
inline void update(int p) {
	for (int i = 0; i < 5; i++)
		sum[p][i] = sum[LP][i] + sum[RP][i];
	cnt[p] = cnt[LP] + cnt[RP];
}
inline void pushdown(int p) {
	if (tag_mov[p] == 0)return;
	MOV(LP, tag_mov[p]);
	MOV(RP, tag_mov[p]);
	tag_mov[p] = 0;
}
int num[N];
int getx(int old) {
	return lower_bound(num + 1, num + 1 + num[0], old) - num;
}
void insert(int p, int l, int r, int pos, int realpos) {
	if (l == r) {
		memset(sum[p], 0, sizeof(sum[p]));
		sum[p][realpos % 5] = num[pos];
		cnt[p] = 1;
		return;
	}
	pushdown(p);
	int mid = (l + r) >> 1;
	if (pos <= mid)insert(LT, pos, realpos);
	else insert(RT, pos, realpos + cnt[LP]);
	update(p);
}
void remove(int p, int l, int r, int pos) {
	if (l == r)
		return (void)(memset(sum[p], 0, sizeof(sum[p])), cnt[p] = 0);
	pushdown(p);
	int mid = (l + r) >> 1;
	if (pos <= mid)remove(LT, pos);
	else remove(RT, pos);
	update(p);
}
void move(int p, int l, int r, int x, int y, int v) {
	if (l >= x && r <= y)return MOV(p, v);
	pushdown(p);
	int mid = (l + r) >> 1;
	if (x <= mid)move(LT, x, y, v);
	if (y > mid)move(RT, x, y, v);
	update(p);
}
void insert(int v) {
	int pos = getx(v);
	move(1, 1, n, pos + 1, n, 1);
	insert(1, 1, n, pos, 1);
}
void remove(int v) {
	int pos = getx(v);
	move(1, 1, n, pos + 1, n, -1);
	remove(1, 1, n, pos);
}
char buff[16];
struct Query {
	int o, x;
}q[N];
int main() {
	n = read();
	for (int i = 1; i <= n; i++) {
		readstr(buff);
		switch (HASH(buff)) {
		case HASH("add"):
			q[i].o = 1; num[++num[0]] = q[i].x = read(); break;
		case HASH("del"):
			q[i].o = 2; num[++num[0]] = q[i].x = read(); break;
		case HASH("sum"):
			q[i].o = 3; break;
		}
	}
	sort(num + 1, num + 1 + num[0]);
	num[0] = unique(num + 1, num + 1 + num[0]) - num - 1;
	for (int i = 1; i <= n; i++) {
		switch (q[i].o) {
		case 1:insert(q[i].x);break;
		case 2:remove(q[i].x);break;
		case 3:printf("%d\n", sum[1][3]);break;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int>x,tmp;
int n;
void add(){
	int a;
	cin>>a;
	x.push_back(a);
}
void del(){
	int a;
	cin>>a;
	tmp.clear();
	for(int i=0;i<x.size();i++)if(x[i]!=a)tmp.push_back(x[i]);
	x=tmp;
}
long long sum(){
	sort(x.begin(),x.end());
	long long ans=0;
	for(int i=0;i*5+2<x.size();i++)
		ans=ans+x[i*5+2];
	return ans;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(s=="add")add();
		if(s=="del")del();
		if(s=="sum")printf("%I64d",sum());
	}
}


#include<bits/stdc++.h>
#define F(i,a,b,c) for(int i=(a);(b);i=(c))
#define Fu(i,a,b) F(i,(a),i<=(b),i+1)
#define Fd(i,a,b) F(i,(a),i>=(b),i-1)
typedef long long LL;char Ch;int Fl;
template<typename T>void in(T&x){Fl=1,Ch=getchar(),x=0;while(!isdigit(Ch)&&Ch!=EOF)Fl=(Ch=='-')?-1:1,Ch=getchar();if(Ch==EOF)return;while(isdigit(Ch))x=x*10+Ch-'0',Ch=getchar();x*=Fl;}
template<typename T,typename...Args>void in(T&x,Args&...args){in(x);in(args...);}
using namespace std;
vector<int>v;
#define add(x) v.insert(lower_bound(v.begin(),v.end(),(x)),(x))
#define del(x) v.erase(lower_bound(v.begin(),v.end(),(x)))
LL sum(){LL res=0;F(i,2,i<v.size(),i+5)res+=v[i];return res;}
int m,x;char op;
int main()
{
	in(m);
	while(m--)
	{
		while(!isalpha(op=getchar()));
		if(op=='a')in(x),add(x);
		if(op=='d')in(x),del(x);
		if(op=='s')printf("%lld\n",sum());
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int Read()
{
	int crfzz=0;char a=getchar();
	while(!isdigit(a)) a=getchar();
	while(isdigit(a)) crfzz=(crfzz<<1)+(crfzz<<3)+a-48,a=getchar();
	return crfzz;
}
inline void Print(long long k)
{
	if(k>9) Print(k/10);
	putchar(k%10+48);
}
string k;
vector<int>jl;int nn,n;
short crf_has_no_jj;
int main()
{
	nn=Read();
	while(nn--)
	{
		cin>>k;
		if(k=="add")
		{
			n=Read();
			jl.insert(lower_bound(jl.begin(),jl.end(),n),n);
		}
		if(k=="del")
		{
			n=Read();
			jl.erase(lower_bound(jl.begin(),jl.end(),n));
		}
		if(k=="sum")
		{
			crf_has_no_jj=0;
			for(int i=2;i<=jl.size();i+=5)
			{
				crf_has_no_jj+=jl[i];
			}
			Print(crf_has_no_jj);
			putchar(10);
		}
	}
}


#include <iostream>
#include <string.h>
#include <algorithm>
#define ll long long
using namespace std;
ll n,x;
ll tree[800005][10],add[100005],pan[100005],shu[100005],haha[100005],id[100005];
ll num[800005];
char a[10];
inline ll read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int ls(int k)
{
	return k<<1;
}
int rs(int k)
{
	return k<<1|1;
}
void push_up(int i)
{
	num[i]=num[ls(i)]+num[rs(i)];
	for(int j=0;j<=4;j++)
	{
		tree[i][j]=tree[ls(i)][j]+tree[rs(i)][((j-num[ls(i)])%5+5)%5];
	}
 }
void in(int left,int right,int i,int wei,int wor,int sum)
{
	if(left==right)
	{
		tree[i][1]+=wor;
		num[i]+=sum;
		return;
	}
	else
	{
		int mid=(left+right)/2;
		if(wei<=mid) in(left,mid,ls(i),wei,wor,sum);
		else in(mid+1,right,rs(i),wei,wor,sum);
		push_up(i);
	}
}
int main()
{
	ll cnt=0;
	n=read();
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		if(a[0]=='a')
		{
			x=read();
			add[++cnt]=x;
			shu[i]=x;
			pan[i]=1;
		}
		if(a[0]=='d')
		{
			x=read();
			shu[i]=x;
			pan[i]=-1;
		}
		if(a[0]=='s')
		{
			haha[i]=1;
		}
	 } //离线
	 sort(add+1,add+cnt+1);
	 ll sum=1;
	 for(int i=1;i<=cnt;i++)
	 {
	 	id[add[i]]=sum;
	 	sum++;
	 }//离散化
	 for(int i=1;i<=n;i++)
	 {
	 	if(haha[i]==1) cout<<tree[1][3]<<endl;
	 	else
	 	{
	 		in(1,n,1,id[shu[i]],pan[i]*shu[i],pan[i]);
		 }
	 }
	 return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#define pp (p<<1)
#define ppp (p<<1|1)
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define REP(a,b,c) for(long long a=b;a<=c;a++)
#define PER(a,b,c) for(long long a=b;a>=c;a--)
#define ll long long
#define lb(a) (a&(-a))
using namespace std;
const long long MAXN=1e6+5;
long long n,m,t;
char s[MAXN];
long long yi[MAXN];
long long sum[MAXN][7];
vector<long long>v;
long long get(long long x)
{
    return lower_bound(v.begin(),v.end(),x)-v.begin()+1;
}
void push_up(long long p)
{
    yi[p]=yi[pp]+yi[ppp];
    REP(i,1,5)sum[p][i]=sum[pp][i]+sum[ppp][(i-yi[pp]+9)%5+1];
}
void update1(long long p,long long l,long long r,long long x,long long val)
{
    if(l==r){sum[p][1]+=val,yi[p]=yi[p]%5+1;return;}

    long long mid=l+r>>1;
    if(x<=mid)update1(pp,l,mid,x,val);
    else update1(ppp,mid+1,r,x,val);
    push_up(p);
}
void update2(long long p,long long l,long long r,long long x,long long val)
{
    if(l==r){sum[p][1]-=val,yi[p]=(yi[p]+3)%5+1;return;}

    long long mid=l+r>>1;
    if(x<=mid)update2(pp,l,mid,x,val);
    else update2(ppp,mid+1,r,x,val);
    push_up(p);
}
struct NODE
{
    char s[5];
    long long a;
}op[MAXN];
int main()
{
    cin>>n;
    REP(i,1,n)
    {
        cin>>op[i].s+1;
        if(op[i].s[1]=='a'||op[i].s[1]=='d')cin>>op[i].a,v.push_back(op[i].a);
    }
    sort(v.begin(),v.end()),v.erase(unique(v.begin(),v.end()),v.end());
    REP(i,1,n)
    {
        if(op[i].s[1]=='a')update1(1,1,v.size(),get(op[i].a),op[i].a);
        else if(op[i].s[1]=='d')update2(1,1,v.size(),get(op[i].a),op[i].a);
        else cout<<sum[1][3]<<endl;
    }
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int m;
struct nd
{
    int l,r;
    ll num;
    ll a[5];
}t[400010];
int tmp[100010];
int cnt=0;
void pu(int now)
{
    t[now].num=t[2*now].num+t[2*now+1].num;
    for(int i=0;i<=4;i++)
    {
        t[now].a[i]=0;
    }
    int d=t[2*now].num%5;
    for(int i=0;i<=4;i++)
    {
        t[now].a[i]+=t[2*now].a[i];
        t[now].a[i]+=t[2*now+1].a[(i-d+5)%5];
    }
    return;

}
struct nd2
{
    int id;
    int opt;
    int num;
    int nn;
}q[100010];
bool cmp1(nd2 x,nd2 y)
{
    if(x.opt!=y.opt)
    {
        return x.opt<y.opt;
    }
    else
    {
        return x.num<y.num;
    }
}
bool cmp2(nd2 x,nd2 y)
{
    return x.id<y.id;
}
int tot;
void bt(int l,int r,int now)
{
    t[now].l=l;
    t[now].r=r;
    if(r<l) return;
    if(l==r)
    {
        return;
    }
    int mid=(l+r)/2;
    bt(l,mid,2*now);
    bt(mid+1,r,2*now+1);
    return;
}
void modify(int now,int pos,ll adi)
{
    if(t[now].l==t[now].r)
    {
        t[now].num=1;
        t[now].a[1]=adi;
        return;
    }
    int mid=(t[now].l+t[now].r)/2;
    if(pos<=mid) modify(2*now, pos, adi);
    if(pos>mid) modify(2*now+1, pos, adi);
    pu(now);
    return;
}
void del(int now,int pos)
{
    if(t[now].l==t[now].r)
    {
        t[now].num=0;
        t[now].a[1]=0;
        return;
    }
    int mid=(t[now].l+t[now].r)/2;
    if(pos<=mid) del(2*now,pos);
    if(pos>mid) del(2*now+1,pos);
    pu(now);
    return;
}
int main()
{
    cin>>m;
    for(int i=1;i<=m;i++)
    {
        string s;
        cin>>s;
        if(s=="add")
        {
            int adm;
            cin>>adm;
            tot++;
            q[tot].id=i;
            q[tot].opt=1;
            q[tot].num=adm;
        }
        if(s=="del")
        {
            int delm;
            cin>>delm;
            tot++;
            q[tot].id=i;
            q[tot].opt=2;
            q[tot].num=delm;
        }
        if(s=="sum")
        {
            tot++;
            q[tot].id=i;
            q[tot].opt=3;
        }
    }
    sort(q+1,q+tot+1,cmp1);
    for(int i=1;;i++)
    {
        if(q[i].opt==2||q[i].opt==3)
        {
            break;
        }
        if(q[i].num==q[i-1].num)
        {
            q[i].nn=q[i-1].nn;
        }
        cnt++;
        tmp[cnt]=q[i].num;
        q[i].nn=cnt;
    }
    bt(1, cnt, 1);
    sort(q+1, q+tot+1, cmp2);
    for(int i=1;i<=m;i++)
    {
        if(q[i].opt==1)
        {
            modify(1,q[i].nn,q[i].num);
        }
        if(q[i].opt==2)
        {
            del(1, q[i].nn);
        }
        if(q[i].opt==3)
        {
            cout<<t[1].a[3]<<endl;
        }
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
struct S
{
	char op[5];
	int x,id;
}e[100005];
template<typename T>
void write(T x)
{
    if(x<0){
        putchar('-');
        x=-x;
    }
    if(x>9)
        write(x/10);
    putchar(x%10+'0');
    return;
}
template<typename T>
inline void read(T &x)
{
    x=0;
    int f=1;
    char ch=getchar();
    while (!isdigit(ch))
    {
        if(ch == '-')f=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        x=x*10+(ch^48);
        ch=getchar();
    }
    x*=f;
    return;
}
bool cmpval(S a,S b){
	if(a.x==b.x)return a.op[0]<b.op[0];
	return a.x<b.x;
}
bool cmpid(S a,S b){
	return a.id<b.id;
}
int n,cnt,val[100005],num[400005];
long long sum[400005][5];
void build(int idx,int s,int e)
{
	if(s!=e)
	{
		int mid=(s+e)>>1;
		build(idx<<1,s,mid);
		build(idx<<1|1,mid+1,e);
	}
	num[idx]=0;
	for(int i=0; i<5; i++) sum[idx][i]=0;
}
void update(int idx,int s,int e,int pos,int flag)
{
	num[idx]+=flag;
	if(s==e){
		sum[idx][1]+=val[s]*flag;
		return;}
	int mid=(s+e)>>1;
	if(pos<=mid) update(idx<<1,s,mid,pos,flag);
	else update(idx<<1|1,mid+1,e,pos,flag);
	for(int i=0; i<5; i++) sum[idx][i]=sum[idx<<1][i]+sum[idx<<1|1][i-num[idx<<1]%5>=0?i-num[idx<<1]%5:i-num[idx<<1]%5+5]; //更新对应区间内下标为模5等于i数的和
}
long long query(int idx,int s,int e,int mod){
	return sum[idx<<1][mod]+sum[idx<<1|1][mod-num[idx<<1]%5>=0?mod-num[idx<<1]%5:mod-num[idx<<1]%5+5];}
int main()
{
	int i;
	long long ans;
	while(~scanf("%d",&n))
	{
		map<int,int>mp;
		for(i=0; i<n; i++)
		{
			scanf("%s",e[i].op);
			if(e[i].op[0]=='s') e[i].x=0;
			else read(e[i].x);

			e[i].id=i;
		}
		sort(e,e+n,cmpval);
		cnt=1;
		for(i=0; i<n; i++)
		{
			if(e[i].op[0]=='a')
			{
				if(!mp[e[i].x]) mp[e[i].x]=cnt++;

				val[mp[e[i].x]]=e[i].x;
				e[i].x=mp[e[i].x];

			}
			else if(e[i].op[0]=='d')
			{
				e[i].x=mp[e[i].x];
			}
		}
		sort(e,e+n,cmpid);
		cnt--;
		if(!cnt)
		{
			for(i=0; i<n; i++)
			{
				if(e[i].op[0]=='s')
				{
					printf("0\n");
				}
			}

			continue;
		}
		build(1,1,cnt);
		for(i=0; i<n; i++)
		{
			if(e[i].op[0]=='a') update(1,1,cnt,e[i].x,1);
			else if(e[i].op[0]=='d') update(1,1,cnt,e[i].x,-1);
			else
			{
				write(query(1,1,n,3));
				printf("\n");
			}
		}
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#define LL long long
#define rg register
#define us unsigned
#define eps 1e-6
#define INF 0x3f3f3f3f
#define ls k<<1
#define rs k<<1|1
#define tmid ((tr[k].l+tr[k].r)>>1)
#define nmid ((ll+rr)>>1)
#define Thispoint tr[k].l==tr[k].r
#define pushup tr[k].wei=tr[ls].wei+tr[rs].wei
using namespace std;
inline void Read(int &x){
	int f=1;
	char c=getchar();
	x=0;
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	x*=f;
}
inline void Print(int x){
	if(x<0){
		x=~(x-1);
		putchar('-');
	}
	if(x>9)Print(x/10);
	putchar(x%10+'0');
}
int n;
#define N 114514
struct Operating {
	int opt,num;
}op[N];
struct Node {
	int l,r,wei;
	LL sum[5];
}tr[N<<2];
inline void Pushup(int k){
	pushup;
	memset(tr[k].sum,0,sizeof(tr[k].sum));
	int lcnt=tr[ls].wei%5;
	for(int i=0;i<5;i++){
		tr[k].sum[i]+=tr[ls].sum[i];
		tr[k].sum[i]+=tr[rs].sum[(i-lcnt+5)%5];
	}
}
inline void Build(int k,int ll,int rr){
	if(ll>rr)return;
	tr[k].l=ll,tr[k].r=rr;
	if(ll==rr)return;
	Build(ls,ll,nmid);
	Build(rs,nmid+1,rr);
}
inline void Add(int k,int pos,int add){
	if(Thispoint){
		tr[k].wei=1;
		tr[k].sum[1]=add;
		return;
	}
	if(pos<=tmid)Add(ls,pos,add);
	if(tmid<pos)Add(rs,pos,add);
	Pushup(k);
}
inline void Del(int k,int pos,int del){
	if(Thispoint){
		tr[k].wei=tr[k].sum[1]=0;
		return;
	}
	if(pos<=tmid)Del(ls,pos,del);
	if(tmid<pos)Del(rs,pos,del);
	Pushup(k);
}
int tmp[N],cnt;
int main(){
	Read(n);
	for(int i=1;i<=n;i++){
		string O;
		cin>>O;
		if(O[0]=='a'){
			op[i].opt=1;
			Read(op[i].num);
			tmp[++cnt]=op[i].num;
		}else if(O[0]=='d'){
			op[i].opt=2;
			Read(op[i].num);
		}else if(O[0]=='s'){
			op[i].opt=3;
		}
	}
	sort(tmp+1,tmp+1+cnt);
	cnt=unique(tmp+1,tmp+1+cnt)-tmp-1;
	map<int,int>mp;
	for(int i=1;i<=cnt;i++)mp[tmp[i]]=i;
	Build(1,1,cnt);
	for(int i=1;i<=n;i++){
		if(op[i].opt==1){
			Add(1,mp[op[i].num],op[i].num);
		}else if(op[i].opt==2){
			Del(1,mp[op[i].num],op[i].num);
		}else {
			printf("%I64d\n",tr[1].sum[3]);
		}
	}
	return 0;
}


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


#include<bits/stdc++.h>
#define int long long
using namespace std;
vector <int> a;
signed main(){
	ios::sync_with_stdio(false);
	int n, x;
	cin >> n;
	while(n--){
		string st;
		cin >> st;
		if(st == "add"){
			cin >> x;
			a.insert(lower_bound(a.begin(), a.end(), x), x);
		}else if(st == "del"){
			cin >> x;
			a.erase(lower_bound(a.begin(),a.end(),x));
		}else{
			x = 0;
			for(int i = 0; i < a.size(); i++){
				x += (i % 5 == 2) * a[i];
			}
			cout << x << endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
struct node{
    int l,r;
    int cnt;
    ll sum[5];
}tr[N<<2];
struct Q{
    int opt;
    int num;
}q[N];
vector<int> num;
void build(int u,int l,int r){
    if(l==r){
        tr[u]={l,r,0};
    }
    else{
        tr[u]={l,r,0};
        int mid=l+r>>1;
        build(u<<1,l,mid);
        build(u<<1|1,mid+1,r);
    }
}
void pushup(int u){
    int i;
    tr[u].cnt=tr[u<<1].cnt+tr[u<<1|1].cnt;
    for(i=0;i<=4;i++){
        tr[u].sum[i]=tr[u<<1].sum[i]+tr[u<<1|1].sum[(i-tr[u<<1].cnt%5+5)%5];
    }
}
void modify(int u,int pos,int x,int k){
    if(tr[u].l==tr[u].r){
        tr[u].cnt+=k;
        for(int i=0;i<=4;i++)
            tr[u].sum[i]=0;
        if(k>0){
            tr[u].sum[1]+=x;
        }
        return ;
    }
    int mid=tr[u].l+tr[u].r>>1;
    if(pos<=mid)
        modify(u<<1,pos,x,k);
    else
        modify(u<<1|1,pos,x,k);
    pushup(u);
}
int find(int x){
    return lower_bound(num.begin(),num.end(),x)-num.begin()+1;
}
int main(){
    ios::sync_with_stdio(false);
    int i;
    int n;
    cin>>n;
    for(i=1;i<=n;i++){
        string s;
        cin>>s;
        if(s=="sum"){
            q[i].opt=0;
        }
        else if(s=="add"){
            q[i].opt=1;
            cin>>q[i].num;
            num.push_back(q[i].num);
        }
        else{
            q[i].opt=-1;
            cin>>q[i].num;
            num.push_back(q[i].num);
        }
    }
    build(1,1,n);
    sort(num.begin(),num.end());
    num.erase(unique(num.begin(),num.end()),num.end());
    for(i=1;i<=n;i++){
        if(q[i].opt==1){
            int pos=find(q[i].num);
            modify(1,pos,q[i].num*q[i].opt,q[i].opt);
        }
        else if(q[i].opt==-1){
            int pos=find(q[i].num);
            modify(1,pos,q[i].num*q[i].opt,q[i].opt);
        }
        else{
            cout<<tr[1].sum[3]<<endl;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
int read()
{
	int d = 0, w = 1;
	char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9'))
		ch = getchar();
	if (ch == '-')
		w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9')
		d = d * 10 + ch - '0', ch = getchar();
	return d * w;
}
void write_(int x)
{
	if (x < 0)
		x = -x, putchar('-');
	if (x > 9)
		write_(x / 10);
	putchar(x % 10 + '0');
}
void writeln(int x)
{
	write_(x);
	putchar('\n');
}
void writesp(int x)
{
	write_(x);
	putchar(' ');
}
struct node
{
	int lc, rc;
	int M[5];
	int fa;
} t[350000];
int cnt;
void pushup(int p)
{
	for (int i = 0; i <= 4; ++i)
		t[p].M[i] = t[t[p].lc].M[i] + t[t[p].rc].M[i];
}
int A[100];
void Move(int p, int fa)
{
	fa = (fa % 5 + 5) % 5;
	for(int i = 0; i <= 4; ++i)
		A[i] = t[p].M[i];
	for(int i = 0; i <= 4; ++i)
		t[p].M[i] = A[((i - fa) % 5 + 5) % 5];
}
void pushdown(int p)
{
	t[p].fa = (t[p].fa % 5 + 5) % 5;
	if(t[p].fa)
	{
		t[t[p].lc].fa += t[p].fa;
		t[t[p].rc].fa += t[p].fa;
		Move(t[p].lc, t[p].fa), Move(t[p].rc, t[p].fa);
		t[p].fa = 0;
	}
}
int build(int l, int r)
{
	int p = ++cnt;
	if (l == r)
		return p;
	int mid = (l + r) >> 1;
	t[p].lc = build(l, mid);
	t[p].rc = build(mid + 1, r);
	pushup(p);
	return p;
}
void mov(int now, int l, int r, int L, int R, int fa)
{
	if(L > R)
		return ;
	if(l >= L && r <= R)
	{
		Move(now, fa);
		t[now].fa = ((t[now].fa + fa) % 5 + 5) % 5;
		return ;
	}
	pushdown(now);
	int mid = (l + r) >> 1;
	if(mid >= L)
		mov(t[now].lc, l, mid, L, R, fa);
	if(mid < R)
		mov(t[now].rc, mid + 1, r, L, R, fa);
	pushup(now);
}
void change(int now, int l, int r, int x, int b, int p)
{
	if(l == r)
	{
		t[now].M[p % 5] = b;
		return ;
	}
	pushdown(now);
	int mid = (l + r) >> 1;
	if(mid >= x)
		change(t[now].lc, l, mid, x, b, p);
	else
		change(t[now].rc, mid + 1, r, x, b, p);
	pushup(now);
}
void dele(int now, int l, int r, int x, int p)
{
	if (l == r)
	{
		t[now].M[p % 5] = 0;
		return;
	}
	pushdown(now);
	int mid = (l + r) >> 1;
	if (mid >= x)
		dele(t[now].lc, l, mid, x, p);
	else
		dele(t[now].rc, mid + 1, r, x, p);
	pushup(now);
}
enum Opt
{
	ADD,
	DELETE,
	SUM,
};
vector<pair<Opt, int>> opts;
vector<int> Id;
int getid(int x)
{
	return lower_bound(Id.begin(), Id.end(), x) - Id.begin();
}
char ch[100];
int tree[150000];
void add(int p, int v)
{
	for(; p <= 100000; p += p & -p)
		tree[p] += v;
}
int ask(int p)
{
	int ans = 0;
	for(; p; p -= p & -p)
		ans += tree[p];
	return ans;
}
int main()
{
#ifdef __clang__
	freopen("data.in", "r", stdin);
	freopen("data.out", "w", stdout);
#endif
	int n = read();
	for (int i = 1; i <= n; ++i)
	{
		scanf("%s", ch);
		if (ch[0] == 'a')
		{
			int x = read();
			Id.push_back(x);
			opts.push_back(make_pair(Opt::ADD, x));
		}
		else if (ch[0] == 'd')
		{
			int x = read();
			Id.push_back(x);
			opts.push_back(make_pair(Opt::DELETE, x));
		}
		else
		{
			opts.push_back(make_pair(Opt::SUM, -1));
		}
	}
	sort(Id.begin(), Id.end());
	Id.erase(unique(Id.begin(), Id.end()), Id.end());
	int lim = Id.size();
	int root = build(1, lim);
	for(int i = 0; i < n; ++i)
	{
		Opt opt = opts[i].first;
		int x = opts[i].second;
		if(opt == Opt::ADD)
		{
			change(root, 1, lim, getid(x) + 1, x, ask(getid(x) + 1) + 1);
			add(getid(x) + 1, 1);
			mov(root, 1, lim, getid(x) + 2, lim, 1);
		}
		else if(opt == Opt::DELETE)
		{
			dele(root, 1, lim, getid(x) + 1, ask(getid(x) + 1));
			add(getid(x) + 1, -1);
			mov(root, 1, lim, getid(x) + 2, lim, -1);
		}
		else
		{
			writeln(t[root].M[3]);
		}
	}

	return 0;
}


#include <iostream>
#include <string.h>
#include <algorithm>
#define ll long long
using namespace std;
ll n,x;
ll tree[400005][5],add[100005],pan[100005],shu[100005],haha[100005],id[100005];
ll num[400005];
char a[10];
inline ll read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int ls(int k)
{
	return k<<1;
}
int rs(int k)
{
	return k<<1|1;
}
void push_up(int i)
{
	num[i]=num[ls(i)]+num[rs(i)];
	for(int j=0;j<=4;j++)
	{
		tree[i][j]=tree[ls(i)][j]+tree[rs(i)][((j-num[ls(i)])%5+5)%5];
	}
 }
void in(int left,int right,int i,int wei,int wor,int sum)
{
	if(left==right)
	{
		tree[i][1]+=wor;
		num[i]+=sum;
		return;
	}
	else
	{
		int mid=(left+right)/2;
		if(wei<=mid) in(left,mid,ls(i),wei,wor,sum);
		else in(mid+1,right,rs(i),wei,wor,sum);
		push_up(i);
	}
}
int main()
{
	ll cnt=0;
	n=read();
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		if(a[0]=='a')
		{
			x=read();
			add[++cnt]=x;
			shu[i]=x;
			pan[i]=1;
		}
		if(a[0]=='d')
		{
			x=read();
			shu[i]=x;
			pan[i]=-1;
		}
		if(a[0]=='s')
		{
			haha[i]=1;
		}
	 } //离线
	 sort(add+1,add+cnt+1);
	 ll sum=1;
	 for(int i=1;i<=cnt;i++)
	 {
	 	id[add[i]]=sum;
	 	sum++;
	 }//离散化
	 for(int i=1;i<=n;i++)
	 {
	 	if(haha[i]==1) cout<<tree[1][3]<<endl;
	 	else
	 	{
	 		in(1,n,1,id[shu[i]],pan[i]*shu[i],pan[i]);
		 }
	 }
	 return 0;
}


#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
using namespace std;

int n;
vector<int> ji;

int main() {
	cin >> n;
	ji.push_back(-1);
	for (int i = 1;i <= n;i ++) {
		string a;
		int b;
		cin >> a;
		if (a[0] == 'a') {
			cin >> b;
			ji.push_back(b);
		}
		if (a[0] == 's') {
			sort(ji.begin(), ji.end());
			int sum = 0;
			for (int j = 1;j < ji.size();j ++) {
				if (j % 5 == 3) {
					sum += ji[j];
				}
			}
			cout << sum << endl;
		}
		if (a[0] == 'd') {
			cin >> b;
			for (int j = 1;j < ji.size();j ++) {
				if (ji[j] == b) {
					ji.erase(ji.begin() + j);
				}
			}
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
const int N=2e5+10;
char s[10];
ll tmp[N];
struct tree
{
	int left,right;
	int cnt; ll val[7];
}t[4*N];
struct query
{
	int type; ll num;
}q[N];
inline void build(int p,int l,int r)
{
	t[p].left=l,t[p].right=r;
	if(l==r) return;
	int mid=(t[p].left+t[p].right)/2;
	build(p*2,l,mid);
	build(p*2+1,mid+1,r);
}
inline void pushup(int p)
{
	for(int i=0;i<=4;i++)
		t[p].val[i]=t[p*2].val[i]+t[p*2+1].val[((i-t[p*2].cnt)%5+5)%5];
	t[p].cnt=(t[p*2].cnt+t[p*2+1].cnt)%5;
}
inline void change(int p,int pos,ll num)
{
	if(t[p].left==t[p].right)
	{
		t[p].val[1]=num;
		t[p].cnt=(t[p].val[1]>0);
		return;
	}
	int mid=(t[p].left+t[p].right)/2;
	if(pos<=mid) change(p*2,pos,num);
	else change(p*2+1,pos,num);
	pushup(p);
}
int main()
{
	int n,m=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s);
		if(s[0]=='a')
		{
			scanf("%lld",&q[i].num);
			q[i].type=1,tmp[++m]=q[i].num;
		}
		if(s[0]=='d')
		{
			scanf("%lld",&q[i].num);
			q[i].type=2,tmp[++m]=q[i].num;
		}
		if(s[0]=='s') q[i].type=3;
	}
	sort(tmp+1,tmp+m+1);
	m=unique(tmp+1,tmp+m+1)-(tmp+1);
	build(1,1,m);
	for(int i=1;i<=n;i++)
	{
		if(q[i].type<3)
		{
			int pos=lower_bound(tmp+1,tmp+m+1,q[i].num)-tmp;
			if(q[i].type==1) change(1,pos,q[i].num);
			else change(1,pos,0);
		}
		else printf("%lld\n",t[1].val[3]);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
const int N=1e5+50;
const int T=N*6;
int n,m,q;

#define mid ((l+r)>>1)
#define ls (p<<1)
#define rs ((p<<1)|1)
#define lt ls,l,mid
#define rt rs,mid+1,r

int lst[N],sz[T];
ll sm[T][7];
struct O{int op,x;}Q[N];
set<int>s[N];
void upp(int p)
{
	sz[p]=sz[ls]+sz[rs];
	for(int i=0;i<5;i++)
		sm[p][i]=sm[ls][i]+sm[rs][((i-sz[ls])%5+5)%5];
}

void ins(int p,int l,int r,int pos,int c,int v)
{
	if(l==r)
	{
		sm[p][1]+=v;
		sz[p]+=c;
		return ;
	}
	if(pos<=mid)ins(lt,pos,c,v);
	else ins(rt,pos,c,v);
	upp(p);
}

int main()
{
	scanf("%d",&n);char sh[50];
	for(int i=1;i<=n;i++)
	{
		scanf("%s",sh);
		if(sh[0]=='a')
		{
			scanf("%d",&Q[i].x);
			lst[++m]=Q[i].x;
			Q[i].op=1;
		}
		else if(sh[0]=='d')
		{
			scanf("%d",&Q[i].x);
			Q[i].op=2;
		}
		else Q[i].op=3;
	}
	sort(lst+1,lst+m+1);
	m=unique(lst+1,lst+m+1)-lst-1;
	for(int i=1,x;i<=n;i++)
	{
		if(Q[i].op==1)
		{
			x=lower_bound(lst+1,lst+m+1,Q[i].x)-lst;
			ins(1,1,m,x,1,Q[i].x);
		}
		else if(Q[i].op==2)
		{
			x=lower_bound(lst+1,lst+m+1,Q[i].x)-lst;
			ins(1,1,m,x,-1,-Q[i].x);
		}
		else printf("%lld\n",sm[1][3]);
	}
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
long long xx[110000],kd[110000],d[6][440000],rd[440000],b[110000];
map<long long,long long>id;
inline long long read(){
      long long x=0,f=1;char s=getchar();
      while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
      while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+(s-'0');s=getchar();}
      return f*x;
}
inline void update(long long le,long long ri,long long pl,long long k,long long wh,long long sum){
      if(le==ri){
          d[1][wh]+=k;
          rd[wh]+=sum;
          return;
      }
      long long mid=(le+ri)>>1;
      if(mid>=pl)update(le,mid,pl,k,wh<<1,sum);
        else update(mid+1,ri,pl,k,wh<<1|1,sum);
      rd[wh]=rd[wh<<1]+rd[wh<<1|1];
      for(long long i=0;i<5;i++)
         d[i][wh]=d[i][wh<<1]+d[(i-rd[wh<<1]%5+5)%5][wh<<1|1];
}
int main()
{     long long n,m,i,j,tot=0,sum=0;
      n=read();
      for(i=1;i<=n;i++){
         string s;
         cin>>s;
         if(s[0]=='a'){
            kd[i]=1;
            xx[i]=read();
            b[++tot]=xx[i];
         }else if(s[0]=='d'){
            kd[i]=2;
            xx[i]=read();
         }else kd[i]=3;
      }
      sort(b+1,b+tot+1);
      for(i=1;i<=tot;i++)
         if(!id[b[i]]){
           id[b[i]]=++sum;
         }
      for(i=1;i<=n;i++){
         if(kd[i]<3){
            update(1,n,id[xx[i]],(kd[i]==1?xx[i]:-xx[i]),1,(kd[i]==1?1:-1));
         }else printf("%lld\n",d[3][1]);
      }
      return 0;
}


#include <iostream>
#include <string.h>
#include<cstdlib>
#include <map>
#include <algorithm>
#define ll long long
using namespace std;
ll n,x;
ll tree[800005][6],add[400005],pan[400005],shu[400005];
ll num[800005];
char a[10];
map <ll,ll> id;
inline ll read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll ls(ll k)
{
	return k<<1;
}
ll rs(ll k)
{
	return k<<1|1;
}
void push_up(ll i)
{
	num[i]=num[ls(i)]+num[rs(i)];
	for(ll j=0;j<=4;j++)
	{
		tree[i][j]=tree[ls(i)][j]+tree[rs(i)][((j-num[ls(i)])%5+5)%5];
	}
 }
inline void in(ll left,ll right,ll i,ll wei,ll wor,ll sum)
{
	if(left==right)
	{
		tree[i][1]+=wor;
		num[i]+=sum;
		return;
	}
	else
	{
		ll mid=(left+right)/2;
		if(wei<=mid) in(left,mid,ls(i),wei,wor,sum);
		else in(mid+1,right,rs(i),wei,wor,sum);
		push_up(i);
	}
}
int main()
{
	ll cnt=0;
	n=read();
	for(ll i=1;i<=n;i++)
	{
		cin>>a;
		if(a[0]=='a')
		{
		    x=read();
			add[++cnt]=x;
			shu[i]=x;
			pan[i]=1;
		}
		if(a[0]=='d')
		{
			x=read();
			shu[i]=x;
			pan[i]=-1;
		}
	 } //离线
	 sort(add+1,add+cnt+1);
	 ll sum=1;
	 for(ll i=1;i<=cnt;i++)
	 {
	 	if(id[add[i]]==0)
		 {
		 	id[add[i]]=sum;
	 		sum++;
	 	}
	 }//离散化
	 for(ll i=1;i<=n;i++)
	 {
	 	if(pan[i]==0) printf("%lld\n",tree[1][3]);
	 	else
	 	{
	 		in(1,n,1,id[shu[i]],pan[i]*shu[i],pan[i]);
		 }
	 }
	 return 0;
}


#include <iostream>
#include <string.h>
#include <algorithm>
#define ll long long
using namespace std;
ll n,x;
ll tree[800005][6],add[400005],pan[400005],shu[400005],id[400005];
ll num[800005];
char a[10];
inline ll read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll ls(ll k)
{
	return k<<1;
}
ll rs(ll k)
{
	return k<<1|1;
}
void push_up(ll i)
{
	num[i]=num[ls(i)]+num[rs(i)];
	for(ll j=0;j<=4;j++)
	{
		tree[i][j]=tree[ls(i)][j]+tree[rs(i)][((j-num[ls(i)])%5+5)%5];
	}
 }
inline void in(ll left,ll right,ll i,ll wei,ll wor,ll sum)
{
	if(left==right)
	{
		tree[i][1]+=wor;
		num[i]+=sum;
		return;
	}
	else
	{
		ll mid=(left+right)/2;
		if(wei<=mid) in(left,mid,ls(i),wei,wor,sum);
		else in(mid+1,right,rs(i),wei,wor,sum);
		push_up(i);
	}
}
int main()
{
	ll cnt=0;
	n=read();
	for(ll i=1;i<=n;i++)
	{
		cin>>a;
		if(a[0]=='a')
		{
		    x=read();
			add[++cnt]=x;
			shu[i]=x;
			pan[i]=1;
		}
		if(a[0]=='d')
		{
			x=read();
			shu[i]=x;
			pan[i]=-1;
		}
	 } //离线
	 sort(add+1,add+cnt+1);
	 ll sum=1;
	 for(ll i=1;i<=cnt;i++)
	 {
	 	if(id[add[i]]==0)
		 {
		 	id[add[i]]=sum;
	 		sum++;
	 	}
	 }//离散化
	 for(ll i=1;i<=n;i++)
	 {
	 	if(pan[i]==0) printf("%lld\n",tree[1][3]);
	 	else
	 	{
	 		in(1,n,1,id[shu[i]],pan[i]*shu[i],pan[i]);
		 }
	 }
	 return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
#define int long long
using namespace std;
const int N=1e5+10;
char s[10];
ll tmp[N];
struct tree
{
	int left,right;
	int cnt; ll val[7];
}t[4*N];
struct query
{
	int type; ll num;
}q[N];
inline void build(int p,int l,int r)
{
	t[p].left=l,t[p].right=r;
	if(l==r) return;
	int mid=(t[p].left+t[p].right)/2;
	build(p*2,l,mid);
	build(p*2+1,mid+1,r);
}
inline void pushup(int p)
{
	for(int i=0;i<=4;i++)
		t[p].val[i]=t[p*2].val[i]+t[p*2+1].val[((i-t[p*2].cnt)%5+5)%5];
	t[p].cnt=(t[p*2].cnt+t[p*2+1].cnt)%5;
}
inline void change(int p,int pos,ll num)
{
	if(t[p].left==t[p].right)
	{
		t[p].val[1]=num;
		t[p].cnt=(t[p].val[1]>0);
		return;
	}
	int mid=(t[p].left+t[p].right)/2;
	if(pos<=mid) change(p*2,pos,num);
	else change(p*2+1,pos,num);
	pushup(p);
}
signed main()
{
	int n,m=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s);
		if(s[0]=='a')
		{
			scanf("%lld",&q[i].num);
			q[i].type=1,tmp[++m]=q[i].num;
		}
		if(s[0]=='d')
		{
			scanf("%lld",&q[i].num);
			q[i].type=2;
		}
		if(s[0]=='s') q[i].type=3;
	}
	sort(tmp+1,tmp+m+1);
	build(1,1,m);
	for(int i=1;i<=n;i++)
	{
		if(q[i].type<3)
		{
			int pos=lower_bound(tmp+1,tmp+m+1,q[i].num)-tmp;
			if(q[i].type==1) change(1,pos,q[i].num);
			else change(1,pos,0);
		}
		else printf("%lld\n",t[1].val[3]);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int tot = 0;
struct TreapNode* Null;
struct TreapNode {
    TreapNode *lc, *rc;
    int key, aux, size;
    int id;
    int sum[5];
    TreapNode(int k = 0): key(k), aux(rand()), size(1), lc(Null), rc(Null) {fill(sum, sum + 5, 0); id = ++tot;};
    void pushup() {
        size = lc -> size + 1 + rc -> size;
        for (int i = 0; i < 5; i++) {
            sum[i] = lc -> sum[i];
//          fprintf(stderr, "sum[%d] of node %d updated to %d\n", i, id, sum[i]);
        }
        int k = lc -> size;
        sum[k % 5] += key;
//      fprintf(stderr, "sum[%d] of node %d updated to %d\n", k % 5, id, sum[k % 5]);
        k++;
        for (int i = 0; i < 5; i++) {
            sum[(k + i) % 5] += rc -> sum[i];
//          fprintf(stderr, "sum[%d] of node %d updated to %d\n", k % 5, id, sum[k % 5]);
        }
    }
}*root;
int getRank(TreapNode* u, int v) {
//    cerr << u -> id << endl;
    if (u == Null) return 0;
    return (v < u -> key) ? getRank(u -> lc, v): getRank(u -> rc, v) + u -> lc -> size + 1;
}
typedef pair <TreapNode*, TreapNode*> PNN;
PNN split(TreapNode* u, int k) {
    if (u == Null) return make_pair(Null, Null);
    PNN ret;
    if (u -> lc -> size < k) {
        ret = split(u -> rc, k - 1 - u -> lc -> size);
        u -> rc = ret.first;
        ret.first = u;
    } else {
        ret = split(u -> lc, k);
        u -> lc = ret.second;
        ret.second = u;
    }
    u -> pushup();
    return ret;
}
TreapNode* merge(TreapNode* u, TreapNode* v) {
    if (u == Null) return v; if (v == Null) return u;
    if (u -> aux < v -> aux) {
        u -> rc = merge(u -> rc, v);
        u -> pushup();
        return u;
    } else {
        v -> lc = merge(u, v -> lc);
        v -> pushup();
        return v;
    }
}
void insert(int v) {
//    fprintf(stderr, "insert %d\n", v);
    int k = getRank(root, v);
//  fprintf(stderr, "ranked %d\n", k);
    PNN t = split(root, k);
    TreapNode* tmp = new TreapNode(v);
    root = merge(merge(t.first, tmp), t.second);
}
void erase(int v) {
    int k = getRank(root, v);
    PNN t1 = split(root, k - 1), t2 = split(t1.second, 1);
    root = merge(t1.first, t2.second);
}
int main() {
    srand(2);
    int n; cin >> n;
    Null = new TreapNode(0); root = new TreapNode(0);
//  cerr << Null -> id << endl;
    Null -> size = 0;
    while (n--) {
        string op; cin >> op;
        if (op == "add") {
            int x; cin >> x;
            insert(x);
        } else if (op == "del") {
            int x; cin >> x;
            erase(x);
        } else {
            cout << root -> sum[3] << endl;
        }
    }
}


#include <iostream>
#include <string.h>
#include <algorithm>
#define ll long long
using namespace std;
ll n,x;
ll tree[800005][5],add[800005],pan[800005],shu[800005],haha[800005],id[800005];
ll num[800005];
char a[10];
inline ll read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int ls(int k)
{
	return k<<1;
}
int rs(int k)
{
	return k<<1|1;
}
void push_up(int i)
{
	num[i]=num[ls(i)]+num[rs(i)];
	for(int j=1;j<=4;j++)
	{
		tree[i][j]=tree[ls(i)][j]+tree[rs(i)][((j-num[ls(i)])%5+5)%5];
	}
 }
void in(int left,int right,int i,int wei,int wor,int sum)
{
	if(left==right)
	{
		tree[i][1]+=wor;
		num[i]+=sum;
		return;
	}
	else
	{
		int mid=(left+right)/2;
		if(wei<=mid) in(left,mid,ls(i),wei,wor,sum);
		else in(mid+1,right,rs(i),wei,wor,sum);
		push_up(i);
	}
}
int main()
{
	ll cnt=0;
	n=read();
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		if(a[0]=='a')
		{
			x=read();
			add[++cnt]=x;
			shu[i]=x;
			pan[i]=1;
		}
		if(a[0]=='d')
		{
			x=read();
			shu[i]=x;
			pan[i]=-1;
		}
		if(a[0]=='s')
		{
			haha[i]=1;
		}
	 } //离线
	 sort(add+1,add+cnt+1);
	 ll sum=1;
	 for(int i=1;i<=cnt;i++)
	 {
	 	id[add[i]]=sum;
	 	sum++;
	 }//离散化
	 for(int i=1;i<=n;i++)
	 {
	 	if(haha[i]==1) cout<<tree[1][3]<<endl;
	 	else
	 	{
	 		in(1,n,1,id[shu[i]],pan[i]*shu[i],pan[i]);
		 }
	 }
	 return 0;
}


#include<bits/stdc++.h>
#define short long long
using namespace std;
inline int Read()
{
	int crfzz=0;char a=getchar();
	while(!isdigit(a)) a=getchar();
	while(isdigit(a)) crfzz=(crfzz<<1)+(crfzz<<3)+a-48,a=getchar();
	return crfzz;
}
inline void Print(long long k)
{
	if(k>9) Print(k/10);
	putchar(k%10+48);
}
string k;
vector<int>jl;
int nn,n;
short crf_has_no_jj;
int main()
{
	nn=Read();
	while(nn--)
	{
		cin>>k;
		if(k=="add")
		{
			n=Read();
			jl.insert(lower_bound(jl.begin(),jl.end(),n),n);
		}
		if(k=="del")
		{
			n=Read();
			jl.erase(lower_bound(jl.begin(),jl.end(),n));
		}
		if(k=="sum")
		{
			crf_has_no_jj=0;
			for(int i=2;i<jl.size();i+=5)
			{
				crf_has_no_jj+=jl[i];
			}
			Print(crf_has_no_jj);
			putchar(10);
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

const int MAXN=200010;
struct tree{
	int cnt;
	ll w[6];
	int l,r,tag;
}t[4*MAXN];
struct commen{
	string typ;
	ll k;
} cm[MAXN];
int N;
int room[MAXN]={0};
int numcnt=0;

void build_tree(int p,int l,int r){
	t[p].l=l;t[p].r=r;
	t[p].cnt=0;t[p].tag=0;
	for(int i=1;i<=5;i++) t[p].w[i]=0;
	if(l==r){
		return;
	}
	int mid=(l+r)>>1;
	build_tree(p*2,l,mid);build_tree(p*2+1,mid+1,r);
}

int mov(int x,ll k){
	k=(k%5+5)%5;
    x=(x+k-1)%5+1;
    return x;
}

void download(int p){
	t[p*2].tag+=t[p].tag;
	t[p*2+1].tag+=t[p].tag;
	ll tmp[2][6];
	for(int i=1;i<=5;i++){
		tmp[0][mov(i,t[p].tag)]=t[p*2].w[i];
		tmp[1][mov(i,t[p].tag)]=t[p*2+1].w[i];
	}
	for(int i=1;i<=5;i++){
		t[p*2].w[i]=tmp[0][i];
		t[p*2+1].w[i]=tmp[1][i];
	}
	t[p].tag=0;
}

void move(int p,int l,int r,int s){
	if(l<=t[p].l&&t[p].r<=r){
	    t[p].tag+=s;
	    ll tmp[6];
	    for(int i=1;i<=5;i++) tmp[mov(i,s)]=t[p].w[i];
	    for(int i=1;i<=5;i++) t[p].w[i]=tmp[i];
	    return;
	}
	download(p);
	int mid=(t[p].l+t[p].r)>>1;
	if(l<=mid) move(p*2,l,r,s);
	if(r>=mid+1) move(p*2+1,l,r,s);
    for(int i=1;i<=5;i++) t[p].w[i]=t[p*2].w[i]+t[p*2+1].w[i];
}

void add(int p,int id,int pnt,ll k){
	if(t[p].l==t[p].r){
	    t[p].w[id]+=k;
	    t[p].cnt++;
	    return;
	}
    download(p);
    int mid=(t[p].l+t[p].r)>>1;
    if(pnt<=mid) add(p*2,id,pnt,k);
    if(pnt>=mid+1) add(p*2+1,id,pnt,k);
    for(int i=1;i<=5;i++) t[p].w[i]=t[p*2].w[i]+t[p*2+1].w[i];
    t[p].cnt=t[p*2].cnt+t[p*2+1].cnt;
}

void del(int p,int id,int pnt,ll k){
	if(t[p].l==t[p].r){
	    t[p].w[id]-=k;
	    t[p].cnt--;
	    return;
	}
    download(p);
    int mid=(t[p].l+t[p].r)>>1;
    if(pnt<=mid) del(p*2,id,pnt,k);
    if(pnt>=mid+1) del(p*2+1,id,pnt,k);
    for(int i=1;i<=5;i++) t[p].w[i]=t[p*2].w[i]+t[p*2+1].w[i];
    t[p].cnt=t[p*2].cnt+t[p*2+1].cnt;
}

ll ask(int p,int l,int r){
	if(l<=t[p].l&&t[p].r<=r){
		return t[p].cnt;
	}
	ll ans=0;
	int mid=(t[p].l+t[p].r)>>1;
	if(l<=mid) ans+=ask(p*2,l,r);
	if(r>=mid+1) ans+=ask(p*2+1,l,r);
	return ans;
}

bool cmp(int a,int b){
	return a<b;
}

int found(int k){
	int l=1,r=N,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(room[mid]==k){
			return mid;
		}
		if(room[mid]>k){
			r=mid-1;
		}
		if(room[mid]<k){
			l=mid+1;
		}
	}
}

void prepare(){
	cin>>N;
	string tmp;
	for(int i=1;i<=N;i++){
		cin>>cm[i].typ;
		if(cm[i].typ=="add"){
			scanf("%d",&cm[i].k);
			room[++numcnt]=cm[i].k;
		}
		if(cm[i].typ=="del"){
			scanf("%d",&cm[i].k);
		}
	}
	sort(room+1,room+1+numcnt,cmp);
	build_tree(1,1,numcnt);
}

void solve(){
	int pnt,id,k;
	for(int i=1;i<=N;i++){
		if(cm[i].typ=="sum"){
			printf("%lld\n",t[1].w[3]);
		}
		if(cm[i].typ=="add"){
			k=cm[i].k;
			pnt=found(k);
			id=ask(1,1,pnt-1)%5+1;
			add(1,id,pnt,k);
            move(1,pnt+1,numcnt,1);
		}
		if(cm[i].typ=="del"){
			k=cm[i].k;
			pnt=found(k);
			id=ask(1,1,pnt-1)%5+1;
			del(1,id,pnt,k);
            move(1,pnt+1,numcnt,-1);
		}
	}
}

int main(){
	prepare();
	solve();
}


#include<bits/stdc++.h>
#define LL long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define MOD(x) ((x)%mod)
#define mod 1000000007
#define pb push_back
#define lson (rt << 1)
#define rson (rt << 1 | 1)
#define STREAM_FAST ios::sync_with_stdio(false)
using namespace std;
const int maxn = 1e5 + 7;
struct node
{
    LL sum[5]; int cnt;
}T[maxn];
int op[maxn], a[maxn];
vector<int>vec;
int getid(int x) {return lower_bound(vec.begin(), vec.end(), x) - vec.begin() + 1;}
void pushup(int rt)
{
    for (int i = 0; i < 5; i++)
        T[rt].sum[i] = T[lson].sum[i] + T[rson].sum[(i - T[lson].cnt % 5 + 5) % 5];
    T[rt].cnt = T[lson].cnt + T[rson].cnt;
}
void update(int rt, int l, int r, int pos, int val)
{
    if (l == r)
    {
        if (val > 0) T[rt].cnt++;
        else T[rt].cnt--;
        T[rt].sum[1] += val;
        return;
    }
    int mid = (l + r) / 2;
    if (pos <= mid) update(lson, l, mid, pos, val);
    else update(rson, mid + 1, r, pos, val);
    pushup(rt);
}
int main()
{
	int n; scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        char s[10]; scanf("%s", s);
        if (s[0] == 'a') {op[i] = 1; scanf("%d", &a[i]); vec.pb(a[i]);}
        else if (s[0] == 'd') {op[i] = 2; scanf("%d", &a[i]);}
        else op[i] = 3;
    }
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    for (int i = 1; i <= n; i++)
    {
        if (op[i] == 1) update(1, 1, n, getid(a[i]), a[i]);
        else if (op[i] == 2) update(1, 1, n, getid(a[i]), -a[i]);
        else printf("%lld\n", T[1].sum[3]);
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int cnt[4000004],n=0,m;
struct xjy{
	int opt;
	int a;
	int id;
}s[4000004];
bool B(xjy a,xjy b)
{
	return a.a<b.a;
 }
bool C(xjy a,xjy b)
{
	return a.id<b.id;
}
long long sum[4000004][5],num[4000004];
void upd(int now)
{
	cnt[now]=cnt[now*2]+cnt[now*2+1];
	cnt[now]%=5;
	for(int i=0;i<=4;i++) sum[now][i]=sum[now*2][i]+sum[now*2+1][(i-cnt[now*2]+5)%5];
}
void add(int x,int l,int r,int now)
{
	//cout<<now<<" "<<l<<" "<<r<<endl;
	if(l==r)
	{
		cnt[now]=1;
		sum[now][1]=num[x];
		return ;
	}
	int mid=(l+r)/2;
	if(mid>=x) add(x,l,mid,now*2);
	else add(x,mid+1,r,now*2+1);
	upd(now);
}
void del(int x,int l,int r,int now)
{
	if(l==r)
	{
		cnt[now]=0;
		sum[now][1]=0;
		return ;
	}
	int mid=(l+r)/2;
	if(mid>=x) del(x,l,mid,now*2);
	else del(x,mid+1,r,now*2+1);
	upd(now);
}
int main()
{
	scanf("%d",&m);
	for(int i=1;i<=m;i++)
	{
		char c[10];
		scanf("%s",c+1);
		if(c[1]=='a')
		{
			s[i].opt=1;
			scanf("%d",&s[i].a);
		}
		if(c[1]=='d')
		{
			s[i].opt=2;
			scanf("%d",&s[i].a);
		}
		if(c[1]=='s')
		{
			s[i].opt=3;
		}
		s[i].id=i;
	}
    sort(s+1,s+m+1,B);
    for(int i=1;i<=m;i++)
    {
    	//cout<<s[i].a<<endl;
    	if(s[i].a&&s[i].a!=num[n])
    	{
    		num[++n]=s[i].a;
		}
		s[i].a=n;
	}
	sort(s+1,s+m+1,C);
	for(int i=1;i<=m;i++)
	{
		if(s[i].opt==1)
		{
			add(s[i].a,1,n,1);
		}
		if(s[i].opt==2)
		{
			del(s[i].a,1,n,1);
		}
		if(s[i].opt==3)
		{
			printf("%lld\n",sum[1][3]);
		}
	}
	return 0;
 }


#include <cstdio>
#include <ctype.h>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAXN = 1e5 + 7;
const int MOD = 5;

typedef long long LL;

int tx[MAXN], cnt, n;

struct Qry {
	int opt;
	int val;
}qry[MAXN];

namespace SGT {
	LL tr[MAXN << 2][6];
	int sum[MAXN << 2];

	inline void pushup(int k, int lson, int rson) {
		for(int i = 0; i < MOD; ++i) tr[k][i] = tr[lson][i];
		for(int i = 0; i < MOD; ++i) tr[k][(sum[lson] + i + MOD) % MOD] += tr[rson][i];
		sum[k] = sum[lson] + sum[rson];
	}

	void update(int k, int l, int r, int x, int val) {
		if(l == r) {
			memset(tr[k], 0, sizeof tr[k]);
			tr[k][1] = val * tx[x];
			sum[k] = val;
			return ;
		}
		int mid = l + r >> 1;
		int lson = k << 1;
		int rson = lson | 1;
		if(x <= mid) update(lson, l, mid, x, val);
		else update(rson, mid + 1, r, x, val);
		pushup(k, lson ,rson);
	}
}

inline int read() {
	int res = 0, flag = 1;
	char in = getchar();
	while(!isdigit(in)) {
		if(in == '-') flag = -1;
		in = getchar();
	}
	while(isdigit(in)) {
		res = (res << 1) + (res << 3) + in - '0';
		in = getchar();
	}
	return res * flag;
}

inline void init() {
	char str[6];
	n = read();
	for(int i = 1; i <= n; ++i) {
		scanf("%s", str);
		if(str[0] == 'a') {
			qry[i].opt = 1; ++cnt;
			qry[i].val = tx[cnt] = read();
		}
		else if(str[0] == 'd') {
			qry[i].opt = -1; ++cnt;
			qry[i].val = tx[cnt] = read();
		}
	}
	sort(tx + 1, tx + cnt + 1);
	cnt = unique(tx + 1, tx + cnt + 1) - tx - 1;
	for(int i = 1; i <= n; ++i) if(qry[i].opt)
		qry[i].val = lower_bound(tx + 1, tx + cnt + 1, qry[i].val) - tx;
}

inline void solve() {
	for(int i = 1; i <= n; ++i) {
		if(!qry[i].opt) printf("%lld\n", SGT::tr[1][3]);
		else if(qry[i].opt == 1) SGT::update(1, 1, cnt, qry[i].val, 1);
		else SGT::update(1, 1, cnt, qry[i].val, 0);
	}
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("CF85D.in","r",stdin);
	freopen("CF85D.out","w",stdout);
#endif

	init();
	solve();
	return 0;
}


#include <iostream>
#include <string.h>
#include <algorithm>
#define ll long long
using namespace std;
ll n,x;
ll tree[800005][6],add[400005],pan[400005],shu[400005],id[400005];
ll num[800005];
char a[10];
inline ll read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int ls(int k)
{
	return k<<1;
}
int rs(int k)
{
	return k<<1|1;
}
void push_up(int i)
{
	num[i]=num[ls(i)]+num[rs(i)];
	for(int j=0;j<=4;j++)
	{
		tree[i][j]=tree[ls(i)][j]+tree[rs(i)][((j-num[ls(i)])%5+5)%5];
	}
 }
void in(int left,int right,int i,int wei,int wor,int sum)
{
	if(left==right)
	{
		tree[i][1]+=wor;
		num[i]+=sum;
		return;
	}
	else
	{
		int mid=(left+right)/2;
		if(wei<=mid) in(left,mid,ls(i),wei,wor,sum);
		else in(mid+1,right,rs(i),wei,wor,sum);
		push_up(i);
	}
}
int main()
{
	ll cnt=0;
	n=read();
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		if(a[0]=='a')
		{
			x=read();
			add[++cnt]=x;
			shu[i]=x;
			pan[i]=1;
		}
		if(a[0]=='d')
		{
			x=read();
			shu[i]=x;
			pan[i]=-1;
		}
	 } //离线
	 sort(add+1,add+cnt+1);
	 ll sum=1;
	 for(int i=1;i<=cnt;i++)
	 {
	 	id[add[i]]=sum;
	 	sum++;
	 }//离散化
	 for(int i=1;i<=n;i++)
	 {
	 	if(pan[i]==0) printf("%lld\n",tree[1][3]);
	 	else
	 	{
	 		in(1,n,1,id[shu[i]],pan[i]*shu[i],pan[i]);
		 }
	 }
	 return 0;
}


#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
using namespace std;

int n;
vector<long long> ji;

int main() {
	cin >> n;
	ji.push_back(-1);
	for (int i = 1;i <= n;i ++) {
		string a;
		long long b;
		cin >> a;
		if (a[0] == 'a') {
			cin >> b;
			ji.push_back(b);
		}
		if (a[0] == 's') {
			sort(ji.begin(), ji.end());
			int sum = 0;
			for (int j = 1;j < ji.size();j ++) {
				if (j % 5 == 3) {
					sum += ji[j];
				}
			}
			cout << sum << endl;
		}
		if (a[0] == 'd') {
			cin >> b;
			for (int j = 1;j < ji.size();j ++) {
				if (ji[j] == b) {
					ji.erase(ji.begin() + j);
				}
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int tot = 0;
struct TreapNode* Null;
struct TreapNode {
    TreapNode *lc, *rc;
    int key, aux, size;
    int id;
    int sum[5];
    TreapNode(int k = 0): key(k), aux(rand()), size(1), lc(Null), rc(Null) {fill(sum, sum + 5, 0); id = ++tot;}
    void pushup() {
        size = lc -> size + 1 + rc -> size;
        for (int i = 0; i < 5; i++) {
            sum[i] = lc -> sum[i];
//          fprintf(stderr, "sum[%d] of node %d updated to %d\n", i, id, sum[i]);
        }
        int k = lc -> size;
        sum[k % 5] += key;
//      fprintf(stderr, "sum[%d] of node %d updated to %d\n", k % 5, id, sum[k % 5]);
        k++;
        for (int i = 0; i < 5; i++) {
            sum[(k + i) % 5] += rc -> sum[i];
//          fprintf(stderr, "sum[%d] of node %d updated to %d\n", k % 5, id, sum[k % 5]);
        }
    }
}*root;
int getRank(TreapNode* u, int v) {
//    cerr << u -> id << endl;
    if (u == Null) return 0;
    return (v < u -> key) ? getRank(u -> lc, v): getRank(u -> rc, v) + u -> lc -> size + 1;
}
typedef pair <TreapNode*, TreapNode*> PNN;
PNN split(TreapNode* u, int k) {
    if (u == Null) return make_pair(Null, Null);
    PNN ret;
    if (u -> lc -> size < k) {
        ret = split(u -> rc, k - 1 - u -> lc -> size);
        u -> rc = ret.first;
        ret.first = u;
    } else {
        ret = split(u -> lc, k);
        u -> lc = ret.second;
        ret.second = u;
    }
    u -> pushup();
    return ret;
}
TreapNode* merge(TreapNode* u, TreapNode* v) {
    if (u == Null) return v; if (v == Null) return u;
    if (u -> aux < v -> aux) {
        u -> rc = merge(u -> rc, v);
        u -> pushup();
        return u;
    } else {
        v -> lc = merge(u, v -> lc);
        v -> pushup();
        return v;
    }
}
void insert(int v) {
//    fprintf(stderr, "insert %d\n", v);
    int k = getRank(root, v);
//  fprintf(stderr, "ranked %d\n", k);
    PNN t = split(root, k);
    TreapNode* tmp = new TreapNode(v);
    root = merge(merge(t.first, tmp), t.second);
}
void erase(int v) {
    int k = getRank(root, v);
    PNN t1 = split(root, k - 1), t2 = split(t1.second, 1);
    root = merge(t1.first, t2.second);
}
int main() {
    srand(2);
    int n; cin >> n;
    Null = new TreapNode(0); root = new TreapNode(0);
//  cerr << Null -> id << endl;
    Null -> size = 0;
    while (n--) {
        string op; cin >> op;
        if (op == "add") {
            int x; cin >> x;
            insert(x);
        } else if (op == "del") {
            int x; cin >> x;
            erase(x);
        } else {
            cout << root -> sum[3] << endl;
        }
    }
}


#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.insert(lower_bound(v.begin(),v.end(),x),x);
               }
               else 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);
                      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];
             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];
                  }
                 printf("%I64d\n",sum);
               }
               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<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;
      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<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'){
                 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 <iostream>
# include <cstdio>
# include <vector>
# include <algorithm>
using namespace std;
vector<int>v;
int main()
{
    int n, t;
    char s[10];
    scanf("%d",&n);
    while(n--)
    {
        scanf("%s",s);
        if(s[0] == 's')
        {
            long long ans = 0;
            for(int i=2; i<v.size(); i+=5)
                ans += v[i];
            printf("%I64d\n",ans);
        }
        else
        {
            scanf("%d",&t);
            if(s[0] == 'a')
                v.insert(lower_bound(v.begin(), v.end(), t), t);
            else
                v.erase(lower_bound(v.begin(), v.end(), t));
        }

    }
    return 0;
}


#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){
                    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<bits/stdc++.h>
#define ll long long
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.insert(lower_bound(v.begin(),v.end(),x),x);
               }
               else if(s[0] == 's'){
                  ll sum = 0;
                  for(int i = 2 ; i < v.size() ; i+=5){
                    sum += v[i];
                  }
                cout << sum << endl;
               }
               else{
                  ll x;
                     scanf("%I64d", &x);
                      v.erase(lower_bound(v.begin(),v.end(),x));
               }

       }
  }