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