.union()

The .union() operator returns the union of a set and the set of elements in an iterable. 

Sometimes, the | operator is used in place of .union() operator, but it operates only on the set of elements in set.
 
Set is immutable to the .union() operation (or | operation).

Example

>>> s = set("Hacker")
>>> print s.union("Rank")
set(['a', 'R', 'c', 'r', 'e', 'H', 'k', 'n'])

>>> print s.union(set(['R', 'a', 'n', 'k']))
set(['a', 'R', 'c', 'r', 'e', 'H', 'k', 'n'])

>>> print s.union(['R', 'a', 'n', 'k'])
set(['a', 'R', 'c', 'r', 'e', 'H', 'k', 'n'])

>>> print s.union(enumerate(['R', 'a', 'n', 'k']))
set(['a', 'c', 'r', 'e', (1, 'a'), (2, 'n'), 'H', 'k', (3, 'k'), (0, 'R')])

>>> print s.union({"Rank":1})
set(['a', 'c', 'r', 'e', 'H', 'k', 'Rank'])

>>> s | set("Rank")
set(['a', 'R', 'c', 'r', 'e', 'H', 'k', 'n'])

Task
  
The students of District College have subscriptions to English and French newspapers. Some students have subscribed only to English, some have subscribed to only French and some have subscribed to both newspapers. 

You are given two sets of student roll numbers. One set has subscribed to the English newspaper, and the other set is subscribed to the French newspaper. The same student could be in both sets. Your task is to find the total number of students who have subscribed to at least one newspaper.

Input Format

The first line contains an integer, $n$, the number of students who have subscribed to the English newspaper. 

The second line contains $n$ space separated roll numbers of those students. 

The third line contains $\boldsymbol{b}$, the number of students who have subscribed to the French newspaper. 

The fourth line contains $\boldsymbol{b}$ space separated roll numbers of those students. 

Constraints

$0<\textit{Total number of students in college}<1000$

Output Format

Output the total number of students who have at least one subscription.

Sample Input
9
1 2 3 4 5 6 7 8 9
9
10 1 2 3 11 21 55 6 8

Sample Output
13

Explanation

Roll numbers of students who have at least one subscription:

$1,2,3,4,5,6,7,8,9,10,11,21$ and $55$. Roll numbers: $1,2,3,6$ and $8$ are in both sets so they are only counted once.

Hence, the total is $13$ students.

Source: hackerrank | Difficulty: EASY
Tags: Data structures


Solutions:
input()
english = set([x for x in input().split()])
input()
french = set([x for x in input().split()])
print(len(english.union(french)))


m = int(input())
english = set(input().split())
n = int(input())
french = set(input().split())
print(len(english | french))


in1 = input('')
set1 = set(map(int, input('').split(' ')))
in2 = input('')
set2 = set(map(int, input('').split(' ')))
set3 = set1.union(set2)
print(len(set3))


input()
English = set(map(int, input().split()))
input()
French = set(map(int, input().split()))
print(len(English | French))


n = int(input())
E = set()
F = set()
for x in input().split(' '):
	if len(E) < n:
		E.add(int(x))
m = int(input())
for x in input().split(' '):
	if len(F) < m:
		F.add(int(x))
print(len(E | F))


n = int(input())
eng = set(map(int, input().strip().split()))
m = int(input())
fre = set(map(int, input().strip().split()))
print(len(eng | fre))


_ = input()
englishS = set(map(int, input().split()))
_ = input()
frenchS = set(map(int, input().split()))
out = englishS.union(frenchS)
print(len(out))


n = int(input())
s1 = set(map(int, input().split()))
m = int(input())
s2 = set(map(int, input().split()))
print(len(s1.union(s2)))


a = input()
eng = set(map(int, input().split()))
b = input()
french = set(map(int, input().split()))
print(len(french.union(eng)))


english_total = int(input())
english_newspaper = set(str(input()).split())
french_total = int(input())
french_newspaper = set(str(input()).split())
print(len(english_newspaper | french_newspaper))


e = int(input())
en = set(map(int, input().split()))
f = int(input())
fr = set(map(int, input().split()))
t = en.union(fr)
print(len(t))


n = int(input())
s = set(input().split())
m = int(input())
p = set(input().split())
l = list(s.union(p))
print(len(l))


a = int(input(''))
b = input('')
A = set(b.split())
c = int(input(''))
d = input('')
B = set(d.split())
C = B.union(A)
print(len(C))


input()
s = set([int(x) for x in input().split()])
input()
t = set([int(x) for x in input().split()])
print(len(s | t))


english = int(input())
roll = input().split(' ')
roll = set(roll)
french = int(input())
roll_two = input().split(' ')
roll_two = set(roll_two)
union = roll.union(roll_two)
union = list(union)
for x in range(len(union)):
	union[x] = int(union[x])
total = len(union)
print(total)


n = input()
a = set(map(int, input().split()))
m = input()
print(len(a.union(set(map(int, input().split())))))


input()
english_subscribers = set((n for n in input().split()))
input()
french_subscribers = set((n for n in input().split()))
print(len(english_subscribers.union(french_subscribers)))


a = int(input().strip())
a_s = set(map(int, input().strip().split()[0:a]))
b = int(input().strip())
b_s = set(map(int, input().strip().split()[0:b]))
u = a_s.union(b_s)
print(len(u))


_ = input()
s1 = set(map(int, input().split()))
_ = input()
s2 = set(map(int, input().split()))
print(len(s1.union(s2)))


n = int(input())
eng = set(map(int, input().split()))
m = int(input())
fre = set(map(int, input().split()))
print(len(eng | fre))


input()
e = set(input().split())
input()
f = set(input().split())
print(len(e.union(f)))


e = int(input())
es = set(map(int, input().split()))
f = int(input())
fs = set(map(int, input().split()))
print(len(es | fs))


m = int(input())
k = set(input().split())
q = int(input())
w = set(input().split())
e = k.union(w)
print(len(e))


input()
Eng = set(input().split())
input()
Fr = set(input().split())
print(len(Eng | Fr))


input()
s1 = set(input().split())
input()
s2 = set(input().split())
print(len(s1.union(s2)))


m = input()
a = set(map(int, input().split()))
n = input()
b = set(map(int, input().split()))
print(len(a.union(b)))


input()
english = {int(x) for x in input().split()}
input()
french = {int(x) for x in input().split()}
print(len(english | french))


input()
st_one = set(input().split())
input()
st_two = set(input().split())
st_out = st_one.union(st_two)
print(len(st_out))


n = int(input())
eng = list(map(int, input().split()))
english = set(eng)
m = int(input())
frn = list(map(int, input().split()))
french = set(frn)
print(len(english | french))


eng_num = int(input())
eng_set = set(input().split())
fre_num = int(input())
fre_set = set(input().split())
print(len(fre_set | eng_set))


n1 = int(input())
s1 = set(map(int, input().split()))
n2 = int(input())
s2 = set(map(int, input().split()))
print(len(s1.union(s2)))


n = int(input())
s1 = set([int(x) for x in input().split()])
m = int(input())
s2 = set([int(x) for x in input().split()])
print(len(s1.union(s2)))


ints = lambda s: set(map(int, s.split()))
n1 = int(input())
s1 = ints(input())
n2 = int(input())
s2 = ints(input())
print(len(s1 | s2))


num1 = int(input())
setA = set(map(int, input().split()))
num2 = int(input())
setB = set(map(int, input().split()))
print(len(setA.union(setB)))


import sys
if sys.version_info[0] >= 3:
	raw_input = input
raw_input()
s1 = set(map(int, input().split()))
raw_input()
s2 = set(map(int, input().split()))
print(len(s1.union(s2)))


k = input()
kset = set(map(int, input().split()))
l = input()
lset = set(map(int, input().split()))
print(len(kset.union(lset)))


E = int(input())
e = set([int(x) for x in input().split()])
F = int(input())
f = set([int(x) for x in input().split()])
ef = e.union(f)
print(len(ef))


a = int(input())
aa = {int(i) for i in input().split()}
b = int(input())
bb = {int(i) for i in input().split()}
print(len(aa.union(bb)))


nA = int(input())
A = set(map(int, input().split()))
nB = int(input())
B = set(map(int, input().split()))
result = A | B
print(len(result))


input()
A = set(map(int, input().split()))
input()
B = set(map(int, input().split()))
print(len(A.union(B)))


def __starting_point():
	n = int(input().strip())
	english = set(map(int, input().strip().split(' ')))
	m = int(input().strip())
	french = set(map(int, input().strip().split(' ')))
	print(len(english.union(french)))
__starting_point()


N = int(input())
english = set(map(int, input().split(' ')[0:N]))
M = int(input())
french = set(map(int, input().split(' ')[0:M]))
print(len(english.union(french)))


numen = int(input())
subs = set(map(int, input().split()[:numen]))
numfr = int(input())
subs = subs.union(map(int, input().split()[:numfr]))
print(len(subs))


e = int(input())
english = [int(x) for x in input().split()]
f = int(input())
french = [int(x) for x in input().split()]
print(len(set(english) | set(french)))


n = input()
eng = set(map(int, input().split()))
b = input()
fre = set(map(int, input().split()))
print(len(eng.union(fre)))


_ = input()
english = set((int(x) for x in input().split(' ')))
_ = input()
french = set((int(x) for x in input().split(' ')))
both = english.union(french)
print(len(both))


N1 = int(input())
s1 = set(map(int, input().split()))
N2 = int(input())
s2 = set(map(int, input().split()))
print(len(s1.union(s2)))


__author__ = 'namii'
input()
English = set(map(int, input().split()))
input()
French = set(map(int, input().split()))
print(len(English.union(French)))


an = int(input())
ast = set(map(int, input().split()))
bn = int(input())
bst = set(map(int, input().split()))
st = ast.union(bst)
print(len(st))


eng = int(input())
engs = set(map(int, input().split()))
fre = int(input())
fres = set(map(int, input().split()))
print(len(engs.union(fres)))


ne = int(input())
eng = set(map(int, input().split()))
nf = int(input())
fren = set(map(int, input().split()))
print(len(eng | fren))


nume = int(input())
english = set(map(int, input().split()))
numf = int(input())
french = set(map(int, input().split()))
print(len(english.union(french)))


en = int(input())
el = list(map(int, input().split()))
fn = int(input())
fl = list(map(int, input().split()))
print('%d' % len(set(el).union(set(fl))))


EN = int(input())
Es = set(map(int, input().split()))
FN = int(input())
Fs = set(map(int, input().split()))
print(len(Es.union(Fs)))


import sys
n = int(input())
setA = set(map(int, sys.stdin.readline().split()))
m = int(input())
setB = set(map(int, sys.stdin.readline().split()))
total = len(setA.union(setB))
print(total)


a = int(input())
b = input().split()
c = set([int(i) for i in b])
d = int(input())
e = input().split()
f = set([int(i) for i in e])
print(len(c.union(f)))


input()
s = set(input().split())
input()
print(len(s.union(set(input().split()))))


input()
a = set(map(int, input().split()))
input()
b = set(map(int, input().split()))
print(len(a.union(b)))


n1 = int(input())
A = set(input().split())
n2 = int(input())
B = set(input().split())
print(len(A.union(B)))


input()
a = set(map(int, input().split()))
input()
b = set(map(int, input().split()))
print(len(a | b))


_ = input()
s1 = set(input().split())
_ = input()
print(len(set(input().split()) | s1))


n = int(input())
set_a = set(input().strip().split())
m = int(input())
set_b = set(input().strip().split())
print(len(set_a | set_b))


a = int(input())
ans = []
s = input()
s = s.split(' ')
for i in range(0, len(s)):
	ans.append(s[i])
b = int(input())
ss = input()
ss = ss.split(' ')
for i in range(0, len(ss)):
	ans.append(ss[i])
ans = set(ans)
ans = sorted(ans)
print(len(ans), end='')


input()
a = input().split(' ')
input()
b = input().split(' ')
print(len(set(a + b)))


numEng = int(input())
eng = list(map(int, input().split()))
numfran = int(input())
fra = list(map(int, input().split()))
eng = set(eng)
fra = set(fra)
total = eng.union(fra)
print(len(total))


input()
e = set(map(int, input().split()))
input()
f = set(map(int, input().split()))
print(len(e.union(f)))


c1 = input()
english = set(map(int, input().split()))
c2 = input()
french = set(map(int, input().split()))
comb = english.union(french)
print(len(comb))


n = input()
english = set(map(int, input().split()))
n = input()
french = set(map(int, input().split()))
print(len(english.union(french)))


n = int(input())
s = set(map(int, input().split()))
m = int(input())
t = set(map(int, input().split()))
print(len(s | t))


input()
s = set(map(int, input().split()))
input()
t = set(map(int, input().split()))
print(len(s.union(t)))


__author__ = 'bishal'
a = input()
b = set(map(int, input().split(' ')))
c = input()
d = set(map(int, input().split(' ')))
e = len(b ^ d)
g = len(d - (b ^ d))
print(e + g)


num_eng = int(input())
list_eng = set(map(int, input().split()))
num_fra = int(input())
list_fra = set(map(int, input().split()))
print(len(list_eng.union(list_fra)))


n = input()
s = set(input().split())
n = input()
t = set(input().split())
print(len(s | t))


input()
s1 = set([x for x in input().split()])
input()
s2 = set([x for x in input().split()])
print(len(s1 | s2))


n1 = int(input())
a = set(map(int, input().split()))
n2 = int(input())
b = set(map(int, input().split()))
print(len(a | b))


a = int(input())
aset = set(input().split())
b = int(input())
bset = set(input().split())
print(len(aset.union(bset)))


input()
english = set([int(elem) for elem in input().split()])
input()
english = english.union(set([int(elem) for elem in input().split()]))
print(len(english))


a = int(input())
s1 = set(map(int, input().split()))
b = int(input())
s2 = set(map(int, input().split()))
s = s1.union(s2)
print(len(s))


_ = input()
A = set(map(int, input().split()))
_ = input()
B = set(map(int, input().split()))
print(len(A | B))


input()
s = set(input().split())
input()
s = s.union(set(input().split()))
print(len(s))


a_num = int(input())
set_a = set(map(int, input().split()))
b_num = int(input())
set_b = set(map(int, input().split()))
newset = set_a.union(set_b)
print(len(newset))


num_english_subs = int(input())
english_sub_ids = set(map(int, input().split()))
num_french_subs = int(input())
french_sub_ids = set(map(int, input().split()))
all_subs = english_sub_ids.union(french_sub_ids)
print(len(all_subs))


i = int(input())
s = set(map(int, input().strip().split(' ')))
i2 = int(input())
s1 = set(map(int, input().strip().split(' ')))
s2 = s | s1
print(len(s2))


l1 = input()
l1 = set([int(i) for i in input().split(' ')])
l2 = input()
l2 = set([int(i) for i in input().split(' ')])
l1 = l1.union(l2)
print(len(l1))


ne = int(input())
ern = input().split()
nf = int(input())
nfn = input().split()
ern = set(ern)
nfn = set(nfn)
both = ern.union(nfn)
d = len(both)
print(d)


n = int(input())
students_n = set(map(int, input().split()))
m = int(input())
students_m = set(map(int, input().split()))
print(len(students_n.union(students_m)))


input()
a = {int(i) for i in input().split()}
input()
b = {int(i) for i in input().split()}
c = a | b
print(len(c))


se = int(input())
english_subscribers = set(map(int, input().split()))
fe = int(input())
french_subscribers = set(map(int, input().split()))
print(len(english_subscribers.union(french_subscribers)))


input()
E = set(map(int, input().split()))
input()
F = set(map(int, input().split()))
print(len(E.union(F)))


E = int(input())
ES = set(map(int, input().split()))
F = int(input())
FS = set(map(int, input().split()))
print(len(ES | FS))


n1 = int(input())
s1 = set(input().split())
n2 = int(input())
s2 = set(input().split())
print(len(s1.union(s2)))


l = int(input())
e = set(map(int, input().split(' ')))
n = int(input())
f = set(map(int, input().split(' ')))
x = e.union(f)
l = len(x)
if l < 1 or l > 1000:
	exit()
print(l)


input()
a = set(input().split())
input()
b = set(input().split())
print(len(a.union(b)))


n = int(input().strip())
s1 = set(map(int, input().strip().split()))
m = int(input().strip())
s2 = set(map(int, input().strip().split()))
print(len(s1.union(s2)))


t = input()
s1 = set(map(int, input().split()))
t = input()
s2 = set(map(int, input().split()))
print(len(s1.union(s2)))


e = int(input())
english = set(map(int, input().split()))
f = int(input())
french = set(map(int, input().split()))
print(len(english.union(french)))


_ = input()
s = set(input().split())
_ = input()
t = set(input().split())
res = len(s.union(t))
print(res)


input()
a = set(input().split())
input()
print(len(a | set(input().split())))