n = input()
ops = []
vals = set()
for i in xrange(n):
	s = raw_input().split()
	x = int(s[1]) if s[0] != 'sum' else None
	ops.append((s[0], x))
	if x is None: continue
	vals.add(x)

nums = list(vals)
numpos = dict([(v, i) for (i, v) in enumerate(nums)])

N = len(nums)
K = int(n ** 0.5)
G = (N + K - 1) / K

on = [False] * N 
sums = [[0, 0, 0, 0, 0] for i in xrange(G)]
counts = [0] * G

def recalc(u):
	global sums, counts
	s = sums[u]
	for i in xrange(5): s[i] = 0
	c = 0
	for i in xrange(u * K, min(u * K + K, N)):
		if not on[i]: continue
		s[c] += nums[i]
		c += 1
		if c == 5: c = 0
	counts[u] = c
		
def query():
	res = 0
	c = 2
	for i in xrange(G):
		res += sums[i][c]
		c -= counts[i]
		if c <= -5: c += 5
	return res

for (op, x) in ops:
	if op == 'sum':
		print query()
		continue
	u = numpos[x]
	on[u] = op == 'add'
	recalc(u / K)

