Problem:
Search II You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S. Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers are given. Output Print C in a line. Constraints  Elements in S is sorted in ascending order  n ≤ 100000  q ≤ 50000  0 ≤ an element in S ≤ 10 9  0 ≤ an element in T ≤ 10 9  Sample Input 1 5
1 2 3 4 5
3
3 4 1 Sample Output 1 3 Sample Input 2 3
1 2 3
1
5 Sample Output 2 0 Sample Input 3 5
1 1 2 2 3
2
1 2 Sample Output 3 2 Notes

Solution (Python):
N = int(input())
S = list(map(int, input().split()))
Q = int(input())
T = list(map(int, input().split()))

def binary_search(target_num, head, tail):
    idx = int((head+tail)/2)
    if target_num == S[idx]:
        return True
    elif target_num < S[idx]:
        if head == idx:
            return False
        return binary_search(target_num, head, idx-1)
    else:
        if tail == idx:
            return False
        return binary_search(target_num, idx+1, tail)


match_count = 0
for target_num in T:
    if binary_search(target_num, 0, len(S)-1):
        match_count += 1

print(str(match_count))

Solution (Python):
N = int(input())
S = list(map(int, input().split()))
Q = int(input())
T = list(map(int, input().split()))

def binary_search(target_num, head, tail):
    idx = int((head+tail)/2)
    if target_num == S[idx]:
        return True
    elif target_num < S[idx]:
        if head == idx:
            return False
        return binary_search(target_num, head, idx-1)
    else:
        if tail == idx:
            return False
        return binary_search(target_num, idx+1, tail)


match_count = 0
for target_num in T:
    if binary_search(target_num, 0, len(S)-1):
        match_count += 1

print(str(match_count))

Solution (Python):
N = int(input())
S = list(map(int, input().split()))
Q = int(input())
T = list(map(int, input().split()))

def binary_search(target_num, head, tail):
    while head <= tail:
        idx = int((head+tail)/2)
        if target_num == S[idx]:
            return True
        elif target_num < S[idx]:
            tail = idx - 1
        else:
            head = idx + 1
    return False


match_count = 0
for target_num in T:
    if binary_search(target_num, 0, len(S)-1):
        match_count += 1

print(str(match_count))

Solution (Python):
N = int(input())
S = set(input().split())
Q = int(input())
T = set(input().split())
print(len(S & T))

Solution (Python):
N = int(input())
S = set(input().split())
Q = int(input())
T = set(input().split())
print(len(S & T))

Solution (Python):
N = int(input())
S = list(map(int, input().split()))
Q = int(input())
T = list(map(int, input().split()))

def binary_search(target_num, head, tail):
    while head <= tail:
        idx = int((head+tail)/2)
        if target_num == S[idx]:
            return True
        elif target_num < S[idx]:
            tail = idx - 1
        else:
            head = idx + 1
    return False


match_count = 0
for target_num in T:
    if binary_search(target_num, 0, len(S)-1):
        match_count += 1

print(str(match_count))

Solution (Python):
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
c = 0
for i in range(q):
    l = 0
    r = n
    t = T[i]
    while r-l > 1:
        m = (r + l)//2
        if (S[m] > t):
            r = m
        else:
            l = m
    if (S[l] == T[i]):
        c += 1
print(c)

Solution (Python):
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

def binary_search(series, key, i_left, i_right):
    if i_right == i_left:
        return int(series[i_right] == key)
    i_center = int((i_left + i_right)/2)
    if series[i_center] == key:
        return 1
    elif series[i_center] > key:
        return binary_search(series, key, i_left, i_center)
    else:
        return binary_search(series, key, i_center + 1, i_right)

cnt = 0
for t in T:
    cnt += binary_search(S, t, 0, n-1)
print(cnt)

Solution (Python):
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
def binary_search(S, key):
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if S[mid] == key:
            return True
        elif S[mid] > key:
            right = mid
        else:
            left = mid + 1
    return False

print(sum(binary_search(S, key) for key in T))

Solution (Python):
iipt=lambda:int(input())
miipt=lambda:list(map(int,input().split(" ")))
import bisect
 
N=iipt()
c=miipt()
M=iipt()
qu=miipt()
ans=0
for q in qu:
    a=0
    b=N-1
    while b-a>1:
        x=(a+b)//2
        if c[a]==q or c[b]==q:
            ans+=1
            break
        if c[x]<q:
            a=x
        else:
            b=x
    else:
        if c[a]==q or c[b]==q:
            ans+=1

    """        
    if a==-1 or b==N:
        print(q,a,b)
        ans-=1"""

print(ans)

Solution (Python):
n=int(input())
S=list(map(int,input().split()))
q=int(input())
T=map(int,input().split())

ans=0
for t in T:
    if S[-1]<t or S[0]>t: continue
    U=n
    L=0
    while True:
        x=(U+L)//2
        if S[x]==t:
            ans+=1
            break
        elif U-L==1:
            break
        elif S[x]>t:
            U=x
        else:
            L=x
print(ans)

Solution (Python):
Ns=int(input())
S=list(map(int,input().split()))
Nt=int(input())
T=list(map(int,input().split()))

answer=0

for i in range(0,len(T)):
    a=0
    b=len(S)-1
    
    while b-a>=2:
        x=(a+b)//2
        
        if T[i]>=S[x]:
            a=x
        else:
            b=x
            
    if T[i]==S[a] or T[i]==S[b]:
        answer+=1
    
print(answer)

Solution (Python):
n = int(input())
sinput = input().split()
s=[]
for i in range(n):
    s.append(int(sinput[i]))

q = int(input())
tinput = input().split()
t=[]
for i in range(q):
    t.append(int(tinput[i]))
answer = 0

import math
for tn in t:
    smin = 0
    smax = n - 1
    c = math.floor((n - 1) / 2)
    while(smax - smin > 1):
        if(tn == s[c]):
            answer = answer + 1
            break
        elif(tn > s[c]):
            if(tn == s[smax]):
                answer = answer + 1
                break
            smin = c
            c = math.floor((smin + smax) / 2) 
        elif(tn < s[c]):
            if(tn == s[smin]):
                answer = answer + 1
                break
            smax = c
            c = math.floor((smin + smax) / 2)

print(answer)

Solution (Python):
N = int(input())
s = list(map(int, input().split()))
Q = int(input())
t = list(map(int, input().split()))
count = 0


def b_search(x, y):
    a = 0
    b = len(x)
    if y > x[b-1] or y < x[a]:
        return 0
    while b - a > 1:
        c = (a + b) // 2
        if x[c] == y:
            return 1
        elif y < x[c]:
            b = c
        else:
            a = c
    return 0


for i in range(len(t)):
    count += b_search(s, t[i])

print(count)

Solution (Python):




N=int(input())
S=[int(i) for i in input().split()]
Q=int(input())
T=[int(i) for i in input().split()] 
C=0
a=0;b=0
for i in T:
    b=len(S)-1
    a=0
    while(a+1<b):
        c=((a+b)//2)
        if(S[c]>=i):
            b=c
        elif(S[c]<i):
            a=c
    if(S[a]==i or S[b]==i):
        C+=1
print(C);

Solution (Python):
Ns=int(input())
S=list(map(int,input().split()))
Nt=int(input())
T=list(map(int,input().split()))

answer=0

for i in range(0,len(T)):
    a=0
    b=len(S)-1
    
    while b-a>1:
        x=(a+b)//2
        
        if T[i]>=S[x]:
            a=x
        else:
            b=x
            
    if T[i]==S[a] or T[i]==S[b]:
        answer+=1
        
print(answer)

Solution (Python):
def binary_search(array, tgt_no): 

    def compare_midpoint(tgt, array, start, end):
        midpoint = (end + start)//2
        if tgt == array[midpoint]:
            return True, None, None
        elif tgt < array[midpoint]:
            return False, start, midpoint
        elif tgt > array[midpoint]:
            return False, midpoint, end

    start = 0
    end = len(array)
    while True:
        ret, start, end = compare_midpoint(tgt_no, array, start, end)
        if ret:
            return True
        if end - start <= 1:
            return tgt_no == array[start]


def main():
    _ = input()
    array_A = list(map(int, input().split()))
    _ = input()
    array_B = list(map(int, input().split()))

    cnt = 0
    for integer_B in array_B:
        if binary_search(array_A, integer_B):
            
            cnt += 1

    print(cnt)
    return


main()

Solution (Python):
def binary_search(array, tgt_no): 

    def compare_midpoint(tgt, array, start, end):
        midpoint = (end + start)//2
        if tgt == array[midpoint]:
            return True, None, None
        elif tgt < array[midpoint]:
            return False, start, midpoint
        elif tgt > array[midpoint]:
            return False, midpoint + 1, end

    start = 0
    end = len(array)
    while True:
        ret, start, end = compare_midpoint(tgt_no, array, start, end)
        if ret:
            return True
        if end <= start:
            return False


def main():
    _ = input()
    array_A = list(map(int, input().split()))
    _ = input()
    array_B = list(map(int, input().split()))

    cnt = 0
    for integer_B in array_B:
        if binary_search(array_A, integer_B):
            
            cnt += 1

    print(cnt)
    return


main()

Solution (Python):
def binary_search(num_list,target):
    first = 0
    last  = len(num_list)-1
    mid   = len(num_list)//2

    while first <= last:
        if   num_list[mid] == target:
            return 1
        elif num_list[mid] >  target:
            last = mid-1 
        elif num_list[mid] <  target:
            first = mid+1
        mid = (first+last)//2
    return 0

n = input()
num_list    = list(map(int,input().split()))
q = input()
target_list = list(map(int,input().split()))
ans = 0

for target in target_list:
    ans += binary_search(num_list,target)
print(ans)

Solution (Python):
import copy

NOT_FOUND = False


def binarySearch(n, S, t):
     
    left = 0
    right = n
    key = t
    while left < right:
        mid = (left + right) // 2
        if S[mid] == key:
            return True
        elif key < S[mid]:
            right = mid
        else:        
            left = mid + 1
    return NOT_FOUND
 
if __name__ == '__main__':
     
    
    n = int(input()) 
    S = list(map(int,input().split())) 
    q = int(input()) 
    T = list(map(int,input().split())) 
     
    
    C = 0 
     
    
    for i in range(q):
        isExist = binarySearch(n, S, T[i])
         
        
        if isExist :
            C = C + 1
    
    print(C)

Solution (Python):
def main():
    input()
    s = [int(i) for i in input().split()]
    input()
    t = [int(i) for i in input().split()]
    number = 0
    for ti in t:
        start, stop = 0, len(s)-1
        while stop - start > 1:
            center = int((start + stop) / 2)
            if ti < s[center]:
                stop = center
            elif ti > s[center]:
                start = center
            else:
                number += 1
                break
        else:
            if ti == s[start] or ti == s[stop]:
                number += 1
    print(number)


if __name__ == '__main__':
    main()

Solution (Python):
def binary_search(arr,key):
	left = 0 
	right = len(arr)
	while left < right:
		mid = (left + right)//2
		if arr[mid] == key:
			return mid 
		elif arr[mid] < key:
			left = mid + 1
		else:
			right = mid
	return -1
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
count = 0
for i in range(q):
	if binary_search(S, T[i]) != -1:
		count += 1

print(str(count))

Solution (Python):
from typing import List
import math

N = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(i) for i in input().split()]


def binary_search(A: List[int], key: int) -> int:
    left = 0
    right = len(A)
    while left < right:
        mid = math.floor((left + right) / 2)
        if A[mid] == key:
            return mid
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return -1


count = 0
for t in T:
    if binary_search(S, t) != -1:
        count += 1
print(count)

Solution (Python):



def binarySearch(num_list, value):
    lo = 0
    hi = len(num_list)
    while lo < hi:
        mid = int((lo + hi) / 2)
        if num_list[mid] == value:
            return True
        elif value < num_list[mid]:
            hi = mid
        elif value > num_list[mid]:
            lo = mid + 1
    return False

num_of_S = int(input())
S = [int(i) for i in input().split()]
num_of_T = int(input())
T = [int(i) for i in input().split()]

cnt = 0
for i in range(num_of_T):
    if binarySearch(S, T[i]):
        cnt += 1
print(cnt)

Solution (Python):
input()
n1 = set(input().split())
input()
n2 = set(input().split())

print(len(n1&n2))

Solution (Python):
def solve(s_list, t_list):
    ans = 0
    s_length = len(s_list)
    for t in t_list:
        left, right = 0, s_length
        if binary_search(s_list, left, right, t):
            ans += 1
    return ans


def binary_search(s_list, left, right, t):
    
    if right > left:
        mid = (left + right) // 2
        if s_list[mid] == t:
            return True
        elif s_list[mid] > t:
            right = mid
        else:
            left = mid + 1
        return binary_search(s_list, left, right, t)
    return False


def main():
    n = int(input())
    s_list = list(map(int, input().split()))
    q = int(input())
    t_list = list(map(int, input().split()))

    ans = solve(s_list, t_list)
    print(ans)


main()

Solution (Python):
def search(l, n):
    l = l.copy()
    l.append(n)
    i = 0
    while l[i] != n:
        i += 1

    if i == len(l) - 1:
        print("NOT FOUND")
    else:
        print("FOUND")


n = int(input())
s = [int(i) for i in input().split()]
q = int(input())
t = [int(i) for i in input().split()]

s = set(s)
ans = 0
for ti in t:
    if ti in s:
        ans += 1

print(ans)

Solution (Python):
def search(l, n):
    left = 0
    right = len(l) - 1
    m = (left + right) // 2

    while right - left > 1:
        if n == l[m]:
            return True
        elif n < l[m]:
            right = m
        elif n > l[m]:
            left = m
        else:
            raise Exception()

        m = (left + right) // 2

    if l[left] == n or l[right] == n:
        return True
    else:
        return False


n = int(input())
s = [int(i) for i in input().split()]
q = int(input())
t = [int(i) for i in input().split()]

ans = 0
for ti in t:
    if search(s, ti):
        ans += 1

print(ans)

Solution (Python):
def search(l, n):
    left = 0
    right = len(l)
    m = (left + right) // 2

    
    while left < right:
        if n == l[m]:
            return True
        elif n < l[m]:
            right = m
        elif n > l[m]:
            left = m + 1
        else:
            raise Exception()

        m = (left + right) // 2


n = int(input())
s = [int(i) for i in input().split()]
q = int(input())
t = [int(i) for i in input().split()]

ans = 0
for ti in t:
    if search(s, ti):
        ans += 1

print(ans)

Solution (Python):
def search(l, n):
    left = 0
    right = len(l) - 1
    while right - left > 1:
        m = (left + right) // 2
        if n == l[m]:
            return True
        elif n < l[m]:
            right = m
        else:
            left = m

    
    if l[left] == n or l[right] == n:
        return True
    else:
        return False


n = int(input())
s = [int(i) for i in input().split()]
q = int(input())
t = [int(i) for i in input().split()]

ans = 0
for ti in t:
    if search(s, ti):
        ans += 1

print(ans)

Solution (Python):
input()
S = set(input().split())
input()
T = set(input().split())
print(len(S & T))

Solution (Python):
n=int(input())
l1=sorted(list(map(int,input().split())))
m=int(input())
l2=sorted(list(map(int,input().split())))
def nibutan(a,k):
    l=0
    r=len(a)
    while r>l:
        m=(r+l)//2
        if a[m]==k:
            return m
        elif k<a[m]:
            r=m
        else:
            l=m+1
    return -1
c=0
for i in l2:
    if nibutan(l1,i)!=-1:
        c+=1
print(c)

Solution (Python):
from bisect import bisect_left

def index(A, x):
	i = bisect_left(A, x)
	if i != len(A) and A[i] == x:
		return i
	else:
		return -1


n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

cnt = 0
for t in T:
	if index(S, t)>=0:
		cnt += 1

print(cnt)

Solution (Python):
from bisect import bisect_left

def index(A, x):
	i = bisect_left(A, x)
	if i != len(A) and A[i] == x:
		return i
	else:
		return -1


n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

cnt = 0
for t in T:
	if index(S, t)>=0:
		cnt += 1

print(cnt)

Solution (Python):




global A
global n

def binarySearch(key):
    left = 0
    right = n
    key = int(key)

    while (left < right):
        mid = (left + right) // 2
        if (key == A[mid]):
            return 1
        if (key < A[mid]):
            right = mid
        elif (key > A[mid]):
            left = mid + 1
    return 0

if __name__ == '__main__':
    sum = 0
    n = int(input())
    A = list(map(int, input().split()))

    q = int(input())
    B = list(map(int, input().split()))

    for i in range(q):
        if binarySearch(B[i]) == 1:
            sum = sum + 1

    print("{}".format(sum))

Solution (Python):
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

ans = 0

def biSearch(A, key):
  left = 0
  right = n
  while left < right:
    mid = int((left + right) / 2)
    if A[mid] == key:
      return 1
    if A[mid] > key:
      right = mid
    if A[mid] < key:
      left = mid + 1
  return 0
for t in T:
  ans += biSearch(S, t)
print(ans)

Solution (Python):
class BinarySearch:

    def __init__(self, S, n):
        self.target = S
        self.length = n
    
    def search(self, key):
        left = 0
        right = self.length
        while left<right:
            mid = int((left+right)/2)
            if self.target[mid]==key:
                return True
            elif self.target[mid]<key:
                left = mid + 1
            elif self.target[mid]>key:
                right = mid
        return False


def main():
    n = int(input())
    S = [int(i) for i in input().split()]
    q = int(input())
    T = (int(i) for i in input().split())
    bs = BinarySearch(S, n)
    count = 0
    for t in T:
        if bs.search(t):
            count += 1
    print(count)

if __name__=='__main__':
    main()

Solution (Python):
def binaryArraySearch(ordered, t):
  low = 0
  high = len(ordered) - 1

  while low <= high:
    mid = (low + high) // 2
    if t == ordered[mid]:
      return True
    elif t < ordered[mid]:
      high = mid - 1
    else:
      low = mid + 1
  return False


n = int(input())
S = [int(x) for x in input().split()] 
q = int(input())
T = [int(x) for x in input().split()]

count = 0
for target in T:
  if binaryArraySearch(S, target):
    count += 1

print(count)

Solution (Python):
input()
s=set(raw_input().split())
input()
t=set(raw_input().split())
print len(s&t)

Solution (Python):
def binarySearch(S, key):
	left = 0
	right = len(S)
	while left < right:
		mid = (left + right) / 2
		if S[mid] == key:
			return True		
		elif key < S[mid]:
			right = mid
		else:
			left = mid + 1
	return False


n = int(raw_input())
S = []
S = map(int, raw_input().split())

q = int(raw_input())
T = []
T = map(int, raw_input().split())
count = 0
for key in T:
	if binarySearch(S, key):
		count += 1
print count

Solution (Python):
n = input()
s = set(map(int, input().split()))
q = input()
t = set(map(int, input().split()))
print(len(t & s))

Solution (Python):
def BinarySearch(A, n, key):
    
    
    left = 0
    right = n

    while left < right:
        mid = (left+right)/2
        if A[mid] == key:
            return mid
        elif key < A[mid]:
            right = mid
        elif key > A[mid]:
            left = mid + 1

    return "NOT_FOUND"


if __name__ == "__main__":
    n1 = int(raw_input())
    x1 = map(int, raw_input().split())
    n2 = int(raw_input())
    x2 = map(int, raw_input().split())

    C_num = 0

    for i in range(n2):
	if BinarySearch(x1, n1, x2[i]) != "NOT_FOUND":
            C_num += 1

    print(C_num)

Solution (Python):



import sys

NO_ANSWER = -1

def binary_sarch(target, ary, start, end):
    if start == end:
        if target == ary[start]:
            return start
        else:
            return NO_ANSWER

    mid = (start + end) / 2
    if target < ary[mid]:
        return binary_sarch(target, ary, start, mid)
    elif target > ary[mid]:
        return binary_sarch(target, ary, mid + 1, end)
    else: 
        return mid



ary_s_len = int(sys.stdin.readline().rstrip())
ary_s = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
ary_t_len = int(sys.stdin.readline().rstrip())
ary_t = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
assert len(ary_s) == ary_s_len
assert len(ary_t) == ary_t_len

count = 0
for e in ary_t:
    idx = binary_sarch(e, ary_s, 0, ary_s_len - 1)
    if idx >= 0:
        count += 1
print count

Solution (Python):
n = int( input( ) )
s = [ int( val ) for val in raw_input( ).split( " " ) ]
q = int( input( ) )
t = [ int( val ) for val in raw_input( ).split( " " ) ]

cnt = 0
cnt = 0
for ti in t:
	low = 0
	high = n - 1
	while low <= high:
		m = ( low+high )/2
		if ti < s[m]:
			high = m - 1
		elif s[m] < ti:
			low = m + 1
		else:
			cnt += 1
			break

print( cnt )

Solution (Python):
n = int( input( ) )
s = [ int( val ) for val in input( ).split( " " ) ]
q = int( input( ) )
t = [ int( val ) for val in input( ).split( " " ) ]

cnt = 0
cnt = 0
for ti in t:
	low = 0
	high = n - 1
	while low <= high:
		m = ( low+high )//2
		if ti < s[m]:
			high = m - 1
		elif s[m] < ti:
			low = m + 1
		else:
			cnt += 1
			break

print( cnt )

Solution (Python):
n = int( raw_input( ) )
s = [ int( val ) for val in raw_input( ).split( " " ) ]
q = int( raw_input( ) )
t = [ int( val ) for val in raw_input( ).split( " " ) ]

cnt = 0
cnt = 0
for ti in t:
	low = 0
	high = n - 1
	while low <= high:
		m = ( low+high )//2
		if ti < s[m]:
			high = m - 1
		elif s[m] < ti:
			low = m + 1
		else:
			cnt += 1
			break

print( cnt )

Solution (Python):
n = int( raw_input( ) )
s = [ int( val ) for val in raw_input( ).split( " " ) ]
q = int( raw_input( ) )
t = [ int( val ) for val in raw_input( ).split( " " ) ]
t.sort( )

cnt = 0
for ti in t:
	low = 0
	high = n - 1
	while low <= high:
		m = ( low+high )//2
		if ti < s[m]:
			high = m - 1
		elif s[m] < ti:
			low = m + 1
		else:
			cnt += 1
			break

print( cnt )

Solution (Python):
n = int( input( ) )
s = [ int( val ) for val in input( ).split( " " ) ]
q = int( input( ) )
t = [ int( val ) for val in input( ).split( " " ) ]
t.sort( )

cnt = 0
for ti in t:
	low = 0
	high = n - 1
	while low <= high:
		m = ( low+high )//2
		if ti < s[m]:
			high = m - 1
		elif s[m] < ti:
			low = m + 1
		else:
			cnt += 1
			break

print( cnt )

Solution (Python):


n = int(raw_input())
S = map(int,raw_input().split())
q = int(raw_input())
T = map(int,raw_input().split())
C = 0

def binary_search(A,n):
    """no recursion version"""
    l = len(A)
    left = l/2
    right = l-1
    while A[left] != n:
        if left == right and A[left] != n:
            
            return False
        elif A[left] > n: 
            right = left
            left = left/2
            
        elif A[left] < n: 
            right = right
            left = (left + right-1)/2 + 1
            
    else:
        return True

for item in T:
    if binary_search(S,item):
        C += 1
print C

Solution (Python):
n = int(raw_input())
S = map(int,raw_input().split())
q = int(raw_input())
T = map(int,raw_input().split())

c = 0
for t in T:
    left = 0
    right = n
    while left < right:
        mid = (left + right)/2
        if(S[mid] == t):
            c+=1
            break
        elif(t<S[mid]):
            right = mid
        else:
            left = mid+1

print c

Solution (Python):
n = int(input())
S = set(map(int, input().split()))
q = int(input())
T = set(map(int, input().split()))
print(len(S & T))

Solution (Python):
n = input()
s = set(input().split())
q = input()
t = set(input().split())
print(len(s & t))

Solution (Python):
def binarySearch(x, S):
    left = 0
    right = len(S)
    while left < right:
        mid = (left + right) / 2
        if x == S[mid]:
            return mid
        elif x < S[mid]:
            right = mid
        else:
            left = mid + 1
    return -1

n = int(raw_input())
S = map(int, raw_input().split())
q = int(raw_input())
T = map(int, raw_input().split())
count = 0
for x in T:
    if binarySearch(x, S) >= 0:
        count += 1
print count

Solution (Python):
n = input()
S = set([int(s) for s in raw_input().split()])
m = input()
T = set([int(s) for s in raw_input().split()])
print len(T & S)

Solution (Python):
n = input()
S = set([int(s) for s in raw_input().split()])
m = input()
T = set([int(s) for s in raw_input().split()])
print len(T & S)

Solution (Python):
n = input()
S = map(int,raw_input().split())
m = input()
T = map(int,raw_input().split())
C=0
def binarySearch(A,p):
    lens = len(A)
    ll = -1
    ul = lens-1
    ms=(ll+ul)/2
    while (ll+1<ul):
    	ms=(ll+ul)/2
        if A[ms] >= p:
            ul =ms
        elif A[ms] < p:
            ll =ms
    return A[ul]==p

for item in T:
    if binarySearch(S,item):
        C += 1
print C

Solution (Python):
n = input()
S = set([int(s) for s in raw_input().split()])
m = input()
T = set([int(s) for s in raw_input().split()])
print len(S&T)

Solution (Python):


n = int(input())
S = set(map(int, input().split()))
q = int(input())
T = set(map(int, input().split()))

print(len(S & T))

Solution (Python):
def binarySearch(A, key):
    left = 0
    right = len(A)
    while (left < right):
        mid = int((left + right) / 2)
        if(A[mid] == key):
            return mid
        elif(A[mid] > key):
            right = mid
        else:
            left = mid + 1

    return -1 

ans = 0
n = int(input())
A = [int(x) for x in input().split()] 
z = int(input())
q = [int(x) for x in input().split()]
for x in q:
    tmp = binarySearch(A, x)
    if(tmp != -1):
        ans += 1

print(ans)

Solution (Python):
n_1=input()
n_1_List=map(int,raw_input().split())
n_2=input()
n_2_List=map(int,raw_input().split())
n_1_List=set(n_1_List)
n_2_List=set(n_2_List)
print(len(n_1_List.intersection(n_2_List)))

Solution (Python):



import bisect


def isincluded(array, value):
    i = bisect.bisect_left(array, value)
    if i != len(array) and array[i] == value:
        return True
    else:
        return False


def main():
    n = int(input())
    s = [int(i) for i in input().split()]
    q = int(input())
    t = [int(j) for j in input().split()]
    print(sum(1 for x in t if isincluded(s, x)))


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))


def binary_search(A, key):
    left = 0
    right = n
    while left < right:
        mid = int((left + right)/2)
        if A[mid] == key:
            return True
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return False

cnt = 0
for i in T:
    if binary_search(S, i):
        cnt += 1

print(cnt)

Solution (Python):
n = int(input())
S = list(map(int, input().split(' ')))

q = input()
T = list(map(int, input().split(' ')))

cnt = 0

for i in T:
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if S[mid] == i:
            cnt += 1
            break
        elif i < S[mid]:
            right = mid
        else:
            left = mid + 1

print(cnt)

Solution (Python):
n = int(input())
S = tuple(map(int, input().split(' ')))

q = input()
T = tuple(map(int, input().split(' ')))

cnt = 0

for i in T:
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if S[mid] == i:
            cnt += 1
            break
        elif i < S[mid]:
            right = mid
        else:
            left = mid + 1

print(cnt)

Solution (Python):
def binarySearch(A, key, n):
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if S[mid] == i:
            return True
        elif i < S[mid]:
            right = mid
        else:
            left = mid + 1
    return False

n = int(input())
S = tuple(map(int, input().split(' ')))

q = input()
T = tuple(map(int, input().split(' ')))

cnt = 0

for i in T:
    if binarySearch(S, i, n):
        cnt += 1

print(cnt)

Solution (Python):
n = int(raw_input())
S = map(int, raw_input().strip().split(' '))
q = int(raw_input())
T = map(int, raw_input().strip().split(' '))

def binary_search(S,k):
    left = 0
    right = len(S) - 1
    while left <= right:
        mid = (left+right)/2
        if S[mid] == k: return True
        elif S[mid] > k:
            right = mid-1
        else:
            left = mid+1

c = 0
for t in T:
    if binary_search(S,t): c += 1
print c

Solution (Python):



def binarySearch(A, key):
    left, right = 0, n
    while left < right:
        mid = int((left + right) / 2)
        if A[mid] == key:
            return True
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return False

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

count = 0

for i in T:
    if binarySearch(S,i):
        count += 1

print (count)

Solution (Python):
def binarySearch(A, key, n):
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            return True
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return False

n = int(input())
S = tuple(map(int, input().split(' ')))

q = input()
T = tuple(map(int, input().split(' ')))

cnt = 0

for i in T:
    if binarySearch(S, i, n):
        cnt += 1

print(cnt)

Solution (Python):
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))


def binary_search(A, key):
    left = 0
    right = n
    while left < right:
        mid = int((left + right)/2)
        if A[mid] == key:
            return True
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return False

cnt = 0
for i in T:
    if binary_search(S, i):
        cnt += 1

print(cnt)

Solution (Python):
iterator = (("NS", "S"), ("NT", "T"))
var = {}

for i, j in iterator:
    var[i] = int(input())
    var[j] = [int(k) for k in input().split()]

count = 0
for T in var["T"]:
    left = 0
    right = len(var["S"])
    while(left < right):
        mid = (left + right)//2
        if var["S"][mid] == T:
            count += 1
            break
        elif var["S"][mid] <= T:
            left = mid+1
        else:
            right = mid
print(count)

Solution (Python):
n = input()
  
S = [int(x) for x in raw_input().split()]
  
q = input()
  
T = [int(x) for x in raw_input().split()]
  
C = 0
 

 
for key in T:
  left = 0
  right = n
  while left<right:
    mid = (right + left)/2
    if key==S[mid]:
      C += 1
      break
    elif key<S[mid]:
      right = mid
    elif key>S[mid]:
      left = mid+1
 

print C