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

Sometimes, the & operator is used in place of the .intersection() operator, but it only operates on the set of elements in set.

The set is immutable to the .intersection() operation (or & operation).

>>> s = set("Hacker")
>>> print s.intersection("Rank")
set(['a', 'k'])

>>> print s.intersection(set(['R', 'a', 'n', 'k']))
set(['a', 'k'])

>>> print s.intersection(['R', 'a', 'n', 'k'])
set(['a', 'k'])

>>> print s.intersection(enumerate(['R', 'a', 'n', 'k']))
set([])

>>> print s.intersection({"Rank":1})
set([])

>>> s & set("Rank")
set(['a', 'k'])

Task
  
The students of District College have subscriptions to English and French newspapers. Some students have subscribed only to English, some have subscribed only to 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, one set has subscribed to the French newspaper. Your task is to find the total number of students who have subscribed to both newspapers.

Input Format

The first line contains $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 subscriptions to both  English and French newspapers.

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

Sample Output
5

Explanation

The roll numbers of students who have both subscriptions:

$1,2,3,6$ and $8$.

Hence, the total is $5$ students.

Source: hackerrank | Difficulty: EASY
Tags: Data structures


Solutions:
input()
A = set(map(int, input().split()))
input()
B = set(map(int, input().split()))
print(len(A & B))


a = input()
eng = set(map(int, input().split()))
b = input()
fr = set(map(int, input().split()))
print(len(eng.intersection(fr)))


N1 = int(input())
s1 = set(input().split())
N2 = int(input())
s2 = set(input().split())
print(len(s1.intersection(s2)))


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.intersection(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.intersection(f)))


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


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


english = int(input())
eng = set(input().split(' '))
french = int(input())
frn = set(input().split(' '))
intersection = eng.intersection(frn)
print(len(intersection))


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


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


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


input()
numbers = set(map(int, input().split()))
input()
numbers = numbers & set(map(int, input().split()))
print(len(numbers))


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


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


input()
s1 = set(input().split())
input()
print(len(s1.intersection(set(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.intersection(french_subscribers)))


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


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


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


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


num_english = int(input())
english_subs = set(map(int, input().split()))
ff = int(input())
french_subs = set(map(int, input().split()))
print(len(english_subs.intersection(french_subs)))


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))


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


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


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


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


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


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


n = int(input())
s1 = set(input().split())
m = int(input())
s2 = set(input().split())
print(len(s1.intersection(s2)))


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


size_a = int(input())
set_a = set(map(int, input().split()))
size_b = int(input())
set_b = set(map(int, input().split()))
intersection = set_a.intersection(set_b)
print(len(intersection))


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


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


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


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


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


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


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.intersection(french)))


n = input()
setA = set(map(int, input().split()))
m = input()
setB = set(map(int, input().split()))
print(len(setA.intersection(setB)))


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


i = int(input())
s = set(input().split())
j = int(input())
s1 = set(input().split())
s2 = s & s1
print(len(s2))


(_, s, _) = (input(), set(input().split()), input())
print(len(set(input().split()) & s))


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


nEnglish = int(input())
english = set(map(int, input().split()))
nFrench = int(input())
french = set(map(int, input().split()))
print(len(english.intersection(french)))


english_total = int(input())
result = set(map(int, input().split()))
french_total = int(input())
result = result.intersection(set(map(int, input().split())))
print(len(result))


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


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


n = int(input())
en = set(input().split())
m = int(input())
fr = set(input().split())
print(len(en.intersection(fr)))


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


n = input()
english = set(input().split())
n = input()
french = set(input().split())
print(len(english.intersection(french)))


N = int(input())
e = set(map(int, input().split(' ')))
M = int(input())
f = set(map(int, input().split(' ')))
print(len(e.intersection(f)))


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


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.intersection(list_fra)))


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


input()
str1 = set(map(int, input().split()))
input()
str2 = set(map(int, input().split()))
print(len(str1.intersection(str2)))


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


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.intersection(f)
print(len(ef))


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


a = int(input())
ans = []
s = input()
s = s.split()
b = int(input())
s1 = input()
s1 = s1.split()
cnt = 0
for i in range(0, len(s)):
	flag = 0
	for j in range(0, len(s1)):
		if s[i] == s1[j]:
			flag = 1
			break
	if flag == 1:
		cnt += 1
print(cnt, end='')


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.intersection(bb)))


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


x1 = int(input())
x1v = set(map(int, input().split()))
x2 = int(input())
x2v = set(map(int, input().split()))
sintersection = x1v.intersection(x2v)
print(len(sintersection))


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


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


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


ne = int(input())
se = set(input().split())
nf = int(input())
sf = set(input().split())
se = se.intersection(sf)
print(len(se))


e = int(input())
english = set(input().split())
f = int(input())
french = set(input().split())
print(len(english & french))


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


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


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


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


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


__author__ = 'bishal'
a = int(input())
b = set(map(int, input().split(' ')))
c = input()
d = set(map(int, input().split(' ')))
print(len(b & d))


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


_ = input()
e = set((int(x) for x in input().split(' ')))
_ = input()
f = set((int(x) for x in input().split(' ')))
print(len(e.intersection(f)))


n = int(input())
e = set(map(int, input().split(' ')))
l = int(input())
f = set(map(int, input().split(' ')))
x = e.intersection(f)
print(len(x))


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.intersection(french)))
__starting_point()


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


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


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


e = int(input())
eng = set(map(int, input().split()))
f = int(input())
fre = set(map(int, input().split()))
print(len(eng & fre))


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.intersection(s2)))


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


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


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


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


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


m = int(input())
n = set(input().split())
q = int(input())
w = set(input().split())
print(len(n & w))


input()
a = set([int(x) for x in input().split(' ')])
input()
b = set([int(x) for x in input().split(' ')])
print(len(a.intersection(b)))


EN = input()
ES = set(input().split())
FN = input()
FS = set(input().split())
print(len(ES & FS))


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


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


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


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


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


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


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.intersection(fra)
print(len(total))


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