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()))
T.append(-1)

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

i = 0
count = 0
while T[i] != -1:
    if bsearch(S, T[i]):
        count += 1
    i += 1

print(count)

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, ret=False):
    left = 0
    right = len(A)
    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            return mid if not ret else ret
        if 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()))
ans = 0
for t in T:
    ans += 1 if binarySearch(S, t, ret=True) else 0
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()]
cnt = 0
for t in T:
    begin = 0
    end = n
    while begin < end:
        mid = (begin + end)//2
        if t == S[mid]:
            cnt += 1
            break
        elif t > S[mid]:
            begin = mid + 1
        else:
            end = mid
print(cnt)

Solution (Python):
def _main():
  N = int(input())
  lst = list(map(int, input().split()))
  K = int(input())
  key_lst = list(map(int, input().split()))

  ans = 0
  for k in range(K):
    if binary_search(N, lst, key_lst[k]): ans += 1
  print(ans)

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

if __name__ == '__main__':
  _main()

Solution (Python):
import bisect
n1 = int(input())
S = list(map(int, input().split()))
n2 = int(input())
T = list(map(int, input().split()))

count = 0
for t in T:
  idx = bisect.bisect_left(S, t)
  if idx < n1 and S[idx] == t:
    count += 1

print(count)

Solution (Python):
n = int(input())
S = input().split()
input()
T = input().split()

cnt = 0

for key in T:
	left = 0
	right = n
	mid = 0
	while left < right:
		mid = (left + right) // 2

		if int(S[mid]) == int(key):
			cnt += 1
			break

		if int(key) < int(S[mid]):
			right = mid
		elif int(key) > int(S[mid]):
			left = mid + 1

print(cnt)

Solution (Python):
import sys


def binary_search(arr, key):
    left = 0
    right = len(arr)
    while left < right:
        mid = int((left + right) / 2)
        if arr[mid] == key:
            return mid
        elif key < arr[mid]:
            right = mid
        else:
            left = mid + 1
    return -1


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

cnt = 0
for t in t_list:
    if binary_search(s_list, t) >= 0:
        cnt += 1
print(cnt)

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

def binary_search(s, x):
    left = 0
    right = len(s)
    while right > left:
        middle = int((left + right) / 2)
        if s[middle] == x:
            return middle
        elif s[middle] > x:
            right = middle
        else:
             left = middle + 1
    return -1
        

sum = 0
for i in range(q):
    if (binary_search(s, t[i]) != -1):
        sum += 1

print(sum)

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

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

Solution (Python):

def linear_search(key, nums):
    for num in nums:
        if num == key:
            return True
    return False

def binary_search(key, nums):
    
    left = 0
    right = len(nums)
    mid = int((left+right)/2)

    while left < right:
        mid = int((left+right)/2)
        
        if nums[mid] == key:
            return key
        elif key < nums[mid]:
            right = mid
        else:
            left = mid + 1
    return -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:
    if binary_search(t, S) > -1:
        count += 1
        
print(count)

Solution (Python):
if __name__ == "__main__":
    N = int(input())
    S = list(map(int, input().split()))
    S.extend([-1, float('inf')])
    S.sort()
    
    Q = int(input())
    T = list(map(int, input().split()))
    T.sort()
    ans = 0
    for ti in T:
        
        ok = 0
        ng = len(S)
        while ng - ok > 1:
            mid = (ng+ok)//2
            if S[mid]<=ti: ok=mid
            else:          ng=mid
        if S[ok]==ti:
            ans += 1

    print(ans)

Solution (Python):
input()
a=set(map(int,input().split()))
n=int(input())
b=sorted(map(int,input().split()))
def bs(b,x):
    ma=len(b)
    mi=0
    while abs(ma-mi)>1:
        mid=(ma+mi)//2
        if b[mid]<x:
            mi=mid
        else:
            ma=mid
    if b[mi]==x:
        return True
    elif ma!=n and b[ma]==x:
        return True
    return False


print(sum([bs(b,i)for i in a]))

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

n = int(input())
S = list(map(lambda x: int(x), input().strip().split()))

q = int(input())

count = 0
for t in input().strip().split():
    t = int(t)
    if S[bisect.bisect_left(S, t)] == t:
        count += 1
print(count)

Solution (Python):
def binarySearch(a, key):
    left = 0
    right = len(a)
    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 = list(map(int, input().split()))
q = int(input())


sum_ = 0

for num in map(int, input().split()):
    if binarySearch(s, num):
        sum_ += 1

print(sum_)

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



def isOK(A, index, key):
    if A[index] >= key:
        return True
    else:
        return False


def binary_search(A, key):
    ng = -1
    ok = len(A)

    while(abs(ok-ng) > 1):
        mid = (ok + ng) // 2

        if isOK(A, mid, key):
            ok = mid
        else:
            ng = mid
    return ok


count = 0
for key in T:
    if S[binary_search(S, key)] == key:
        count += 1

print(count)

Solution (Python):
def BinarySearch(data, key):
    left = 0
    right = len(data)
    while left < right:
        mid = (left + right) // 2
        if data[mid] == key:
            return True
        elif key < data[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()))
ans = 0
for i in t:
    if BinarySearch(s,i):
        ans += 1
print(ans)

Solution (Python):
n = int(input())
SS = set([int(i) for i in input().split()])
q = int(input())
TS = set([int(i) for i in input().split()])

print(len(SS & TS))

Solution (Python):
def binary_search(nums, key, length):
    left = 0
    right = length - 1
    while left <= right:
        mid = left + (right - left) //2
        if nums[mid] == key:
            return True
        elif nums[mid] < key:
            left = mid + 1
        else:
            right = mid - 1
    return False


n1 = int(input())
nums1 = list(map(int, input().split(' ')))
n2 = int(input())
nums2 = list(map(int, input().split(' ')))
sum = 0 
for i in range(n2):
    flag = binary_search(nums1,nums2[i],n1)
    if flag:
        sum += 1
print(sum)

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

ans = 0
for v in t:
    si, ei = 0, n-1
    while si < (ei-1):
        mi = (si+ei)//2
        if v < s[mi]:
            ei = mi
        else:
            si = mi
    if s[si] == v or s[ei] == v:
        ans += 1
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 T[i] > S[mid]:
            left = mid + 1
        elif T[i] < S[mid]:
            right = mid
        else:
            C += 1
            break
print(C)

Solution (Python):

n = int(input())
T = list(map(int, input().split()))
q = int(input())
cnt = 0
def midle(left, right):
    return int((left + right)/2)

for i in input().split():
    right = n
    left = 0
    while left - right < 0:
        mid = midle(left, right)
        if T[mid] == int(i):
            cnt += 1
            break
        elif T[mid] < int(i):
            left = mid +1
        else:
            right = mid

print(cnt)

Solution (Python):

n = int(input().rstrip())
S = list(map(int,input().rstrip().split()))
q = int(input().rstrip())
T = list(map(int,input().rstrip().split()))
count = 0
for i in range(q):
    start = 0
    end = n - 1
    half = 0
    while start <= end:
        half = int((start + end)/2)
        if S[half] == T[i]:
            count += 1
            break
        elif S[half] > T[i]:
            end = half - 1
        else:
            start = half + 1

print(count)

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

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 = len(a)
    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

cnt = 0
for tmpT in T:
    cnt += binarySearch(S, tmpT)
print(str(cnt))

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

num = int(input())
array = list(map(int, input().split()))

num2 = int(input())
array2 = list(map(int, input().split()))

count = 0
for i in range(num2):
        if binarySearch(array2[i], array):
                count += 1

print(count)

Solution (Python):
n = int(input())
s = list(map(int, input().split())) + [-1]
q = int(input())
t = map(int, input().split())
c = 0

for i in t:
    L = -1
    U = n
    while U - L > 1:
        x = (L+U) // 2
        if s[x] >= i: U = x
        else: L = x
    if s[U] == i: c += 1

print(c)

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

def bsearch(target, S, N):
    left = 0
    right = N
    while left < right:
        mid = (right + left) // 2
        mid_value = S[mid]
        if mid_value == target:
            return 1
        elif mid_value > target:
            right = mid
            continue
        elif mid_value < target:
            left = mid + 1
            continue
    return 0

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

cnt = 0

for t in T:
    cnt += bsearch(t, S, N)

print(cnt)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
m=int(input())
B=list(map(int,input().split()))
c=0
def binary(A,key):
    global c
    left=0
    right=len(A)
    while left<right:
        mid=(left+right)//2
        
        if A[mid]==key:
            c+=1
            return c
        elif A[mid]<key:
            left=mid+1
        else:
            right=mid
    return False
for i in B:
    binary(A,i)
    
print(c)

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

Solution (Python):
n=int(input())
a=set(map(int, input().split()))
n=int(input())
b=set(map(int, input().split()))
print(len(a&b))

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
S = [int(x) for x in stdin.readline().rstrip().split()]
S.sort()
stdin.readline().rstrip()
T = [int(x) for x in stdin.readline().rstrip().split()]

def binSearch(S, val, l=0, r=n-1):
    while l < r:
        m = (l+r)//2
        if val < S[m]:
        	r = m-1
        elif val > S[m]:
        	l = m+1
        else:
        	l = r = m

    return ( l == r and S[l] == val)

C = 0
for ti in T:
    if binSearch(S, ti):
        C += 1

print(C)

Solution (Python):
from operator import add
from functools import reduce

def exist(S, x):
    
    left, right = 0, len(S)
    while left < right:
        idx = (left + right) // 2
        if S[idx] == x:
            return 1
        if S[idx] < x:
            left = idx + 1
        else: 
            right = idx
    return 0

def solve(S, T):
    return reduce(add, (exist(S, x) for x in T))

if __name__ == '__main__':
    n = int(input())
    
    S = [int(s) for s in input().split()]
    
    assert len(S) == n
    q = int(input())
    
    T = [int(s) for s in input().split()]
    
    assert len(T) == q
    print(solve(S, T))

Solution (Python):
import sys
import math

def InputData():
    
    data_len = int(input())
    
    data = list(map(int, input().split()))

    searchdata_len = int(input())
    
    searchdata = list(map(int, input().split()))
    
    
    
    
    
    

    
    

    return data_len, data, searchdata_len, searchdata

def Binary_Search(Data, key):
    
    right = len(Data)
    left = 0
    while left < right:
        mid = (left + right) // 2
        
        if key == Data[mid]:
            
            return mid
        elif key < Data[mid]:
            right = mid
        elif key > Data[mid]:
            left = mid + 1
        

    return "NOT_FOUND"

def PrintOut(count):
    print(count)

def main():
    [data_len, data, searchdata_len, searchdata] = InputData()
    count = 0
    for i in searchdata:
        if Binary_Search(data, i) != "NOT_FOUND":
            count += 1

    PrintOut(count)

if __name__=='__main__':
    main()

Solution (Python):
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
S = sorted(S)
T = sorted(T)
reg = 0
count = 0
for i in range(q):
    for j in range(reg, n):
        if T[i] > S[j]:
            reg = j
        elif T[i] == S[j]:
            reg = j
            count += 1
            break
        else:
            break
print(count)

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

Solution (Python):


"""
二分探索
"""

from bisect import bisect_left

N = int(input())
sN = list(map(int, input().split()))
Q = int(input())
tQ = list(map(int, input().split()))

cnt = 0
for i in range(Q):
    idx = bisect_left(sN, tQ[i])
    
    if idx < N and sN[idx] == tQ[i]:
        cnt += 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 = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if s[mid] == i:
            count += 1
            break
        elif i < s[mid]:
            right = mid
        else:
            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()))

def find(key,l,r):
    m = int(l+(r-l)/2)
    
    if key == S[m]:
        return True
    elif r-l <= 1:
        return False
    elif key < S[m]:
        return find(key,l,m)
    elif key > S[m]:
        return find(key,m+1,r)

cnt = 0
for x in T:
    if find(x,0,n) is True:
        cnt += 1
    
print(cnt)

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

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

ans = 0
for i in range(q):
    L = 0
    R = n
    while L + 1 < R:
        M = (L + R) // 2
        if S[M] <= T[i]:
            L = M
        else:
            R = M

    find = S[L] == T[i]
    ans = ans + find
print(ans)

Solution (Python):
def find_sorted(elt, sarray):
    """Finds an element in a sorted array.

    Args:
        elt (int)     -- Element to search
        array (array) -- Sorted array (element in increasing order)
    Returns:
        Index of "elt" in "array", or "None" if "elt" is not in "array"
    """
    
    
    
    
    left = 0
    right = len(sarray)
    while left < right:
        mid = (left + right) // 2
        if sarray[mid] == elt:
            return mid
        elif sarray[mid] < elt:
            left = mid + 1
        else:
            right = mid
    else:
        return None

n  = int(input())
S = list(map(int,input().split()))
q = int(input())
T = list(map(int,input().split()))
count = 0
for i in range(len(T)):
    if find_sorted(T[i],S) != None:
        count += 1

print(count)

Solution (Python):
import sys

sys.stdin.readline()
s = set(map(int, sys.stdin.readline().split()))
sys.stdin.readline()

print(sum(
    t in s
    for t in map(int, sys.stdin.readline().split())
))

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






import sys
input = sys.stdin.readline


def main():
    n1 = int(input())
    s1 = set(map(int,input().split()))
    n2 = int(input())
    s2 = set(map(int,input().split()))
    print (len(s1 & s2))

if __name__ == '__main__':
   main()

Solution (Python):
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 i in range(q):
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if S[mid] == T[i]:
            counter += 1
            break
        elif S[mid] > T[i]:
            right = mid
        else:
            left = mid + 1
print(counter)

Solution (Python):

"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B
"""
def input_array():
    n = int(input())
    S = list(map(int, input().split()))
    return S

def input_from_txt():
    import requests
    url = "https://judgedat.u-aizu.ac.jp/testcases/ALDS1_4_A/8/in"
    res = requests.get(url)
    input = res.text.split("\n")
    n = input[0]
    S = list(map(int, input[1].split()))
    q = input[2]
    T = list(map(int, input[3].split()))
    return (n, S, q, T)


def get_set(S, T):
    C = []
    for s in S:
        for t in T:
            if s == t: C.append(t)
    return C


def get_set2(S, T):
    return list(set(S).intersection(set(T)))


def get_set3(S:list, T:list):
    D:dict = {}
    C = []
    for s in S:
        D[s] = 1
    for t in T:
        if t in D.keys() and D[t] == 1:
            D[t] = 2
            C.append(t)
    return C


if __name__ == '__main__':
    S = input_array()
    T = input_array()
    
    
    ret = get_set3(S, T)
    print(len(set(ret)))

Solution (Python):
n = int(input())
S = list(map(int, input().split(" ")))
n = int(input())
T = list(map(int, input().split(" ")))
def divide(A,a):
    left = 0
    right = len(A)
    
    while left < right:
        mid = (left + right)//2
        if a < A[mid]:
            right = mid
        elif A[mid] < a:
            left = mid + 1
        else:
            return True
    return False
cnt = 0
for t in T:
    if t < S[0] or S[-1] < t:
        continue
    if divide(S,t):
        cnt += 1
print(cnt)

Solution (Python):


def binary_search(key, A):
    left = 0
    right = len(A)
    while left < right:
        mid = int((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__":
    
    
    
    
    n = int(input())
    S = list(map(int, input().strip().split()))
    q = int(input())
    T = list(map(int, input().strip().split()))

    c = 0
    for k in T:
        if binary_search(k, S) != 'Not Found':
            c += 1
    print(c)

Solution (Python):



def solve():
    _ = int(input())
    S = set(map(int, input().split()))
    _ = int(input())
    T = set(map(int, input().split()))

    print(len(S & T))


if __name__ == '__main__':
    solve()

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

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

    cnt = 0
    for key in T:
        if binarySearch(S,key):
            cnt +=1
    print(cnt)

if __name__ == "__main__":
    main()

Solution (Python):
n1=int(input())
a=list(map(int,input().split()))
n2=int(input())
b=list(map(int,input().split()))
c=[]
d=0
for i in b:
		left=0
		right=n1
		while left<right:
			mid=int((left+right)/2)
			if i==int(a[mid]):
				d+=1
				break
			elif i<a[mid]:
				right=mid
			else:
				left=mid+1
print(d)

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

Solution (Python):
def binarySearch(alist, item):
    left=0
    right=len(alist)
    found = False
    while left < right and not found:
        mid=int((left+right)/2)
        if alist[mid] == item:
            found=True
        elif item<=alist[mid]:
            right=mid
        else:
            left=mid+1
    return found

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

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):
n = int(input())
slist = list(map(int, input().split()))
q = int(input())
tlist = list(map(int, input().split()))

s_unique = list(set(slist))
s_unique.sort()

cnt = 0
for t in tlist:
    low = 0
    high = len(s_unique)
    s = (low + high) // 2

    while low <= high:
        if t == s_unique[s]:
            break
        elif t > s_unique[s]:
            low = s + 1
        elif t < s_unique[s]:
            high = s - 1
        s = (low + high) // 2

    if t == s_unique[s]:
        cnt += 1

print(cnt)

Solution (Python):
n = int(input())
s = [-1]
s.extend(list(map(int,input().split())))
q = int(input())
lfin=list(map(int,input().split()))
ans = 0

for item in lfin:
    ok = n
    ng = 0
    while(abs(ok-ng)>1):
        num = (ok+ng)//2
        if s[num] >= item:
            ok = num
        else:
            ng = num
    else:
        if s[ok] == item:
            ans += 1
print(ans)

Solution (Python):
import math

s_num=int(input())
s_list=list(map(int,input().split()))
q_num=int(input())
q_list=list(map(int,input().split()))


count = 0

for q in q_list:
    left = 0
    right = s_num
    while left < right:
        mid = math.floor((left + right) / 2)
        if s_list[mid] == q:
            count += 1
            break
        elif s_list[mid] < q:
            left = mid+1
        else:
            right = mid

print(count)

Solution (Python):
def binary_search(key,S,start,end):
    if(start > end):
        return 0
    tmp_med=(start + end)//2
    if(S[tmp_med] == key):
        return 1
    elif(S[tmp_med] <key):
        return binary_search(key,S,tmp_med + 1, end)
    else:
        return binary_search(key,S,start,tmp_med-1)





n=int(input())
S=input().split()

q=input()
T=input().split()

S.sort()

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

print(cnt)

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


def Binary_Search(A, key):
    A_left = 0
    A_right = n
    while A_left < A_right:
        mid = (A_right+A_left) // 2
        if A[mid] < key:
            A_left = mid+1
        elif key < A[mid]:
            A_right = mid
        else:
            return mid
    return "Not_Found"


sol_coun = 0
for i in t:
    if Binary_Search(s, i) != "Not_Found":
        sol_coun += 1
    else:
        continue
print(sol_coun)

Solution (Python):
import math

def binarySearch(key, nums, left=0, right=None):
    if right == None:
        right = len(nums)-1

    if right < left:
        return 0

    mid = math.floor((right - left)/2)+left

    if key == nums[mid]:
        return 1

    if key < nums[mid]:
        return binarySearch(key, nums, left ,mid-1)
    else:
        return binarySearch(key, nums, mid+1 ,right)

def main():
    input()
    ss = [int(x) for x in input().split()]

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

    nums = {}
    cnt = 0

    for t in ts:
        if t in nums:
            continue;

        nums[t] = binarySearch(t, ss)
        cnt += nums[t]

    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.stdin.readline()
ss = list(map(int,sys.stdin.readline().split()))
sys.stdin.readline()
tt = list(map(int,sys.stdin.readline().split()))

cnt = 0
for t in tt:
    beg = 0
    end = len(ss)-1
    while beg<=end:
        ctr = (beg+end)//2
        if t==ss[ctr]:
            cnt += 1
            break
        elif t<ss[ctr]:
            end=ctr-1
        else: 
            beg=ctr+1
print(cnt)

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

n = int(input())
list_s = list((map(int, input().split())))
q = int(input())
list_t = list((map(int, input().split())))
ans = 0
for numbert in list_t:
    if binarySearch(list_s,numbert) != "NOT_FOUND":
        ans += 1
    
print(ans)

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

Solution (Python):


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

Solution (Python):
import sys


sys.setrecursionlimit(1000000)


def li_input():
    return [int(_) for _ in input().split()]


def is_exist(A, x):
    l = 0
    r = len(A) - 1

    while l <= r:
        m = (l + r) // 2
        if A[m] == x:
            return True
        
        if A[m] < x:
            l = m + 1
        else:
            r = m - 1

    return False
            


def main():
    n = int(input())
    S = li_input()
    q = int(input())
    T = li_input()

    ans = 0

    for t in T:
        if is_exist(S, t):
            ans += 1

    print(ans)


main()

Solution (Python):
a = input()
b = list(map(int, input().split()))
c = input()
d = list(map(int, input().split()))

def binary_search(A, f, t, val):
    n = (t + f) // 2
    
    
    if f > t: return None
    elif val == A[n]: return A[n]
    elif val > A[n]: return binary_search(A, n + 1, t, val)
    elif val < A[n]: return binary_search(A, f, n - 1, val)
A = [e for e in d if binary_search(b, 0, len(b) - 1, e) is not None]
print(len(A))

Solution (Python):



from bisect import bisect_left

def search(S, y):
    pos = bisect_left(S, y)
    return S[pos] == y

def count(S, T):
    c = 0
    for y in T:
        if search(S, y):
            c += 1
    return c

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

_ = int(input())
T = [int(y) for y in input().split()]

print(count(S, T))

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

    count = 0

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

    print(count)

Solution (Python):
import sys


f = sys.stdin
n = ''


n = f.readline().replace('\n','')
S = set(map(int, f.readline().replace('\n','').split()))
q = f.readline().replace('\n','')
T = set(map(int, f.readline().replace('\n','').split()))

print(len(S & T))

Solution (Python):
def binary_search(A, n, B, q):
    cnt = 0
    for i in range(q):
        left = 0
        right = n
        while left < right:
            mid = int((left + right) / 2)
            if A[mid] == B[i]:
                cnt += 1
                break
            elif B[i] < A[mid]:
                right = mid
            else:
                left = mid + 1
    return cnt

n = int(input())
A = list(map(int,input().split()))
q = int(input())
B = list(map(int,input().split()))
print(binary_search(A, n, B, q))

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

Solution (Python):
def binSearch(l, x):
	u = 0
	d = len(l) - 1
	while True:
		if u > d:
			break
		m = int((u + d) / 2)
		if l[m] == x:
			return True
		elif l[m] < x:
			u = m + 1
		else:
			d = m - 1
	return False

n = int(input())
ni = [int(x) for x in input().split()]
q = int(input())
qi = [int(x) for x in input().split()]

print(sum([1 for x in qi if binSearch(ni, x) is True]))

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