Input Format
The first line contains integer , the number of elements in the set .
The second line contains  space separated elements of set . All of the elements are non-negative integers, less than or equal to 9.
The third line contains integer , the number of commands.
The next  lines contains either pop, remove and/or discard commands followed by their associated value.
Constraints

Output Format
Print the sum of the elements of set  on a single line.

### Problem solution in python 2 programming language.

n = int(raw_input())
s = set([int(x) for x in raw_input().strip().split()])
for _ in range(int(raw_input())):

a = list(raw_input().strip().split())

if a == 'pop':
s.pop()
else:
s.remove(int(a))

print sum(s)

### Problem solution in python 3 programming language.

n = int(input())
s = set([int(x) for x in input().strip().split()])
for _ in range(int(input())):

a = list(input().strip().split())

if a == 'pop':
s.pop()
else:
s.remove(int(a))

print sum(s)

#### second solution

n = int(input())
s = set(map(intinput().split()))
N = int(input())
lists = []
for i in range(N):
x = input().split()
lists.append(x)
for i in range(N):
if lists[i] == 'pop':
if len(s) == 0:
continue
else:
s.pop()
if lists[i] == 'remove':
x = lists[i]
if int(x) in s:
s.remove(int(x))
else:
continue