#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#include<bitset>
#include<map>
#include<ctime>
#include<deque>

#include<tr1/unordered_map>
using namespace std::tr1;

using namespace std;

template <typename T> void read(T &x) {
	x = 0; int f = 1; char c;
	for (c = getchar(); c < '0' || c > '9'; c = getchar()) if (c == '-') f = -f;
	for (; c >= '0' && c <= '9'; c = getchar()) x = 10 * x + c - '0' ;
	x *= f;
}
template <typename T> void write(T x){
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) { write(x); putchar('\n'); }
template <typename T> void writesn(T x) { write(x); putchar(' '); }
inline void into() { ios::sync_with_stdio(false); }

#define ll long long
#define next kkksc03
#define mid ((l+r)>>1)
#define lson (o<<1)
#define rson (o<<1|1)
#define R register
#define debug puts("zxt")
#define IT set<PP>::iterator
#define PP pair<int, int>

const int MAXN = 1e5 + 10;
const int N = 1e9;

int T;
int tree[MAXN << 2][5], num[MAXN << 2], ls[MAXN << 2], rs[MAXN << 2], tot;

inline void pushup(int o)
{
	num[o] = num[ls[o]] + num[rs[o]];
	for(R int i = 0; i < 5; i++) tree[o][i] = tree[ls[o]][i] + tree[rs[o]][((i - num[ls[o]]) % 5 + 5) % 5];
}

inline void add(int &o, int l, int r, int val)
{
	if(!o) o = ++tot;
	if(l == r)
	{
		num[o] = 1;
		tree[o][1] = val;
		return;
	}
	if(val <= mid) add(ls[o], l, mid, val);
	else add(rs[o], mid + 1, r, val);
	pushup(o);
}

inline void del(int o, int l, int r, int val)
{
	if(l == r)
	{
		num[o] = 0;
		tree[o][1] = 0;
		return;
	}
	if(val <= mid) del(ls[o], l, mid, val);
	else del(rs[o], mid + 1, r, val);
	pushup(o);
}

char opt[10];
int x, root;

signed main()
{
	into();
	cin >> T;
	while(T--)
	{
		cin >> opt;
		if(opt[0] == 'a') cin >> x, add(root, 1, N, x);
		if(opt[0] == 'd') cin >> x, del(root, 1, N, x);
		if(opt[0] == 's') writeln(tree[1][3]);
	}
	return 0;
}