#include <bits/stdc++.h>
using namespace std;
const int maxn = (1e5 + 10) * 32;
typedef long long ll;
int n, tot, root;
char op[10];
set<int> S;
struct Tree
{
	int ls, rs, cnt, shift;
	ll sum[5];
	Node() { ls = rs = cnt = shift = 0; memset(sum, 0, sizeof(sum));}
}Node[maxn];
void pushup(Tree & rt, const Tree & ls, const Tree & rs)
{
	rt.cnt = ls.cnt + rs.cnt;
	for(int i = 0; i < 5; ++i)
		rt.sum[i] = ls.sum[i] + rs.sum[i];
}
void lazy(int rt, int shift)
{
	if(rt && shift)
	{
		Node[rt].shift += shift;
		ll tmp[5];
		for(int i = 0; i < 5; ++i)
			tmp[i] = Node[rt].sum[i];
		if(shift > 0)
		{
			for(int i = 0; i < 5; ++i)
				Node[rt].sum[(i + shift) % 5] = tmp[i];
		}
		else
		{
			shift = -shift;
			for(int i = 0; i < 5; ++i)
				Node[rt].sum[i] = tmp[(i + shift) % 5];
		}
	}
}
void pushdown(int rt)
{
	if(Node[rt].shift)
	{
		lazy(Node[rt].ls, Node[rt].shift);
		lazy(Node[rt].rs, Node[rt].shift);
		Node[rt].shift = 0;
	}
}
void update(int & rt, int l, int r, int val, int x, int pos)
{
	if(!rt) rt = ++tot;
	if(l == r)
	{
		Node[rt].cnt += val;
		Node[rt].sum[pos % 5] += x;
		return;
	}
	pushdown(rt);
	int mid = l + r >> 1;
	if(x <= mid)
		update(Node[rt].ls, l, mid, val, x, pos);
	else
		update(Node[rt].rs, mid + 1, r, val, x, Node[Node[rt].ls].cnt + pos);
	pushup(Node[rt], Node[Node[rt].ls], Node[Node[rt].rs]); 
}
void shift(int rt, int l, int r, int a, int b, int val)
{
	if(!rt) return;
	if(a <= l && r <= b)
	{
		lazy(rt, val);
		return;
	}
	pushdown(rt);
	int mid = l + r >> 1;
	if(a <= mid) shift(Node[rt].ls, l, mid, a, b, val);
	if(b > mid) shift(Node[rt].rs, mid + 1, r, a, b, val);
	pushup(Node[rt], Node[Node[rt].ls], Node[Node[rt].rs]);
}
void add()
{
	int x;
	scanf("%d", &x);
	if(S.find(x) != S.end()) return;
	S.insert(x);
	update(root, 1, 1e9, 1, x, 0);
	if(x + 1 <= 1e9) shift(1, 1, 1e9, x + 1, 1e9, 1);
}
void del()
{
	int x;
	scanf("%d", &x);
	if(S.find(x) == S.end()) return;
	S.erase(x);
	update(root, 1, 1e9, -1, -x, 0);
	if(x + 1 <= 1e9) shift(1, 1, 1e9, x + 1, 1e9, -1);
} 
int main()
{
	root = ++tot;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%s", op);
		if(op[0] == 'a')
			add();
		else if(op[0] == 'd')
			del();
		else
			printf("%I64d\n", Node[1].sum[2]);
	}
	return 0;
}