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 binarySearch(A, key):
    left = 0
    right = n

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

        elif key < A[mid]:
            right = mid
        else:
            left = mid+1
    return 0

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

Solution (Python):
def binarySearch(A, n, key):
	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


if __name__ == "__main__":
	n = int(input())
	S = list(map(int, input().split()))
	q = int(input())
	sum = 0
	for key in list(map(int, input().split())):
		if binarySearch(S, n, key):
			sum += 1
	print(sum)

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())
S = list(map(int, input().split()))
q = int(input())
P = list(map(int, input().split()))
count = 0

for i in P:
    left = 0
    right = n

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

        if i == S[mid]:
            count += 1
            
            break

        elif i < S[mid]:
            right = mid - 1
        else:
            left = mid + 1

print(count)

Solution (Python):
import sys
from sys import stdin
input = stdin.readline

def BinarySearch(L, key, left, right):
    if left+1 == right:
        return False
    
    mid = (left+right)//2
    if L[mid] == key:
        return True
    elif L[mid] >key:
        return BinarySearch(L, key, left, mid)
    else:
        return BinarySearch(L, key, mid, right)

n = int(input())
NUM_LIST = list(map(int, input().split()))

k = int(input())
keys = list(map(int, input().split()))

cnt = 0
for key in keys:
    if BinarySearch(NUM_LIST, key, 0, len(NUM_LIST)):
        
        cnt += 1

print(cnt)

Solution (Python):





import copy

Sn = int(input())
S = list(map(int, input().split()))

Tn = int(input())
T = list(map(int, input().split()))

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


if __name__ == "__main__":
    count = 0 
    for t in T:
        if binary_search(S, Sn, t):
            count += 1

    print(count)

Solution (Python):




from bisect import bisect_left




def find_exact_equal(a: list, x: int):
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return 1  
    return 0  


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

cnt = 0
for t in T:
    cnt += find_exact_equal(S, t)

print(cnt)

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

def binarysearch(x, i):
    left = 0
    right = len(x)
    while left < right:
        mid = (left + right) // 2
        if x[mid] == i:
            return True
        elif x[mid] < i:
            left = mid + 1
        else:
            right = mid
    return False
    
cnt = 0
for i in t:
    if binarysearch(s, i):
        cnt += 1
print(cnt)

Solution (Python):
import bisect 
input()
S=list(map(int,input().split()))
input()
T=list(map(int,input().split()))
ans=0
for t in T:
  if bisect.bisect_left(S,t)!=bisect.bisect_right(S,t):
    ans+=1
print(ans)

Solution (Python):
n = int(input())
S = list(map(int,input().split()))
q = int(input())
T = list(map(int,input().split()))
ans = 0
for i in T:
    l = 0
    r = n
    while l<r:
        mid = (l+r)//2
        if S[mid] == i:
            ans+=1
            break
        elif S[mid]>i:
            r=mid
        elif S[mid]<i:
            l=mid+1  
print(ans)

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


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


print(count)

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

from bisect import bisect_right
def index_right(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect_right(a, x)
    i = i-1
    if i != len(a) and a[i] == x:
        return i
    raise ValueError
    
ans = 0
for t in T:
    try:
        index_right(S, t)
        ans += 1
    except:
        continue
print(ans)

Solution (Python):
def binarySearch(S, x, l, r):
    if r-l<=1:
        if S[l]==x:
            return True
        else:
            return False
    else:
        m=(l+r)//2
        if x<S[m]:
            return binarySearch(S, x, l, m)
        elif S[m]<x:
            return binarySearch(S, x, m+1, r)
        else:
            return True

n=int(input())
S=list(map(int,input().split()))
q=int(input())
T=list(map(int,input().split()))
ans=0
for x in T:
    if binarySearch(S, x, 0, n):
        ans+=1
print(ans)

Solution (Python):
def bs(array, n, v):
    l = 0
    r = n - 1
    while l <= r:
        p = (l + r) // 2
        if array[p] == v:
            return True
        elif v < array[p]:
            r = p - 1
        else:
            l = p + 1
    return False


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

    input()
    b = [int(i) for i in input().split()]

    cnt = 0
    for i in b:
        if bs(a, n, i):
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
s=int(input())
S=list(map(int,input().split()))
t=int(input())
T=list(map(int,input().split()))
S=list(set(S))
ans=0
S.sort()
def bs(n,key,S):
  left=0
  right=n
  while left<right:
    mid=int((left+right)/2)
    if S[mid]==key:
      return 1
    elif key<S[mid]:
      right=mid
    else:
      left=mid+1
  return 0

for i in range(len(T)):
  if bs(len(S),T[i],S):
    ans+=1
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 A[mid] > key:
            right = mid
        else:
            left = mid + 1
    return "NOT_FOUND"

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

C = 0
for i in T:
    if binarySearch(S, i) != "NOT_FOUND":
        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 isOK(index,key):
    if S[index]>=key:
        return True
    else:
        return False


def binary_search(key):
    left=-1
    right=n

    while(right-left>1):
        mid = int(left+(right-left)/2)
        if isOK(mid,key):
            right = mid
        else:
            left = mid
    
    return right

ans=0
for x in T:
    index=binary_search(x)
    if x==S[index]:
        ans+=1
    

print(ans)

Solution (Python):

num = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]


def binsearch(list,q):
    min = 0
    max = len(list) -1
    mid = (min + max)//2
    while min <= max:
        
        if q < list[min]  or list[max] < q:
            return False
        if list[mid] == q:
            return True
        elif list[mid] > q:
            max = mid - 1
            mid = (min + max) // 2
        else:
            min = mid + 1
            mid = (min + max) // 2
    return False

count = 0
for k in t:
    if binsearch(s, k):
        count += 1
print(count)

Solution (Python):
from bisect import bisect_left


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


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

q = int(input())
t = list(map(int, input().split()))
cnt = 0
for num in t:
    if search(s, num) == 1:
        cnt += 1

print(cnt)

Solution (Python):
import sys

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

def test():

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

	count = 0

	for i in range(q):
		find = binarySearch(S,T[i])
		if find != -1:
			count += 1

	print(f"{count}")

if __name__ == "__main__":
	test()

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

cnt = 0

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

print(cnt)

Solution (Python):
import bisect

n_count = int(input())
n = list(map(int, input().split()))

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

n_and_q = 0

for i in q:
    j = bisect.bisect_left(n, i)
    if i == n[j]:
        n_and_q += 1
        
print(n_and_q)

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

cnt = 0
for i in range(q):
    target = t[i]
    
    upper = n
    lower = 0
    while upper > lower:
        j = int((upper+lower)/2)
        
        if s[j] == target:
            cnt += 1
            break
        elif s[j] > target:
            upper = j
        elif s[j] < target:
            lower = j+1

print(cnt)

Solution (Python):
n=int(input())
s=list(map(int,input().split()))
q=int(input())
t=list(map(int,input().split()))
count=0
for i in t:
	left,right=0,n
	while left<right:
		mid=(left+right)//2
		if s[mid] ==i:
			count+=1
			break
		elif s[mid]<i:
			left =mid+1
		else:
			right=mid
print(count)

Solution (Python):
def b_search(s_list,s, e, x):
    while (e-s) > 1:
        mid = (s + e) // 2
        w = s_list[mid]
        if w == x:
            return True
        elif w < x:
            s = mid+1
        elif w > x:
            e = mid

    if s_list[s] == x:
        return True
    else:
        return False

n_num = int(input())
n_list = [int(s) for s in input().split()]
q_num = int(input())
q_list = [int(s) for s in input().split()]

cnt = 0
for q in q_list:
    if b_search(n_list, 0, len(n_list)-1, q):
        cnt += 1

print(cnt)

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

def bs(alist, num):
  left = 0
  right = len(alist)
  while left < right:
    mid = (left + right) // 2
    if num == alist[mid]:
      return 1
    else:
      if alist[mid] < num:
        left = mid + 1
      else:
        right = mid

  return 0

ans = 0

for num in t:
  ans += bs(s, num)

print(ans)

Solution (Python):
import math

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

def main():
    n = int(input())
    S = [int(s) for s in input().split(" ")]
    _ = int(input())
    T = [int(s) for s in input().split(" ")]

    sum = 0

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

if __name__ == '__main__':
    main()

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

def BinarySearch(S,T):
    count = 0
    for i in range(q):
        left = 0
        right = n
        
        
        while left < right:
            mid = int((left + right) / 2)
            if T[i] == S[mid]:
                count += 1
                break
            elif T[i] < S[mid]:
                right = mid
            else:
                left = mid + 1
    return count

print(BinarySearch(S,T))

Solution (Python):
n = int(input())
S,T = set(),set()
a = [int(i) for i in input().split()]
for i in range(n):
    S.add(a[i])
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
    T.add(a[i])
print(len(S&T))

"""
5
1 2 3 4 5
3
3 4 1
"""

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

center = int(n / 2)
result = 0

for ti in t:
  if s[center] < ti:
    left = int(n / 2)
    right = n - 1
  elif ti < s[center]:
    left = 0
    right = int(n / 2)
  else:
    result += 1
    continue

  while True:
    tmp = int(left + int((right - left) / 2))
    if 'current' in locals() and current == tmp:
      if right == (n - 1):
        current += 1
      else:
        current -= 1
    else:
      current = tmp

    if s[current] < ti:
      if current < left:
        break
      left = current
    elif ti < s[current]:
      if right < current:
        break
      right = current
    elif ti == s[current]:
      result += 1
      break

print(result)

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

def binary_search(lst, n, val):
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if lst[mid] == val:
            return True
        elif lst[mid] < val:
            left = mid + 1
        elif lst[mid] > val:
            right = mid
    return False

ans = 0
for val in t:
    if binary_search(s, n, val):
        ans += 1

print(ans)

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

Solution (Python):
n = input()
s = set(input().split())
q = input()
t = set(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):
N = int(input())
SET = set()
table = list(map(int,input().split()))
 
for i in range(len(table)):
    SET.add(table[i])
 
ans = 0
 
num_query = int(input())
num_array = list(map(int,input().split()))
 
for i in range(len(num_array)):
    if num_array[i] in SET:
        ans += 1
 
print("%d"%ans)

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

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    S = input().split()
    q = int(input())
    T = input().split() 
    a = set()
    count = 0
    for i in range(q):
        ch = 0
        j1 = 0
        j3 = len(S)-1
        j2 = int((j1+j3)/2)
        while j1<=j3:
            ch = j2
            if T[i] == S[j2]: 
                if T[i] in a: break
                else :
                    a.add(T[i])
                    count += 1
                    break
            elif int(T[i]) < int(S[j2]): 
                j3 = j2-1
                j2 = int((j1+j3)/2)
            elif int(T[i]) > int(S[j2]): 
                j1 = j2+1
                j2 = int((j1+j3)/2)
    
    print(str(count))

Solution (Python):

def main():
    n = int(input())
    ns = list(map(int, input().split(' ')))
    _ = int(input())
    qs = list(map(int, input().split(' ')))
    count = 0
    start = 0
    end = n
    target = int((start + end) / 2)
    for q in qs:
        while end > start:
            if ns[target] > q:
                end = target
            elif ns[target] < q:
                start = target + 1
            else:
                count += 1
                break
            target = int((start + end) / 2)
        start = 0
        end = n
        target = int((start + end) / 2)
    print(count)


if __name__ == '__main__':
    main()

Solution (Python):
import collections


if __name__ == "__main__":
    S_num = int(input())
    S = collections.Counter(set(map(lambda x: int(x), input().split())))
    T_num = int(input())
    T = list(map(lambda x: int(x), input().split()))

    print(f"{sum(map(lambda x: S[x], T))}")

Solution (Python):
if __name__ == '__main__':
	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(arr, val):
    left = 0
    right = len(arr)

    while left < right:
        mid = (left + right)//2
        if arr[mid] == val:
            return mid
        elif arr[mid] < val:
            left = mid + 1
        else:
            right = mid
    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
    for i in T:
        if binary_search(S, i) != -1:
            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 binSearch(A, key):
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            return mid
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return False

ans = []
for i in t:
    v = binSearch(s, i)
    if v != False:
        ans.append(v)

print(len(set(ans)))

Solution (Python):
"""


 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())


 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  


a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    n= int(sys.stdin.readline())
    S= list(map(int, sys.stdin.readline().split()))
    q= int(sys.stdin.readline())
    T= list(map(int, sys.stdin.readline().split()))
    c=0
    for i in T:
        left = 0
        right =len(S)-1
        while left <= right:
            center = (left+right)//2
            if i == S[center]:
                c+=1
                break
            elif i > S[center]:
                left = center+1
            elif i < S[center]:
                right = center -1
    print(c)

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


if __name__ == '__main__':
    n = int(input())
    S = list(map(int, input().split()))
    q = int(input())
    T = list(map(int, input().split()))
    ans = 0
    for t in T:
        ans += binarySearch(S, t)
    print(ans)

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):
	left=0
	right=n
	while left < right:
		mid =(left +right)//2
		if s[mid]==t[i]:
			c+=1
			break
		elif t[i] < s[mid]:
			right=mid
		else:
			left=mid+1
	

print(c)

Solution (Python):
from bisect import bisect_left
from collections import Counter
from sys import stdin
N = int(stdin.readline().rstrip())
S = [int(_) for _ in stdin.readline().rstrip().split()]
S.sort()
Q = int(stdin.readline().rstrip())
T = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0

def bisect_search(l, x):
    i = bisect_left(l, x)
    if i != len(l) and l[i] == x:
        return True
    return False

for i in T:
    if bisect_search(S, i):
        ans += 1
print(ans)

Solution (Python):
if __name__ == '__main__':
    n = int(raw_input())
    S = map(int, raw_input().split())
    q = int(raw_input())
    T = map(int, raw_input().split())
    cnt = 0
    for x in T:
        left = 0
        right = n
        
        while left < right:
            mid = (left + right) / 2
            if S[mid] == x:
                cnt += 1
                break
            elif S[mid] > x:
                right = mid
            else:
                left = mid + 1
    print cnt

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

print(len(set(S) & set(T)))

Solution (Python):
def binary(s,num):
    left=0
    right=len(s)-1
    while left<=right:
        m=(left+right)//2
        if s[m]==num:
            return 1
        elif s[m]>num:
            right=m-1
        else:
            left=m+1
    return 0


n=int(input())
s=list(map(int,input().split()))
q=int(input())
t=list(map(int,input().split()))
cnt=0
for i in range(q):
    cnt+=binary(s,t[i])
print(cnt)

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


n = int(input())
v = list(map(int,input().split()))
q = int(input())
w = list(map(int,input().split()))
cnt = 0
for i in w:
    if binary_search(v,0,n,i):
        cnt+=1
print(cnt)

Solution (Python):
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

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

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


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

print("%d"%(ans))

Solution (Python):
class Binary_search():
    def __init__(self,S):
        self.num = 0
        self.S = S
    def binary_search(self,left,right,key):
        if left < right:
            mid =int((left + right) / 2)
            if self.S[mid] == key:
                self.num += 1
            elif self.S[mid] < key:
                self.binary_search(mid+1,right,key)
            else:
                self.binary_search(left,mid,key)

def main():
    N = int(input())
    S = [int(c) for c in input().split()]
    M = int(input())
    T = [int(c) for c in input().split()]
    binary_search = Binary_search(S)
    for i in range(M):
        binary_search.binary_search(0,N,T[i])
    print(binary_search.num)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
As = list(map(int, input().split()))
q = int(input())
Ts = list(map(int, input().split()))

from bisect import bisect_left
ans = 0
As += [10**9]
for T in Ts:
    ind = bisect_left(As,T)
    if As[ind] == T:
        ans += 1
print(ans)

Solution (Python):
from bisect import bisect_left

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

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


cnt = 0

for v in T:
    index = bisect_left(S, v)
    if index < len(S) and S[index] == v:
        cnt += 1

print(cnt)

Solution (Python):
import math

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

count = 0
for t in t_list:
    left = 0
    right = len(s_list) - 1
    while left <= right:
        mid = math.floor((left + right) / 2)
        if s_list[mid] == t:
            count = count + 1
            break
        elif s_list[mid] > t:
            right = mid - 1
            continue
        elif s_list[mid] < t:
            left = mid + 1
            continue

print(count)

Solution (Python):

n=int(input())
L=input().split( )
q=int(input())
M=input().split( )

S=[int(L[i]) for i in range(n)]
T=[int(M[i]) for i in range(q)]

C=0



for i in range(q):
    max=n
    min=0
    while max>min:
        mid=int((max+min)/2)
        if S[mid]==T[i]:
            C+=1
            break
        elif S[mid]<T[i]:
            min=mid+1
            
        elif S[mid]>T[i]:
            max=mid
            
print(C)

Solution (Python):
n=int(input())
s=list(map(lambda x:int(x),input().split()))
q=int(input())
t=list(map(lambda x:int(x),input().split()))
c=0
for i in t:
    start=0
    end=n-1
    while start<=end:
        mid=(start+end)//2
        if s[mid]==i:
            c+=1
            break
        if s[mid]>i:
            end=mid-1
        if s[mid]<i:
            start=mid+1

print(c)

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

if __name__=="__main__":
    n=int(input())
    S=list(map(int,input().split()))
    q=int(input())
    T=list(map(int,input().split()))
    result=0
    for i in range(q):
        result+=binarysearch(n,T[i],S)
    print(result)

Solution (Python):
n=int(input())
da=list(map(int ,input().split()))
m=int(input())
di=list(map(int ,input().split()))

def bino(le,ri,k):
    if ri-le<2:
        return False
    x=(ri+le)//2
    if da[x]==k:
        return True
    elif da[x]>k:
        return bino(le,x,k)
    else:
        return bino(x,ri,k)

ans=0
for i in di:
    if da[0]==i or da[n-1]==i:
        ans+=1
        continue
    if bino(0,n-1,i):
        ans+=1
print(ans)

Solution (Python):

def main():
    n = int(input())
    s = list(map(int, input().split()))
    s.sort()
    q = int(input())
    t = list(map(int, input().split()))
    ans = 0
    for i in range(q):
        l = 0
        h = n
        m = (l + n) // 2
        while l < h:
            if t[i] == s[m]:
                ans += 1
                break
            elif t[i] < s[m]:
                h = m
            else:
                l = m + 1
            m = (l + h) // 2
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import bisect


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

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


cnt = 0

for t in T:
    
    index = bisect.bisect_left(S, t)

    if ((index < len(S)) and
        (S[index] == t)):
        cnt += 1
        

print(cnt)

Solution (Python):
n = int(input())
S = [int(s) for s in input().split()]
q = int(input())
T = [int(s) for s in input().split()]
def isOK(index,key):
    if S[index] >= key:
        return True
    else:
        return False
def search(key):
    ng = -1
    ok = len(S)
    while abs(ok-ng)>1:
        mid = int((ok+ng)/2)
        if isOK(mid,key):
            ok = mid
        else:
            ng = mid
    return ok
counter = 0
for t in T:
    index = search(t)
    if S[index] == t and index != -1 and index != len(S):
        counter += 1
print(counter)

Solution (Python):
def binary_serch(target, num_list):
    start = 0
    end = len(num_list) - 1

    while(start <= end):
        mid = int((start + end) / 2)
        mid_num = num_list[mid]
        if mid_num == target:
            return True
        elif mid_num > target:
            end = mid - 1
        else:
            start = mid + 1
    return False

if __name__ == '__main__':
    n = int(input())
    S = [int(i) for i in input().split()]
    q = int(input())
    T = [int(i) for i in input().split()]

    counter = 0

    for num in T:
        if binary_serch(num, S):
            counter += 1

    print(counter)

Solution (Python):

import string
import sys
from itertools import chain, dropwhile, takewhile


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in readi(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[fill_value]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    n = readi()
    S = readi(n)
    q = readi()
    T = readi(q)
    ans = 0
    for t in T:
        left = 0
        right = n - 1
        while left != right:
            mid = (left + right - 1) // 2
            if t <= S[mid]:
                right = mid
            else:
                left = mid + 1
        if t == S[left]:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def isOK(lis, index, key):
    if lis[index] >= key:
        return True
    else:
        return False
def binary_search(lis, key):
    ng = -1
    ok = len(lis)
    while abs(ok - ng) > 1:
        mid = int((ok + ng)/2)
        if isOK(lis, mid, key):
            ok = mid
        else:
            ng = mid
    return ok

n = int(input())
S = [int(s) for s in input().split()]
q = int(input())
count = 0
for t in input().split():
    key = int(t)
    index = binary_search(S, key)
    if index != len(S) and index != -1 and S[index] == key:
        count += 1
print(count)

Solution (Python):
def binary_search(lst, target, start, end):
    if (start > end):
        return 0

    mid = (start + end) // 2

    if (lst[mid] < target):
        return binary_search(lst, target, mid + 1, end)
    elif (lst[mid] == target):
        return 1
    else:
        return binary_search(lst, target, start, mid - 1)

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

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