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

Solution (Python):
def gost(lis,ky,r,l):
    
    lens=l-r+1
    
    if lens <= 5:
        if ky in lis[r:l+1]:
            return True
        else:
            return False
    
    if ky <= lis[r+(lens//2)-1]:
        return gost(lis,ky,r,r+(lens//2)-1)
    else:
        return gost(lis,ky,r+(lens//2),l)
    

n = int(input())
a = input()
s=list(map(int,a.split()))

q = int(input())
a = input()
t=list(map(int,a.split()))


i = 0
for it in t:
    if gost(s,it,0,n-1):
        i = i+1
print(i)

Solution (Python):
n = input()

S = map(int, raw_input().split())

q = input()

T = map(int, raw_input().split())

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

print cnt

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


s.sort()


def binary_search(i):
    global s
    l, r = 0, len(s)
    while l < r:
        m = (l + r) // 2
        sm = s[m]
        if sm == i:
            return 1
        elif i < sm:
            r = m
        else:
            l = m + 1
    return 0


print(sum(binary_search(i) for i in t))

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 = int((left + right)/2)
        if(S[mid] == t):
            c+=1
            break
        elif(t<S[mid]):
            right = mid
        else:
            left = mid+1
 
print c

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

Solution (Python):
def binarySearch(n, S, search):
    low    = 1 - 1
    high   = n - 1
    middle = 0

    while low < high:
        middle = (high + low)/2
        if S[middle] == search or S[low] == search or S[high] == search:
            return 1
        elif search < S[middle]:
            high = middle - 1
        elif S[middle] < search:
            low = middle + 1
    return 0

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

count = 0

for j in range(q):
    search = T[j]
    count = count + binarySearch(n, S, search)

print count

Solution (Python):
n = raw_input()
S = set(raw_input().split())
q = raw_input()
T = set(raw_input().split())

print len(S & T)

Solution (Python):
def binarySearch(key, lst):
    start = 0
    end = len(lst) - 1
    while end - start >= 0:
        i = (end - start) / 2 + start
        if lst[i] > key:
            end = i - 1
        elif lst[i] < key:
            start = i + 1
        else:
            del lst[i]
            return True
    return False

if __name__ == "__main__":
    input()
    S = map(int, raw_input().split())
    input()
    T = map(int, raw_input().split())

    n = 0
    for t in T:
        if binarySearch(t, S):
            n += 1
    print n

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

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

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

	cnt = 0
	for i in range(q):
		if (binarySearch(L, n, Key[i])):
			cnt += 1

	print(cnt)

Solution (Python):


def sort(a, left, right):
    if left < right:
        mid = (left+right)/2
        pivot = a[mid]
        a[mid] = a[left]
        p = left
        for i in range(left+1, right+1):
            if a[i] < pivot:
                p = p+1
                p, i = i, p
        a[left] = a[p]
        a[p] = pivot
        sort(a, left, p-1)
        sort(a, p+1, right)

def search(a, target):
    lo = 0
    hi = n-1
    while lo <= hi:
        mid = (lo+hi)/2
        if target <= a[mid]:
            hi = mid-1
        if target >= a[mid]:
            lo = mid+1
    if lo == hi+2:
        return True
    else:
        return False

n = int(raw_input())
S = map(int, raw_input().split())
q = int(raw_input())
T = map(int, raw_input().split())
count = 0
sort(S, 0, n-1)
for i in range(q):
    if search(S, T[i]):
        count += 1
print count

Solution (Python):
n=input()
s=map(int,raw_input().split())
q=input()
t=map(int,raw_input().split())
ct=0
for i in t:
    l=0
    r=n
    while r>l:
        m=(r+l)/2
        if s[m]==i:
            ct+=1
            break
        elif i<s[m]:
            r=m
        else:
            l=m+1
print(ct)

Solution (Python):
def binary_search(key, a):
    l = 0
    r = len(a)
    ix = (r - l) // 2

    while r - l > 0:
        if key == a[ix]:
            return True

        if key < a[ix]:
            r = ix
        else:
            l = ix + 1
        ix = l + (r - l) // 2

    return False

if __name__ == '__main__':
    n = input()
    s = [int(x) for x in input().split()]
    q = input()
    t = [int(x) for x in input().split()]

    ans = 0
    for e in t:
        ans += 1 if binary_search(e, s) else 0

    print(ans)

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

if __name__=='__main__':
    n=int(input())
    S=list(map(int,input().split()))
    q=int(input())
    T=list(map(int,input().split()))
    cnt = 0
    print(sum(map(lambda t: binarySearch(S,t) >= 0, T)))

Solution (Python):
n = input()
S = set(raw_input().split())
q = input()
T = set(raw_input().split())

print len(T&S)

Solution (Python):



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


if __name__ == '__main__':
    n = input()
    S = map(int, raw_input().split())
    q = input()
    T = map(int, raw_input().split())

    count = 0
    for i in xrange(len(T)):
        if binary_search(T[i], S):
            count += 1
    print count

Solution (Python):
count_n = int(input())
N = []
n = input()
N = n.split()
N = list(map(lambda x: int(x), N))


count_p = int(input())
P = []
p = input()
P = p.split()
P = list(map(lambda x: int(x), P))


N.sort()
P.sort()


def b(i, l):
    left = 0
    right = len(l)
    while left < right:
        mid = int((left + right) / 2)
        if l[mid] > i:
            right = mid
        elif l[mid] < i:
            left = mid + 1
        elif l[mid] == i:
            return True
    return False
answer = 0
for p in P:
    if b(p, N):
        answer += 1
print (answer)

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


def binarysearch(key, a, length):
    left = 0
    right = length
    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 binarysearch(i, S, n):
        cnt += 1
print(cnt)

Solution (Python):

sample_input = list(range(3))
sample_input[0] = '''5
1 2 3 4 5
3
3 4 1'''
sample_input[1] = '''3
1 2 3
1
5'''
sample_input[2] = ''''''
give_sample_input = None
if give_sample_input is not None:
    sample_input_list = sample_input[give_sample_input].split('\n')
    def input():
        return sample_input_list.pop(0)
        

num_of_S = int(input())
S = list(map(int, input().split(' ')))
num_of_T = int(input())
T = list(map(int, input().split(' ')))

def binary_search(increasing_list, elem):
    index_min = 0
    index_max = num_of_S-1
    
    while index_max - index_min >= 2:
        index_middle = int((index_min + index_max) / 2)
        if increasing_list[index_middle] == elem:
            return True
        elif increasing_list[index_middle] > elem:
            index_max = index_middle
        else:
            index_min = index_middle
            
    if increasing_list[index_min] == elem:
        return True
    elif increasing_list[index_max] == elem:
        return True
    else:
        return False

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

Solution (Python):
def search(S,t):
    return _search(S,t,0,len(S)-1)

def _search(S,t,l,r):
    if l > r:
        return False
    m = (l+r)/2
    if S[m] == t:
        return True
    elif S[m] > t:
        return _search(S,t,l,m-1)
    else:
        return _search(S,t,m+1,r)


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


ret = 0
for t in T:
    if search(S,t):
        ret += 1
print ret

Solution (Python):
n = int(input())
S = set(int(i) for i in input().split())
q = int(input())
T = set(int(i) for i in input().split())
print(len(S & T))

Solution (Python):
def binary_search(array, value, begin, end):
    if begin >= end:
        return None
    else:
        next_index = begin + (end - begin) // 2
        if array[next_index] == value:
            return next_index
        elif array[next_index] < value:
            return binary_search(array, value, next_index + 1, end)
        else:
            return binary_search(array, value, begin, next_index)

def main():
    n = int(input())
    S = [int(i) for i in input().split()]
    q = int(input())
    T = [int(i) for i in input().split()]

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

    print(count)

if __name__ == '__main__':
    main()

Solution (Python):
import sys


def binary_search(a, t, n):
    low = 0
    high = n - 1
    while low <= high:
        mid = (high + low) // 2
        if a[mid] == t:
            return True
        elif a[mid] < t:
            low = mid + 1
        else:
            high = mid - 1
    return False


def main():
    n = int(sys.stdin.readline())
    s = [int(x) for x in sys.stdin.readline().split()]
    q = int(sys.stdin.readline())
    t = [int(x) for x in sys.stdin.readline().split()]
    cnt = 0

    for i in t:
        if binary_search(s, i, n):
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

n = input()
s = set([x for x in sys.stdin.readline().split()])
q = input()
t = set([x for x in sys.stdin.readline().split()])
print(len(s & t))

Solution (Python):
import sys

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

Solution (Python):
def find(target, list):
  l = 0
  r = len(list)-1
  while l < r:
    m = (l + r) / 2
    if list[m] == target:
      return 1
    if target < list[m]:
      r = m
    else:
      l = m + 1
  if list[l] == target:
    return 1
  else:
    return 0

n = int(raw_input())
S = map(int, raw_input().split())
q = int(raw_input())
T = map(int, raw_input().split())
count = 0
for i in xrange(q):
  count += find(T[i], S)
print count

Solution (Python):
import sys
n = int(sys.stdin.readline()[:-1])
S = [int(x) for x in (sys.stdin.readline()[:-1].split())]
q = int(sys.stdin.readline()[:-1])
T = [int(x) for x in (sys.stdin.readline()[:-1].split())]

count = 0
for t in T:
    l = 0
    h = n - 1
    while l <= h:
        half = (h + l) // 2
        if S[half] == t:
            count += 1
            break
        elif S[half] < t:
            l = half + 1
        else:
            h = half - 1

print(count)

Solution (Python):
import math as ma

def bs(num, li):
    low, high = 0, len(li)
    if num >= li[low] and num <= li[high-1]:
        while(low <= high):
            center = ma.floor((low + high)/2 )
            if li[center] < num:
                low = center + 1
            elif li[center] > num:
                high = center -1
            else:
                return True
                break

flag = False
cnt = 0

n = int(input())
li1 = list(map(int, input().split()))
m = int(input())
li2 = list(map(int, input().split()))

for i in li2:
    flag = bs(i, li1)
    if flag:
        cnt += 1
print(cnt)

Solution (Python):


def binary_search(S,t,imin,imax):
    if imin>imax:
        return 0
    else:
        imid = imin + (imax - imin)/2
        if S[imid] > t:
            return binary_search(S,t,imin,imid-1)
        elif S[imid]<t:
            return binary_search(S,t,imid+1,imax)
        else:
            return 1

def main():
    n = input()
    S = map(int,raw_input().split())
    q = input()
    T = map(int,raw_input().split())
    ans = 0
    for t in T:
        ans += binary_search(S,t,0,len(S))
    print ans

if __name__ == '__main__':
    main()

Solution (Python):
input()
slist = map(int, raw_input().split())
input()
tlist = map(int, raw_input().split())

def func(v, low, high):

    
    if low > high:
        return 0

    mid = (low + high)/2
    
    
    
    if mid >= len(slist):
        
        return 0
    
    if v > slist[mid]:
        if low == high:
            
            return 0
        
        return func(v, mid+1, high)
        
    elif v == slist[mid]:
        
        return 1
    else:
        if low == high:
            
            return 0

        
        return func(v, low, mid-1)

count = 0
for t in tlist:
    count += func(t, 0, len(slist)-1)
print count

Solution (Python):

def BS(n,S,q,T):
    count=0
    for i in range(q):
        left=0
        right=n
        while left < right:
            mid=int((left+right)/2)
            if S[mid]==T[i]:
                count+=1
                break
            elif T[i]<S[mid]:
                right=mid
            else:
                left=mid+1
        
    print(count)
  
if __name__=="__main__":
    n=int(input())
    S=input().split(" ")
    for i in range(n):
        S[i]=int(S[i])
    q=int(input())
    T=input().split(" ")
    for i in range(q):
        T[i]=int(T[i])
    BS(n,S,q,T)

Solution (Python):



import sys


class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        length_1 = int(self.__input[0])
        array_1 = list(map(int, self.__input[1].split()))
        length_2 = int(self.__input[2])
        array_2 = list(map(int, self.__input[3].split()))

        

        count = 0

        for each in array_2:
            if self.binary_search(key=each, array=array_1, array_length=length_1):
                count += 1

        return str(count)

    @staticmethod
    def binary_search(key, array, array_length):
        
        left, right = 0, array_length
        while left < right:
            mid = (left + right) // 2
            if key == array[mid]:
                return True
            elif key < array[mid]:
                right = mid
            else:
                left = mid + 1
                


if __name__ == '__main__':
    case = Solution()
    print(case.solution)

Solution (Python):



import sys


class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        length_1 = int(self.__input[0])
        array_1 = list(map(int, self.__input[1].split()))
        length_2 = int(self.__input[2])
        array_2 = list(map(int, self.__input[3].split()))

        assert length_1 == len(array_1) and length_2 == len(array_2)

        count = 0

        for each in array_2:
            if self.binary_search(key=each, array=array_1, array_length=length_1):
                count += 1

        return str(count)

    @staticmethod
    def binary_search(key, array, array_length):
        
        left, right = 0, array_length
        while left < right:
            mid = (left + right) // 2
            if key == array[mid]:
                return True
            elif key < array[mid]:
                right = mid
            else:
                left = mid + 1
        return False


if __name__ == '__main__':
    case = Solution()
    print(case.solution)

Solution (Python):

def binary_search_internal(l, r, k, S):
    if l > r:
        return None
    center = (l + r) // 2
    v = S[center]
    if v == k:
        return center
    elif v < k:
        return binary_search_internal(center + 1, r, k, S)
    else:
        return binary_search_internal(l, center - 1, k, S)

def binary_search(k, S):
    return binary_search_internal(0, len(S) - 1, k, S)

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

count = 0
for k in Q:
    index = binary_search(k, S)
    if index != None:
        count += 1

print(count)

Solution (Python):



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

def main():
	Ns = int(raw_input())
	S  = map(int, raw_input().split())
	Nt = int(raw_input())
	T  = map(int, raw_input().split())
	
	total_v = 0
	for key in T:
		if binarySearch(S,key):
			total_v += 1

	print total_v
			
	



if __name__ == '__main__':
	main()

Solution (Python):



def binary_search(list_1, list_2):
    count = 0

    for b in list_2:
        left_index = 0
        right_index = len(list_1)
        
        while left_index < right_index:
            center = int((left_index + right_index) / 2)
            if list_1[center] == b:
                count += 1
                break
            elif b < list_1[center]:
                right_index = center
            elif b > list_1[center]:
                left_index = center + 1
                
    return count

if __name__ == "__main__":
    n_listA = int(input())
    a = sorted(set([n for n in input().split()]))
    n_listB = int(input())
    b = [n for n in input().split()]
    print(binary_search(a,b))

Solution (Python):



def binary_search(list_1, list_2):
    count = 0

    for b in list_2:
        left_index = 0
        right_index = len(list_1)
        
        while left_index < right_index:
            center = int((left_index + right_index) / 2)
            if list_1[center] == b:
                count += 1
                break
            elif b < list_1[center]:
                right_index = center
            elif b > list_1[center]:
                left_index = center + 1
                
    return count

if __name__ == "__main__":
    n_listA = int(input())
    a = sorted(set([n for n in input().split()]))
    n_listB = int(input())
    b = set([n for n in input().split()])
    print(binary_search(a,b))

Solution (Python):
if __name__ == '__main__':
    
    S_size = int(input())
    S = set([int(x) for x in input().split(' ')])
    T_size = int(input())
    T = set([int(x) for x in input().split(' ')])
    
    

    
    U = S.intersection(T)

    
    print('{0}'.format(len(U)))

Solution (Python):
from bisect import bisect_left



def index(a, x):
    ''' Locate the leftmost value exactly equal to x
    http: // docs.python.jp / 3.5 / library / bisect.html
    '''
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError


if __name__ == '__main__':
    
    
    
    num = int(input())
    S = [int(x) for x in input().split(' ')]
    num = int(input())
    T = [int(x) for x in input().split(' ')]

    
    found = 0
    for t in T:
        try:
            index(S, t)
        except ValueError:
            pass
        else:
            found += 1

    
    print(found)

Solution (Python):
from bisect import bisect_left



def index(a, x):
    ''' Locate the leftmost value exactly equal to x
    http: // docs.python.jp / 3.5 / library / bisect.html
    '''
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError


if __name__ == '__main__':
    
    
    
    num = int(input())
    S = tuple(int(x) for x in input().split(' '))
    num = int(input())
    T = [int(x) for x in input().split(' ')]

    
    found = 0
    for t in T:
        try:
            index(S, t)
        except ValueError:
            pass
        else:
            found += 1

    
    print(found)

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

for i in T:
    if i in S:
        C += 1

print(C)

Solution (Python):


n = int(input())
s = tuple(map(int, input().rstrip().split()))
q = int(input())
t = tuple(map(int, input().rstrip().split()))

count = 0

def binary_search(array, value):
    ''' array must be sorted'''
    
    size = len(array)
    start = 0
    end = size - 1
    found = False
    while True:
        middle = (start + end)//2
        
        v = array[middle]
        if v == value:
            
            return True
        elif start == end:
            
            return False
        elif v > value:
            
            end = middle
        elif v < value:
            
            start = middle + 1

for i in range(q):
    if binary_search(s, t[i]):
        count += 1
print(count)

Solution (Python):



''' ????????¢?´¢ '''





def binary_search(key, A):
    imin, imax = 0, len(S)

    while imin < imax:
        mid = int((imin + imax) / 2)
        if A[mid] == key:
            return True
        elif key < A[mid]:
            imax = mid
        else:
            imin = mid + 1
    return False


if __name__ == '__main__':
    NS = int(input())
    S = list(map(int, input().split()))
    NT = int(input())
    T = list(map(int, input().split()))

    count = 0

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

Solution (Python):
def binarySearch(l, v):
    stt = 0
    end = len(l)
    while stt < end:
        mid = (stt + end) // 2
        lmid = l[mid]
        if lmid == v:
            return mid
        if lmid > v:
            end = mid
        else:
            stt = mid + 1
    raise ValueError

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

ans = 0
for t in T:
    try:
        binarySearch(S, t)
        ans += 1
    except ValueError:
        pass

print ans

Solution (Python):
import math

def binary_search(A, key):
    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

n = int(input())
S = [int(x) for i, x in enumerate(input().split()) if i < n]
q = int(input())
T = [int(x) for i, x in enumerate(input().split()) if i < q]
count = 0
for key in T:
    if binary_search(S, key) > -1:
        count += 1
print(count)

Solution (Python):

n=int(input())
s=map(int,input().split())
q=int(input())
t=map(int,input().split())

ans=len(set(s)&set(t))

print(ans)

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

n = int(input())
L = list(map(int, input().split()))
q = int(input())
Key = list(map(int, input().split()))
cnt = 0

for i in range(q):
    if binarySearch(L, n, Key[i]):
        cnt += 1
print(cnt)

Solution (Python):
def binary_search(v, arr, s, e):
  if s > e: return False
  m = (e - s) // 2 + s
  if arr[m] == v: return True
  elif arr[m] < v:
    return binary_search(v, arr, m + 1, e)
  else:
    return binary_search(v, arr, s, m - 1)

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

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

Solution (Python):

n = int(input())
S = {int(s) for s in input().split()}

q = int(input())
T = {int(t) for t in input().split()}

cnt = sum(t in S for t in T)

print(cnt)

Solution (Python):

def BinarySearch(n, S, t):
    """ ????????????????????? """
    left = 0
    right = n - 1

    while left <= right:
        center = (left + right) // 2

        if t > S[center]:
            left = center + 1
        elif t < S[center]:
            right = center - 1
        else:
            return center

    return -1

n = int(input())
S = [int(s) for s in input().split()]

q = int(input())
T = [int(t) for t in input().split()]

cnt = 0

for t in T:
    if BinarySearch(n, S, t) != -1:
        cnt += 1

print(cnt)

Solution (Python):
import sys

def BinarySearch(S, n, t):
    bottom = 0
    top = n - 1

    while bottom <= top:
        center = (bottom + top) // 2

        if S[center] == t:
            return center
        elif S[center] < t:
            bottom = center + 1
        else:
            top = center - 1

    return -1


n = int(sys.stdin.readline())
S = [int(s) for s in sys.stdin.readline().split()]

q = int(sys.stdin.readline())
T = {int(t) for t in sys.stdin.readline().split()}

ans = sum(BinarySearch(S, n, t) != -1 for t in T)

print(ans)

Solution (Python):
def binary_search(A, n, key):
    start = 0
    end = n - 1
    while start + 1 < end:
        mid = (start + end) // 2
        if key > A[mid]:
            start = mid
        elif key < A[mid]:
            end = mid
        else:
            end = mid
    if A[start] == key:
        return True
    elif A[end] == key:
        return True
    else:
        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 binary_search(S, n, i):
        count += 1


print(count)

Solution (Python):
def main():
    input()
    a = set(input().split())
    input()
    b = set(input().split())
    print(len(a.intersection(b)))


if __name__ == "__main__":
    import os
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main()

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

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

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

def binary_search(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

count = 0
for i in T:
    if binary_search(S, i, n):
        count += 1
print(count)

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

binarySearch(S, T)

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

binarySearch()

Solution (Python):
def binarySearch():
    n = int(input())
    S = set(input().split())
    q = int(input())
    T = set(input().split())
    print(len(S.intersection(T)))
    

binarySearch()

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

binarySearch()

Solution (Python):


import re
a=raw_input()
s=set(raw_input().split())
b=raw_input()
t=set(raw_input().split())

print len(list(s&t)) if list(s&t) else 0

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

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

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

sum = 0
for c in T:
    left = 0
    right = n
    mid = 0
    if c == S[left] or c == S[right-1]:
        sum += 1
    else:
        while left+1 < right:
            mid = int(( left + right ) / 2)
            if c == S[mid]:
                sum += 1
                break
            if c > S[mid]:
                left = mid
                mid = 0
            elif c < S[mid]:
                right = mid
                mid = 0
print(sum)

Solution (Python):
import sys
import bisect

def index(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	return -1



fin = sys.stdin

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

ret = 0

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

print(ret)

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

def binarySearch(a,b):
    left = 0
    right = len(b)
    while left < right:
        mid = int((left + right)/2)
        if b[mid] == a:
            return 1
        elif b[mid] < a:
            left = mid+1
        elif b[mid] > a:
            right = mid
    return 0

count = 0
for i in T:
    count += binarySearch(i, S)
    
print(count)

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

def binarySearch(a,b):
    left = 0
    right = n
    
    while left < right:
        middle = (left + right)//2
        if b[middle] == a:
            return 1
        elif b[middle] < a:
            left = middle + 1
        elif b[middle] > a:
            right = middle 
    return 0

            
for a in t:
    count += binarySearch(a, s)

print(count)

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

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

def binarySearch(k,a):
    left = 0
    right = len(a)
    while left < right:
        middle = (left + right) // 2
        if a[middle] == k:
            return 1
        elif a[middle] < k:
            left = middle+1
        elif a[middle] > k:
            right = middle 
    return 0


count = 0
for t in T:
    count += binarySearch(t,S)
print(count)