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

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