Objective 

Today, we're learning about a new data type: sets. 

Concept

If the inputs are given on one line separated by a character (the delimiter), use split() to get the separate values in the form of a list.  The delimiter is space (ascii 32) by default.  To specify that comma is the delimiter, use string.split(',').  For this challenge, and in general on HackerRank, space will be the delimiter.

Usage:

>> a = raw_input()
5 4 3 2
>> lis = a.split()
>> print (lis)
['5', '4', '3', '2']

If the list values are all integer types, use the map() method to convert all the strings to integers.

>> newlis = list(map(int, lis))
>> print (newlis)
[5, 4, 3, 2]

Sets are an unordered collection of unique values. A single set contains values of any immutable data type. 

CREATING SETS

>> myset = {1, 2} # Directly assigning values to a set
>> myset = set()  # Initializing a set
>> myset = set(['a', 'b']) # Creating a set from a list
>> myset
{'a', 'b'}

MODIFYING SETS 

Using the add() function:

>> myset.add('c')
>> myset
{'a', 'c', 'b'}
>> myset.add('a') # As 'a' already exists in the set, nothing happens
>> myset.add((5, 4))
>> myset
{'a', 'c', 'b', (5, 4)}

Using the update() function:

>> myset.update([1, 2, 3, 4]) # update() only works for iterable objects
>> myset
{'a', 1, 'c', 'b', 4, 2, (5, 4), 3}
>> myset.update({1, 7, 8})
>> myset
{'a', 1, 'c', 'b', 4, 7, 8, 2, (5, 4), 3}
>> myset.update({1, 6}, [5, 13])
>> myset
{'a', 1, 'c', 'b', 4, 5, 6, 7, 8, 2, (5, 4), 13, 3}

REMOVING ITEMS

Both the discard() and remove() functions take a single value as an argument and removes that value from the set. If that value is not present, discard() does nothing, but remove() will raise a KeyError exception.

>> myset.discard(10)
>> myset
{'a', 1, 'c', 'b', 4, 5, 7, 8, 2, 12, (5, 4), 13, 11, 3}
>> myset.remove(13)
>> myset
{'a', 1, 'c', 'b', 4, 5, 7, 8, 2, 12, (5, 4), 11, 3}

COMMON SET OPERATIONS
Using union(), intersection() and difference() functions.

>> a = {2, 4, 5, 9}
>> b = {2, 4, 11, 12}
>> a.union(b) # Values which exist in a or b
{2, 4, 5, 9, 11, 12}
>> a.intersection(b) # Values which exist in a and b
{2, 4}
>> a.difference(b) # Values which exist in a but not in b
{9, 5}

The union() and intersection() functions are symmetric methods: 

>> a.union(b) == b.union(a)
True
>> a.intersection(b) == b.intersection(a)
True
>> a.difference(b) == b.difference(a)
False

These other built-in data structures in Python are also useful.

Task 

Given $2$ sets of integers, $\mbox{M}$ and $N$, print their symmetric difference in ascending order. The term symmetric difference indicates those values that exist in either $\mbox{M}$ or $N$ but do not exist in both.

Input Format

The first line of input contains an integer, $\mbox{M}$. 

The second line contains $\mbox{M}$ space-separated integers. 

The third line contains an integer, $N$. 

The fourth line contains $N$ space-separated integers. 

Output Format

Output the symmetric difference integers in ascending order, one per line.

Sample Input
STDIN       Function
-----       --------
4           set a size M = 4
2 4 5 9     a = {2, 4, 5, 9}
4           set b size N = 4
2 4 11 12   b = {2, 4, 11, 12}

Sample Output
5
9
11
12

Source: hackerrank | Difficulty: EASY
Tags: Data structures


Solutions:
list1size = input()
list1 = input().split()
intlist1 = list(map(int, list1))
list2size = input()
list2 = input().split()
intlist2 = list(map(int, list2))
a = set(intlist1)
b = set(intlist2)
c = a ^ b
lprint = sorted(c)
for i in range(len(lprint)):
	print(lprint[i])


a_set_length = input()
a_set_length = int(a_set_length.rstrip())
a_set = set()
ip = input()
ip.rstrip()
ip = ip.split()
ip = list(map(int, ip))
a_set.update(ip)
b_set_length = input()
b_set_length = int(b_set_length.rstrip())
b_set = set()
ip = input()
ip.rstrip()
ip = ip.split()
ip = list(map(int, ip))
b_set.update(ip)
ans_set = a_set.symmetric_difference(b_set)
ans_list = []
for item in ans_set:
	ans_list.append(item)
ans_list.sort()
for item in ans_list:
	print(item)


N = int(input())
s1 = [int(x) for x in input().split()]
M = int(input())
s2 = [int(x) for x in input().split()]
set1 = set(s1)
set2 = set(s2)
diff1 = set1.difference(set2)
diff2 = set2.difference(set1)
output = diff1.union(diff2)
final = []
while output != set():
	final.append(output.pop())
final.sort()
for x in final:
	print(x)


n = int(input())
a = set([int(i) for i in input().strip().split()])
m = int(input())
b = set([int(i) for i in input().strip().split()])
ans = []
for x in a:
	if x in b:
		b.remove(x)
	else:
		ans.append(x)
ans += b
ans.sort()
for x in ans:
	print(x)


t = input()
m = list(map(int, input().split()))
t = input()
n = list(map(int, input().split()))
m = set(m)
n = set(n)
p = list(m.union(n) - m.intersection(n))
p.sort()
for i in p:
	print(i)


n1 = int(input())
a = input()
l1 = list(map(int, a.split()))
n2 = int(input())
a = input()
l2 = list(map(int, a.split()))
s1 = set(l1)
s2 = set(l2)
s3 = set()
s3.update(s1.difference(s2))
s3.update(s2.difference(s1))
l = list(s3)
l = sorted(l)
for i in range(len(l)):
	print(l[i])


input()
M = set([int(x) for x in input().split(' ')])
input()
N = set([int(x) for x in input().split(' ')])
for x in sorted(M.symmetric_difference(N)):
	print(x)


def symmdiff(a, b):
	inter = a.intersection(b)
	da = a.difference(inter)
	db = b.difference(inter)
	return da.union(db)
cardinalN = int(input())
elementsN = input()
cardinalM = int(input())
elementsM = input()
listN = elementsN.split()
setN = set(list(map(int, listN)))
listM = elementsM.split()
setM = set(list(map(int, listM)))
symmdiffset = symmdiff(setN, setM)
for num in sorted(list(symmdiffset)):
	print(num)


import sys

def freopen(f, option, stream):
	import os
	oldf = open(f, option)
	oldfd = oldf.fileno()
	newfd = stream.fileno()
	os.close(newfd)
	os.dup2(oldfd, newfd)
n = int(input())
nlist = set(map(int, input().split()))
m = int(input())
mlist = set(map(int, input().split()))
ans = nlist.difference(mlist)
ans.update(mlist.difference(nlist))
ans = list(ans)
ans.sort()
for i in ans:
	print(i)


M = input()
mSet = set(list(map(int, input().split())))
N = input()
nLst = list(map(int, input().split()))
nSet = set(nLst)
fSet = sorted(set(mSet.difference(nSet)).union(nSet.difference(mSet)))
for x in fSet:
	print(x)


m = int(input())
a = input().split()
n = int(input())
b = input().split()
re = set(list(map(int, [])))
for i in a:
	if i not in b:
		re.add(int(i))
for i in b:
	if i not in a:
		re.add(int(i))
s = list(re)
s.sort()
for i in s:
	print(i)


m = int(input())
M = set([int(i) for i in input().split()])
n = int(input())
N = set([int(i) for i in input().split()])
xs = sorted(list(M ^ N))
for x in xs:
	print(x)


n = int(input())
lis = []
a = input()
lis = a.split()
s = set()
for i in lis:
	s.add(int(i))
n1 = int(input())
lis1 = []
a1 = input()
lis1 = a1.split()
s1 = set()
for i in lis1:
	s1.add(int(i))
ans = set()
ans = s.difference(s1)
lis2 = []
for i in ans:
	lis2.append(i)
ans = set()
ans = s1.difference(s)
for i in ans:
	lis2.append(i)
lis2.sort()
for i in lis2:
	print(i)


N = int(input().strip())
a = input().strip().split()
a = set(map(int, a))
M = int(input().strip())
b = input().strip().split()
b = set(map(int, b))
for i in sorted(list(a ^ b)):
	print(i)


def __starting_point():
	M = int(input().strip())
	set_m = set(map(int, input().strip().split(' ')))
	N = int(input().strip())
	set_n = set(map(int, input().strip().split(' ')))
	for el in sorted(set_m ^ set_n):
		print(el)
__starting_point()


import sys
m = int(sys.stdin.readline())
set_m = set([int(x) for x in sys.stdin.readline().split()])
n = int(sys.stdin.readline())
set_n = set([int(x) for x in sys.stdin.readline().split()])
set_all = set_m.union(set_n)
result = []
for x in set_all:
	if x in set_n and x not in set_m or (x not in set_n and x in set_m):
		result.append(x)
result.sort()
for x in result:
	print(x)


input()
setM = set(map(int, input().split()))
input()
setN = set(map(int, input().split()))
diff = setM.difference(setN).union(setN.difference(setM))
print('\n'.join(map(str, sorted(diff))))


m = int(input())
set_a_str_ar = input().strip().split()
set_a_ar = list(map(int, set_a_str_ar))
n = int(input())
set_b_str_ar = input().strip().split()
set_b_ar = list(map(int, set_b_str_ar))
set_a_set = set(set_a_ar)
set_b_set = set(set_b_ar)
set_a_dif_set = set_a_set.difference(set_b_set)
set_b_dif_set = set_b_set.difference(set_a_set)
res_set = set_a_dif_set.union(set_b_dif_set)
res_ar = list(res_set)
res_ar.sort()
for i in res_ar:
	print(i)


n = int(input())
s = input()
lis1 = s.split()
m = int(input())
s = input()
lis2 = s.split()
set1 = set(map(int, lis1))
set2 = set(map(int, lis2))
myList = []
ans = []
iterator1 = set1.difference(set2)
iterator2 = set2.difference(set1)
for id in set(iterator1):
	ans.append(id)
for id in set(iterator2):
	ans.append(id)
ans.sort()
for id in list(ans):
	print(id)


a = int(input())
a1 = input()
a1 = map(int, a1.split())
a1 = set(a1)
b = int(input())
b1 = input()
b1 = map(int, b1.split())
b1 = set(b1)
i = list(a1.union(b1).difference(a1.intersection(b1)))
i.sort()
for j in i:
	print(j)


lengthm = input()
m = set([int(i) for i in input().split()])
lengthn = input()
n = set([int(i) for i in input().split()])
for i in sorted((m - n).union(n - m)):
	print(i)


N = int(input())
A = map(int, input().split())
SA = set(A)
M = int(input())
B = map(int, input().split())
SB = set(B)
C = SB.intersection(SA)
D = SA.union(SB)
E = list(D.difference(C))
E.sort()
for it in E:
	print(it)


_ = int(input())
set1 = set(map(int, input().split()))
_ = int(input())
set2 = set(map(int, input().split()))
symDiff = sorted(list(set1 - set2 | set2 - set1))
for v in symDiff:
	print(v)


M = int(input())
a = set([int(x) for x in input().split()])
N = int(input())
b = set([int(x) for x in input().split()])
union = a.union(b)
intersection = a.intersection(b)
ans = union.difference(intersection)
ans = sorted(list(ans))
for x in ans:
	print(x)


M = int(input())
a = set([int(i) for i in input().strip().split()])
N = int(input())
b = set([int(i) for i in input().strip().split()])
un = a.union(b)
total = (a | b) - (a & b)
for n in sorted(list(total)):
	print(n)


input()
set1 = set(map(int, input().split()))
input()
set2 = set(map(int, input().split()))
list(map(print, sorted(set1 ^ set2)))


n = int(input())
nn = map(int, input().split(' '))
m = int(input())
mm = map(int, input().split(' '))
nset = set(nn)
mset = set(mm)
c = nset.difference(mset).union(mset.difference(nset))
for x in sorted(c):
	print(x)


m = int(input())
listM = set(list(map(int, input().split())))
n = int(input())
listN = set(list(map(int, input().split())))
sets = listM.difference(listM.intersection(listN)).union(listN.difference(listM.intersection(listN)))
lists = list(sets)
lists = sorted(lists)
[print(i) for i in lists]


import itertools
m = int(input())
r = set(map(int, input().split()))
n = int(input())
s = set(map(int, input().split()))
arr = []
g = list(r.difference(s))
p = list(s.difference(r))
for q in g:
	arr.append(q)
for t in p:
	arr.append(t)
arr.sort()
for z in arr:
	print(z)


L = []
for i in range(4):
	s = input()
	L.append(s)
set1 = L[1].split()
set2 = L[3].split()
setlist1 = set()
setlist2 = set()
for i in set1:
	setlist1.add(i)
for j in set2:
	setlist2.add(j)
intersect = setlist1.intersection(setlist2)
setlist1 = setlist1.difference(intersect)
setlist2 = setlist2.difference(intersect)
setlist3 = setlist1.union(setlist2)
L = []
for i in setlist3:
	L.append(int(i))
L.sort()
for i in L:
	print(i)


n = int(input())
a = set(map(int, input().split()))
m = int(input())
b = set(map(int, input().split()))
res = list(a - b | b - a)
res.sort()
for el in res:
	print(el)


def get_set():
	input()
	return {int(x) for x in input().split()}
[a, b] = [get_set() for _ in range(2)]
r = a.symmetric_difference(b)
rl = list(r)
rl.sort()
for x in rl:
	print(x)


alen = int(input())
a = set(map(int, input().split()))
blen = int(input())
b = set(map(int, input().split()))
c = a.union(b)
d = a.intersection(b)
for x in sorted(c.difference(d)):
	print(x)


x = input()
n = set(list(map(int, input().split())))
x = input()
m = set(list(map(int, input().split())))
for x in sorted(n.symmetric_difference(m)):
	print(x)


n1 = int(input())
s1 = set([int(a) for a in input().split()])
n2 = int(input())
s2 = set([int(a) for a in input().split()])
s3 = s1.difference(s2).union(s2.difference(s1))
l = list(s3)
l.sort()
for i in l:
	print(i)


m = input()
mIntegers = input()
mlist = mIntegers.split()
newmList = list(map(int, mlist))
n = input()
nIntegers = input()
nlist = nIntegers.split()
newnList = list(map(int, nlist))
my_setm = set(newmList)
my_setn = set(newnList)
d1 = my_setm.difference(my_setn)
d2 = my_setn.difference(my_setm)
d3 = d1.union(d2)
d4 = list(d3)
d4.sort()
for x in d4:
	print(x)


(_, s) = (input(), {int(i) for i in input().split()})
(_, t) = (input(), {int(i) for i in input().split()})
print(*sorted((s | t) - (s & t)), sep='\n')


def main():
	n = int(input())
	a = set([int(x) for x in str(input()).split()])
	n = int(input())
	b = set([int(x) for x in str(input()).split()])
	r = a.difference(b)
	s = b.difference(a)
	print('\n'.join([str(x) for x in sorted(list(s) + list(r))]))
main()


import collections
N = int(input())
setN = set()
line = input().split()
for i in line:
	setN.add(int(i))
M = int(input())
setM = set()
line1 = input().split()
for j in line1:
	setM.add(int(j))
setMN = setM & setN
setN1 = setN - setMN
setM1 = setM - setMN
setAll = setN1 | setM1
setsorted = sorted(setAll)
for k in setsorted:
	print(k)


M = int(input())
setM = set()
lisM = [int(x) for x in input().split()]
for i in lisM:
	setM.add(i)
N = int(input())
setN = set()
lisN = [int(x) for x in input().split()]
for i in lisN:
	setN.add(i)
diff1 = set()
diff2 = set()
diff1 = setM.difference(setN)
diff2 = setN.difference(setM)
unionset = diff1.union(diff2)
li = []
for i in unionset:
	li.append(i)
li.sort()
for i in li:
	print(i)


m = int(input())
lm = input().split()
lm = list(map(int, lm))
n = int(input())
ln = input().split()
ln = list(map(int, ln))
sm = set(lm)
sn = set(ln)
ld = list(set(sm.difference(sn)).union(set(sn.difference(sm))))
ld.sort()
for i in range(len(ld)):
	print(ld[i])


m = int(input())
m_nums = map(int, input().split())
n = int(input())
n_nums = map(int, input().split())
m_set = set(m_nums)
n_set = set(n_nums)
result = set()
result.update(m_set.difference(n_set))
result.update(n_set.difference(m_set))
result_lst = list(result)
fin = sorted(result_lst)
for i in fin:
	print(i)


M = int(input())
set_M = set(map(int, input().split()))
N = int(input())
set_N = set(map(int, input().split()))
result = map(str, sorted(list((set_M | set_N) - (set_M & set_N))))
print('\n'.join(result))


m = int(input())
lm = list(map(int, input().split(' ')))
n = int(input())
ln = list(map(int, input().split(' ')))
sm = set(lm)
sn = set(ln)
c = sm.intersection(sn)
k = []
k = set()
k.update(sm.difference(c))
k.update(sn.difference(c))
l = list(k)
l.sort()
for i in l:
	print(i)


input()
a = set(input().split())
input()
b = set(input().split())
a.symmetric_difference_update(b)
ans = sorted([int(i) for i in a])
for i in ans:
	print(i)


input()
m = set(map(int, input().split()))
input()
n = set(map(int, input().split()))
for x in sorted(list(m.union(n) - m.intersection(n))):
	print(x)


read_set = lambda : [input(), set(map(int, input().split()))][1]
x = read_set()
y = read_set()
for i in sorted(x.symmetric_difference(y)):
	print(i)


def main():
	n = int(input())
	s1 = input()
	m = int(input())
	s2 = input()
	lis = s1.split()
	lis1 = s2.split()
	a = set(lis)
	c = set(lis)
	b = set(lis1)
	d = set()
	e = set()
	c = a.union(b)
	d = a.intersection(b)
	e = c.difference(d)
	l = list(e)
	nl = list(map(int, l))
	nl.sort()
	for x in nl:
		print(x)
main()


k = eval(input())
l = input().split(' ')
nl = list(map(int, l))
l.clear()
k = eval(input())
l = input().split(' ')
ml = list(map(int, l))
k = set()
l = set()
for i in nl:
	k.add(i)
nl.clear()
for i in ml:
	l.add(i)
f = set(k.difference(l))
f1 = set(l.difference(k))
f = set(f.union(f1))
for i in f:
	nl.append(i)
nl.sort()
for i in nl:
	print(i)


n = int(input())
n_num = input()
n_num = n_num.split(' ')
n_num = set(n_num)
m = int(input())
m_num = input()
m_num = m_num.split(' ')
m_num = set(m_num)
diff = m_num.union(n_num) - m_num.intersection(n_num)
diff = list(diff)
for i in range(len(diff)):
	diff[i] = int(diff[i])
diff.sort()
for i in diff:
	print(i)


def symmetric_difference(s1, s2):
	intersect = s1.intersection(s2)
	return set.union(s1 - intersect, s2 - intersect)
n = int(input())
set1 = set(map(int, input().split()))
m = int(input())
set2 = set(map(int, input().split()))
print(*sorted(list(symmetric_difference(set1, set2))), sep='\n')


from sys import stdin

def get_sets():
	num_m = int(stdin.readline())
	set_m = set(map(int, stdin.readline().split()))

def main():
	num_m = int(stdin.readline())
	set_m = set(map(int, stdin.readline().split()))
	num_n = int(stdin.readline())
	print('\n'.join(map(str, sorted(set_m.symmetric_difference(set(map(int, stdin.readline().split())))))))
main()


M = int(input())
m = set([int(splitted) for splitted in input().split(' ')])
N = int(input())
n = set([int(splitted) for splitted in input().split(' ')])
[print(item) for item in sorted(m.difference(n).union(n.difference(m)))]


M = int(input())
L = input().split(' ')
L = list(map(lambda x: int(x), L))
N = int(input())
K = input().split(' ')
K = list(map(lambda x: int(x), K))
L = set(L)
K = set(K)
J = L.difference(K).union(K.difference(L))
J = sorted(J)
for i in J:
	print(i)


a = input()
M = set(list(map(int, input().split(' '))))
a = input()
N = set(list(map(int, input().split(' '))))
differ = list(M.difference(N).union(N.difference(M)))
differ.sort()
for x in differ:
	print(x)


input()
a = set(list(map(int, input().split())))
input()
b = set(list(map(int, input().split())))
ans = sorted(a ^ b)
for x in ans:
	print(x)


n = int(input())
a = set(list(map(int, input().split())))
m = int(input())
b = set(list(map(int, input().split())))
x = a.union(b)
y = a.intersection(b)
for it in sorted(x.difference(y)):
	print(it)


import fileinput
M = int(input())
SM = set(map(int, input().split(' ')))
N = int(input())
SN = set(map(int, input().split(' ')))
diff = list(SM.difference(SN).union(SN.difference(SM)))
diff.sort()
for v in diff:
	print(v)


input()
a = set(input().split())
input()
b = set(input().split())
ans = a.union(b)
[ans.discard(x) for x in a.intersection(b)]
ans = sorted(list(map(int, ans)))
[print(x) for x in ans]


n = int(input())
nset = set(map(int, input().split()))
m = int(input())
mset = set(map(int, input().split()))
thing = set(nset.difference(mset))
thing.update(mset.difference(nset))
for i in sorted(list(thing)):
	print(i)


a = int(input())
x = input()
x = x.split()
x = set(list(map(int, x)))
b = int(input())
y = input()
y = y.split()
y = set(list(map(int, y)))
z = set()
z = x.intersection(y)
p = x.union(y)
q = p.difference(z)
c = list(q)
c.sort()
for i in range(len(c)):
	print(c[i])


i = input()
a = str(input())
temp1 = a.split()
i = input()
a = str(input())
temp2 = a.split()
s = set(temp2)
temp3 = [x for x in temp1 if x not in s]
s = set(temp1)
temp4 = [x for x in temp2 if x not in s]
temp4.extend(temp3)
s = set(temp4)
s = list(map(int, s))
s.sort()
print('\n'.join([str(i) for i in s]))


m = int(input())
strm = input()
lis_m = strm.split()
lis_m = list(map(int, lis_m))
set_m = set(lis_m)
n = int(input())
strn = input()
lis_n = strn.split()
lis_n = list(map(int, lis_n))
set_n = set(lis_n)
full_set = set_n.union(set_m)
inter_set = set_n.intersection(set_m)
final_set = full_set.difference(inter_set)
final = list(final_set)
final.sort()
for k in final:
	print(k)


n = int(input())
s1 = set(map(int, input().split()))
m = int(input())
s2 = set(map(int, input().split()))
s3 = s1.symmetric_difference(s2)
x = len(s3)
ll = list(s3)
sorted(ll)
ll.sort()
for i in range(0, x):
	print(ll[i])


m = int(input())
lis = input().split()
M = list(map(int, lis))
n = int(input())
lis = input().split()
N = list(map(int, lis))
setM = set(M)
setN = set(N)
result = setM.union(setN).difference(setM.intersection(setN))
while result:
	t = min(result)
	print(t)
	result.discard(t)


from sys import stdin

def main():
	stdin.readline()
	a = set(map(int, stdin.readline().split()))
	stdin.readline()
	b = set(map(int, stdin.readline().split()))
	symm_diff = a.difference(b)
	symm_diff = symm_diff.union(b.difference(a))
	for i in sorted(symm_diff):
		print(i)
main()


m = int(input())
a = map(int, input().split())
n = int(input())
a1 = set(a)
b = map(int, input().split())
b1 = set(b)
adb = a1.difference(b1)
bda = b1.difference(a1)
zm = sorted(bda.union(adb))
for x in zm:
	print(x)


a = input()
a = input()
lis = a.split()
seta = list(map(int, lis))
seta = set(seta)
a = input()
a = input()
lis = a.split()
setb = list(map(int, lis))
setb = set(setb)
ans = list(seta.difference(setb))
ans1 = list(setb.difference(seta))
for x in ans:
	ans1.append(x)
ans1 = sorted(ans1)
for x in ans1:
	print(x)


M = int(input())
a = [int(x) for x in input().split()]
N = int(input())
b = [int(x) for x in input().split()]
a = set(a)
b = set(b)
sd = a.union(b).difference(a.intersection(b))
sd = list(sd)
sd.sort()
if len(sd) > 0:
	for x in sd:
		print(x)


a = int(input())
b = list(map(int, input().split()))
c = int(input())
d = list(map(int, input().split()))
b1 = set(b)
d1 = set(d)
k1 = b1.union(d1)
k2 = b1.intersection(d1)
k3 = k1.difference(k2)
k4 = list(k3)
k4.sort()
for i in k4:
	print(i)


m = input()
a = set(map(int, input().split()))
n = input()
b = set(map(int, input().split()))
l = list(a.difference(b).union(b.difference(a)))
l.sort()
for i in l:
	print(i)


m = int(input())
set1 = set(map(int, input().split(' ')))
n = int(input())
set2 = set(map(int, input().split(' ')))
result1 = set1.difference(set2)
result2 = set2.difference(set1)
result1 = result1.union(result2)
result1 = sorted(result1)
for i in result1:
	print(i)


M_count = int(input())
M = set(map(int, input().split()))
N_count = int(input())
N = set(map(int, input().split()))
sym_diff = M.union(N).difference(M.intersection(N))
sdl = list(sym_diff)
sdl.sort()
for i in sdl:
	print(i)


_ = input()
a = set((int(x) for x in input().split()))
_ = input()
b = set((int(x) for x in input().split()))
print('\n'.join((str(x) for x in sorted((x for x in a.difference(b).union(b.difference(a)))))))


n = int(input())
nar = set(list(map(int, input().split())))
m = int(input())
mar = set(list(map(int, input().split())))
un = nar.union(mar)
ins = nar.intersection(mar)
j = sorted(un.difference(ins))
for item in j:
	print(item)


def get_input():
	input()
	set_a = set(map(int, input().split()))
	input()
	set_b = set(map(int, input().split()))
	return (set_a, set_b)

def symmetric_difference(set_a, set_b):
	for i in sorted(set_a.difference(set_b).union(set_b.difference(set_a))):
		print(i)

def main():
	(set_a, set_b) = get_input()
	symmetric_difference(set_a, set_b)
main()


m_c = input()
m = input().split()
n_c = input()
n = input().split()
(M, N) = (set(m), set(n))
ar = []
ar0 = M.difference(N)
ar1 = N.difference(M)
for x in ar0:
	ar.append(x)
for x in ar1:
	ar.append(x)
ar = list(map(int, ar))
ar.sort()
for x in ar:
	print(x)


def main():
	input()
	a = set(map(int, input().split()))
	input()
	b = set(map(int, input().split()))
	ans = a.difference(b)
	ans.update(b.difference(a))
	answer = list(ans)
	answer.sort()
	for num in answer:
		print(num)
main()


m = int(input())
ms = set((int(x) for x in input().split()))
n = int(input())
ns = set((int(x) for x in input().split()))
for x in sorted(ms ^ ns):
	print(x)


import sys
m = int(input())
mm = set([int(x) for x in sys.stdin.readline().strip().split()])
n = int(input())
nn = set([int(x) for x in sys.stdin.readline().strip().split()])
tt = mm ^ nn
tt = list(tt)
tt.sort()
for xx in tt:
	print(xx)


M = int(input())
m = input()
m1 = m.split(' ')
N = int(input())
n = input()
n1 = n.split(' ')
s = set(m1)
t = set(n1)
s1 = s.union(t)
t1 = s.intersection(t)
s1 = s1.difference(t1)
l = []
for i in s1:
	l.append(int(i))
for j in sorted(l):
	print(j)


def read_numbers():
	return input().split(' ')
m = int(input())
ms = set(read_numbers())
n = int(input())
ns = set(read_numbers())
result = list(ms.difference(ns))
result.extend(ns.difference(ms))
result.sort(key=int)
print('\n'.join(result))


m = int(input())
s1 = set(map(int, input().split()))
n = int(input())
s2 = set(map(int, input().split()))
print('\n'.join(map(str, sorted((s1 | s2) - (s1 & s2)))))


n = int(input())
a = input()
l1 = a.split(' ')
l1 = [int(x) for x in l1]
m = int(input())
a = input()
l2 = a.split(' ')
l2 = [int(x) for x in l2]
(s1, s2) = (set(l1), set(l2))
x = s1.difference(s2)
y = s2.difference(s1)
z = x.union(y)
l = list(z)
l.sort()
for i in l:
	print(i)


na = int(input())
A = set(map(int, input().split()))
nb = int(input())
B = set(map(int, input().split()))
for e in sorted(A ^ B):
	print(e)


m = int(input())
a = set([int(x) for x in input().split()])
n = int(input())
b = set([int(x) for x in input().split()])
union = a.union(b)
inter = a.intersection(b)
symm_diff = union.difference(inter)
[print(x) for x in sorted(symm_diff)]


import sys
if sys.version_info[0] >= 3:
	raw_input = input
raw_input()
a = {int(e) for e in raw_input().split()}
raw_input()
b = {int(e) for e in raw_input().split()}
for e in sorted(list(a - b) + list(b - a)):
	print(e)


m = int(input())
mysetm = set()
mysetn = set()
mysetm = set(map(int, input().split()))
n = int(input())
mylist = []
mysetn = set(map(int, input().split()))
mylist.extend(list(mysetm.difference(mysetn)))
mylist.extend(list(mysetn.difference(mysetm)))
mylist.sort()
for i in range(0, len(mylist), 1):
	print('{}'.format(mylist[i]))


input()
s1 = set(input().split())
input()
s2 = set(input().split())
print('\n'.join(sorted(s1 - s2 | s2 - s1, key=int)))


import sys
num1 = int(sys.stdin.readline())
b = set([int(x) for x in sys.stdin.readline().split()])
num2 = int(sys.stdin.readline())
a = set([int(x) for x in sys.stdin.readline().split()])
final = a.union(b).difference(a.intersection(b))
lst = list(final)
for x in sorted(lst):
	print(x)


a = input()
a = input()
M = set(list(map(int, a.split())))
a = input()
a = input()
N = set(list(map(int, a.split())))

def symeticDiff(m, n):
	return m.difference(n).union(n.difference(m))
[print(i) for i in sorted(symeticDiff(M, N))]


input()
a = set((int(el) for el in input().split()))
input()
b = set((int(el) for el in input().split()))
print('\n'.join((str(el) for el in sorted(a.difference(b).union(b.difference(a))))))


input()
set1 = {int(n) for n in input().split()}
input()
set2 = {int(n) for n in input().split()}
out = list(set1 ^ set2)
out.sort()
for n in out:
	print(n)


input()
M = set(map(int, input().split()))
input()
N = set(map(int, input().split()))
for a in sorted(list(M ^ N)):
	print(a)


m = int(input())
ms = set(map(int, input().split()))
n = int(input())
ns = set(map(int, input().split()))
for x in sorted(ms ^ ns):
	print(x)


n = int(input())
a = set(list(map(int, input().split())))
m = int(input())
b = set(list(map(int, input().split())))
a = a ^ b
l = list()
for x in a:
	l.append(x)
l.sort()
for x in l:
	print(x)


input()
first_set = set(input().split())
input()
second_set = set(input().split())
for i in sorted(map(int, first_set ^ second_set)):
	print(i)


m = int(input())
ma = list(map(int, input().split()))
n = int(input())
na = list(map(int, input().split()))
ii = set(ma).intersection(set(na))
uu = set(ma).union(set(na))
rr = uu.difference(ii)
r = []
for i in rr:
	r.append(i)
r.sort()
for i in r:
	print(i)


N = int(input())
N_list = map(int, input().split(' '))
M = int(input())
M_list = map(int, input().split(' '))
N_set = set(N_list)
M_set = set(M_list)
tmp_set1 = N_set.difference(M_set)
tmp_set2 = M_set.difference(N_set)
result = tmp_set1.union(tmp_set2)
result = sorted(result)
for el in result:
	print(el)


input()
li = set([int(x) for x in input().split()])
input()
li2 = set([int(x) for x in input().split()])
x = li.symmetric_difference(li2)
x = sorted(x)
for w in x:
	print(w)


m = int(input())
setA = set()
for i in input().split():
	setA.add(int(i))
n = int(input())
setB = set()
for i in input().split():
	setB.add(int(i))
setC = setA.union(setB)
setC = setC.difference(setA.intersection(setB))
setC = sorted(setC)
for i in setC:
	print(i)