.remove(x)
  
This operation removes element $\boldsymbol{x}$ from the set. 

If element $\boldsymbol{x}$ does not exist, it raises a KeyError.

The .remove(x) operation returns None.

Example

>>> s = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> s.remove(5)
>>> print s
set([1, 2, 3, 4, 6, 7, 8, 9])
>>> print s.remove(4)
None
>>> print s
set([1, 2, 3, 6, 7, 8, 9])
>>> s.remove(0)
KeyError: 0

.discard(x)
  
This operation also removes element $\boldsymbol{x}$ from the set. 

If element $\boldsymbol{x}$ does not exist, it does not raise a KeyError.

The .discard(x) operation returns None.

Example

>>> s = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> s.discard(5)
>>> print s
set([1, 2, 3, 4, 6, 7, 8, 9])
>>> print s.discard(4)
None
>>> print s
set([1, 2, 3, 6, 7, 8, 9])
>>> s.discard(0)
>>> print s
set([1, 2, 3, 6, 7, 8, 9])

.pop()
  
This operation removes and return an arbitrary element from the set. 

If there are no elements to remove, it raises a KeyError.

Example

>>> s = set([1])
>>> print s.pop()
1
>>> print s
set([])
>>> print s.pop()
KeyError: pop from an empty set
  
Task
  
You have a non-empty set $\boldsymbol{\mathrm{~S~}}$, and you have to execute $N$ commands given in $N$ lines.

The commands will be pop, remove and discard. 

Input Format

The first line contains integer $n$, the number of elements in the set $\boldsymbol{\mathrm{~S~}}$. 

The second line contains $n$ space separated elements of set $\boldsymbol{\mathrm{~S~}}$. All of the elements are non-negative integers, less than or equal to 9. 

The third line contains integer $N$, the number of commands.

The next $N$ lines contains either pop, remove and/or discard commands followed by their associated value.

Constraints

$0<n<20$ 

$\boldsymbol{0<N<20}$

Output Format

Print the sum of the elements of set $\boldsymbol{\mathrm{~S~}}$ on a single line.

Sample Input
9
1 2 3 4 5 6 7 8 9
10
pop
remove 9
discard 9
discard 8
remove 7
pop 
discard 6
remove 5
pop 
discard 5

Sample Output
4

Explanation

After completing these $10$ operations on the set, we get set$\left([4]\right)$. Hence, the sum is $\begin{array}{c}4\end{array}$.

Note: Convert the elements of set s to integers while you are assigning them. To ensure the proper input of the set, we have added the first two lines of code to the editor.

Difficulty: EASY
Tags: Data structures
Skill types: Data structures

Starter code:

Solutions:
cmds = {'pop': lambda x: s.pop(), 'remove': lambda x: s.remove(int(x[1])), 'discard': lambda x: s.discard(int(x[1]))}
input()
s = set(map(int, input().split()))
n = int(input())
for i in range(n):
	args = input().split()
	cmds[args[0]](args)
print(sum(s))


n = int(input())
s = set([int(x) for x in input().split()])
N = int(input())
for i in range(0, N):
	cmd = input().split()
	if cmd[0] == 'pop':
		if len(s) != 0:
			s.pop()
	elif cmd[0] == 'remove':
		if int(cmd[1]) in s:
			s.remove(int(cmd[1]))
	elif cmd[0] == 'discard':
		s.discard(int(cmd[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
t = int(input())
for i in range(t):
	a = input().strip()
	if 'pop' in a:
		s.pop()
	elif 'remove' in a:
		s.remove(int(a.split()[1]))
	elif 'discard' in a:
		s.discard(int(a.split()[1]))
	else:
		continue
print(sum(s))


input()
s = set(map(int, input().split()))
n = int(input())
for _ in range(n):
	tmp = input().split()
	if tmp[0] == 'pop':
		s.pop()
	elif tmp[0] == 'remove':
		s.remove(int(tmp[1]))
	elif tmp[0] == 'discard':
		s.discard(int(tmp[1]))
	else:
		pass
print(sum(s))


n = int(input())
st = set(map(int, input().split()))
for i in range(0, int(input())):
	line = input().split()
	opt = line[0]
	if opt == 'pop':
		st.pop()
	elif opt == 'remove':
		num = int(line[1])
		try:
			st.remove(num)
		except KeyError:
			continue
	elif opt == 'discard':
		num = int(line[1])
		st.discard(num)
result = 0
for j in st:
	result += j
print(result)


n = int(input())
s = set(map(int, input().split()))
for _ in range(int(input())):
	x = input()
	if x[0] == 'p':
		s.pop()
	elif x[0] == 'r':
		x = x.split()
		s.remove(int(x[1]))
	else:
		x = x.split()
		s.discard(int(x[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for _ in range(int(input())):
	a = list(input().strip().split())
	if a[0] == 'pop':
		s.pop()
	elif a[0] == 'discard':
		s.discard(int(a[1]))
	else:
		s.remove(int(a[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
T = int(input())
while T > 0:
	L = list(input().split())
	if L[0] == 'pop':
		s.pop()
	elif L[0] == 'remove':
		s.remove(int(L[1]))
	elif L[0] == 'discard':
		s.discard(int(L[1]))
	T = T - 1
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for _ in range(int(input())):
	args = input().strip().split()
	if args[0] == 'pop':
		s.pop()
	elif int(args[1]) in s:
		eval('s.' + args[0] + '(' + args[1] + ')')
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for _ in range(int(input())):
	tokens = input().split()
	command = 's.' + tokens[0] + '('
	if len(tokens) == 2:
		command += tokens[1]
	command += ')'
	eval(command)
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
N = int(input())
for i in range(N):
	com = input().split()
	if len(com) == 1:
		eval('s.' + com[0] + '()')
	else:
		eval('s.' + com[0] + '(' + com[1] + ')')
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for i in range(int(input())):
	cmd = input().split()
	eval('s.' + (cmd[0] + '()' if len(cmd) < 2 else cmd[0] + '(' + cmd[1] + ')'))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for i in range(int(input())):
	x = input().split()
	if len(x) > 1:
		num = int(x[1])
	if x[0] == 'pop':
		s.pop()
	elif x[0] == 'remove':
		s.remove(num)
	elif x[0] == 'discard':
		s.discard(num)
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
t = int(input())
for _ in range(t):
	c = input().split()
	if len(c) > 1:
		c[1] = int(c[1])
	if c[0] == 'pop':
		s.pop()
	elif c[0] == 'remove':
		try:
			s.remove(c[1])
		except:
			continue
	elif c[0] == 'discard':
		s.discard(c[1])
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
cmd = int(input(''))
while cmd > 0:
	str1 = input('').split(' ')
	if str1[0] == 'pop':
		s.pop()
	elif str1[0] == 'remove':
		s.remove(int(str1[1]))
	elif str1[0] == 'discard':
		s.discard(int(str1[1]))
	cmd -= 1
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
num = int(input())
for _ in range(num):
	i = input().split()
	if i[0] == 'pop':
		s.pop()
	elif i[0] == 'remove':
		s.remove(int(i[1]))
	elif i[0] == 'discard':
		s.discard(int(i[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
t = int(input())
for _ in range(t):
	c = input().split()
	if c[0] == 'pop':
		s.pop()
	if c[0] == 'remove':
		s.remove(int(c[1]))
	if c[0] == 'discard':
		s.discard(int(c[1]))
print(sum(s))


input()
a = set(map(int, input().split()))
for i in range(int(input())):
	b = input().split()
	if len(b) == 1:
		a.pop()
	else:
		exec('a.' + b[0] + '({})'.format(b[1]))
print(sum(a))


n = int(input())
s = set(map(int, input().split()))
for _ in range(int(input())):
	a = input().split()
	if a[0] == 'remove':
		s.remove(int(a[1]))
	elif a[0] == 'discard':
		s.discard(int(a[1]))
	elif a[0] == 'pop':
		s.pop()
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for i in range(int(input())):
	k = [x for x in input().split()]
	if k[0] == 'remove':
		s.remove(int(k[1]))
	elif k[0] == 'discard':
		s.discard(int(k[1]))
	elif k[0] == 'pop':
		s.pop()
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
m = int(input())
for i in range(0, m):
	str = input().split()
	if str[0] == 'pop':
		s.pop()
	elif str[0] == 'discard':
		s.discard(int(str[1]))
	else:
		s.remove(int(str[1]))
print(sum(s))


input()
s = set(map(int, input().split()))
for _ in range(int(input())):
	statement = input().strip().split()
	cmd = statement[0]
	if cmd == 'pop':
		arg = ''
	else:
		arg = statement[1]
	cmd += '(' + arg + ')'
	eval('s.' + cmd)
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for _ in range(int(input())):
	(comm, *arg) = input().split()
	if arg:
		getattr(s, comm)(int(arg[0]))
	else:
		getattr(s, comm)()
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
m = int(input())
for item in range(m):
	temp = list(input().split())
	if temp[0] == 'pop':
		s.pop()
	elif temp[0] == 'remove':
		s.remove(int(temp[1]))
	elif temp[0] == 'discard':
		s.discard(int(temp[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for i in range(int(input())):
	actions = input().split()
	command = actions[0]
	if command == 'pop':
		s.pop()
	else:
		getattr(s, command)(int(actions[1]))
print(sum(s))


n = int(input())
s = set([int(x) for x in input().split(' ')])
com = int(input())
for x in range(com):
	i = input().split(' ')
	if len(i) == 2:
		eval('s.' + i[0] + '(' + i[1] + ')')
	elif len(i) == 1:
		eval('s.' + i[0] + '()')
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for _ in range(int(input())):
	command = input().strip()
	if command == 'pop':
		s.pop()
	else:
		(rem, elem) = command.split()
		if rem == 'remove':
			s.remove(int(elem))
		elif rem == 'discard':
			s.discard(int(elem))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for i in range(int(input())):
	b = input().split()
	if len(b) == 1:
		s.pop()
	else:
		eval('s.' + b[0] + '(' + b[1] + ')')
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for i in range(int(input())):
	cm = input().split()
	if cm[0] == 'pop':
		s.pop()
	elif cm[0] == 'remove':
		s.remove(int(cm[1]))
	else:
		s.discard(int(cm[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
number_of_operations = int(input())
for x in range(number_of_operations):
	operation = input().split(' ')
	if operation[0] == 'pop':
		s.pop()
	elif operation[0] == 'remove':
		s.remove(int(operation[1]))
	elif operation[0] == 'discard':
		s.discard(int(operation[1]))
total = sum(s)
print(total)


n = int(input())
s = set(map(int, input().split()))
inp = int(input())
for i in range(inp):
	cmd = input().split()
	if len(s) > 0 and cmd[0] == 'pop':
		s.pop()
	elif len(s) > 0 and cmd[0] == 'remove':
		if int(cmd[1]) in s:
			s.remove(int(cmd[1]))
	elif len(s) > 0 and cmd[0] == 'discard':
		if int(cmd[1]) in s:
			s.discard(int(cmd[1]))
if len(s) > 0:
	print(sum(s))
else:
	print('0')


n = int(input())
s = set(map(int, input().split()))
N = int(input())
for i in range(N):
	line = input()
	if line.startswith('p') and len(s):
		s.pop()
	if line.startswith('r'):
		s.remove(int(line[-1]))
	if line.startswith('d') and len(s):
		s.discard(int(line[-1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for i in range(int(input())):
	t = input().split()
	if t[0] == 'pop':
		s.pop()
	elif t[0] == 'remove':
		s.remove(int(t[1]))
	elif t[0] == 'discard':
		s.discard(int(t[1]))
print(sum(s))


N = int(input())
value = set([int(i) for i in input().split(' ')])
for i in range(int(input())):
	cmd = input().split(' ')
	if cmd[0] == 'remove':
		value.remove(int(cmd[1]))
	elif cmd[0] == 'discard':
		value.discard(int(cmd[1]))
	else:
		value.pop()
print(sum(value))


n = int(input())
s = set(map(int, input().split()))
m = int(input())
for i in range(0, m):
	cmd = input().split()
	if cmd[0] == 'pop':
		s.pop()
	if cmd[0] == 'remove':
		s.remove(int(cmd[1]))
	if cmd[0] == 'discard':
		s.discard(int(cmd[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
t = int(input())
for _ in range(t):
	line = input().split()
	if len(line) == 2:
		getattr(s, line[0])(int(line[1]))
	elif len(line) == 1:
		getattr(s, line[0])()
	else:
		print('ERROR')
print(sum(s))


l = int(input())
if l < 1 or l > 19:
	exit()
s = set(map(int, input().split(' ')))
n = int(input())
if n < 1 or n > 19:
	exit()
arr = []
for i in range(0, n):
	arr.append(input())
for i in range(0, n):
	if 'pop' in arr[i]:
		s.pop()
	elif 'remove' in arr[i]:
		(a, b) = arr[i].split(' ')
		b = int(b)
		s.remove(b)
	elif 'discard' in arr[i]:
		(a, b) = arr[i].split(' ')
		b = int(b)
		s.discard(b)
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
m = int(input())
res = 0
for _ in range(0, m):
	cmd = input().strip().split()
	if cmd[0] == 'pop':
		res += s.pop()
	elif cmd[0] == 'discard':
		res += int(cmd[1])
		s.discard(int(cmd[1]))
	else:
		res += int(cmd[1])
		s.remove(int(cmd[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
N = int(input())
for i in range(N):
	cs = input()
	c = cs.split()[0]
	if c == 'pop':
		s.pop()
	elif c == 'remove':
		v = int(cs.split()[1])
		s.remove(v)
	elif c == 'discard':
		v = int(cs.split()[1])
		s.discard(v)
	else:
		pass
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
m = int(input())
for i in range(m):
	t = list(map(str, input().split()))
	if len(t) == 1:
		getattr(s, str(t[0]))()
	else:
		getattr(s, str(t[0]))(int(t[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
N = int(input())
for i in range(N):
	tmp = input().split()
	if len(tmp) > 1:
		tmp2 = int(tmp[1])
		if tmp[0] == 'remove':
			s.remove(tmp2)
		else:
			s.discard(tmp2)
	else:
		s.pop()
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for _ in range(int(input())):
	r = input().split()
	if r[0] == 'pop':
		s.pop()
	elif r[0] == 'remove':
		s.remove(int(r[1]))
	else:
		s.discard(int(r[1]))
print(sum(s))


n = int(input())
S = set(map(int, input().split()))
m = int(input())
for _ in range(m):
	A = input().split()
	op = A[0]
	if len(A) > 1:
		num = int(A[1])
	if op == 'pop':
		S.pop()
	if op == 'remove':
		S.remove(num)
	if op == 'discard':
		S.discard(num)
print(sum(S))


n = int(input())
s = set(map(int, input().split()))
m = int(input())
for i in range(m):
	l = input().split()
	if l[0] == 'pop':
		s.pop()
	elif l[0] == 'discard':
		s.discard(int(l[1]))
	elif l[0] == 'remove':
		s.remove(int(l[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
m = int(input().strip())
for i in range(m):
	num = 0
	command = input().strip()
	if command != 'pop':
		(command, num) = command.strip().split()
		num = int(num)
	if command == 'pop':
		if len(s) == 0:
			break
		else:
			s.pop()
	elif command == 'remove':
		if num in s:
			s.remove(num)
	elif command == 'discard':
		s.discard(num)
if len(s):
	print(sum(s))
else:
	print('0')


n = input()
n = set([int(i) for i in input().split(' ')])

def gotch(x):
	op = x[0]
	if op == 'pop':
		n.pop()
	elif op == 'remove':
		n.remove(int(x[1]))
	elif op == 'discard':
		n.discard(int(x[1]))
for i in range(int(input())):
	gotch(input().split(' '))
sum = 0
for i in n:
	sum += i
print(sum)


n = int(input())
s = set(map(int, input().split()))
for i in range(int(input())):
	cmd = input().split()
	if cmd[0] == 'pop':
		s.pop()
	if cmd[0] == 'remove':
		s.remove(int(cmd[1]))
	if cmd[0] == 'discard':
		s.discard(int(cmd[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for _ in range(int(input())):
	(command, *arr) = input().split()
	getattr(s, command)(*(int(x) for x in arr))
print(sum(s))


input()
s = {int(x) for x in input().split()}
I = [input().split() for x in range(int(input()))]
for x in I:
	eval('s.' + x[0] + '(' + ','.join(x[1:]) + ')')
print(sum(s))


n = int(input())
s = set([int(x) for x in input().strip().split()])
for a in range(int(input())):
	a = list(input().strip().split())
	if a[0] == 'pop':
		s.pop()
	elif a[0] == 'discard':
		s.discard(int(a[1]))
	else:
		s.remove(int(a[1]))
print(sum(s))


n = int(input())
s = set([int(x) for x in input().split()])
num_commands = int(input())
for _ in range(num_commands):
	command = tuple(input().split())
	if command[0] == 'pop':
		s.pop()
	elif command[0] == 'remove':
		s.remove(int(command[1]))
	elif command[0] == 'discard':
		s.discard(int(command[1]))
print(sum(s))


N = int(input())
elements = set(map(int, input().split(' ')[0:N]))
N_CMDS = int(input())
for i in range(N_CMDS):
	commands = input().split(' ')
	if commands[0] == 'pop':
		elements.pop()
	elif commands[0] == 'remove':
		elements.remove(int(commands[1]))
	elif commands[0] == 'discard':
		elements.discard(int(commands[1]))
print(sum(elements))


n = int(input())
s = set(map(int, input().split()))
N = int(input())
L = []
for i in range(0, N):
	L = input()
	if L[0:6] == 'remove':
		s.remove(int(L[7:]))
	elif L[0:7] == 'discard':
		s.discard(int(L[8:]))
	else:
		s.pop()
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
m = int(input())
for i in range(m):
	cmnd = input()
	if cmnd.find('pop') > -1:
		s.pop()
	elif cmnd.find('remove') > -1:
		s.remove(int(cmnd.split()[1]))
	elif cmnd.find('discard') > -1:
		s.discard(int(cmnd.split()[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
operations = {'pop': s.pop, 'remove': s.remove, 'discard': s.discard}
for _ in range(int(input())):
	text = input().split()
	operations[text[0]](*map(int, text[1:]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
j = int(input())
for i in range(j):
	command = input().strip().split(' ')
	if len(command) > 1:
		if command[0] == 'remove':
			s.remove(int(command[1]))
		else:
			s.discard(int(command[1]))
	else:
		s.pop()
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
NofC = int(input())
for _ in range(NofC):
	C = input().split()
	if len(C) == 1:
		eval('s.' + C[0] + '()')
	else:
		eval('s.' + C[0] + '(' + C[1] + ')')
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
m = int(input())
x = set()
for i in range(m):
	try:
		command = input().split()
		if len(command) > 1:
			getattr(s, command[0])(int(command[1]))
		else:
			getattr(s, command[0])()
	except KeyError:
		continue
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
a = int(input())
for i in range(0, a):
	b = list(input().split(' '))
	if b[0] == 'pop':
		s.pop()
	if b[0] == 'remove':
		e = int(b[1])
		s.remove(e)
	if b[0] == 'discard':
		s.discard(int(b[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
numops = int(input())
for opn in range(numops):
	op = input().strip().split()
	if op[0] == 'pop':
		s.pop()
	if op[0] == 'remove':
		s.remove(int(op[1]))
	if op[0] == 'discard':
		s.discard(int(op[1]))
print(sum(s))


input()
s = set((int(x) for x in input().split()))
for __ in range(int(input())):
	(op, *args) = input().split()
	op = getattr(s, op)
	args = (int(x) for x in args)
	op(*args)
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
n = int(input())
for i in range(n):
	cmd = list(input().split(' '))
	if len(cmd) == 1:
		s.pop()
	else:
		value = int(cmd[1])
		s.discard(value)
print(sum(s))


__author__ = 'namii'
n = int(input())
setti = set(map(int, input().split()))
N = int(input())
for _ in range(N):
	command = input().split()
	if command[0] == 'pop':
		setti.pop()
	elif command[0] == 'remove':
		setti.remove(int(command[1]))
	elif command[0] == 'discard':
		setti.discard(int(command[1]))
print(sum(setti))


n = int(input())
s = set(map(int, input().split()))
m = int(input())
for i in range(m):
	ss = input().split()
	if ss[0] == 'pop':
		s.pop()
	elif ss[0] == 'discard':
		s.discard(int(ss[1]))
	elif ss[0] == 'remove':
		s.remove(int(ss[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
commands = int(input())
for i in range(commands):
	c = input().split()
	if c[0] == 'remove':
		s.remove(int(c[1]))
	elif c[0] == 'discard':
		s.discard(int(c[1]))
	elif c[0] == 'pop':
		s.pop()
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
total = 0
testNum = int(input())

def performOperation(a, digit):
	if a == 'remove':
		s.remove(digit)
	elif a == 'discard':
		s.discard(digit)
	elif a == 'pop':
		s.pop()
for i in range(0, testNum):
	a = list(input().split())
	if len(a) > 1:
		performOperation(a[0], int(a[1]))
	else:
		performOperation(a[0], 0)
for each_element in s:
	total = total + each_element
print(total)


n = int(input())
s = set(list(map(int, input().split())))
tasks = int(input())
for i in range(tasks):
	task = input().split()
	if task[0] == 'pop':
		s.pop()
	elif task[0] == 'remove':
		s.remove(int(task[1]))
	elif task[0] == 'discard':
		s.discard(int(task[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for _ in range(int(input())):
	v = input().split()
	if len(v) == 1:
		s.pop()
	elif v[0] == 'discard':
		s.discard(int(v[1]))
	else:
		s.remove(int(v[1]))
print(sum(s))


n = input()
s = set(map(int, input().split()))
for i in range(int(input())):
	c = input().split()
	if c[0] == 'pop':
		s.pop()
	elif c == 'remove':
		s.remove(int(c[1]))
	else:
		s.discard(int(c[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for _ in range(int(input())):
	task = input().split()
	if len(task) > 1:
		eval('s.' + task[0] + '(' + task[1] + ')')
	else:
		eval('s.' + task[0] + '()')
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
N = int(input())
for i in range(0, N):
	cmd = input().split()
	if cmd[0] == 'pop':
		s.pop()
	elif cmd[0] == 'remove':
		s.remove(int(cmd[1]))
	else:
		s.discard(int(cmd[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for i in range(int(input())):
	cmd = input().split()
	if cmd[0] == 'pop':
		s.pop()
	elif cmd[0] == 'remove':
		s.remove(int(cmd[1]))
	elif cmd[0] == 'discard':
		s.discard(int(cmd[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
t = int(input())
for _ in range(t):
	x = input()
	opern = x.split()[0]
	if opern == 'remove':
		s.remove(int(x.split(' ')[1]))
	if opern == 'pop':
		s.pop()
	if opern == 'discard':
		s.discard(int(x.split(' ')[1]))

def sum(seta):
	s = 0
	for i in seta:
		s += i
	return s
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
N = int(input())
for _ in range(N):
	args = input().split()
	if len(args) == 1:
		eval('s.' + args[0] + '()')
	else:
		eval('s.' + args[0] + '(' + args[1] + ')')
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
commandsNumber = int(input())
for i in range(0, commandsNumber):
	inp = input().split()
	if inp[0] == 'pop':
		s.pop()
	elif inp[0] == 'discard':
		s.discard(int(inp[1]))
	elif inp[0] == 'remove':
		s.remove(int(inp[1]))
print(sum(s))


def execute(n, S, cmd):
	if cmd[0] == 'p':
		S.pop()
	elif cmd[0] == 'r':
		x = int(cmd.split()[1])
		S.remove(x)
	else:
		x = int(cmd.split()[1])
		S.discard(x)
	return None
n = int(input())
S = set(map(int, input().split()))
for i in range(int(input())):
	cmd = input()
	execute(n, S, cmd)
print(sum(S))


n = int(input())
s = set(map(int, input().split()))
task = int(input())
for i in range(0, task):
	order = input()
	order = order.split()
	if order[0] == 'remove':
		s.remove(int(order[1]))
	elif order[0] == 'discard':
		s.discard(int(order[1]))
	elif order[0] == 'pop':
		s.pop()
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
N = int(input())
for _ in range(N):
	line = input().split()
	cmd = line[0]
	if cmd == 'pop':
		s.pop()
	elif cmd == 'remove':
		s.remove(int(line[1]))
	elif cmd == 'discard':
		s.discard(int(line[1]))
	else:
		print('wtf')
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
m = int(input())
for i in range(m):
	c = list(input().split())
	if c[0] == 'pop':
		s.pop()
	elif c[0] == 'remove':
		s.remove(int(c[1]))
	elif c[0] == 'discard':
		s.discard(int(c[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
N = int(input())
com = []
for i in range(N):
	com.append(list(input().split()))

def findsum(s, com):
	for command in com:
		if command[0] == 'pop':
			s.pop()
		elif command[0] == 'remove':
			s.remove(int(command[1]))
		else:
			s.discard(int(command[1]))
	return sum(s)
print(findsum(s, com))


n = int(input())
s = set(map(int, input().split()))
N = int(input())
for i in range(N):
	arr = input().split()
	name = arr[0]
	args = list(map(int, arr[1:]))
	getattr(s, name)(*args)
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
for _ in range(int(input())):
	line = iter(input().split())
	(st, x) = (next(line), next(line, None))
	if st == 'pop':
		s.pop()
	elif st == 'discard':
		s.discard(int(x))
	else:
		try:
			s.remove(int(x))
		except:
			pass
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
n = int(input())
for _ in range(n):
	command = input().split()
	if command[0] == 'pop':
		try:
			s.pop()
		except KeyError:
			pass
	if command[0] == 'remove':
		try:
			s.remove(int(command[1]))
		except KeyError:
			pass
	if command[0] == 'discard':
		s.discard(int(command[1]))
print(sum(s))


import sys
if sys.version_info[0] >= 3:
	raw_input = input
n = int(raw_input())
s = set(map(int, raw_input().split()))
for _ in range(int(raw_input())):
	a = raw_input().split()
	if a[0] == 'pop':
		s.pop()
	elif a[0] == 'discard':
		s.discard(int(a[1]))
	elif a[0] == 'remove':
		s.remove(int(a[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
m = int(input())
for i in range(m):
	q = input().split()
	if q[0] == 'pop':
		s.pop()
	elif q[0] == 'remove':
		s.remove(int(q[1]))
	elif q[0] == 'discard':
		s.discard(int(q[1]))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
N = int(input())
for i in range(N):
	S = input().split()
	if len(S) == 1:
		s.pop()
	elif S[0] == 'remove':
		s.remove(int(S[1]))
	else:
		s.discard(int(S[1]))
print(sum(list(s)))


n = int(input())
s = set(map(int, input().split()))
numcmds = int(input())
cmds = [input().strip() for _ in range(numcmds)]
for cmd in cmds:
	if cmd == 'pop':
		s.pop()
	elif cmd.startswith('remove'):
		(rmv, val) = cmd.split()
		if int(val) in s:
			s.remove(int(val))
	elif cmd.startswith('discard'):
		(rmv, val) = cmd.split()
		s.discard(int(val))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
c = int(input())
for commands in range(0, c):
	command = input().split()
	if command[0] == 'pop':
		s.pop()
	if command[0] == 'remove':
		s.remove(int(command[1]))
	if command[0] == 'discard':
		s.discard(int(command[1]))
print(sum(s))


def __starting_point():
	n = int(input())
	s = set(map(int, input().split()))
	num_cmds = int(input())
	for _ in range(num_cmds):
		cmd = list(input().strip().split(' '))
		if cmd[0] == 'pop':
			s.pop()
		elif cmd[0] == 'remove':
			s.remove(int(cmd[1]))
		elif cmd[0] == 'discard':
			s.discard(int(cmd[1]))
	print(sum(s))
__starting_point()


n = int(input())
s = set(map(int, input().split()))
for i in range(int(input())):
	L = list(map(str, input().split()))
	if L[0] == 'pop':
		s.pop()
	else:
		getattr(s, L[0])(int(L[1]))
print(sum(s))


n = int(input().strip())
s = set(map(int, input().split()[0:n]))
N = int(input().strip())
for _ in range(N):
	l = input().strip().split()
	(cmd, args) = (l[0], tuple(map(int, l[1:])))
	getattr(s, cmd)(*args)
print(sum(s))


num = int(input())
data = set(map(int, input().split()))
operations = int(input())
for x in range(operations):
	oper = input().split()
	if oper[0] == 'remove':
		data.remove(int(oper[1]))
	elif oper[0] == 'discard':
		data.discard(int(oper[1]))
	else:
		data.pop()
print(sum(data))


n = int(input())
s = set(map(int, input().split()))
commands_number = int(input())
commands = [str(input()).split() for i in range(commands_number)]

def execute_command(command, arguments=None):
	if command[0] == 'pop':
		s.pop()
	if command[0] == 'remove':
		s.remove(arguments[0])
	if command[0] == 'discard':
		s.discard(arguments[0])
for command in commands:
	execute_command(command[:1], list(map(int, command[1:])))
print(sum(s))


n = int(input())
s = set(map(int, input().split()))
N = int(input())
for i in range(N):
	cmd = input().split()
	if cmd[0] != 'pop':
		num = int(cmd[1])
	if cmd[0] == 'pop':
		s.pop()
	elif cmd[0] == 'remove':
		s.remove(num)
	elif cmd[0] == 'discard':
		s.discard(num)
print(sum(s))