#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 400010
using namespace std;
ll n,qx[N],num[N],segt[N][5],maxn;
string qu[N];
vector<ll> nm;
void update(ll fa,ll lft,ll rgt)
{
	ll i;
	num[fa]=num[lft]+num[rgt];
	for(i=0;i<5;i++)
	{
		segt[fa][i]=segt[lft][i];
	}
	for(i=0;i<5;i++)
	{
		segt[fa][(i+num[lft])%5]+=segt[rgt][i];
	}
	return;
}
void add(ll x)
{
	x+=maxn;
	segt[x][0]=nm[x-maxn];
	num[x]=1;
	do
	{
		x/=2;
		update(x,x*2,x*2+1);
	}while(x>0);
	return;
}
void del(ll x)
{
	x+=maxn;
	segt[x][0]=0;
	num[x]=0;
	do
	{
		x/=2;
		update(x,x*2,x*2+1);
	}while(x>0);
	return;
}
int main(){
	ll i,x;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>qu[i];
		if(qu[i]!="sum")
		{
			cin>>qx[i];
			nm.push_back(qx[i]);
		}
		else
		{
			qx[i]=-1;
		}
	}
	memset(num,0,sizeof(num));
	memset(segt,0,sizeof(segt));
	sort(nm.begin(),nm.end());
	maxn=1;
	while(maxn<=nm.size())
	{
		maxn*=2;
	}
	for(i=0;i<n;i++)
	{
		if(qu[i]=="sum")
		{
			cout<<segt[1][2]<<endl;
		}
		else
		{
			x=lower_bound(nm.begin(),nm.end(),qx[i])-nm.begin();
			if(qu[i]=="add")
			{
				add(x);
			}
			else
			{
				del(x);
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
vector<int>ch;
map<int,int>has;
int const M=4e5+10;
int cnt=0;
int seg[M*4][7];
int sv[M],a[M],lazy[M*4],seg2[M*4];
string x[M];
void check(int n1,int n2)
{
	lazy[n2]+=lazy[n1];
	for(int j=0;j<=4;j++)sv[j]=seg[n2][j];
	for(int j=0;j<=4;j++)
	{
		int hlp=j+lazy[n1];
		hlp+=5*1000000;
		hlp%=5;
		seg[n2][hlp]=sv[j];
	}
}
void lz(int node)
{
	check(node,node*2);
	check(node,node*2+1);
	lazy[node]=0;
}
int get1(int l,int r,int st,int en,int node)
{
	if(st<=l && r<=en)
	{
	//	int tmp=0;
	//	for(int i=0;i<=4;i++)tmp+=seg[node][i];
		return seg2[node];
	}
	if(l>=en || st>=r)return 0;
	int mid=(l+r)>>1;
	lz(node);
	return get1(l,mid,st,en,node*2)+get1(mid,r,st,en,node*2+1);
}
void update(int l,int r,int ind,int m5,int node,int inc)
{
	seg[node][m5]+=inc;
	if(inc>0)seg2[node]++;
	else seg2[node]--;
	if(r-l==1)return;
	int mid=(l+r)>>1;
	lz(node);
	if(ind<mid)update(l,mid,ind,m5,node*2,inc);
	else update(mid,r,ind,m5,node*2+1,inc);
}
void shift(int l,int r,int st,int en,int node,bool flag)
{
	if(st<=l && r<=en)
	{
		for(int j=0;j<=4;j++)sv[j]=seg[node][j];
		if(!flag)
		{
			lazy[node]++;
			for(int j=0;j<=4;j++)
			{
				int hlp=j+1;
				if(j==4)hlp=0;
				seg[node][hlp]=sv[j];
			}
			return;
		}
		lazy[node]--;
		for(int j=0;j<=4;j++)
		{
			int hlp=j-1;
			if(!j)hlp=4;
			seg[node][hlp]=sv[j];
		}
		return;
	}
	if(l>=en || st>=r)return;
	int mid=(l+r)>>1;
	lz(node);
	shift(l,mid,st,en,node*2,flag);
	shift(mid,r,st,en,node*2+1,flag);
	for(int j=0;j<=4;j++)seg[node][j]=seg[node*2][j]+seg[node*2+1][j];
}
main()
{
	int q;
	cin>>q;
	for(int i=1;i<=q;i++){
		cin>>x[i];
		if(x[i][0]!='s')
			cin>>a[i],ch.pb(a[i]);
	}
	sort(ch.begin(),ch.end());
	for(int i=0;i<ch.size();i++)
	{
		if(i==0 || ch[i]!=ch[i-1])has[ch[i]]=++cnt;
	}
	for(int i=1;i<=q;i++)
	{
	//	for(int j=0;j<=4;j++)cout<<j<<" "<<seg[1][j]<<"*******"<<endl;
		if(x[i]=="sum")
		{
			cout<<seg[1][3]<<"\n";
			continue;
		}
		else if(x[i]=="add"){
			int ind=get1(1,cnt+1,1,has[a[i]],1);
			ind++;
			//cout<<i<<" "<<ind<<"*******"<<endl;
			update(1,cnt+1,has[a[i]],ind%5,1,a[i]);
			shift(1,cnt+1,has[a[i]]+1,cnt+1,1,0);
		}
		else
		{
			int ind=get1(1,cnt+1,1,has[a[i]],1);
			ind++;
			update(1,cnt+1,has[a[i]],ind%5,1,-a[i]);
			shift(1,cnt+1,has[a[i]]+1,cnt+1,1,1);
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
vector<int>ch;
map<int,int>has;
int const M=2e5+10;
int cnt=0;
int seg[M*4][7];
int sv[M],a[M],lazy[M],seg2[M];
string x[M];
void check(int n1,int n2)
{
	lazy[n2]+=lazy[n1];
	for(int j=0;j<=4;j++)sv[j]=seg[n2][j];
	for(int j=0;j<=4;j++)
	{
		int hlp=j+lazy[n1];
		hlp+=5*1000000;
		hlp%=5;
		seg[n2][hlp]=sv[j];
	}
}
void lz(int node)
{
	check(node,node*2);
	check(node,node*2+1);
	lazy[node]=0;
}
int get1(int l,int r,int st,int en,int node)
{
	if(st<=l && r<=en)
	{
	//	int tmp=0;
	//	for(int i=0;i<=4;i++)tmp+=seg[node][i];
		return seg2[node];
	}
	if(l>=en || st>=r)return 0;
	int mid=(l+r)>>1;
	lz(node);
	return get1(l,mid,st,en,node*2)+get1(mid,r,st,en,node*2+1);
}
void update(int l,int r,int ind,int m5,int node,int inc)
{
	seg[node][m5]+=inc;
	if(inc>0)seg2[node]++;
	else seg2[node]--;
	if(r-l==1)return;
	int mid=(l+r)>>1;
	lz(node);
	if(ind<mid)update(l,mid,ind,m5,node*2,inc);
	else update(mid,r,ind,m5,node*2+1,inc);
}
void shift(int l,int r,int st,int en,int node,bool flag)
{
	if(st<=l && r<=en)
	{
		for(int j=0;j<=4;j++)sv[j]=seg[node][j];
		if(!flag)
		{
			lazy[node]++;
			for(int j=0;j<=4;j++)
			{
				int hlp=j+1;
				if(j==4)hlp=0;
				seg[node][hlp]=sv[j];
			}
			return;
		}
		lazy[node]--;
		for(int j=0;j<=4;j++)
		{
			int hlp=j-1;
			if(!j)hlp=4;
			seg[node][hlp]=sv[j];
		}
		return;
	}
	if(l>=en || st>=r)return;
	int mid=(l+r)>>1;
	lz(node);
	shift(l,mid,st,en,node*2,flag);
	shift(mid,r,st,en,node*2+1,flag);
	for(int j=0;j<=4;j++)seg[node][j]=seg[node*2][j]+seg[node*2+1][j];
}
main()
{
	int q;
	cin>>q;
	for(int i=1;i<=q;i++){
		cin>>x[i];
		if(x[i][0]!='s')
			cin>>a[i],ch.pb(a[i]);
	}
	sort(ch.begin(),ch.end());
	for(int i=0;i<ch.size();i++)
	{
		if(i==0 || ch[i]!=ch[i-1])has[ch[i]]=++cnt;
	}
	for(int i=1;i<=q;i++)
	{
	//	for(int j=0;j<=4;j++)cout<<j<<" "<<seg[1][j]<<"*******"<<endl;
		if(x[i]=="sum")
		{
			cout<<seg[1][3]<<"\n";
			continue;
		}
		else if(x[i]=="add"){
			int ind=get1(1,cnt+1,1,has[a[i]],1);
			ind++;
			//cout<<i<<" "<<ind<<"*******"<<endl;
			update(1,cnt+1,has[a[i]],ind%5,1,a[i]);
			shift(1,cnt+1,has[a[i]]+1,cnt+1,1,0);
		}
		else
		{
			int ind=get1(1,cnt+1,1,has[a[i]],1);
			ind++;
			update(1,cnt+1,has[a[i]],ind%5,1,-a[i]);
			shift(1,cnt+1,has[a[i]]+1,cnt+1,1,1);
		}
	}
}


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

typedef long long LL;

const int N = 1 << 18;
int a[N], tp[N], v[N], x[N], xn;
char s[10];

struct Treap {
	Treap *le, *ri;
	int pri, siz, val;
	LL sum;
	bool rev;
	Treap(int v): le(NULL), ri(NULL), pri(rand()), siz(1), val(LL(v)), sum(LL(v)), rev(false) {}
	void reduce() {
		siz = 1, sum = val;
		if (le != NULL) siz += le-> siz, sum += le->sum;
		if (ri != NULL) siz += ri-> siz, sum += ri->sum;
	}
};

void down(Treap *u) {
	if (u == NULL) return;
	if (u -> rev) {
		swap(u -> le, u -> ri);
		if (u -> le) u -> le -> rev ^= 1;
		if (u -> ri) u -> ri -> rev ^= 1;
		u -> rev = 0;
	}
}

Treap* merge(Treap *a, Treap *b) {
	if (a == NULL) return b;
	if (b == NULL) return a;
	down(a);
	down(b);
	if (a->pri >= b->pri) {
		a->ri = merge(a->ri, b);
		a->reduce();
		return a;
	}
	else {
		b->le = merge(a, b->le);
		b->reduce();
		return b;
	}
}

void split(Treap *u, int k, Treap *&a, Treap *&b) {
	if (k <= 0) {a = NULL; b = u; return;}
	if (k >= u->siz) {a = u; b = NULL; return;}
	down(u);
	const int uls = u->le != NULL? u->le->siz: 0;
	if (k <= uls) {
		b = u;
		split(u->le, k, a, u->le);
	}
	else {
		a = u;
		split(u->ri, k- uls - 1, u->ri, b);
	}
	u -> reduce();
}

void add(int x, int v) {
	for ( ; x < N; x += x & -x) a[x] += v;
}

int get(int x) {
	int ret = 0;
	for (; x; x -= x & -x) ret += a[x];
	return ret;
}

Treap *ans[6], *spt[6];

int main() {

//	freopen("in.txt", "r", stdin);

	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s%d", s, v + i);
		if (s[0] == 'a') tp[i] = 1, x[xn++] = v[i];
		if (s[0] == 'd') tp[i] = 2, x[xn++] = v[i];
	}
	sort (x, x + xn);
	xn = unique(x, x + xn) - x;

	for (int i = 0; i < 5; i++) ans[i] = new Treap(0);

	for (int i = 0; i < n; i++) {
		if (tp[i] == 0) {
			printf("%lld\n", ans[2] -> sum);
			continue;
		}
		int pos = lower_bound(x, x + xn, v[i]) - x + 1;
		int w = get(pos);
		add(pos, (tp[i] == 1 ? 1 : -1));
		for (int j = 0; j < 5; j++) spt[j] = NULL;
		if (tp[i] == 1) {
			int rem = w % 5, dv = w / 5;
			Treap *tp = new Treap(v[i]);
			for (int j = 0; j < 5; j++) split(ans[j], 1 + dv + (j < rem), ans[j], spt[j]);
			ans[rem] = merge(ans[rem], tp);
			for (int j = 0; j < 5; j++) ans[j] = merge(ans[j], spt[(j + 4) % 5]);
		} else {
			int rem = (w - 1) % 5, dv = (w - 1) / 5;
			Treap *tp = NULL;
			for (int j = 0; j < 5; j++) split(ans[j], 1 + dv + (j <= rem), ans[j], spt[j]);
			split(ans[rem], (ans[rem] -> siz) - 1, ans[rem], tp);
			for (int j = 0; j < 5; j++) ans[j] = merge(ans[j], spt[(j + 1) % 5]);
		}
	}

	return 0;
}


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

typedef long long LL;

const int N = 1 << 18;
int a[N], tp[N], v[N], x[N], xn;
char s[10];

struct Treap {
	Treap *le, *ri;
	int pri, siz, val;
	LL sum;
	bool rev;
	Treap(int v): le(NULL), ri(NULL), pri(rand()), siz(1), val(LL(v)), sum(LL(v)), rev(false) {}
	void reduce() {
		siz = 1, sum = val;
		if (le != NULL) siz += le-> siz, sum += le->sum;
		if (ri != NULL) siz += ri-> siz, sum += ri->sum;
	}
};

void down(Treap *u) {
	if (u == NULL) return;
	if (u -> rev) {
		swap(u -> le, u -> ri);
		if (u -> le) u -> le -> rev ^= 1;
		if (u -> ri) u -> ri -> rev ^= 1;
		u -> rev = 0;
	}
}

Treap* merge(Treap *a, Treap *b) {
	if (a == NULL) return b;
	if (b == NULL) return a;
	down(a);
	down(b);
	if (a->pri >= b->pri) {
		a->ri = merge(a->ri, b);
		a->reduce();
		return a;
	}
	else {
		b->le = merge(a, b->le);
		b->reduce();
		return b;
	}
}

void split(Treap *u, int k, Treap *&a, Treap *&b) {
	if (k <= 0) {a = NULL; b = u; return;}
	if (k >= u->siz) {a = u; b = NULL; return;}
	down(u);
	const int uls = u->le != NULL? u->le->siz: 0;
	if (k <= uls) {
		b = u;
		split(u->le, k, a, u->le);
	}
	else {
		a = u;
		split(u->ri, k- uls - 1, u->ri, b);
	}
	u -> reduce();
}

void add(int x, int v) {
	for ( ; x < N; x += x & -x) a[x] += v;
}

int get(int x) {
	int ret = 0;
	for (; x; x -= x & -x) ret += a[x];
	return ret;
}

Treap *ans[6], *spt[6];

int main() {

//	freopen("in.txt", "r", stdin);

	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s%d", s, v + i);
		if (s[0] == 'a') tp[i] = 1, x[xn++] = v[i];
		if (s[0] == 'd') tp[i] = 2, x[xn++] = v[i];
	}
	sort (x, x + xn);
	xn = unique(x, x + xn) - x;

	for (int i = 0; i < 5; i++) ans[i] = new Treap(0);

	for (int i = 0; i < n; i++) {
		if (tp[i] == 0) {
			printf("%lld\n", ans[2] -> sum);
			continue;
		}
		int pos = lower_bound(x, x + xn, v[i]) - x + 1;
		int w = get(pos);
		add(pos, (tp[i] == 1 ? 1 : -1));
		int rem = w % 5, dv = w / 5;
		for (int j = 0; j < 5; j++) spt[j] = NULL;
		if (tp[i] == 1) {
			Treap *tp = new Treap(v[i]);
			for (int j = 0; j < 5; j++) split(ans[j], 1 + dv + (j < rem), ans[j], spt[j]);
			ans[rem] = merge(ans[rem], tp);
			for (int j = 0; j < 5; j++) ans[j] = merge(ans[j], spt[(j + 4) % 5]);
		} else {
			Treap *tp;
			for (int j = 0; j < 5; j++) split(ans[j], 1 + dv + (j < rem), ans[j], spt[j]);
			split(ans[rem], ans[rem] -> siz - 1, ans[rem], tp);
			for (int j = 0; j < 5; j++) ans[j] = merge(ans[j], spt[(j + 1) % 5]);
		}
	}

	return 0;
}


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

typedef long long LL;

const int N = 1 << 18;
int a[N], tp[N], v[N], x[N], xn;
char s[10];

struct Treap {
	Treap *le, *ri;
	int pri, siz, val;
	LL sum;
	bool rev;
	Treap(int v): le(NULL), ri(NULL), pri(rand()), siz(1), val(LL(v)), sum(LL(v)), rev(false) {}
	void reduce() {
		siz = 1, sum = val;
		if (le != NULL) siz += le-> siz, sum += le->sum;
		if (ri != NULL) siz += ri-> siz, sum += ri->sum;
	}
};

void down(Treap *u) {
	if (u == NULL) return;
	if (u -> rev) {
		swap(u -> le, u -> ri);
		if (u -> le) u -> le -> rev ^= 1;
		if (u -> ri) u -> ri -> rev ^= 1;
		u -> rev = 0;
	}
}

Treap* merge(Treap *a, Treap *b) {
	if (a == NULL) return b;
	if (b == NULL) return a;
	down(a);
	down(b);
	if (a->pri >= b->pri) {
		a->ri = merge(a->ri, b);
		a->reduce();
		return a;
	}
	else {
		b->le = merge(a, b->le);
		b->reduce();
		return b;
	}
}

void split(Treap *u, int k, Treap *&a, Treap *&b) {
	if (k <= 0) {a = NULL; b = u; return;}
	if (k >= u->siz) {a = u; b = NULL; return;}
	down(u);
	const int uls = u->le != NULL? u->le->siz: 0;
	if (k <= uls) {
		b = u;
		split(u->le, k, a, u->le);
	}
	else {
		a = u;
		split(u->ri, k- uls - 1, u->ri, b);
	}
	u -> reduce();
}

void add(int x, int v) {
	for ( ; x < N; x += x & -x) a[x] += v;
}

int get(int x) {
	int ret = 0;
	for (; x; x -= x & -x) ret += a[x];
	return ret;
}

Treap *ans[6], *spt[6];

int main() {

//	freopen("in.txt", "r", stdin);

	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s%d", s, v + i);
		if (s[0] == 'a') tp[i] = 1, x[xn++] = v[i];
		if (s[0] == 'd') tp[i] = 2, x[xn++] = v[i];
	}
	sort (x, x + xn);
	xn = unique(x, x + xn) - x;

	for (int i = 0; i < 5; i++) ans[i] = new Treap(0);

	for (int i = 0; i < n; i++) {
		if (tp[i] == 0) {
			printf("%lld\n", ans[2] -> sum);
			continue;
		}
		int pos = lower_bound(x, x + xn, v[i]) - x + 1;
		int w = get(pos);
		add(pos, (tp[i] == 1 ? 1 : -1));
		int rem = w % 5, dv = w / 5;
		if (tp[i] == 1) {
			Treap *tp = new Treap(v[i]);
			for (int j = 0; j < 5; j++) split(ans[j], 1 + dv + (j < rem), ans[j], spt[j]);
			ans[rem] = merge(ans[rem], tp);
			for (int j = 0; j < 5; j++) ans[j] = merge(ans[j], spt[(j + 4) % 5]);
		} else {
			Treap *tp;
			for (int j = 0; j < 5; j++) split(ans[j], 1 + dv + (j < rem), ans[j], spt[j]);
			split(ans[rem], ans[rem] -> siz - 1, ans[rem], tp);
			for (int j = 0; j < 5; j++) ans[j] = merge(ans[j], spt[(j + 1) % 5]);
		}
	}

	return 0;
}


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

typedef long long LL;

const int N = 1 << 18;
int a[N], tp[N], v[N], x[N], xn;
char s[10];

struct Treap {
	Treap *le, *ri;
	int pri, siz, val;
	LL sum;
	bool rev;
	Treap(int v): le(NULL), ri(NULL), pri(rand()), siz(1), val(LL(v)), sum(LL(v)), rev(false) {}
	void reduce() {
		siz = 1, sum = val;
		if (le != NULL) siz += le-> siz, sum += le->sum;
		if (ri != NULL) siz += ri-> siz, sum += ri->sum;
	}
};

void down(Treap *u) {
	if (u == NULL) return;
	if (u -> rev) {
		swap(u -> le, u -> ri);
		if (u -> le) u -> le -> rev ^= 1;
		if (u -> ri) u -> ri -> rev ^= 1;
		u -> rev = 0;
	}
}

Treap* merge(Treap *a, Treap *b) {
	if (a == NULL) return b;
	if (b == NULL) return a;
	down(a);
	down(b);
	if (a->pri >= b->pri) {
		a->ri = merge(a->ri, b);
		a->reduce();
		return a;
	}
	else {
		b->le = merge(a, b->le);
		b->reduce();
		return b;
	}
}

void split(Treap *u, int k, Treap *&a, Treap *&b) {
	if (k <= 0) {a = NULL; b = u; return;}
	if (k >= u->siz) {a = u; b = NULL; return;}
	down(u);
	const int uls = u->le != NULL? u->le->siz: 0;
	if (k <= uls) {
		b = u;
		split(u->le, k, a, u->le);
	}
	else {
		a = u;
		split(u->ri, k- uls - 1, u->ri, b);
	}
	u -> reduce();
}

void add(int x, int v) {
	for ( ; x < N; x += x & -x) a[x] += v;
}

int get(int x) {
	int ret = 0;
	for (; x; x -= x & -x) ret += a[x];
	return ret;
}

Treap *ans[6], *spt[6];

int main() {

//	freopen("in.txt", "r", stdin);

	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s%d", s, v + i);
		if (s[0] == 'a') tp[i] = 1, x[xn++] = v[i];
		if (s[0] == 'd') tp[i] = 2, x[xn++] = v[i];
	}
	sort (x, x + xn);
	xn = unique(x, x + xn) - x;

	for (int i = 0; i < 5; i++) ans[i] = new Treap(0);

	for (int i = 0; i < n; i++) {
		if (tp[i] == 0) {
			printf("%lld\n", ans[2] -> sum);
			continue;
		}
		int pos = lower_bound(x, x + xn, v[i]) - x + 1;
		int w = get(pos);
		add(pos, (tp[i] == 1 ? 1 : -1));
		int rem = w % 5, dv = w / 5;
		for (int j = 0; j < 5; j++) spt[j] = NULL;
		if (tp[i] == 1) {
			Treap *tp = new Treap(v[i]);
			for (int j = 0; j < 5; j++) split(ans[j], 1 + dv + (j < rem), ans[j], spt[j]);
			ans[rem] = merge(ans[rem], tp);
			for (int j = 0; j < 5; j++) ans[j] = merge(ans[j], spt[(j + 4) % 5]);
		} else {
			Treap *tp;
			for (int j = 0; j < 5; j++) split(ans[j], 1 + dv + (j <= rem), ans[j], spt[j]);
			split(ans[rem], ans[rem] -> siz - 1, ans[rem], tp);
			for (int j = 0; j < 5; j++) ans[j] = merge(ans[j], spt[(j + 1) % 5]);
		}
	}

	return 0;
}


#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

struct node
{
	LL val,key,ls,rs,sz,sum[10];
}a[1000000];

LL n,x,len=1,root=0;
string s;

LL newnode(LL y)
{
	a[len].key=rand()*rand()%MOD;
	a[len].val=a[len].sum[0]=y;
	memset(a[len].sum,0,sizeof(a[len].sum));
	a[len].ls=a[len].rs=0;
	a[len].sz=1;
	return len++;
}

void calc(LL y)
{
	if(y==0) return;
	a[y].sz=a[a[y].ls].sz+1+a[a[y].rs].sz;
	rep(i,5) a[y].sum[i]=a[a[y].ls].sum[i];
	a[y].sum[a[a[y].ls].sz%5]+=a[y].val;
	rep(i,5) a[y].sum[(i+(a[a[y].ls].sz+1)%5)%5]+=a[a[y].rs].sum[i];
}

LL merge(LL y,LL z)
{
	if(y==0||z==0)
	{
		calc(max(y,z));
		return max(y,z);
	}
	if(a[y].val>a[z].val) swap(y,z);
	LL ret;
	if(a[y].key<a[z].key)
	{
		ret=y;
		a[ret].rs=merge(a[ret].rs,z);
	}
	else
	{
		ret=z;
		a[ret].ls=merge(a[ret].ls,y);
	}
	calc(ret);
	return ret;
}

pii split(LL y,LL z)
{
	if(y==0) return mpr(0,0);
	LL ret,ret2;
	if(a[y].val<=z)
	{
		ret=y;
		pii p=split(a[y].rs,z);
		a[ret].rs=p.fi;
		ret2=p.se;
	}
	else
	{
		ret2=y;
		pii p=split(a[y].ls,z);
		a[ret2].ls=p.se;
		ret=p.fi;
	}
	calc(ret);
	calc(ret2);
	return mpr(ret,ret2);
}

void add(LL y)
{
	pii p=split(root,y);
	LL pp=merge(p.fi,newnode(y));
	root=merge(pp,p.se);
}

void del(LL y)
{
	pii p=split(root,y);
	pii pp=split(p.fi,y-1);
	pp.se=merge(a[pp.se].ls,a[pp.se].rs);
	root=merge(merge(pp.fi,pp.se),p.se);
}

int main()
{
	srand(984324);
	cin>>n;
	rep(i,n)
	{
		cin>>s;
		if(s[0]=='a')
		{
			scanf("%I64d",&x);
			add(x);
		}
		else if(s[0]=='d')
		{
			scanf("%I64d",&x);
			del(x);
		}
		else printf("%I64d\n",a[root].sum[2]);
	}
	return 0;
}


#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

struct node
{
	int val,key,ls,rs,sz,sum[10];
}a[1000000];

int n,x,len=1,root=0;
string s;

int newnode(int y)
{
	a[len].key=rand()*rand()%MOD;
	a[len].val=a[len].sum[0]=y;
	//cout<<len<<' '<<y<<'p'<<endl;
	memset(a[len].sum,0,sizeof(a[len].sum));
	a[len].ls=a[len].rs=0;
	a[len].sz=1;
	return len++;
}

void calc(int y)
{
	if(y==0) return;
	a[y].sz=a[a[y].ls].sz+1+a[a[y].rs].sz;
	rep(i,5) a[y].sum[i]=a[a[y].ls].sum[i];
	a[y].sum[a[a[y].ls].sz%5]+=a[y].val;
	rep(i,5) a[y].sum[(i+(a[a[y].ls].sz+1)%5)%5]+=a[a[y].rs].sum[i];
	//cout<<y<<' '<<a[y].val<<' '<<a[y].sz<<endl;
	//rep(i,5) cout<<a[y].sum[i]<<' ';cout<<endl;
}

int merge(int y,int z)
{
	if(y==0||z==0) return max(y,z);
	if(a[y].val>a[z].val) swap(y,z);
	int ret;
	if(a[y].key<a[z].key)
	{
		ret=y;
		a[ret].rs=merge(a[ret].rs,z);
	}
	else
	{
		ret=z;
		a[ret].ls=merge(a[ret].ls,y);
	}
	calc(ret);
	return ret;
}

pii split(int y,int z)
{
	if(y==0) return mpr(0,0);
	int ret,ret2;
	if(a[y].val<=z)
	{
		ret=y;
		pii p=split(a[y].rs,z);
		a[ret].rs=p.fi;
		ret2=p.se;
	}
	else
	{
		ret2=y;
		pii p=split(a[y].ls,z);
		a[ret2].ls=p.se;
		ret=p.fi;
	}
	calc(ret);
	calc(ret2);
	return mpr(ret,ret2);
}

void add(int y)
{
	//cout<<root<<'p'<<endl;
	pii p=split(root,y);//cout<<"stane"<<endl;
	int pp=merge(p.fi,newnode(y));//cout<<"stane"<<endl;
	root=merge(pp,p.se);
}

void del(int y)
{
	pii p=split(root,y),pp=split(p.fi,y-1);
	pp.se=merge(a[pp.se].ls,a[pp.se].rs);
	root=merge(merge(pp.fi,pp.se),p.se);
}

int main()
{
	srand(114514);
	cin>>n;
	rep(i,n)
	{
		cin>>s;
		if(s[0]=='a')
		{
			scanf("%d",&x);
			add(x);
		}
		else if(s[0]=='d')
		{
			scanf("%d",&x);
			//cout<<endl<<endl<<endl<<endl;
			del(x);
		}
		else printf("%d\n",a[root].sum[2]);
	}
	return 0;
}
/*
11
add 1
add 2
add 3
add 4
add 5
add 6
add 7
add 8
add 9
del 8
sum
*/


#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

struct node
{
	int val,key,ls,rs,sz,sum[10];
}a[1000000];

int n,x,len=1,root=0;
string s;

int newnode(int y)
{
	a[len].key=rand()*rand()%MOD;
	a[len].val=a[len].sum[0]=y;
	memset(a[len].sum,0,sizeof(a[len].sum));
	a[len].ls=a[len].rs=0;
	a[len].sz=1;
	return len++;
}

void calc(int y)
{
	if(y==0) return;
	a[y].sz=a[a[y].ls].sz+1+a[a[y].rs].sz;
	rep(i,5) a[y].sum[i]=a[a[y].ls].sum[i];
	a[y].sum[a[a[y].ls].sz%5]+=a[y].val;
	rep(i,5) a[y].sum[(i+(a[a[y].ls].sz+1)%5)%5]+=a[a[y].rs].sum[i];
}

int merge(int y,int z)
{
	if(y==0||z==0)
	{
		calc(max(y,z));
		return max(y,z);
	}
	if(a[y].val>a[z].val) swap(y,z);
	int ret;
	if(a[y].key<a[z].key)
	{
		ret=y;
		a[ret].rs=merge(a[ret].rs,z);
	}
	else
	{
		ret=z;
		a[ret].ls=merge(a[ret].ls,y);
	}
	calc(ret);
	return ret;
}

pii split(int y,int z)
{
	if(y==0) return mpr(0,0);
	int ret,ret2;
	if(a[y].val<=z)
	{
		ret=y;
		pii p=split(a[y].rs,z);
		a[ret].rs=p.fi;
		ret2=p.se;
	}
	else
	{
		ret2=y;
		pii p=split(a[y].ls,z);
		a[ret2].ls=p.se;
		ret=p.fi;
	}
	calc(ret);
	calc(ret2);
	return mpr(ret,ret2);
}

void add(int y)
{
	pii p=split(root,y);
	int pp=merge(p.fi,newnode(y));
	root=merge(pp,p.se);
}

void del(int y)
{
	pii p=split(root,y);
	pii pp=split(p.fi,y-1);
	pp.se=merge(a[pp.se].ls,a[pp.se].rs);
	root=merge(merge(pp.fi,pp.se),p.se);
}

int main()
{
	srand(984324);
	cin>>n;
	rep(i,n)
	{
		cin>>s;
		if(s[0]=='a')
		{
			scanf("%d",&x);
			add(x);
		}
		else if(s[0]=='d')
		{
			scanf("%d",&x);
			del(x);
		}
		else printf("%d\n",a[root].sum[2]);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 200005;

int m;
pair<char, int> b[N];

int n;
vector<int> v;
map<int, int> mp;
int rmp[N];

struct ban
{
    int q;
    long long ans[5];
    ban()
    {
        q = 0;
        memset(ans, 0, sizeof ans);
    }
    ban(int x)
    {
        q = 1;
        memset(ans, 0, sizeof ans);
        ans[0] = x;
    }
};

ban t[N * 4];

ban mer(const ban& l, const ban& r)
{
    ban ans;
    ans = l;
    for (int i = 0; i < 5; ++i)
    {
        ans.ans[(l.q + i) % 5] += r.ans[i];
    }
    ans.q += r.q;
    return ans;
}

void ubd(int tl, int tr, int x, int y, int pos)
{
    if (tl == tr)
    {
        if (y > 0)
            t[pos] = ban(rmp[x]);
        else
            t[pos] = ban();
        return;
    }
    int m = (tl + tr) / 2;
    if (x <= m)
        ubd(tl, m, x, y, pos * 2);
    else
        ubd(m + 1, tr, x, y, pos * 2 + 1);
    t[pos] = mer(t[pos * 2], t[pos * 2 + 1]);
}

int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d", &m);
    for (int i = 0; i < m; ++i)
    {
        char ty[5];
        scanf(" %s", ty);
        int x = 0;
        if (ty[0] == 'a' || ty[0] == 'd')
        {
            scanf("%d", &x);
            v.push_back(x);
        }
        b[i] = m_p(ty[0], x);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); ++i)
    {
        if (!i || v[i] != v[i - 1])
        {
            mp[v[i]] = ++n;
            rmp[n] = v[i];
        }
    }
    for (int i = 0; i < m; ++i)
    {
        if (b[i].first == 'a')
            ubd(1, n, mp[b[i].second], 1, 1);
        else if (b[i].first == 'd')
            ubd(1, n, mp[b[i].second], -1, 1);
        else
            printf("%I64d\n", t[1].ans[2]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 200005;

int m;
pair<char, int> b[N];

int n;
vector<int> v;
map<int, int> mp;

struct ban
{
    int q;
    long long ans[5];
    ban()
    {
        q = 0;
        memset(ans, 0, sizeof ans);
    }
    ban(int x)
    {
        q = 1;
        memset(ans, 0, sizeof ans);
        ans[0] = x;
    }
};

ban t[N * 4];

ban mer(const ban& l, const ban& r)
{
    ban ans;
    ans = l;
    for (int i = 0; i < 5; ++i)
    {
        ans.ans[(l.q + i) % 5] += r.ans[i];
    }
    ans.q += r.q;
    return ans;
}

void ubd(int tl, int tr, int x, int y, int pos)
{
    if (tl == tr)
    {
        if (y > 0)
            t[pos] = ban(mp[x]);
        else
            t[pos] = ban();
        return;
    }
    int m = (tl + tr) / 2;
    if (x <= m)
        ubd(tl, m, x, y, pos * 2);
    else
        ubd(m + 1, tr, x, y, pos * 2 + 1);
    t[pos] = mer(t[pos * 2], t[pos * 2 + 1]);
}

int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d", &m);
    for (int i = 0; i < m; ++i)
    {
        char ty[5];
        scanf(" %s", ty);
        int x = 0;
        if (ty[0] == 'a' || ty[0] == 'd')
        {
            scanf("%d", &x);
            v.push_back(x);
        }
        b[i] = m_p(ty[0], x);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); ++i)
    {
        if (!i || v[i] != v[i - 1])
            mp[v[i]] = ++n;
    }
    for (int i = 0; i < m; ++i)
    {
        if (b[i].first == 'a')
            ubd(1, n, mp[b[i].second], 1, 1);
        else if (b[i].first == 'd')
            ubd(1, n, mp[b[i].second], -1, 1);
        else
            printf("%I64d\n", t[1].ans[2]);
    }
    return 0;
}


#include<cstdio>
#include<cmath>
#include<cctype>
#include<cstring>
#include<iostream>
#include<string>
#include<sstream>
//stringstream ss(line)
#include<algorithm>
//sort(a,a+n,cmp)
//p=lower_bound(a,a+n,x)-a+1(���ڻ����x�ĵ�һ��λ��)
#include<vector>
#include<bitset>
//bitset<N> xx

using namespace std;

typedef long long ll;

const int MAXN = 1e5+10;
const int INF = 1e9+10;
int pos = 0,N=0;
int num[MAXN];

void add(int x){
	num[pos++]=x;
	N++;
}

void del(int x){
	int p=0;
	for(p=0;p<N;p++){
		if(num[p]==x){
			break;
		}
	}
	for(;p<N-1;p++){
		num[p]=num[p+1];
	}
	N--;
	pos--;
}

ll query(){
	sort(num,num+N);
	ll sum=0;
	for(int i=0;i<N;i++){
		if(i%5==2)	sum+=num[i];
	}
	return sum;
}

int main(){
	char op[5];
	int total=0;
	scanf("%d",&total);
	while(total--){
		int d;
		scanf("%s",op);
		if(op[0]=='a'){
			scanf("%d",&d);
			add(d);
		}else if(op[0]=='d'){
			scanf("%d",&d);
			del(d);
		}else{
			printf("%I64d\n",query());
		}
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        char s[5];
        vector<int>v;
        vector<int>::iterator it;
        while(n--)
        {
            scanf("%s",s);
            if(s[0]=='a')
            {
                int x;
                scanf("%d",&x);
                it=lower_bound(v.begin(),v.end(),x);
                v.insert(it,x);
            }
            else
                if(s[0]=='d')
                {
                    int x;
                    scanf("%d",&x);
                    it=lower_bound(v.begin(),v.end(),x);
                    v.erase(it);
                }
                else
                {
                    __int64 sum=0;
                    for(int i=2;i<v.size();i+=5)
                    {
                        sum+=v[i];
                    }
                    printf("%I64d\n",sum);
                }
        }
    }
}


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

#define int long long

const int L=300;

struct Node
{
	deque<int> v;
	vector<int> sum;

	Node()
	{
		for(int i=0;i<5;i++) sum.push_back(0);
	}

	inline int ty()
	{
		if(v.size()==0) return -1;
		if(v.size()>=L) return 1;
		return 0;
	}

	inline void add(int ne)
	{
		vector<int> tmp;
		while(!v.empty() && v.front()<=ne)
		{
			tmp.push_back(v.front());
			v.pop_front();
		}
		v.push_front(ne);
		while(!tmp.empty())
		{
			v.push_front(tmp.back());
			tmp.pop_back();
		}
	}

	inline void del(int de)
	{
		vector<int> tmp;
		while(!v.empty() && v.front()<de)
		{
			tmp.push_back(v.front());
			v.pop_front();
		}
		v.pop_front();
		while(!tmp.empty())
		{
			v.push_front(tmp.back());
			tmp.pop_back();
		}
	}

	inline int moveL(int ne)
	{
		sum[0]-=v.front();
		int t=sum[0];
		for(int i=1;i<5;i++) sum[i-1]=sum[i];
		sum[4]=t;
		if(ne!=-1) sum[(v.size()-1)%5]+=ne;

		int res=v.front();
		v.pop_front();
		if(ne!=-1) v.push_back(ne);
		return res;
	}

	inline int moveR(int ne)
	{
		sum[(v.size()-1)%5]-=v.back();
		int t=sum[4];
		for(int i=3;i>=0;i--) sum[i+1]=sum[i];
		sum[0]=t;
		sum[0]+=ne;

		int res=v.back();
		v.pop_back();
		v.push_front(ne);
		return res;
	}

	inline void calc()
	{
		for(int i=0;i<5;i++) sum[i]=0;
		for(int i=0;i<v.size();i+=5)
		{
			for(int j=0;j<5;j++)
			{
				if(i+j<v.size()) sum[j]+=v[i+j];
			}
		}
	}
};

vector<Node> a;

main()
{
	int Q; cin>>Q;
	while(Q--)
	{
		if(a.empty()) a.push_back(Node());
		string op; cin>>op;
		if(op[0]=='a')
		{
			int ne; cin>>ne;
			for(int i=0;i<=a.size();i++)
			{
				if(i==a.size()) a.push_back(Node());
				if(a[i].ty()==-1 || a[i].ty()==0)
				{
					a[i].add(ne);
					a[i].calc();
					break;
				}
				else if(a[i].ty()==1 && a[i].v.back()>=ne)
				{
					a[i].add(ne);
					int t=a[i].v.back();
					a[i].v.pop_back();
					a[i].calc();
					for(int j=i+1;j<=a.size();j++)
					{
						if(j==a.size()) a.push_back(Node());
						if(a[j].ty()==1) t=a[j].moveR(t);
						else
						{
							a[j].v.push_front(t);
							a[j].calc();
							break;
						}
					}
					break;
				}
			}
		}
		else if(op[0]=='d')
		{
			int de; cin>>de;
			for(int i=0;i<a.size();i++)
			{
				if(a[i].v.front()<=de && de<=a[i].v.back())
				{
					a[i].del(de);
					int t=-1;
					for(int j=a.size()-1;j>=i+1;j--)
					{
						t=a[j].moveL(t);
					}
					if(t!=-1) a[i].v.push_back(t);
					a[i].calc();
					if(a.back().ty()==-1) a.pop_back();
					break;
				}
			}
		}
		else if(op[0]=='s')
		{
			int res=0;
			for(int i=0;i<a.size();i++)
			{
				res+=a[i].sum[2];
			}
			cout<<res<<endl;
		}
	}

	return 0;
}


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

#define int long long

const int L=400;

struct Node
{
	deque<int> v;
	vector<int> sum;

	Node()
	{
		for(int i=0;i<5;i++) sum.push_back(0);
	}

	inline int ty()
	{
		if(v.size()==0) return -1;
		if(v.size()>=L) return 1;
		return 0;
	}

	inline void add(int ne)
	{
		vector<int> tmp;
		while(!v.empty() && v.front()<=ne)
		{
			tmp.push_back(v.front());
			v.pop_front();
		}
		v.push_front(ne);
		while(!tmp.empty())
		{
			v.push_front(tmp.back());
			tmp.pop_back();
		}
	}

	inline void del(int de)
	{
		vector<int> tmp;
		while(!v.empty() && v.front()<de)
		{
			tmp.push_back(v.front());
			v.pop_front();
		}
		v.pop_front();
		while(!tmp.empty())
		{
			v.push_front(tmp.back());
			tmp.pop_back();
		}
	}

	inline int moveL(int ne)
	{
		sum[0]-=v.front();
		int t=sum[0];
		for(int i=1;i<5;i++) sum[i-1]=sum[i];
		sum[4]=t;
		if(ne!=-1) sum[(v.size()-1)%5]+=ne;

		int res=v.front();
		v.pop_front();
		if(ne!=-1) v.push_back(ne);
		return res;
	}

	inline int moveR(int ne)
	{
		sum[(v.size()-1)%5]-=v.back();
		int t=sum[4];
		for(int i=3;i>=0;i--) sum[i+1]=sum[i];
		sum[0]=t;
		sum[0]+=ne;

		int res=v.back();
		v.pop_back();
		v.push_front(ne);
		return res;
	}

	inline void calc()
	{
		for(int i=0;i<5;i++) sum[i]=0;
		for(int i=0;i<v.size();i+=5)
		{
			for(int j=0;j<5;j++)
			{
				if(i+j<v.size()) sum[j]+=v[i+j];
			}
		}
	}
};

vector<Node> a;

main()
{
	int Q; cin>>Q;
	while(Q--)
	{
		if(a.empty()) a.push_back(Node());
		string op; cin>>op;
		if(op[0]=='a')
		{
			int ne; cin>>ne;
			for(int i=0;i<=a.size();i++)
			{
				if(i==a.size()) a.push_back(Node());
				if(a[i].ty()==-1 || a[i].ty()==0)
				{
					a[i].add(ne);
					a[i].calc();
					break;
				}
				else if(a[i].ty()==1 && a[i].v.back()>=ne)
				{
					a[i].add(ne);
					int t=a[i].v.back();
					a[i].v.pop_back();
					a[i].calc();
					for(int j=i+1;j<=a.size();j++)
					{
						if(j==a.size()) a.push_back(Node());
						if(a[j].ty()==1) t=a[j].moveR(t);
						else
						{
							a[j].v.push_front(t);
							a[j].calc();
							break;
						}
					}
					break;
				}
			}
		}
		else if(op[0]=='d')
		{
			int de; cin>>de;
			for(int i=0;i<a.size();i++)
			{
				if(a[i].v.front()<=de && de<=a[i].v.back())
				{
					a[i].del(de);
					int t=-1;
					for(int j=a.size()-1;j>=i+1;j--)
					{
						t=a[j].moveL(t);
					}
					if(t!=-1) a[i].v.push_back(t);
					a[i].calc();
					if(a.back().ty()==-1) a.pop_back();
					break;
				}
			}
		}
		else if(op[0]=='s')
		{
			int res=0;
			for(int i=0;i<a.size();i++)
			{
				res+=a[i].sum[2];
			}
			cout<<res<<endl;
		}
	}

	return 0;
}


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

#define int long long

const int L=350;

struct Node
{
	deque<int> v;
	vector<int> sum;

	Node()
	{
		for(int i=0;i<5;i++) sum.push_back(0);
	}

	inline int ty()
	{
		if(v.size()==0) return -1;
		if(v.size()>=L) return 1;
		return 0;
	}

	inline void add(int ne)
	{
		vector<int> tmp;
		while(!v.empty() && v.front()<=ne)
		{
			tmp.push_back(v.front());
			v.pop_front();
		}
		v.push_front(ne);
		while(!tmp.empty())
		{
			v.push_front(tmp.back());
			tmp.pop_back();
		}
	}

	inline void del(int de)
	{
		vector<int> tmp;
		while(!v.empty() && v.front()<de)
		{
			tmp.push_back(v.front());
			v.pop_front();
		}
		v.pop_front();
		while(!tmp.empty())
		{
			v.push_front(tmp.back());
			tmp.pop_back();
		}
	}

	inline int moveL(int ne)
	{
		sum[0]-=v.front();
		int t=sum[0];
		for(int i=1;i<5;i++) sum[i-1]=sum[i];
		sum[4]=t;
		if(ne!=-1) sum[(v.size()-1)%5]+=ne;

		int res=v.front();
		v.pop_front();
		if(ne!=-1) v.push_back(ne);
		return res;
	}

	inline int moveR(int ne)
	{
		sum[(v.size()-1)%5]-=v.back();
		int t=sum[4];
		for(int i=3;i>=0;i--) sum[i+1]=sum[i];
		sum[0]=t;
		sum[0]+=ne;

		int res=v.back();
		v.pop_back();
		v.push_front(ne);
		return res;
	}

	inline void calc()
	{
		for(int i=0;i<5;i++) sum[i]=0;
		for(int i=0;i<v.size();i+=5)
		{
			for(int j=0;j<5;j++)
			{
				if(i+j<v.size()) sum[j]+=v[i+j];
			}
		}
	}
};

vector<Node> a;

main()
{
	int Q; cin>>Q;
	while(Q--)
	{
		if(a.empty()) a.push_back(Node());
		string op; cin>>op;
		if(op[0]=='a')
		{
			int ne; cin>>ne;
			for(int i=0;i<=a.size();i++)
			{
				if(i==a.size()) a.push_back(Node());
				if(a[i].ty()==-1 || a[i].ty()==0)
				{
					a[i].add(ne);
					a[i].calc();
					break;
				}
				else if(a[i].ty()==1 && a[i].v.back()>=ne)
				{
					a[i].add(ne);
					int t=a[i].v.back();
					a[i].v.pop_back();
					a[i].calc();
					for(int j=i+1;j<=a.size();j++)
					{
						if(j==a.size()) a.push_back(Node());
						if(a[j].ty()==1) t=a[j].moveR(t);
						else
						{
							a[j].v.push_front(t);
							a[j].calc();
							break;
						}
					}
					break;
				}
			}
		}
		else if(op[0]=='d')
		{
			int de; cin>>de;
			for(int i=0;i<a.size();i++)
			{
				if(a[i].v.front()<=de && de<=a[i].v.back())
				{
					a[i].del(de);
					int t=-1;
					for(int j=a.size()-1;j>=i+1;j--)
					{
						t=a[j].moveL(t);
					}
					if(t!=-1) a[i].v.push_back(t);
					a[i].calc();
					if(a.back().ty()==-1) a.pop_back();
					break;
				}
			}
		}
		else if(op[0]=='s')
		{
			int res=0;
			for(int i=0;i<a.size();i++)
			{
				res+=a[i].sum[2];
			}
			cout<<res<<endl;
		}
	}

	return 0;
}


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

const int maxn = 1e5+5;

vector<int> v;
struct Tree{
    ll sum[5]; int cnt;
}T[maxn<<2];
#define mid ((l+r)>>1)
#define ls (u<<1)
#define rs (u<<1|1)
void build(int u,int l,int r){
    memset(&T[u], 0, sizeof(Tree));
    if(l == r) return;
    build(ls,l,mid); build(rs,mid+1,r);
}
inline void pushup(int u){
    T[u] = T[ls];
    T[u].cnt += T[rs].cnt;
    int dt = T[ls].cnt%5;
    for(int i = 0; i < 5; i++) T[u].sum[i] += T[rs].sum[(i-dt+5)%5];
}
void change(int u,int l,int r,int p,int x){
    if(l == r){
        T[u].cnt += x;
        T[u].sum[0] += 1ll*x*v[p];
        return;
    }
    if(p <= mid) change(ls,l,mid,p,x);
    else change(rs,mid+1,r,p,x);
    pushup(u);
}
int n, m;
int oper[maxn];
int main() {
    scanf("%d", &n);
    char op[5];
    v.clear();
    for(int i = 1; i <= n; i++){
        cin>>op;
        if(op[0] == 'a' || op[0] == 'd'){
            cin>>oper[i], v.push_back(oper[i]);
            if(op[0] == 'd') oper[i] *= -1;
        }
        else oper[i] = 0;
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    m = n; n = v.size();
    if(n == 0){
        for(int i = 1; i <= m; i++) puts("0");
        return 0;
    }
    v.insert(v.begin(), -1);
    build(1,1,n);
    for(int i = 1; i <= m; i++){
        if(oper[i] == 0){
            printf("%lld\n", T[1].sum[2]);
        }else if(oper[i] > 0){
            change(1,1,n,lower_bound(v.begin(),v.end(),oper[i])-v.begin(),+1);
        }else{
            change(1,1,n,lower_bound(v.begin(),v.end(),-oper[i])-v.begin(),-1);
        }
    }
    return 0;
}


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

const int maxn = 1e5+5;

vector<int> v;
struct Tree{
    ll sum[5]; int cnt;
}T[maxn<<2];
#define mid ((l+r)>>1)
#define ls (u<<1)
#define rs (u<<1|1)
void build(int u,int l,int r){
    memset(&T[u], 0, sizeof(Tree));
    if(l == r) return;
    build(ls,l,mid); build(rs,mid+1,r);
}
inline void pushup(int u){
    T[u] = T[ls];
    T[u].cnt += T[rs].cnt;
    int dt = T[ls].cnt%5;
    for(int i = 0; i < 5; i++) T[u].sum[i] += T[rs].sum[(i-dt+5)%5];
}
void change(int u,int l,int r,int p,int x){
    if(l == r){
        T[u].cnt += x;
        T[u].sum[0] += 1ll*x*v[p];
        return;
    }
    if(p <= mid) change(ls,l,mid,p,x);
    else change(rs,mid+1,r,p,x);
    pushup(u);
}
int n, m;
int oper[maxn];
int main() {
    scanf("%d", &n);
    char op[5];
    v.clear();
    for(int i = 1; i <= n; i++){
        cin>>op;
        if(op[0] == 'a' || op[0] == 'd'){
            cin>>oper[i], v.push_back(oper[i]);
            if(op[0] == 'd') oper[i] *= -1;
        }
        else oper[i] = 0;
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    m = n; n = v.size();
    v.insert(v.begin(), -1);
    build(1,1,n);
    for(int i = 1; i <= m; i++){
        if(oper[i] == 0){
            printf("%lld\n", T[1].sum[2]);
        }else if(oper[i] > 0){
            change(1,1,n,lower_bound(v.begin(),v.end(),oper[i])-v.begin(),+1);
        }else{
            change(1,1,n,lower_bound(v.begin(),v.end(),-oper[i])-v.begin(),-1);
        }
    }
    return 0;
}


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

#define pb push_back
#define fi first
#define se second
#define ll long long
#define pq priority_queue
#define pii pair<int,int>
#define mod 998244353
#define debug(x) cerr<<#x<<"="<<x<<'\n'
#define lc v*2
#define rc v*2+1

int n,Q;
const int maxn=1e5+10;
pii q[maxn];
map<int,int> mp;
ll sum[4*maxn][5];
int cnt[4*maxn];

void update(int v) {
	cnt[v]=cnt[lc]+cnt[rc];
	for (int i=0;i<5;i++)
		sum[v][i]=sum[lc][i]+sum[rc][(i-cnt[lc]%5+5)%5];
	return;
}

int main(){
	scanf("%d",&Q);
	for (int i=0;i<Q;i++) {
		string s;
		cin>>s;
		if (s[0]=='s') {
			q[i].fi=2,q[i].se=0;
			continue;
		}
		int x;scanf("%d",&x);
		if (s[0]=='a') q[i]=make_pair(0,x);
		else if (s[0]=='d') q[i]=make_pair(1,x);
		mp[x]=0;
	}
	n=1;
	for (map<int,int>:: iterator it=mp.begin();it!=mp.end();it++)
		it->second=n++;
	for (int i=0;i<Q;i++) {
		if (q[i].fi==2) cout<<sum[1][2]<<endl;
		else {
			int pos=maxn+mp[q[i].se];
			cnt[pos]=1-q[i].fi;
			sum[pos][0]=cnt[pos]*(ll)q[i].se;
			while (pos>1) {
				pos/=2;
				update(pos);
			}
		}
	}
	return 0;
}


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

#define pb push_back
#define fi first
#define se second
#define ll long long
#define pq priority_queue
#define pii pair<int,int>
#define mod 998244353
#define debug(x) cerr<<#x<<"="<<x<<'\n'
#define lc v*2
#define rc v*2+1

int n,Q;
const int maxn=(1<<17);
pii q[maxn];
map<int,int> mp;
ll sum[4*maxn][5];
int cnt[4*maxn];

void update(int v) {
	cnt[v]=cnt[lc]+cnt[rc];
	for (int i=0;i<5;i++)
		sum[v][i]=sum[lc][i]+sum[rc][(i-cnt[lc]%5+5)%5];
	return;
}

int main(){
	scanf("%d",&Q);
	for (int i=0;i<Q;i++) {
		string s;
		cin>>s;
		if (s[0]=='s') {
			q[i].fi=2,q[i].se=0;
			continue;
		}
		int x;scanf("%d",&x);
		if (s[0]=='a') q[i]=make_pair(0,x);
		else if (s[0]=='d') q[i]=make_pair(1,x);
		mp[x]=0;
	}
	n=0;
	for (map<int,int>:: iterator it=mp.begin();it!=mp.end();it++)
		it->second=n++;
	for (int i=0;i<Q;i++) {
		if (q[i].fi==2) cout<<sum[1][2]<<endl;
		else {
			int pos=maxn+mp[q[i].se];
			cnt[pos]=1-q[i].fi;
			sum[pos][0]=cnt[pos]*(ll)q[i].se;
			while (pos>1) {
				pos/=2;
				update(pos);
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/rope> //header with rope
// using namespace __gnu_cxx;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/// Typedef
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector< pii > vii;

#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x)-1; i>=int(y); i--)
#define Binary(x,b)         std::bitset< b >( x ).to_string()
#define fastIO              ios::sync_with_stdio(false);    cin.tie(nullptr);   cout.tie(nullptr)
#define ran()               (((((1ULL*rand())<<31)|(1ULL*rand()))<<13)^((((1ULL*rand())<<32)|(1ULL*rand()))))
#define rran(a, b)          ((ran() % ((b) - (a) + 1)) + (a))
#define CLR(x, y)           memset(x, y, sizeof(x))
#define sc(n)               sf("%d",&n)
#define sc2(a,b)            sf("%d%d",&a,&b)
#define sc3(a,b,c)          sf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d)        sf("%d%d%d%d",&a,&b,&c,&d)
#define scll(n)             sf("%lld",&n)
#define scll2(a,b)          sf("%lld%lld",&a,&b)
#define scll3(a,b,c)        sf("%lld%lld%lld",&a,&b,&c)
#define scll4(a,b,c,d)      sf("%lld%lld%lld%lld",&a,&b,&c,&d)
#define bitCheck(N,in)      ((bool)(N&(1LL<<(in))))
#define bitOff(N,in)        (N&(~(1LL<<(in))))
#define bitOn(N,in)         (N|(1LL<<(in)))
#define bitFlip(a,k)        (a^(1LL<<(k)))
#define bitCount(a)         __builtin_popcount(a)
#define bitCountLL(a)       __builtin_popcountll(a)
#define bitRightMost(a)     __builtin_ctzll(a)
#define bitLeftMost(a)      (63-__builtin_clzll(a))
#define SQR(x)              ((x)*(x))
#define mxEq(a,b)           (a = max(a,b))
#define all(c)              c.begin(), c.end()
#define unq(v)              sort(all(v)), (v).resize(unique(all(v)) - v.begin())
#define common(a,b)         sort(all(a)), sort(all(b)), a.erase(set_intersection(all(a),all(b),a.begin()),a.end())
#define uncommon(a,b)       sort(all(a)), sort(all(b)), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end())

// uniform random generator -->
// uniform_int_distribution<int> dist(0, 1);
// default_random_engine gen;

// *X.find_by_order(k) //returns the kth largest element.(0-based)
// X.order_of_key(val) //returns the no. of values less than val
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // C++98
// template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline T bigMod(T p,T e,T M){ T ret = 1; for(; e > 0; e >>= 1){ if(e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T) ret;}
template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
template <class T> inline string int2String(T a){ostringstream str; str<<a; return str.str();}
const int dr[] = { 0,  1,  0, -1,        -1,  1,  1, -1,     -2, -2,  2,  2, -1, -1,  1,  1};
const int dc[] = { 1,  0, -1,  0,         1,  1, -1, -1,     -1,  1, -1,  1, -2,  2, -2,  2};

/// Constants
#define MOD                 (int)(1e9+7)
#define eps                 1e-9
#define INF                 0x3f3f3f3f3f3f3f3f
#define inf                 0x3f3f3f3f // CLR(63)
#define PI                  (2.0*acos(0.0))  // 3.1415926535897932
#define Log(b,x)            (log(x)/log(b))

/// Debug
#define out(a,T,str)        copy(a.begin(),a.end()-1,ostream_iterator<T>(cout,str)),cout<<a.back()<<endl
#ifdef VAMP
    #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define dbg(...)
#endif

/// Priority Queue custom compare
// bool cmp(const int &a, const int &b){ return a > b;}
// std::priority_queue<int, std::vector<int>, decltype(&cmp) > pq(cmp);

#include <tr1/unordered_map>
tr1 :: unordered_map<int,int> mp;
vector<int> X;

namespace SQRT_Decomposition {
    const int maxn = 1e5+500;

    struct BLOCK {
        vi v;
        vll sum;
    }
    b[int(sqrt(maxn))+1000];
    int N, block_size;

    inline void preprocess(){
        block_size = int(sqrt(N))+1;// dbg(block_size);
        for(int i = 0; i*block_size < N; i++){
            b[i].v.clear();
            b[i].sum = vll(5,0);
        }
    }
    inline void add(const int &x){
        int P = mp[x];
        int r = P/block_size;
        b[r].v.pb(x);
        b[r].sum = vll(5,0);
        for(int i = b[r].v.size()-1; i > 0; i--){
            if(b[r].v[i-1] > b[r].v[i]) swap(b[r].v[i-1],b[r].v[i]);
            b[r].sum[i%5] += b[r].v[i];
        }
        b[r].sum[0] += b[r].v[0];
    }
    inline void del(const int &x){
        int P = mp[x];
        int r = P/block_size;
        b[r].sum = vll(5,0);
        for(int i = 0; i < b[r].v.size()-1; i++){
            if(b[r].v[i] == x) swap(b[r].v[i],b[r].v[i+1]);
            b[r].sum[i%5] += b[r].v[i];
        }
        b[r].v.ppb();
    }
    inline ll query(){
        ll sum = 0,sz = 0;
        for(int i = 0; i*block_size < N; i++){
            sum += b[i].sum[(2-sz+5)%5];
            sz = (sz+b[i].v.size())%5;
        }
        return sum;
    }
}
using namespace SQRT_Decomposition;

struct info{
    int type,x;
}Q[maxn];

char ch[10];
int main(){
    #ifdef VAMP
        int start_s=clock();
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    // fastIO;
    // srand((rand()-time(NULL))%MOD);

    int n; sc(n);
    FOR(i,0,n){
        sf("%s",ch);
        if(ch[0]=='s') Q[i].type = 0;
        else if(ch[0]=='a') Q[i].type = 1, sc(Q[i].x), X.pb(Q[i].x);
        else if(ch[0]=='d') Q[i].type = 2, sc(Q[i].x), X.pb(Q[i].x);
    }
    unq(X);
    N = X.size();
    FOR(i,0,N) mp[ X[i]] = i;

    // dbg(N);
    preprocess();
    FOR(i,0,n){
             if(Q[i].type == 1) add(Q[i].x);
        else if(Q[i].type == 2) del(Q[i].x);
        else pf("%lld\n", query());

        // for(int j = 0; j*block_size < N; j++){
        //     for(auto x: b[j].v) cout << x << " "; cout << endl;
        // }
        // puts("___________________");
    }

    #ifdef VAMP
        int end_s=clock();
        printf("\nTime :: %.2lf\n", (double)(end_s-start_s)/CLOCKS_PER_SEC);
    #endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/rope> //header with rope
// using namespace __gnu_cxx;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/// Typedef
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector< pii > vii;

#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x)-1; i>=int(y); i--)
#define Binary(x,b)         std::bitset< b >( x ).to_string()
#define fastIO              ios::sync_with_stdio(false);    cin.tie(nullptr);   cout.tie(nullptr)
#define ran()               (((((1ULL*rand())<<31)|(1ULL*rand()))<<13)^((((1ULL*rand())<<32)|(1ULL*rand()))))
#define rran(a, b)          ((ran() % ((b) - (a) + 1)) + (a))
#define CLR(x, y)           memset(x, y, sizeof(x))
#define sc(n)               sf("%d",&n)
#define sc2(a,b)            sf("%d%d",&a,&b)
#define sc3(a,b,c)          sf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d)        sf("%d%d%d%d",&a,&b,&c,&d)
#define scll(n)             sf("%lld",&n)
#define scll2(a,b)          sf("%lld%lld",&a,&b)
#define scll3(a,b,c)        sf("%lld%lld%lld",&a,&b,&c)
#define scll4(a,b,c,d)      sf("%lld%lld%lld%lld",&a,&b,&c,&d)
#define bitCheck(N,in)      ((bool)(N&(1LL<<(in))))
#define bitOff(N,in)        (N&(~(1LL<<(in))))
#define bitOn(N,in)         (N|(1LL<<(in)))
#define bitFlip(a,k)        (a^(1LL<<(k)))
#define bitCount(a)         __builtin_popcount(a)
#define bitCountLL(a)       __builtin_popcountll(a)
#define bitRightMost(a)     __builtin_ctzll(a)
#define bitLeftMost(a)      (63-__builtin_clzll(a))
#define SQR(x)              ((x)*(x))
#define mxEq(a,b)           (a = max(a,b))
#define all(c)              c.begin(), c.end()
#define unq(v)              sort(all(v)), (v).resize(unique(all(v)) - v.begin())
#define common(a,b)         sort(all(a)), sort(all(b)), a.erase(set_intersection(all(a),all(b),a.begin()),a.end())
#define uncommon(a,b)       sort(all(a)), sort(all(b)), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end())

// uniform random generator -->
// uniform_int_distribution<int> dist(0, 1);
// default_random_engine gen;

// *X.find_by_order(k) //returns the kth largest element.(0-based)
// X.order_of_key(val) //returns the no. of values less than val
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // C++98
// template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline T bigMod(T p,T e,T M){ T ret = 1; for(; e > 0; e >>= 1){ if(e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T) ret;}
template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
template <class T> inline string int2String(T a){ostringstream str; str<<a; return str.str();}
const int dr[] = { 0,  1,  0, -1,        -1,  1,  1, -1,     -2, -2,  2,  2, -1, -1,  1,  1};
const int dc[] = { 1,  0, -1,  0,         1,  1, -1, -1,     -1,  1, -1,  1, -2,  2, -2,  2};

/// Constants
#define MOD                 (int)(1e9+7)
#define eps                 1e-9
#define INF                 0x3f3f3f3f3f3f3f3f
#define inf                 0x3f3f3f3f // CLR(63)
#define PI                  (2.0*acos(0.0))  // 3.1415926535897932
#define Log(b,x)            (log(x)/log(b))

/// Debug
#define out(a,T,str)        copy(a.begin(),a.end()-1,ostream_iterator<T>(cout,str)),cout<<a.back()<<endl
#ifdef VAMP
    #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define dbg(...)
#endif

/// Priority Queue custom compare
// bool cmp(const int &a, const int &b){ return a > b;}
// std::priority_queue<int, std::vector<int>, decltype(&cmp) > pq(cmp);

#include <tr1/unordered_map>
tr1 :: unordered_map<int,int> mp;
vector<int> X;

namespace SQRT_Decomposition {
    const int maxn = 1e5+500;

    struct BLOCK {
        vi v;
        vll sum;
    }
    b[int(sqrt(maxn))+1000];
    int N, block_size;

    inline void preprocess(){
        block_size = 1+int(sqrt(N)*2);
        for(int i = 0; i*block_size < N; i++){
            b[i].v.clear();
            b[i].sum = vll(5,0);
        }
    }
    inline void add(const int &x){
        int P = mp[x];
        int r = P/block_size;
        b[r].v.pb(x);
        b[r].sum = vll(5,0);
        for(int i = b[r].v.size()-1; i > 0; i--){
            if(b[r].v[i-1] > b[r].v[i]) swap(b[r].v[i-1],b[r].v[i]);
            b[r].sum[i%5] += b[r].v[i];
        }
        b[r].sum[0] += b[r].v[0];
    }
    inline void del(const int &x){
        int P = mp[x];
        int r = P/block_size;
        b[r].sum = vll(5,0);
        for(int i = 0; i < b[r].v.size()-1; i++){
            if(b[r].v[i] == x) swap(b[r].v[i],b[r].v[i+1]);
            b[r].sum[i%5] += b[r].v[i];
        }
        b[r].v.ppb();
    }
    inline ll query(){
        ll sum = 0,sz = 0;
        for(int i = 0; i*block_size < N; i++){
            sum += b[i].sum[(2-sz+5)%5];
            sz = (sz+b[i].v.size())%5;
        }
        return sum;
    }
}
using namespace SQRT_Decomposition;

struct info{
    int type,x;
}Q[maxn];

char ch[10];
int main(){
    #ifdef VAMP
        int start_s=clock();
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    // fastIO;
    // srand((rand()-time(NULL))%MOD);

    int n; sc(n);
    FOR(i,0,n){
        sf("%s",ch);
        if(ch[0]=='s') Q[i].type = 0;
        else if(ch[0]=='a') Q[i].type = 1, sc(Q[i].x), X.pb(Q[i].x);
        else if(ch[0]=='d') Q[i].type = 2, sc(Q[i].x), X.pb(Q[i].x);
    }
    unq(X);
    N = X.size();
    FOR(i,0,N) mp[ X[i]] = i;

    preprocess();
    FOR(i,0,n){
             if(Q[i].type == 1) add(Q[i].x);
        else if(Q[i].type == 2) del(Q[i].x);
        else pf("%lld\n", query());
    }

    #ifdef VAMP
        int end_s=clock();
        printf("\nTime :: %.2lf\n", (double)(end_s-start_s)/CLOCKS_PER_SEC);
    #endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/rope> //header with rope
// using namespace __gnu_cxx;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/// Typedef
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector< pii > vii;

#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x)-1; i>=int(y); i--)
#define Binary(x,b)         std::bitset< b >( x ).to_string()
#define fastIO              ios::sync_with_stdio(false);    cin.tie(nullptr);   cout.tie(nullptr)
#define ran()               (((((1ULL*rand())<<31)|(1ULL*rand()))<<13)^((((1ULL*rand())<<32)|(1ULL*rand()))))
#define rran(a, b)          ((ran() % ((b) - (a) + 1)) + (a))
#define CLR(x, y)           memset(x, y, sizeof(x))
#define sc(n)               sf("%d",&n)
#define sc2(a,b)            sf("%d%d",&a,&b)
#define sc3(a,b,c)          sf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d)        sf("%d%d%d%d",&a,&b,&c,&d)
#define scll(n)             sf("%lld",&n)
#define scll2(a,b)          sf("%lld%lld",&a,&b)
#define scll3(a,b,c)        sf("%lld%lld%lld",&a,&b,&c)
#define scll4(a,b,c,d)      sf("%lld%lld%lld%lld",&a,&b,&c,&d)
#define bitCheck(N,in)      ((bool)(N&(1LL<<(in))))
#define bitOff(N,in)        (N&(~(1LL<<(in))))
#define bitOn(N,in)         (N|(1LL<<(in)))
#define bitFlip(a,k)        (a^(1LL<<(k)))
#define bitCount(a)         __builtin_popcount(a)
#define bitCountLL(a)       __builtin_popcountll(a)
#define bitRightMost(a)     __builtin_ctzll(a)
#define bitLeftMost(a)      (63-__builtin_clzll(a))
#define SQR(x)              ((x)*(x))
#define mxEq(a,b)           (a = max(a,b))
#define all(c)              c.begin(), c.end()
#define unq(v)              sort(all(v)), (v).resize(unique(all(v)) - v.begin())
#define common(a,b)         sort(all(a)), sort(all(b)), a.erase(set_intersection(all(a),all(b),a.begin()),a.end())
#define uncommon(a,b)       sort(all(a)), sort(all(b)), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end())

// uniform random generator -->
// uniform_int_distribution<int> dist(0, 1);
// default_random_engine gen;

// *X.find_by_order(k) //returns the kth largest element.(0-based)
// X.order_of_key(val) //returns the no. of values less than val
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // C++98
// template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline T bigMod(T p,T e,T M){ T ret = 1; for(; e > 0; e >>= 1){ if(e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T) ret;}
template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
template <class T> inline string int2String(T a){ostringstream str; str<<a; return str.str();}
const int dr[] = { 0,  1,  0, -1,        -1,  1,  1, -1,     -2, -2,  2,  2, -1, -1,  1,  1};
const int dc[] = { 1,  0, -1,  0,         1,  1, -1, -1,     -1,  1, -1,  1, -2,  2, -2,  2};

/// Constants
#define MOD                 (int)(1e9+7)
#define eps                 1e-9
#define INF                 0x3f3f3f3f3f3f3f3f
#define inf                 0x3f3f3f3f // CLR(63)
#define PI                  (2.0*acos(0.0))  // 3.1415926535897932
#define Log(b,x)            (log(x)/log(b))

/// Debug
#define out(a,T,str)        copy(a.begin(),a.end()-1,ostream_iterator<T>(cout,str)),cout<<a.back()<<endl
#ifdef VAMP
    #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define dbg(...)
#endif

/// Priority Queue custom compare
// bool cmp(const int &a, const int &b){ return a > b;}
// std::priority_queue<int, std::vector<int>, decltype(&cmp) > pq(cmp);

#include <tr1/unordered_map>
tr1 :: unordered_map<int,int> mp;
vector<int> X;

namespace SQRT_Decomposition {
    const int maxn = 1e5+500;

    struct BLOCK {
        vi v;
        vll sum;
    }
    b[int(sqrt(maxn))+1000];
    int N, block_size;

    inline void preprocess(){
        block_size = 1+int(sqrt(N)/2);
        for(int i = 0; i*block_size < N; i++){
            b[i].v.clear();
            b[i].sum = vll(5,0);
        }
    }
    inline void add(const int &x){
        int P = mp[x];
        int r = P/block_size;
        b[r].v.pb(x);
        b[r].sum = vll(5,0);
        for(int i = b[r].v.size()-1; i > 0; i--){
            if(b[r].v[i-1] > b[r].v[i]) swap(b[r].v[i-1],b[r].v[i]);
            b[r].sum[i%5] += b[r].v[i];
        }
        b[r].sum[0] += b[r].v[0];
    }
    inline void del(const int &x){
        int P = mp[x];
        int r = P/block_size;
        b[r].sum = vll(5,0);
        for(int i = 0; i < b[r].v.size()-1; i++){
            if(b[r].v[i] == x) swap(b[r].v[i],b[r].v[i+1]);
            b[r].sum[i%5] += b[r].v[i];
        }
        b[r].v.ppb();
    }
    inline ll query(){
        ll sum = 0,sz = 0;
        for(int i = 0; i*block_size < N; i++){
            sum += b[i].sum[(2-sz+5)%5];
            sz = (sz+b[i].v.size())%5;
        }
        return sum;
    }
}
using namespace SQRT_Decomposition;

struct info{
    int type,x;
}Q[maxn];

char ch[10];
int main(){
    #ifdef VAMP
        int start_s=clock();
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    // fastIO;
    // srand((rand()-time(NULL))%MOD);

    int n; sc(n);
    FOR(i,0,n){
        sf("%s",ch);
        if(ch[0]=='s') Q[i].type = 0;
        else if(ch[0]=='a') Q[i].type = 1, sc(Q[i].x), X.pb(Q[i].x);
        else if(ch[0]=='d') Q[i].type = 2, sc(Q[i].x), X.pb(Q[i].x);
    }
    unq(X);
    N = X.size();
    FOR(i,0,N) mp[ X[i]] = i;

    preprocess();
    FOR(i,0,n){
             if(Q[i].type == 1) add(Q[i].x);
        else if(Q[i].type == 2) del(Q[i].x);
        else pf("%lld\n", query());
    }

    #ifdef VAMP
        int end_s=clock();
        printf("\nTime :: %.2lf\n", (double)(end_s-start_s)/CLOCKS_PER_SEC);
    #endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/rope> //header with rope
// using namespace __gnu_cxx;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/// Typedef
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector< pii > vii;

#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x)-1; i>=int(y); i--)
#define Binary(x,b)         std::bitset< b >( x ).to_string()
#define fastIO              ios::sync_with_stdio(false);    cin.tie(nullptr);   cout.tie(nullptr)
#define ran()               (((((1ULL*rand())<<31)|(1ULL*rand()))<<13)^((((1ULL*rand())<<32)|(1ULL*rand()))))
#define rran(a, b)          ((ran() % ((b) - (a) + 1)) + (a))
#define CLR(x, y)           memset(x, y, sizeof(x))
#define sc(n)               sf("%d",&n)
#define sc2(a,b)            sf("%d%d",&a,&b)
#define sc3(a,b,c)          sf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d)        sf("%d%d%d%d",&a,&b,&c,&d)
#define scll(n)             sf("%lld",&n)
#define scll2(a,b)          sf("%lld%lld",&a,&b)
#define scll3(a,b,c)        sf("%lld%lld%lld",&a,&b,&c)
#define scll4(a,b,c,d)      sf("%lld%lld%lld%lld",&a,&b,&c,&d)
#define bitCheck(N,in)      ((bool)(N&(1LL<<(in))))
#define bitOff(N,in)        (N&(~(1LL<<(in))))
#define bitOn(N,in)         (N|(1LL<<(in)))
#define bitFlip(a,k)        (a^(1LL<<(k)))
#define bitCount(a)         __builtin_popcount(a)
#define bitCountLL(a)       __builtin_popcountll(a)
#define bitRightMost(a)     __builtin_ctzll(a)
#define bitLeftMost(a)      (63-__builtin_clzll(a))
#define SQR(x)              ((x)*(x))
#define mxEq(a,b)           (a = max(a,b))
#define all(c)              c.begin(), c.end()
#define unq(v)              sort(all(v)), (v).resize(unique(all(v)) - v.begin())
#define common(a,b)         sort(all(a)), sort(all(b)), a.erase(set_intersection(all(a),all(b),a.begin()),a.end())
#define uncommon(a,b)       sort(all(a)), sort(all(b)), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end())

// uniform random generator -->
// uniform_int_distribution<int> dist(0, 1);
// default_random_engine gen;

// *X.find_by_order(k) //returns the kth largest element.(0-based)
// X.order_of_key(val) //returns the no. of values less than val
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // C++98
// template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline T bigMod(T p,T e,T M){ T ret = 1; for(; e > 0; e >>= 1){ if(e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T) ret;}
template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
template <class T> inline string int2String(T a){ostringstream str; str<<a; return str.str();}
const int dr[] = { 0,  1,  0, -1,        -1,  1,  1, -1,     -2, -2,  2,  2, -1, -1,  1,  1};
const int dc[] = { 1,  0, -1,  0,         1,  1, -1, -1,     -1,  1, -1,  1, -2,  2, -2,  2};

/// Constants
#define MOD                 (int)(1e9+7)
#define eps                 1e-9
#define INF                 0x3f3f3f3f3f3f3f3f
#define inf                 0x3f3f3f3f // CLR(63)
#define PI                  (2.0*acos(0.0))  // 3.1415926535897932
#define Log(b,x)            (log(x)/log(b))

/// Debug
#define out(a,T,str)        copy(a.begin(),a.end()-1,ostream_iterator<T>(cout,str)),cout<<a.back()<<endl
#ifdef VAMP
    #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define dbg(...)
#endif

/// Priority Queue custom compare
// bool cmp(const int &a, const int &b){ return a > b;}
// std::priority_queue<int, std::vector<int>, decltype(&cmp) > pq(cmp);

#include <tr1/unordered_map>
tr1 :: unordered_map<int,int> mp;
vector<int> X;

namespace SQRT_Decomposition {
    const int maxn = 1e5+500;

    struct BLOCK {
        vi v;
        vll sum;
    }
    b[int(sqrt(maxn))+1000];
    int N, block_size;

    inline void preprocess(){
        block_size = 1+int(sqrt(N<<4));
        for(int i = 0; i*block_size < N; i++){
            b[i].v.clear();
            b[i].sum = vll(5,0);
        }
    }
    inline void add(const int &x){
        int P = mp[x];
        int r = P/block_size;
        b[r].v.pb(x);
        b[r].sum = vll(5,0);
        for(int i = b[r].v.size()-1; i > 0; i--){
            if(b[r].v[i-1] > b[r].v[i]) swap(b[r].v[i-1],b[r].v[i]);
            b[r].sum[i%5] += b[r].v[i];
        }
        b[r].sum[0] += b[r].v[0];
    }
    inline void del(const int &x){
        int P = mp[x];
        int r = P/block_size;
        b[r].sum = vll(5,0);
        for(int i = 0; i < b[r].v.size()-1; i++){
            if(b[r].v[i] == x) swap(b[r].v[i],b[r].v[i+1]);
            b[r].sum[i%5] += b[r].v[i];
        }
        b[r].v.ppb();
    }
    inline ll query(){
        ll sum = 0,sz = 0;
        for(int i = 0; i*block_size < N; i++){
            sum += b[i].sum[(2-sz+5)%5];
            sz = (sz+b[i].v.size())%5;
        }
        return sum;
    }
}
using namespace SQRT_Decomposition;

struct info{
    int type,x;
}Q[maxn];

char ch[10];
int main(){
    #ifdef VAMP
        int start_s=clock();
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    // fastIO;
    // srand((rand()-time(NULL))%MOD);

    int n; sc(n);
    FOR(i,0,n){
        sf("%s",ch);
        if(ch[0]=='s') Q[i].type = 0;
        else if(ch[0]=='a') Q[i].type = 1, sc(Q[i].x), X.pb(Q[i].x);
        else if(ch[0]=='d') Q[i].type = 2, sc(Q[i].x), X.pb(Q[i].x);
    }
    unq(X);
    N = X.size();
    FOR(i,0,N) mp[ X[i]] = i;

    preprocess();
    FOR(i,0,n){
             if(Q[i].type == 1) add(Q[i].x);
        else if(Q[i].type == 2) del(Q[i].x);
        else pf("%lld\n", query());
    }

    #ifdef VAMP
        int end_s=clock();
        printf("\nTime :: %.2lf\n", (double)(end_s-start_s)/CLOCKS_PER_SEC);
    #endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/rope> //header with rope
// using namespace __gnu_cxx;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/// Typedef
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector< pii > vii;

#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x)-1; i>=int(y); i--)
#define Binary(x,b)         std::bitset< b >( x ).to_string()
#define fastIO              ios::sync_with_stdio(false);    cin.tie(nullptr);   cout.tie(nullptr)
#define ran()               (((((1ULL*rand())<<31)|(1ULL*rand()))<<13)^((((1ULL*rand())<<32)|(1ULL*rand()))))
#define rran(a, b)          ((ran() % ((b) - (a) + 1)) + (a))
#define CLR(x, y)           memset(x, y, sizeof(x))
#define sc(n)               sf("%d",&n)
#define sc2(a,b)            sf("%d%d",&a,&b)
#define sc3(a,b,c)          sf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d)        sf("%d%d%d%d",&a,&b,&c,&d)
#define scll(n)             sf("%lld",&n)
#define scll2(a,b)          sf("%lld%lld",&a,&b)
#define scll3(a,b,c)        sf("%lld%lld%lld",&a,&b,&c)
#define scll4(a,b,c,d)      sf("%lld%lld%lld%lld",&a,&b,&c,&d)
#define bitCheck(N,in)      ((bool)(N&(1LL<<(in))))
#define bitOff(N,in)        (N&(~(1LL<<(in))))
#define bitOn(N,in)         (N|(1LL<<(in)))
#define bitFlip(a,k)        (a^(1LL<<(k)))
#define bitCount(a)         __builtin_popcount(a)
#define bitCountLL(a)       __builtin_popcountll(a)
#define bitRightMost(a)     __builtin_ctzll(a)
#define bitLeftMost(a)      (63-__builtin_clzll(a))
#define SQR(x)              ((x)*(x))
#define mxEq(a,b)           (a = max(a,b))
#define all(c)              c.begin(), c.end()
#define unq(v)              sort(all(v)), (v).resize(unique(all(v)) - v.begin())
#define common(a,b)         sort(all(a)), sort(all(b)), a.erase(set_intersection(all(a),all(b),a.begin()),a.end())
#define uncommon(a,b)       sort(all(a)), sort(all(b)), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end())

// uniform random generator -->
// uniform_int_distribution<int> dist(0, 1);
// default_random_engine gen;

// *X.find_by_order(k) //returns the kth largest element.(0-based)
// X.order_of_key(val) //returns the no. of values less than val
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // C++98
// template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline T bigMod(T p,T e,T M){ T ret = 1; for(; e > 0; e >>= 1){ if(e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T) ret;}
template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
template <class T> inline string int2String(T a){ostringstream str; str<<a; return str.str();}
const int dr[] = { 0,  1,  0, -1,        -1,  1,  1, -1,     -2, -2,  2,  2, -1, -1,  1,  1};
const int dc[] = { 1,  0, -1,  0,         1,  1, -1, -1,     -1,  1, -1,  1, -2,  2, -2,  2};

/// Constants
#define MOD                 (int)(1e9+7)
#define eps                 1e-9
#define INF                 0x3f3f3f3f3f3f3f3f
#define inf                 0x3f3f3f3f // CLR(63)
#define PI                  (2.0*acos(0.0))  // 3.1415926535897932
#define Log(b,x)            (log(x)/log(b))

/// Debug
#define out(a,T,str)        copy(a.begin(),a.end()-1,ostream_iterator<T>(cout,str)),cout<<a.back()<<endl
#ifdef VAMP
    #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define dbg(...)
#endif

/// Priority Queue custom compare
// bool cmp(const int &a, const int &b){ return a > b;}
// std::priority_queue<int, std::vector<int>, decltype(&cmp) > pq(cmp);

#include <tr1/unordered_map>
tr1 :: unordered_map<int,int> mp;
vector<int> X;

namespace SQRT_Decomposition {
    const int maxn = 1e5+500;

    struct BLOCK {
        vi v;
        vll sum;
    }
    b[int(sqrt(maxn))+1000];
    int N, block_size;

    inline void preprocess(){
        block_size = 1+int(sqrt(N*3));
        for(int i = 0; i*block_size < N; i++){
            b[i].v.clear();
            b[i].sum = vll(5,0);
        }
    }
    inline void add(const int &x){
        int P = mp[x];
        int r = P/block_size;
        b[r].v.pb(x);
        b[r].sum = vll(5,0);
        for(int i = b[r].v.size()-1; i > 0; i--){
            if(b[r].v[i-1] > b[r].v[i]) swap(b[r].v[i-1],b[r].v[i]);
            b[r].sum[i%5] += b[r].v[i];
        }
        b[r].sum[0] += b[r].v[0];
    }
    inline void del(const int &x){
        int P = mp[x];
        int r = P/block_size;
        b[r].sum = vll(5,0);
        for(int i = 0; i < b[r].v.size()-1; i++){
            if(b[r].v[i] == x) swap(b[r].v[i],b[r].v[i+1]);
            b[r].sum[i%5] += b[r].v[i];
        }
        b[r].v.ppb();
    }
    inline ll query(){
        ll sum = 0,sz = 0;
        for(int i = 0; i*block_size < N; i++){
            sum += b[i].sum[(2-sz+5)%5];
            sz = (sz+b[i].v.size())%5;
        }
        return sum;
    }
}
using namespace SQRT_Decomposition;

struct info{
    int type,x;
}Q[maxn];

char ch[10];
int main(){
    #ifdef VAMP
        int start_s=clock();
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    // fastIO;
    // srand((rand()-time(NULL))%MOD);

    int n; sc(n);
    FOR(i,0,n){
        sf("%s",ch);
        if(ch[0]=='s') Q[i].type = 0;
        else if(ch[0]=='a') Q[i].type = 1, sc(Q[i].x), X.pb(Q[i].x);
        else if(ch[0]=='d') Q[i].type = 2, sc(Q[i].x), X.pb(Q[i].x);
    }
    unq(X);
    N = X.size();
    FOR(i,0,N) mp[ X[i]] = i;

    preprocess();
    FOR(i,0,n){
             if(Q[i].type == 1) add(Q[i].x);
        else if(Q[i].type == 2) del(Q[i].x);
        else pf("%lld\n", query());
    }

    #ifdef VAMP
        int end_s=clock();
        printf("\nTime :: %.2lf\n", (double)(end_s-start_s)/CLOCKS_PER_SEC);
    #endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/rope> //header with rope
// using namespace __gnu_cxx;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/// Typedef
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector< pii > vii;

#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x)-1; i>=int(y); i--)
#define Binary(x,b)         std::bitset< b >( x ).to_string()
#define fastIO              ios::sync_with_stdio(false);    cin.tie(nullptr);   cout.tie(nullptr)
#define ran()               (((((1ULL*rand())<<31)|(1ULL*rand()))<<13)^((((1ULL*rand())<<32)|(1ULL*rand()))))
#define rran(a, b)          ((ran() % ((b) - (a) + 1)) + (a))
#define CLR(x, y)           memset(x, y, sizeof(x))
#define sc(n)               sf("%d",&n)
#define sc2(a,b)            sf("%d%d",&a,&b)
#define sc3(a,b,c)          sf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d)        sf("%d%d%d%d",&a,&b,&c,&d)
#define scll(n)             sf("%lld",&n)
#define scll2(a,b)          sf("%lld%lld",&a,&b)
#define scll3(a,b,c)        sf("%lld%lld%lld",&a,&b,&c)
#define scll4(a,b,c,d)      sf("%lld%lld%lld%lld",&a,&b,&c,&d)
#define bitCheck(N,in)      ((bool)(N&(1LL<<(in))))
#define bitOff(N,in)        (N&(~(1LL<<(in))))
#define bitOn(N,in)         (N|(1LL<<(in)))
#define bitFlip(a,k)        (a^(1LL<<(k)))
#define bitCount(a)         __builtin_popcount(a)
#define bitCountLL(a)       __builtin_popcountll(a)
#define bitRightMost(a)     __builtin_ctzll(a)
#define bitLeftMost(a)      (63-__builtin_clzll(a))
#define SQR(x)              ((x)*(x))
#define mxEq(a,b)           (a = max(a,b))
#define all(c)              c.begin(), c.end()
#define unq(v)              sort(all(v)), (v).resize(unique(all(v)) - v.begin())
#define common(a,b)         sort(all(a)), sort(all(b)), a.erase(set_intersection(all(a),all(b),a.begin()),a.end())
#define uncommon(a,b)       sort(all(a)), sort(all(b)), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end())

// uniform random generator -->
// uniform_int_distribution<int> dist(0, 1);
// default_random_engine gen;

// *X.find_by_order(k) //returns the kth largest element.(0-based)
// X.order_of_key(val) //returns the no. of values less than val
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // C++98
// template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline T bigMod(T p,T e,T M){ T ret = 1; for(; e > 0; e >>= 1){ if(e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T) ret;}
template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
template <class T> inline string int2String(T a){ostringstream str; str<<a; return str.str();}
const int dr[] = { 0,  1,  0, -1,        -1,  1,  1, -1,     -2, -2,  2,  2, -1, -1,  1,  1};
const int dc[] = { 1,  0, -1,  0,         1,  1, -1, -1,     -1,  1, -1,  1, -2,  2, -2,  2};

/// Constants
#define MOD                 (int)(1e9+7)
#define eps                 1e-9
#define INF                 0x3f3f3f3f3f3f3f3f
#define inf                 0x3f3f3f3f // CLR(63)
#define PI                  (2.0*acos(0.0))  // 3.1415926535897932
#define Log(b,x)            (log(x)/log(b))

/// Debug
#define out(a,T,str)        copy(a.begin(),a.end()-1,ostream_iterator<T>(cout,str)),cout<<a.back()<<endl
#ifdef VAMP
    #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define dbg(...)
#endif

/// Priority Queue custom compare
// bool cmp(const int &a, const int &b){ return a > b;}
// std::priority_queue<int, std::vector<int>, decltype(&cmp) > pq(cmp);

#include <tr1/unordered_map>
tr1 :: unordered_map<int,int> mp;
vector<int> X;

namespace SQRT_Decomposition {
    const int maxn = 1e5+500;

    struct BLOCK {
        vi v,sum;
    }
    b[int(sqrt(maxn))+1000];
    int N, block_size, a[maxn];

    inline void preprocess(){
        block_size = int(sqrt(N))+1;// dbg(block_size);
        for(int i = 0; i*block_size < N; i++){
            b[i].v.clear();
            b[i].sum = vi(5,0);
        }
    }
    inline void add(const int &x){
        int P = mp[x];
        int r = P/block_size;
        b[r].v.pb(x);
        b[r].sum = vi(5,0);
        for(int i = b[r].v.size()-1; i > 0; i--){
            if(b[r].v[i-1] > b[r].v[i]) swap(b[r].v[i-1],b[r].v[i]);
            b[r].sum[i%5] += b[r].v[i];
        }
        b[r].sum[0] += b[r].v[0];
    }
    inline void del(const int &x){
        int P = mp[x];
        int r = P/block_size;
        b[r].sum = vi(5,0);
        for(int i = 0; i < b[r].v.size()-1; i++){
            if(b[r].v[i] == x) swap(b[r].v[i],b[r].v[i+1]);
            b[r].sum[i%5] += b[r].v[i];
        }
        b[r].v.ppb();
    }
    inline int query(){
        int sum = 0,sz = 0;
        for(int i = 0; i*block_size < N; i++){
            sum += b[i].sum[(2-sz+5)%5];
            sz = (sz+b[i].v.size())%5;
        }
        return sum;
    }
}
using namespace SQRT_Decomposition;

struct info{
    int type,x;
}Q[maxn];

char ch[10];
int main(){
    #ifdef VAMP
        int start_s=clock();
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    // fastIO;
    // srand((rand()-time(NULL))%MOD);

    int n; sc(n);
    FOR(i,0,n){
        sf("%s",ch);
        if(ch[0]=='s') Q[i].type = 0;
        else if(ch[0]=='a') Q[i].type = 1, sc(Q[i].x), X.pb(Q[i].x);
        else if(ch[0]=='d') Q[i].type = 2, sc(Q[i].x), X.pb(Q[i].x);
    }
    unq(X);
    N = X.size();
    FOR(i,0,N) mp[ X[i]] = i;

    // dbg(N);
    preprocess();
    FOR(i,0,n){
             if(Q[i].type == 1) add(Q[i].x);
        else if(Q[i].type == 2) del(Q[i].x);
        else pf("%d\n", query());

        // for(int j = 0; j*block_size < N; j++){
        //     for(auto x: b[j].v) cout << x << " "; cout << endl;
        // }
        // puts("___________________");
    }

    #ifdef VAMP
        int end_s=clock();
        printf("\nTime :: %.2lf\n", (double)(end_s-start_s)/CLOCKS_PER_SEC);
    #endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/rope> //header with rope
// using namespace __gnu_cxx;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/// Typedef
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector< pii > vii;

#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x)-1; i>=int(y); i--)
#define Binary(x,b)         std::bitset< b >( x ).to_string()
#define fastIO              ios::sync_with_stdio(false);    cin.tie(nullptr);   cout.tie(nullptr)
#define ran()               (((((1ULL*rand())<<31)|(1ULL*rand()))<<13)^((((1ULL*rand())<<32)|(1ULL*rand()))))
#define rran(a, b)          ((ran() % ((b) - (a) + 1)) + (a))
#define CLR(x, y)           memset(x, y, sizeof(x))
#define sc(n)               sf("%d",&n)
#define sc2(a,b)            sf("%d%d",&a,&b)
#define sc3(a,b,c)          sf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d)        sf("%d%d%d%d",&a,&b,&c,&d)
#define scll(n)             sf("%lld",&n)
#define scll2(a,b)          sf("%lld%lld",&a,&b)
#define scll3(a,b,c)        sf("%lld%lld%lld",&a,&b,&c)
#define scll4(a,b,c,d)      sf("%lld%lld%lld%lld",&a,&b,&c,&d)
#define bitCheck(N,in)      ((bool)(N&(1LL<<(in))))
#define bitOff(N,in)        (N&(~(1LL<<(in))))
#define bitOn(N,in)         (N|(1LL<<(in)))
#define bitFlip(a,k)        (a^(1LL<<(k)))
#define bitCount(a)         __builtin_popcount(a)
#define bitCountLL(a)       __builtin_popcountll(a)
#define bitRightMost(a)     __builtin_ctzll(a)
#define bitLeftMost(a)      (63-__builtin_clzll(a))
#define SQR(x)              ((x)*(x))
#define mxEq(a,b)           (a = max(a,b))
#define all(c)              c.begin(), c.end()
#define unq(v)              sort(all(v)), (v).resize(unique(all(v)) - v.begin())
#define common(a,b)         sort(all(a)), sort(all(b)), a.erase(set_intersection(all(a),all(b),a.begin()),a.end())
#define uncommon(a,b)       sort(all(a)), sort(all(b)), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end())

// uniform random generator -->
// uniform_int_distribution<int> dist(0, 1);
// default_random_engine gen;

// *X.find_by_order(k) //returns the kth largest element.(0-based)
// X.order_of_key(val) //returns the no. of values less than val
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // C++98
// template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline T bigMod(T p,T e,T M){ T ret = 1; for(; e > 0; e >>= 1){ if(e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T) ret;}
template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
template <class T> inline string int2String(T a){ostringstream str; str<<a; return str.str();}
const int dr[] = { 0,  1,  0, -1,        -1,  1,  1, -1,     -2, -2,  2,  2, -1, -1,  1,  1};
const int dc[] = { 1,  0, -1,  0,         1,  1, -1, -1,     -1,  1, -1,  1, -2,  2, -2,  2};

/// Constants
#define MOD                 (int)(1e9+7)
#define eps                 1e-9
#define INF                 0x3f3f3f3f3f3f3f3f
#define inf                 0x3f3f3f3f // CLR(63)
#define PI                  (2.0*acos(0.0))  // 3.1415926535897932
#define Log(b,x)            (log(x)/log(b))

/// Debug
#define out(a,T,str)        copy(a.begin(),a.end()-1,ostream_iterator<T>(cout,str)),cout<<a.back()<<endl
#ifdef VAMP
    #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define dbg(...)
#endif

/// Priority Queue custom compare
// bool cmp(const int &a, const int &b){ return a > b;}
// std::priority_queue<int, std::vector<int>, decltype(&cmp) > pq(cmp);

#include <tr1/unordered_map>
tr1 :: unordered_map<int,int> mp;
vector<int> X;

namespace SQRT_Decomposition {
    const int maxn = 1e5+500;

    struct BLOCK {
        vi v;
        vll sum;
    }
    b[int(sqrt(maxn))+1000];
    int N, block_size;

    inline void preprocess(){
        block_size = 1+int(sqrt(N/2));
        for(int i = 0; i*block_size < N; i++){
            b[i].v.clear();
            b[i].sum = vll(5,0);
        }
    }
    inline void add(const int &x){
        int P = mp[x];
        int r = P/block_size;
        b[r].v.pb(x);
        b[r].sum = vll(5,0);
        for(int i = b[r].v.size()-1; i > 0; i--){
            if(b[r].v[i-1] > b[r].v[i]) swap(b[r].v[i-1],b[r].v[i]);
            b[r].sum[i%5] += b[r].v[i];
        }
        b[r].sum[0] += b[r].v[0];
    }
    inline void del(const int &x){
        int P = mp[x];
        int r = P/block_size;
        b[r].sum = vll(5,0);
        for(int i = 0; i < b[r].v.size()-1; i++){
            if(b[r].v[i] == x) swap(b[r].v[i],b[r].v[i+1]);
            b[r].sum[i%5] += b[r].v[i];
        }
        b[r].v.ppb();
    }
    inline ll query(){
        ll sum = 0,sz = 0;
        for(int i = 0; i*block_size < N; i++){
            sum += b[i].sum[(2-sz+5)%5];
            sz = (sz+b[i].v.size())%5;
        }
        return sum;
    }
}
using namespace SQRT_Decomposition;

struct info{
    int type,x;
}Q[maxn];

char ch[10];
int main(){
    #ifdef VAMP
        int start_s=clock();
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    // fastIO;
    // srand((rand()-time(NULL))%MOD);

    int n; sc(n);
    FOR(i,0,n){
        sf("%s",ch);
        if(ch[0]=='s') Q[i].type = 0;
        else if(ch[0]=='a') Q[i].type = 1, sc(Q[i].x), X.pb(Q[i].x);
        else if(ch[0]=='d') Q[i].type = 2, sc(Q[i].x), X.pb(Q[i].x);
    }
    unq(X);
    N = X.size();
    FOR(i,0,N) mp[ X[i]] = i;

    preprocess();
    FOR(i,0,n){
             if(Q[i].type == 1) add(Q[i].x);
        else if(Q[i].type == 2) del(Q[i].x);
        else pf("%lld\n", query());
    }

    #ifdef VAMP
        int end_s=clock();
        printf("\nTime :: %.2lf\n", (double)(end_s-start_s)/CLOCKS_PER_SEC);
    #endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/rope> //header with rope
// using namespace __gnu_cxx;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/// Typedef
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector< pii > vii;

#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x)-1; i>=int(y); i--)
#define Binary(x,b)         std::bitset< b >( x ).to_string()
#define fastIO              ios::sync_with_stdio(false);    cin.tie(nullptr);   cout.tie(nullptr)
#define ran()               (((((1ULL*rand())<<31)|(1ULL*rand()))<<13)^((((1ULL*rand())<<32)|(1ULL*rand()))))
#define rran(a, b)          ((ran() % ((b) - (a) + 1)) + (a))
#define CLR(x, y)           memset(x, y, sizeof(x))
#define sc(n)               sf("%d",&n)
#define sc2(a,b)            sf("%d%d",&a,&b)
#define sc3(a,b,c)          sf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d)        sf("%d%d%d%d",&a,&b,&c,&d)
#define scll(n)             sf("%lld",&n)
#define scll2(a,b)          sf("%lld%lld",&a,&b)
#define scll3(a,b,c)        sf("%lld%lld%lld",&a,&b,&c)
#define scll4(a,b,c,d)      sf("%lld%lld%lld%lld",&a,&b,&c,&d)
#define bitCheck(N,in)      ((bool)(N&(1LL<<(in))))
#define bitOff(N,in)        (N&(~(1LL<<(in))))
#define bitOn(N,in)         (N|(1LL<<(in)))
#define bitFlip(a,k)        (a^(1LL<<(k)))
#define bitCount(a)         __builtin_popcount(a)
#define bitCountLL(a)       __builtin_popcountll(a)
#define bitRightMost(a)     __builtin_ctzll(a)
#define bitLeftMost(a)      (63-__builtin_clzll(a))
#define SQR(x)              ((x)*(x))
#define mxEq(a,b)           (a = max(a,b))
#define all(c)              c.begin(), c.end()
#define unq(v)              sort(all(v)), (v).resize(unique(all(v)) - v.begin())
#define common(a,b)         sort(all(a)), sort(all(b)), a.erase(set_intersection(all(a),all(b),a.begin()),a.end())
#define uncommon(a,b)       sort(all(a)), sort(all(b)), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end())

// uniform random generator -->
// uniform_int_distribution<int> dist(0, 1);
// default_random_engine gen;

// *X.find_by_order(k) //returns the kth largest element.(0-based)
// X.order_of_key(val) //returns the no. of values less than val
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // C++98
// template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline T bigMod(T p,T e,T M){ T ret = 1; for(; e > 0; e >>= 1){ if(e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T) ret;}
template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
template <class T> inline string int2String(T a){ostringstream str; str<<a; return str.str();}
const int dr[] = { 0,  1,  0, -1,        -1,  1,  1, -1,     -2, -2,  2,  2, -1, -1,  1,  1};
const int dc[] = { 1,  0, -1,  0,         1,  1, -1, -1,     -1,  1, -1,  1, -2,  2, -2,  2};

/// Constants
#define MOD                 (int)(1e9+7)
#define eps                 1e-9
#define INF                 0x3f3f3f3f3f3f3f3f
#define inf                 0x3f3f3f3f // CLR(63)
#define PI                  (2.0*acos(0.0))  // 3.1415926535897932
#define Log(b,x)            (log(x)/log(b))

/// Debug
#define out(a,T,str)        copy(a.begin(),a.end()-1,ostream_iterator<T>(cout,str)),cout<<a.back()<<endl
#ifdef VAMP
    #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define dbg(...)
#endif

/// Priority Queue custom compare
// bool cmp(const int &a, const int &b){ return a > b;}
// std::priority_queue<int, std::vector<int>, decltype(&cmp) > pq(cmp);

#include <tr1/unordered_map>
tr1 :: unordered_map<int,int> mp;
vector<int> X;

namespace SQRT_Decomposition {
    const int maxn = 1e5+500;

    struct BLOCK {
        vi v;
        vll sum;
    }
    b[int(sqrt(maxn))+1000];
    int N, block_size;

    inline void preprocess(){
        block_size = int(sqrt(N)<<2)+1;
        for(int i = 0; i*block_size < N; i++){
            b[i].v.clear();
            b[i].sum = vll(5,0);
        }
    }
    inline void add(const int &x){
        int P = mp[x];
        int r = P/block_size;
        b[r].v.pb(x);
        b[r].sum = vll(5,0);
        for(int i = b[r].v.size()-1; i > 0; i--){
            if(b[r].v[i-1] > b[r].v[i]) swap(b[r].v[i-1],b[r].v[i]);
            b[r].sum[i%5] += b[r].v[i];
        }
        b[r].sum[0] += b[r].v[0];
    }
    inline void del(const int &x){
        int P = mp[x];
        int r = P/block_size;
        b[r].sum = vll(5,0);
        for(int i = 0; i < b[r].v.size()-1; i++){
            if(b[r].v[i] == x) swap(b[r].v[i],b[r].v[i+1]);
            b[r].sum[i%5] += b[r].v[i];
        }
        b[r].v.ppb();
    }
    inline ll query(){
        ll sum = 0,sz = 0;
        for(int i = 0; i*block_size < N; i++){
            sum += b[i].sum[(2-sz+5)%5];
            sz = (sz+b[i].v.size())%5;
        }
        return sum;
    }
}
using namespace SQRT_Decomposition;

struct info{
    int type,x;
}Q[maxn];

char ch[10];
int main(){
    #ifdef VAMP
        int start_s=clock();
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    // fastIO;
    // srand((rand()-time(NULL))%MOD);

    int n; sc(n);
    FOR(i,0,n){
        sf("%s",ch);
        if(ch[0]=='s') Q[i].type = 0;
        else if(ch[0]=='a') Q[i].type = 1, sc(Q[i].x), X.pb(Q[i].x);
        else if(ch[0]=='d') Q[i].type = 2, sc(Q[i].x), X.pb(Q[i].x);
    }
    unq(X);
    N = X.size();
    FOR(i,0,N) mp[ X[i]] = i;

    preprocess();
    FOR(i,0,n){
             if(Q[i].type == 1) add(Q[i].x);
        else if(Q[i].type == 2) del(Q[i].x);
        else pf("%lld\n", query());
    }

    #ifdef VAMP
        int end_s=clock();
        printf("\nTime :: %.2lf\n", (double)(end_s-start_s)/CLOCKS_PER_SEC);
    #endif
    return 0;
}