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


import sys

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

count = 0
for t in T:

    left = 0
    right = len(S)
    pmid = 0

    while left < right:
        mid = (right + left) // 2
        if mid == pmid:
            break
        pmid = mid
        m = S[mid]
        if t == m:
            count += 1
            break
        else:
            if t < m:
                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(' ')))


C = 0
def binarySearch(A, key):
    left = 0
    right = len(A)
    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            global C
            C+= 1
            break
        elif A[mid] < key:
            left = mid + 1
        else:
            right = mid
    
            
for key in T:
    binarySearch(S, key)
    
print(C)

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

Solution (Python):
n = int(input())
S = set(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
ans = 0
for t in T:
    if t in S:
        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 range(q):
    tmp=t[i]
    l=0
    r=len(s)-1
    mid=(l+r)//2
    while l<=r:
        if tmp==s[mid]:
            ans+=1
            break
        elif s[mid]>tmp:
            r=mid-1
        else:
            l=mid+1
        mid=(l+r)//2
print(ans)

Solution (Python):
def binarySearchLeft(nums, target):
    low = 0
    high = len(nums) - 1
    while low <= high:
        mid = low + high >> 1
        if target == nums[mid]:
            if mid == 0 or target != nums[mid - 1]:
                return mid
            else:
                high = mid - 1
        elif target < nums[mid]:
            high = mid - 1
        else:
            low = mid + 1
    return -1

def solve(n, S, q, T):
    counter = 0
    for t in T:
        idx = binarySearchLeft(S, t)
        counter += 1 if 0 <= idx < len(S) else 0
    print(counter)

if __name__ == "__main__":
    n = int(input())
    S = list(map(int, input().split()))
    q = int(input())
    T = list(map(int, input().split()))
    solve(n, S, q, T)

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

Solution (Python):
N=int(input())
N_list=list(map(int,input().split()))
S=int(input())
S_list=list(map(int,input().split()))
def search(target):
    left=-1
    right=N
    while(left<right):
        middle = (left + right) // 2
        mid=N_list[middle]
        if mid==target:
            return True
        if target>mid:
            left=middle+1
            middle =(left + right) // 2
        else:
            right=middle
            middle = (left + right) // 2
    return False
count=0
for s in S_list:
    if search(s):
        count+=1
print(count)

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

count = 0
for item in t:
    idx = bisect.bisect_left(s, item)
    if idx < n:
        count += s[idx] == item
print(count)

Solution (Python):
def resolve():
    N = int(input())
    S = [int(i) for i in input().split()]
    Q = int(input())
    T = [int(i) for i in input().split()]

    ans = 0
    for t in T:
        ok = 0
        ng = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if S[mid] <= t:
                ok = mid
            else:
                ng = mid
        if S[ok] == t:
            ans += 1
    print(ans)


resolve()

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
s = LI()
q = I()
t = LI()
c = 0


def is_bin_search(l, v):
    left = 0  
    right = len(l) - 1  
    mid = (left + right) // 2
    while left <= right:
        mid = (left + right) // 2
        if l[mid] == v:
            return True
        elif v < l[mid]:
            right = mid - 1  
        else:
            left = mid + 1  
        mid = (left + right) // 2
    return False


for ti in t:
    if is_bin_search(s, ti):
        c += 1

print(c)

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

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

c = 0

for target in t:
    left = 0
    right = n-1

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

        if s[mid] > target:
            right = mid - 1

        elif s[mid] < target:
            left = mid + 1

        else:
            c += 1
            break

print(c)

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

def binary_search(A, x):
    right = len(A)
    center = right // 2
    left = 0
    pre_center = -1
    result = False
    while left < right:
        if x < A[center]:
            right = center
            center = (right + left) // 2
        elif x > A[center]:
            left = center + 1
            center = (right + left) // 2
        else:
            result = True
            break


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

print(cnt)

Solution (Python):
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
ans = 0
ansl = []
for t in T:
    l = 0
    r = n
    while l < r:
        i = (l + r)//2

        if S[i] > t:
            r = i
        elif S[i] < t:
            l = i + 1
        else:
            ans += 1
            ansl.append(t)
            break
print(ans)

Solution (Python):
from typing import List


def binary_search(S: List[int], key: int) -> int:
    left: int = 0
    right: int = len(S)

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


def main():
    _ = input()
    S: List[int] = list(map(int, input().split()))
    _ = input()
    T: List[int] = list(map(int, input().split()))
    count = 0

    for num in T:
        count += binary_search(S, num)

    print(count)


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

ans = 0
for i in T:
  insert_index = bisect.bisect_left(S, i)
  if insert_index == n:
    continue
  else:
    if S[insert_index] == i:
      ans += 1

print(ans)

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


def search(target, st, en):
    h_len = (en + st) // 2
    if st > en:
        return False
    if S[h_len] == target:
        return True
    if S[h_len] > target:
        return search(target, st, h_len-1)
    if S[h_len] < target:
        return search(target, h_len+1, en)


def main():
    num = 0
    for i in T:
        st = 0
        en = n - 1
        if search(i, st, en):
            num += 1
    print(num)


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()))
        
ans = 0
for t in T:
    if bisect.bisect_left(S, t) != bisect.bisect_right(S, t):
        ans += 1
    
print(ans)

Solution (Python):


def is_ok(idx,key,target):

    if target[idx] >= key:
        return True
    return False

def meguru_bisect(key,target):
    left = -1
    right = len(target)
    while (abs(right - left) > 1):
        mid = left + (right - left) // 2
        if is_ok(mid,key,target):
            right = mid
        else:
            left = mid
    if key == target[right]:
        return True
    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 meguru_bisect(i,S):
        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:
    if i<s[0] or i>s[-1]: continue 
    lo,hi=0,len(s)
    while hi-lo>1:
        mid=(lo+hi)//2
        if s[mid]<i:
            lo=mid
        else:
            hi=mid
    l=[s[hi],s[lo]]
    if i in l:
        ans+=1
print(ans)

Solution (Python):
def binarySearch(t, n, S):
    low = 0
    high = n-1
    while low <= high:
        mid = (low + high) // 2
        item = S[mid]
        if t == item:
            return True
        elif t < item:
            high = mid - 1
        else:
            low = mid + 1
    return False

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 binarySearch(t, n, S):
        c += 1
print(c)

Solution (Python):
n = int(input())
S = list(map(int,input().split()))
p = int(input())
T = list(map(int,input().split()))
count = 0
time = 0
import math
for i in T:
    left = 0
    right = n
    while right - left > 5:
        mid = math.floor((right + left)/2)
        
        if i > S[mid-1]:
            left = mid
        else:
            right = mid
    for j in range(left,right):
        if i == S[j]:
            count += 1
            break        

        
print(count)

Solution (Python):
from bisect import bisect_left

input()
S = sorted(list(map(int, input().split())))
input()
T = sorted(list(map(int, input().split())))
count = 0

for t in T:
    i = bisect_left(S, t)
    if i > len(S)-1 or i < 0:
        continue
    if S[i] == t:
        count += 1

print(count)

Solution (Python):
def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1

    return None

n=int(input())
s=[int(i) for i in input().split()]
q=int(input())
t=[int(i) for i in input().split()]
ans=0
for item in t:
    if(binary_search(s,item) != None):
        ans+=1
print(ans)

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

    cnt = 0

    for i in range(len(o)):
        left = 0
        right = n
        while left < right:
            mid = int((left + right) / 2)
            if t[mid] == o[i]:
                cnt +=1
                break
            elif o[i] < t[mid]:
                right = mid
            else:
                left = mid + 1
    
    return cnt

if __name__ == '__main__':
    print(Binary_Serch())

Solution (Python):
import sys
import copy

def 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 range(q):
    tmp = T[i]
    L = 0
    R = n - 1
    M = n // 2

    while M >= L:
      if tmp == S[M]:
        C += 1
        break
      elif tmp > S[M]:
        L = M + 1
      else:
        R = M - 1

      M = (R + L) // 2

  print(C)

if __name__ == '__main__':
  main()

Solution (Python):
from bisect import bisect_left

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

for t in T:
  index = bisect_left(S,t)
  if t == S[index]:
    ans += 1
    
print(ans)

Solution (Python):
N = int(input())
lisS = list(map(int,input().split()))
Q = int(input())
lisT = list(map(int,input().split()))


def check(mid,key):
    return lisS[mid] > key

def binary_search(key):
    OK = N 
    NG = -1 
    while abs(OK-NG)>1:
        mid = (OK+NG)//2
        if check(mid,i):
            OK = mid
        else:
            NG = mid
    return lisS[NG] == key

ans = 0
for i in lisT:
    ans += binary_search(i)

print(ans)

Solution (Python):
def binary_search(num_list, key):
    left = 0
    right = len(num_list)
    while right > left:
        mid = (left + right)//2
        if num_list[mid] == key:
            return 1
        
        if num_list[mid] > key:
            right = mid
        
        elif num_list[mid] < key:
            left = mid + 1            
    return 0
            
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
ans = 0
for i in T:
    ans += binary_search(S, i)
print(ans)

Solution (Python):
import bisect

N = int(input())
S = sorted(tuple(map(int, input().split(' '))))
Q = int(input())
T = tuple(map(int, input().split(' ')))

c = 0
for t in T:
    index = bisect.bisect_left(S, t)
    if index < N and S[index] == t:
        c += 1

print(c)

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

def binary_search(n,li):
    low = 0
    high = len(li)-1
    while low <= high:
        mid = (low+high)//2
        if li[mid] == n:
            return True
        elif n < li[mid]:
            high = mid -1
        else:
            low = mid + 1
    return False
n = int(input())
a = list(map(int,input().split()))
t = int(input())
u = list(map(int,input().split()))
cnt = 0
a.sort()
for i in range(len(u)):
    if binary_search(u[i],a):
        cnt += 1
print(cnt)

Solution (Python):
from sys import stdin

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

def binary_search(num,L):
    left = 0
    right = n
    while left != right:
        middle = (left+right)//2
        if L[middle] == num:
            return True
        elif L[middle] < num:
            left = middle+1
        else:
            right = middle

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

print(count)

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

c = 0
for t in T:
    l = 0
    r = len(S)
    while (r - l) > 1:
        m = (l + r)//2
        if S[m] > t:
            r = m
        else:
            l = m
        
        if S[l] == t:
            c += 1
            break
        
print(c)

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 i in T:
    index = bisect.bisect_left(S, i)
    if index >= len(S):
        continue
    if S[bisect.bisect_left(S, i)] == i:
        cnt += 1
print(cnt)

Solution (Python):
import bisect
if __name__ == "__main__":
    n = int(input())
    s = list(map(int, input().split()))
    q = int(input())
    t = list(map(int, input().split()))

    ans = 0
    for i in range(q):
        index = bisect.bisect_left(s, t[i])
        if index == len(s) or s[index] != t[i]:
            continue
        ans += 1
    print(ans)

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



def fn(num):
    left=0
    right=n-1
    mid=(left+right)//2
    while right-left>1:
        if s[mid]>num:
            right=mid
        else:
            left=mid
        mid=(left+right)//2
    if s[left]==num:
        return 1
    elif s[right]==num:
        return 1
    else:
        return 0
ans=0
for i in range(m):
    ans+=fn(t[i])
print(ans)

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

Solution (Python):
def binary_search(A, q):
    left = -1
    right = len(A)

    while (right - left) > 1:
        mid = (left + right) // 2 
        if q >= A[mid]:
            left = mid
        else:
            right = mid

    if A[left] == q:
        return True

    else:
        return False


def main():
    _ = int(input())
    S = list(map(int, input().split()))
    _ = int(input())
    T = list(map(int, input().split()))
    cnt = 0
    for t in T:
        if binary_search(S, t):
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()

Solution (Python):
def is_included(i, n):
    return True if S[i] >= n else False


def search(n):
    inc = N
    exc = -1
    while abs(inc-exc) > 1:
        mid = (exc+inc) // 2
        if is_included(mid, n):
            inc = mid
        else:
            exc = mid
    return inc < N and S[inc] == n


def main():
    ans = 0
    for t in T:
        if search(t):
            ans += 1
    print(ans)


if __name__ == "__main__":
    N = int(input())
    S = sorted([int(s) for s in input().split()])
    Q = int(input())
    T = [int(t) for t in input().split()]
    main()

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

S=(set(S))
T=(set(T))

l=S & T

print(len(l))

Solution (Python):
def binary_search(char, letter):
    bottom = 0
    top = len(char)
    while bottom < top:
        m = (bottom+top)//2
        if char[m] == letter:
            return True
        elif letter < char[m]:
            top = m
        else:
            bottom = m + 1
    return False


a = int(input())
x = list(map(int, input().split()))
b = int(input())
xx = list(map(int, input().split()))
total = 0

for i in xx:
    if binary_search(x, i):
        total += 1

print(total)

Solution (Python):

n=int(input())
s=list(map(int,input().split()))
q=int(input())
count=0
t=list(map(int,input().split()))
for i in range(q):
	l=0
	r=n
	while r>l:
                
		mid=(l+r)//2
		
		if s[mid]==t[i]: 
			count+=1
			break
		
		elif s[mid]>t[i]:
			r=mid
                
		else:
			l=mid+1
print(count)

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

print(len(S & T))

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

def binary_search(n,S,data):
    left=0
    right=n
    mid=int((left+right)/2)
    while left<right:
        if S[mid]==data:
            return True

        elif data<S[mid]:
            right=mid
            mid=int((left+right)/2)

        elif data>S[mid]:
            left=mid+1
            mid=int((left+right)/2)

    return False

answer=0
for i in range(q):
    if binary_search(n,S,T[i]):
        answer+=1

print(answer)

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 t in T:
    id = bisect_left(S, t)
    if S[id] == t:
        cnt += 1

print(cnt)

Solution (Python):
def BinarySearch(list, x):
    l = 0
    r = len(list)
    while l < r:
        m = (l+r)//2
        if list[m] == x:
            return True
        elif x < list[m]:
            r = m
        else:
            l = m+1
    return False


a = int(input())
listA = list(map(int, input().split()))
b = int(input())
listB = list(map(int, input().split()))
total = 0

for i in listB:
    if BinarySearch(listA, i):
        total += 1

print(total)

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

for t in T:
    ans += t in S
    
print(ans)

Solution (Python):
from collections import deque
import sys
import math

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

    count = 0
    for t in T:
        left = 0
        right = n

        while left < right:
            mid = (left + right) // 2
            if t == S[mid]:
                count += 1
                break
            elif t < S[mid]:
                right = mid
            else:
                left = mid + 1
    print(count)

Solution (Python):
from bisect import bisect_right, bisect_left

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

cnt = 0
for num in t:
    if bisect_right(s, num) != bisect_left(s, num):
        cnt += 1
print(cnt)

Solution (Python):
def binarySearch(N, S, T):
	cnt = 0  
	left = 0  
	
	right = N 
	mid = (left + right) // 2
	while left < right:

		if S[mid] == T:
			cnt = cnt + 1
			return cnt
			
			
















		elif S[mid] > T:
			left = left
			right = mid
			mid =  (left + right) // 2
		elif S[mid] < T:
			left = mid + 1
			right = right
			mid =  (left + right) // 2
	
	

	return cnt


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

for i in t:
	sum = sum + binarySearch(n, s, i)
	
	

print(sum)

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

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

            break
        
print(cnt)

Solution (Python):
def binary_search(a,n,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

n1 = int(input())
s1 = list(map(int,input().split()))
n2 = int(input())
s2 = list(map(int,input().split()))
i = 0
cnt = 0
while i < n2:
  cnt += binary_search(s1,n1,s2[i])
  i += 1
print(cnt)

Solution (Python):


import sys

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


def search(i, S):  
    if S[0] > i:
        return False
    if S[-1] == i:
        return True

    left = 0
    right = len(S) - 1

    while right - left != 1:
        mid = int((left + right) / 2)
        if S[mid] <= i:
            left = mid
        else:
            right = mid

    if S[left] == i:
        return True
    else:
        return False


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

print(ans)

Solution (Python):
n=int(input())
s=list(map(int,input().split()))
q=int(input())
t=list(map(int,input().split()))
left = 0
right = len(s)
mid = (left + right) // 2
cnt = 0

for i in t:
    while left < right:
        if i == s[mid]:
            cnt += 1
            break
        elif i < s[mid]:
            right = mid
        else:
            left = mid + 1
        mid = (left + right) // 2
    left = 0
    right = len(s)
    mid = (left + right) // 2
print(cnt)

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 True
        elif(key < A[mid]):
            right = mid
        else:
            left = mid + 1
    return False

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

Solution (Python):
n = int(input())
S_list = list( map(int,input().split()) )
q = int(input())
T_list = list( map(int,input().split()) )





def binary_search(list, x):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high)//2

        if list[mid] == x:
            return True
        elif list[mid] < x:
            low = mid + 1
        else:
            high = mid - 1

    return False


S_set = sorted(set(S_list))


cnt = 0
for t in T_list:
    if binary_search(S_set, t):
        cnt += 1

print(cnt)

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

import bisect
ans = 0

for i in T:
    ok = bisect.bisect(S,i) - 1
    if S[max(ok,0)] == i:
        ans += 1

print(ans)

Solution (Python):
from sys import stdin
import bisect
def main():
    
    readline=stdin.readline
    n=int(readline())
    s=list(map(int,readline().split()))
    q=int(readline())
    t=list(map(int,readline().split()))

    cnt=0
    for x in t:
        if bisect.bisect_left(s,x)!=bisect.bisect_right(s,x):
            cnt+=1

    print(cnt)
if __name__=="__main__":
    main()

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

a = 0
for i in T:
  if i in S:
    a += 1
print(a)

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

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

ans = 0
for i in t:
    ans += bisearch(s,i)

print(ans)

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

print(len(s&t))

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


def bisearch(S, target):
    left, right = 0, len(S)-1

    while right - left > 0:
        mid = left + (right - left) // 2  
        if S[mid] < target:
            left = mid + 1
        else:
            right = mid
    return S[left] == target


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

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

cnt = 0
for t in T :
    left = 0
    right = n

    while (right - left) > 1:
        mid = (left+right)//2 
        if t >= S[mid]:
            left = mid
        else:
            right = mid
    if t == S[left]:
        cnt += 1
print(cnt)

Solution (Python):
def binary_search_loop(data,target):
    left, right = 0, len(data)

    while left <= right:
        mid = (left + right) // 2
        if data[mid] == target:
            return True
        elif data[mid] < target:
            left = mid + 1
        else:
            right = 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:
    if binary_search_loop(S,t):
        ans +=1
    
print(ans)

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

icnt=0
for ti in t:
    if ti in s:
        icnt+=1
print(icnt)

Solution (Python):




def binarySearch(target, data_list, n):
    left = 0
    right = n
    middle = int((right - left) / 2)

    while data_list[middle] != target:
        if (middle == left or middle == right):
            return 0

        left, right = [left, middle
                       ] if data_list[middle] > target else [middle, right]
        middle = left + int((right - left) / 2)

    return 1


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

    total = 0

    for target in T:
        total += binarySearch(target, S, n)

    print(total)

Solution (Python):
from bisect import bisect_left

def readinput():
    n=int(input())
    s=list(map(int,input().split()))
    q=int(input())
    t=list(map(int,input().split()))
    return n,s,q,t

def bisect_search(s,i):
    left=0
    right=len(s)
    while(left<right):
        middle=(left+right)//2
        
        if(i==s[middle]):
            return True
        elif(s[middle]<i):
            left=middle+1
        else:
            right=middle
    return False

def main(n,s,q,t):
    c=0
    for i in t:
        res=bisect_search(s,i)
        if(res==True):
            c+=1
        
    return c

def find(a,x):
    i = bisect_left(a,x)
    if i != len(a) and a[i]==x:
        return True
    else:
        return False
     

def main2(n,s,q,t):
    c=0
    for i in t:
        if(find(s,i)==True):
            c+=1
    return c

if __name__=='__main__':
    n,s,q,t=readinput()
    ans=main2(n,s,q,t)
    print(ans)

Solution (Python):
n = int(input())
S = [-1] + [int(x) for x in input().split()] + [10 ** 9 + 1]
q = int(input())
T = [int(x) for x in input().split()]

ans = 0
for t in T:
    ok = 0
    ng = n + 1
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if S[mid] <= t:
            ok = mid
        else:
            ng = mid
    if S[ok] == t:
        ans += 1

print(ans)

Solution (Python):
import bisect

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

ans = 0

for t in T:
    if S[bisect.bisect_left(S, t)] == t:
        ans += 1
        continue

print(ans)

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

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 range(q):
    left = 0
    right = n
    while right - left > 1:
        mid = (left + right) // 2
        if S[mid] <= T[i]:
            left = mid
        else:
            right = mid
    count += (T[i] == S[left])

print(count)

Solution (Python):
def binary_search(A, x):
    left, right = 0, len(A) - 1
    while left <= right:
        mid = (left + right) // 2
        if A[mid] == x:
            return True
        elif A[mid] < x:
            left = mid + 1
        elif A[mid] > x:
            right = mid - 1


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

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

print(count)

Solution (Python):
def solve():
    N = int(input())
    A = set(list(map(int, input().split())))
    Q = int(input())
    B = set(list(map(int, input().split())))
    ans = len(A&B)  
    return ans
print(solve())