#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef
tree<
  int,
  null_type,
  less<int>,
  rb_tree_tag,
  tree_order_statistics_node_update>
order_set;

#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
#define N 100010
using namespace std;
ll treex[4 * N][5], lazy[4 * N], cur_ans = 0;
map<int, int> id;
void push(int low, int high, int node){
	if(lazy[node]){
		vector<int> cur;
		for(int i = 0; i < 5; i++)cur.pb(treex[node][i]);
		for(int i = 0; i < 5; i++){
			treex[node][i] = cur[(i + lazy[node]) % 5];
		}
		if(low != high){
			lazy[2 * node] = (lazy[2 * node] + lazy[node]) % 5;
			lazy[2 * node + 1] = (lazy[2 * node + 1] + lazy[node]) % 5;
		}
		lazy[node] = 0;
	}
}
void updateval(int low, int high, int ind, int val, int mod, int node){
	push(low, high, node);
	if(low > ind || high < ind)
		return;
	if(low == high){
		treex[node][mod] += val;
		return;
	}
	int mid = (low + high) / 2;
	updateval(low, mid, ind, val, mod, 2 * node);
	updateval(mid + 1, high, ind, val, mod, 2 * node + 1);
	for(int i = 0; i < 5; i++)
		treex[node][i] = treex[2 * node][i] + treex[2 * node + 1][i];
}
void updaterange(int low, int high, int begin, int end, int val, int node){
	push(low, high, node);
	if(low > end || high < begin)
		return;
	if(low >= begin && high <= end){
		//cout << low << " " << high << " " << "UPDATED\n" << " " << val << '\n';
		lazy[node] = (lazy[node] + val + 5) % 5;
		push(low, high, node);
		
		return;
 	}
 	int mid = (low + high) / 2;
 	updaterange(low, mid, begin, end, val, 2 * node);
 	updaterange(mid + 1, high, begin, end, val, 2 * node + 1);
 	for(int i = 0; i < 5; i++)
 		treex[node][i] = treex[2 * node][i] + treex[2 * node + 1][i];
}
ll query(int low, int high, int begin, int end, int node){
	push(low, high, node);
	if(low > end || high < begin)
		return 0;
	if(low >= begin && high <= end){
		return treex[node][2];
	}
	int mid = (low + high) / 2;
	return query(low, mid, begin, end, 2 * node) + query(mid + 1, high, begin, end, 2 * node + 1);
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<pair<int, int> > quer;
	vector<int> df;
	while(n--){
		string s;
		cin >> s;
		if(s == "add"){
			int x;
			cin >> x;
			quer.pb(mp(1, x));
			df.pb(x);
		}
		else if(s == "del"){
			int x;
			cin >> x;
			quer.pb(mp(2, x));
		}
		else{
			quer.pb(mp(3, -1));
		}
	}
	set<int> rt(df.begin(), df.end());
	df.assign(rt.begin(), rt.end());
	for(int i = 0; i < df.size(); i++){
		id[df[i]] = i;
	}
	order_set cur;
	for(int i = 0; i < quer.size(); i++){
		if(quer[i].first == 1){
			int val = quer[i].second;
			int less_than = cur.order_of_key(val);
			int mod = less_than % 5;
			//mod = (mod + 4) % 5;
			//cerr << val << " " << mod << '\n';
			updaterange(0, N - 1, id[val], N - 1, -1, 1);
			updateval(0, N - 1, id[val], val, mod, 1);
			cur.insert(val);
			//cerr << treex[1][0] << " " << treex[1][1] << " " << treex[1][2] << " " << treex[1][3] << " " << treex[1][4] << '\n';
			// for(int i = 1; i <= 7; i++){
			// 	cout << i << " ";
			// 	for(int j = 0; j < 5; j++)
			// 		cout << treex[i][j] << " ";
			// 	cout << lazy[i];
			// 	cout << '\n';
			// }
			// cout << '\n';
		}	
		else if(quer[i].first == 2){
			int val = quer[i].second;
			int less_than = cur.order_of_key(val);
			int mod = less_than % 5;
			updateval(0, N - 1, id[val], -1 * val, mod, 1);
			updaterange(0, N - 1, id[val], N - 1, 1, 1);
			cur.erase(val);
			//cerr << treex[1][0] << " " << treex[1][1] << " " << treex[1][2] << " " << treex[1][3] << " " << treex[1][4] << '\n';

		}

		else{
			cout << query(0, N - 1, 0, N - 1, 1) << '\n';
		}
	}

}