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 = set(map(int, input().split()))
q = int(input())
t = set(map(int, input().split()))

print(len(s & t))

Solution (Python):
import bisect

n = int(input())
s_li = list(map(int, input().split()))
q = int(input())
t_li = list(map(int, input().split()))

def binary_search(li, item):
    low = 0
    high = len(li) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = li[mid]
        
        if guess == item:
            return mid
        
        if guess > item:
            high = mid - 1
        
        if guess < item:
            low = mid + 1
    return None

cnt = 0
for i in t_li:
    if binary_search(s_li, i) is not None:
        cnt += 1
        
print(cnt)

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

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


n = int(input())
*s, = map(int, input().split())
input()
*t, = map(int, input().split())
print(sum(bs(i) for i in t))

Solution (Python):

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


def binary_search(x: int) -> bool:
    low = 0
    high = len(S) - 1
    while low <= high:
        mid = (low + high) // 2
        guess = S[mid]
        if guess == x:
            return True
        if guess < x:
            low = mid + 1
        else:
            high = mid - 1
    return False


ans = 0
for t in T:
    ans += binary_search(t)


print(ans)

Solution (Python):
import bisect 
s=int(input())
S=list(map(int,input().split()))
t=int(input())
T=sorted(list(map(int,input().split())))
ans=0
for x in T:
    ok = bisect.bisect(S,x)-1
    if S[max(ok,0)]==x:
        ans += 1
print(ans)

Solution (Python):
import bisect

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

ans = 0
for num in t:
    index = bisect.bisect_left(s, num)
    
    if index >= n:
        continue
    if num == s[index]:
        ans += 1

print(ans)

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


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

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque
import copy

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    S = set(il())
    Q = ii()
    T = set(il())

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


if __name__ == '__main__':
    main()

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

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

ans = 0

for i in range(q):
    x = bisect_left(S, T[i])
    if x < n:
        if S[x]==T[i]:
            ans += 1
print(ans)

Solution (Python):
n1 = int(input())
nums1 = list(map(int, input().split()))
n2 = int(input())
nums2 = list(map(int, input().split()))

def binary_search(nums1, n1, key):
    L,R = 0, n1
    while L < R:
        pivot = (L + R) // 2
        if nums1[pivot] == key:
            return True

        if key > nums1[pivot]:
            L = pivot + 1
        else:
            R = pivot
    return False

output = 0
nums1.append(None)
for key in nums2:
    if binary_search(nums1, n1, key):
        output += 1

print(output)

Solution (Python):
import sys
from bisect import bisect_left, bisect_right

n = int(sys.stdin.buffer.readline().rstrip())
q = list(map(int, sys.stdin.buffer.readline().split()))
s = int(sys.stdin.buffer.readline().rstrip())
t = list(map(int, sys.stdin.buffer.readline().split()))

ans = 0
for i in t:
    if q[bisect_left(q, i, 0, n-1)] == 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 binary_search(a, x):
    
    left = -1
    right = len(x)
    mid = (left + right) // 2
    if not x[0] <= a <= x[-1]:
        return False
    
    while True:
        if x[mid] == a:
            return True
        if a < x[mid]:
            right =  mid
            mid = (left + right) // 2
        else:
            left = mid
            mid = (left + right) // 2
        if right == mid or left == mid:
            return False
    return False

s.sort()
cnt = 0
for i in t:
    if binary_search(i, s):
        cnt += 1

print(cnt)

Solution (Python):
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
S.sort()
ans = 0
for t in T:
    l = -1
    r = n
    while r-l > 1:
        mid = (r+l)//2
        if S[mid] <= t:
            l = mid
        else:
            r = mid
    if l != -1 and S[l] == 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:
    if S[0] == i or S[n-1] == i:
        ans += 1
        continue
        
    l, r = 0, n-1
    while r-l > 1:
        m = (l+r)//2
        if S[m] == i:
            ans += 1
            break
        if S[m] < i:
            l = m
        else:
            r = m

print(ans)

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
    flag = 0
    while left < right:
        mid = (left + right) // 2
        if S[mid] == i:
            flag = 1
            break
        elif S[mid] > i:
            right = mid
        else:
            left = mid+1
    if flag:
        cnt+=1
print(cnt)

Solution (Python):
import sys
from bisect import bisect_left


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    s = list(map(int, input().split()))
    _ = int(input())
    t = list(map(int, input().split()))
    cnt = 0
    for e in t:
        pos = bisect_left(s, e)

        if pos != n and s[bisect_left(s, e)] == e:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from collections import deque
from itertools import *

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

def binary_search(list, target):
    left = 0
    right = len(list) - 1
    while left <= right:
        center = int((left + right) / 2)
        if list[center] == target:
            return center
        elif list[center] < target:
            left = center + 1
        elif list[center] > target:
            right = center - 1
    return None

n = I()
s = LI()
q = I()
t = LI()
ans = 0
for t_t in t:
    if binary_search(s,t_t) is not None:
        ans += 1
print(ans)

Solution (Python):
def binary_serach(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 'Not Found'

if __name__ == '__main__':
    n = int(input())
    l = list(map(int, input().split()))
    q = int(input())
    t = list(map(int, input().split()))
    res = 0
    for i in t:
        if binary_serach(l,i) == 'Not Found':
            continue
        else:
            res += 1
    print(res)

Solution (Python):
import bisect

_ = int(input())
A = list(map(int, input().split()))
_ = int(input())
B = list(map(int, input().split()))

ans = 0

if len(A) > len(B):
    B, A = A, B

for a in A:
    i = bisect.bisect_left(B, a)
    if i >= 0 and i < len(B) and B[i] == a:
        ans += 1
print(ans)

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:
    l = 0
    r = n-1
    while l <= r:
        idx = l + (r-l) // 2
        s = S[idx]
        if t == s:
            cnt += 1
            break
        elif t < s:
            r = idx - 1
        else:
            l = idx + 1
print(cnt)

Solution (Python):
def bin_search(arr, i):
    left = 0 
    right = len(arr) - 1
    while left <= right:
        mid = (left + right) //2
        if arr[mid] == i:
            return True
        elif arr[mid] < i:
            left = mid + 1
        else:
            right = mid - 1
        
    return False
n = int(input())
S = list(map(int, input().split()))
n = int(input())
T = list(map(int, input().split()))
ans = 0
for i in T:
    if bin_search(S, i) is True:
        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 key in t:
    left = 0
    right = n
    while (left<right):
        mid = (left + right)//2
        if ( key == s[mid]):
            ans += 1
            break
        elif ( key > s[mid]):
            left = mid + 1
        else:
            right = mid
print(ans)

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:
    l = 0
    r = n-1

    while l <= r:
        half = (l+r)//2
        if s[half] == i:
            cnt += 1
            break
        elif i < s[half]:
            r = half-1
        else:
            l = half+1

print(cnt)

Solution (Python):
import bisect

N=int(input())
NL=[0]+list(map(int,input().split()))+[10**9]
NL.sort()
M=int(input())
ML=list(map(int,input().split()))

ans=0
for i in ML:
    if NL[bisect.bisect_left(NL,i)]==i:
        ans+=1
print(ans)

Solution (Python):
n,ss,q,tt = [list(map(int, s.split())) for s in open(0)]

import bisect

ans = 0
for t in tt:
    i = bisect.bisect_left(ss,t)
    if i < len(ss):
        ans += (ss[i] == t)

print(ans)

Solution (Python):
n = int(input())
s = [int(_) for _ in input().split()]
q = int(input())
t = [int(_) for _ in input().split()]
ans = 0
for i in t:
    if s[0] == i or s[n-1] == i:
        ans += 1
        continue
    l, r = 0, n-1
    while r-l > 1:
        m = (l+r)//2
        if s[m] == i:
            ans += 1
            
            break
        if s[m] < i:
            l = m
        else:
            r = m

print(ans)

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

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
cnt = 0
for i in range(len(T)):
    
    if binary_search(S,T[i]) != None:
        
        cnt += 1
print(cnt)

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

counter=0
for x in t:
    low=0
    high=n-1
    while low<=high :
        mid=(low+high)//2 
        if x==s[mid]:
            counter+=1
            break
        if x<s[mid]:
            high=mid-1
        else :
            low=mid+1

print(counter)

Solution (Python):
import bisect
INF=10**18
n=int(input())
s=sorted(list(map(int,input().split())))+[INF]
q=int(input())
t=list(map(int,input().split()))
cnt=0
for i in t:
  if s[bisect.bisect_left(s,i)]==i:cnt+=1
print(cnt)

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


def binary_search(A: [int], e: int):
    """List A must be sorted """
    left, right = 0, len(A) - 1
    while left <= right:
        mid = (left+right) // 2
        if A[mid] > e:
            right = mid - 1
        elif A[mid] < e:
            left = mid + 1
        elif A[mid] == e:
            return mid
    return None


_ = int(input())
S = [int(i) for i in input().strip().split()]
_ = int(input())
T = [int(i) for i in input().strip().split()]

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

print(ans)

Solution (Python):
import bisect
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):
    a=0
    b=n-1
    while True:
        c=(a+b)//2
        if c==b or c==a:
            break
        if S[c]>T[i]:
            b=c
        elif S[c]<T[i]:
            a=c
        else:
            break
    if S[a]==T[i] or S[c]==T[i] or S[b]==T[i]:
        ans+=1
print(ans)

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

    q = int(input())
    T = list(map(int, input().split()))
    
    res = 0
    for t in T:
        res += binary_search(S, t)
        
    print(res)
        
def binary_search(S, t):
    left = 0
    right = len(S)
    
    res = 0
    while left < right:
        mid = (left + right) // 2
    
        if t > S[mid]:
            left = mid + 1
        elif t < S[mid]:
            right = mid
        else:
            res += 1
            break
            
    return res
    
if __name__ == '__main__':
    main()

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

def bisect(l,i,n):
    left = 0
    right = n
    while left < right:
        mid = int((left + right)//2)
        if l[mid] == i:
            return 1
        else:
            if i < l[mid]:
                right = mid
            else:
                left  = mid+1
    return 0

for j in range(q):
    cnt += bisect(s,t[j],n)
    
print(cnt)

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

ans = 0

for item in T:
    low = 0
    high = len(S)-1
    while low <= high:
        mid = (low+high)//2
        guess = S[mid]
        if guess == item:
            ans += 1
            break
        elif guess > item:
            high = mid -1
        else:
            low = mid +1
print(ans)

Solution (Python):
import sys
from bisect import bisect_left

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    res = 0
    for t in T:
        idx = bisect_left(S, t)
        if idx < n and S[idx] == t:
            res += 1
    print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
def bisect(l, r, x):
    while abs(r - l) > 1:
        if arr[l] == x or arr[r] == x:
            return 1
        mid = (l + r) // 2
        if arr[mid] == x:
            return 1
        if arr[mid] < x:
            l = mid
        else:
            r = mid
    return 0


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

l = 0
r = n - 1

ans = 0
for x in t:
    if bisect(l, r, x):
        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):
  def is_ok(idx):
    return S[idx] <= T[i]

  def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
      mid = (ok + ng) // 2
      if is_ok(mid):
        ok = mid
      else:
        ng = mid
    return ok
  
  if T[i] == S[meguru_bisect(N, -1)]:
    ans += 1
print(ans)

Solution (Python):
def bisect_left(A, x, lo=0, hi=None):
    hi = len(A)
    while lo < hi:
        mid = (lo + hi) // 2
        if A[mid] < x:
            lo = mid + 1
        else:
            hi = mid
    return lo


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

ans = 0
for t in T:
    idx = bisect_left(S, t)

    if 0 <= idx < len(S):
        if t == S[idx]: ans += 1

print(ans)

Solution (Python):
S_len = int(input().rstrip())
S = input().rstrip().split(" ")
T_len = int(input().rstrip())
T = input().rstrip().split(" ")

S = [int(s) for s in S]
T = [int(t) for t in T]


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


cnt = 0    
for t in T:
    temp_res = binary_search(S, t)
    cnt += temp_res
print(cnt)

Solution (Python):
import bisect

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

point = 0

for i in t:
    if bisect.bisect(s,i)-bisect.bisect_left(s,i) > 0:
        point += 1
    
print(point)

Solution (Python):
def binary_search(lst, value):
    l = 0
    r = len(lst) - 1
    while l <= r:
        mid = (r + l) // 2
        guess = lst[mid]
        if guess == value:
            return True
        elif guess > value:
            r = mid - 1
        else:
            l = mid + 1
    return False


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

    for value in T:
        if binary_search(S, value):
            ans += 1
    
    print(ans)
    return


if __name__ == "__main__":
    main()

Solution (Python):
def bin_search(s, i):
    l = -1
    r = len(s)
    
    while r-l>1:
        m = (l+r)//2
        
        if s[m]>i:
            r = m
        else:
            l = m
    
    return(s[l]==i)
    
n = int(input())
S = sorted(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

counter = 0

for t in T:
    if bin_search(S, t):
        counter += 1
        
print(counter)

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

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

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

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


def binary_search(num, items):
    low = 0
    high = len(s) - 1
    while low <= high:
        mid = (low + high) // 2
        guess = items[mid]
        if guess == num:
            return True
        if guess > num:
            high = mid -1
        else:
            low = mid + 1
    return False

cnt = 0
for i in range(q):
    if binary_search(t[i], s):
        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 is_ok(vector, key, middle):
    if vector[middle] <= key:
        return True
    else:
        return False

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(S, t, mid):
            ok = mid
        else:
            ng = mid
    return ok

ans = 0
for t in T:
    ind = meguru_bisect(n,0)
    if S[ind] == t:
        ans += 1
print(ans)

Solution (Python):
from bisect import bisect_left
n=int(input())
s=sorted(list(map(int,input().split())))
q=int(input())
t=list(map(int,input().split()))
cnt=0
for i in t:
    if s[bisect_left(s,i)]==i:
        cnt+=1
print(cnt)

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

    T.sort()
    S.sort()
    cnt = 0
    for i in range(n):
        if (i != 0) and (S[i] == S[i-1]):
            continue

        left = 0
        right = q
        mid = 0
        while True:
            
            mid = int( (left+right)/2 )
            if T[mid] == S[i]:
                cnt += 1
                break
            elif S[i] < T[mid]:
                right = mid
            elif S[i] > T[mid]:
                left = mid + 1


            if left == right:
                break
    return cnt

print(main())

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

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

  def binarySearch(x):
    left=0
    right=n
    while left<right:
      if right-left==1:
        if S[left]==x:
          return True
        else:
          return False
      
      p=(right-left)//2
      if S[left+p]==x:
        return True
      elif x<S[left+p]:
        right=left+p
      else:
        left=left+p+1
    return False

    
















  ans=0
  for t in T:
    
    if binarySearch(t)==True:
      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()))
S.sort()
ans = 0
for t in T:
    i = bisect_left(S, t)
    if 0<=i<n and S[i]==t:
        ans += 1
print(ans)

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

print(len(A & T))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
M = int(input())
B = list(map(int,input().split()))

def bisect(key, L):
    left = 0
    right = len(L)-1
    while right - left >= 0:
        mid = left + (right - left) // 2
        if L[mid] == key:
            return mid
        if L[mid] > key:
            right = mid - 1
        else:
            left = mid +1
    return -1

count = 0
for b in B:
    if bisect(b,A) != -1:
        count += 1
print(count)

Solution (Python):
n = int(input())-1
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
    mid = (right + left) // 2
    while right >= left:
        
        if S[mid] == i:
            cnt+=1
            break
        elif i < S[mid]:
            right = mid-1
        else:
            left = mid + 1
        mid = (right + left) // 2
    
    
print(cnt)

Solution (Python):
import sys
import itertools

import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

ans = 0
for t in T:
    left = -1
    right = n
    while (right - left > 1):
        mid = left + (right - left) // 2
        if S[mid] >= t:
            right = mid
        else:
            left = mid
    if S[right] == 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()))

def binary_search(data, value):
    left = 0
    right = len(data) 

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

count = 0
for i in t:
    exist = binary_search(s, i)
    count = count + exist

print(count)

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 binary_serch(t, n, S):
    left=0
    right=n
    while left<right:
        mid=(left+right)//2
        if t == S[mid]:
            return t
        elif t > S[mid]:
            left = mid +1
        else:
            right = mid
    return -1

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

Solution (Python):

from sys import stdin

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

def binary_search(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
  else:
    return -1

cnt = 0
for t in T:
  if binary_search(S, t) != -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()))

res = 0
for t in T: 
  l,r = 0,N-1
  while r>=l:
    m = (l+r)//2
    if S[m] == t:
      res += 1
      break
    if S[m] < t:
      l = m+1
    else:
      r = m-1

print(res)

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

def binary(l, key):
    left = 0
    right = len(l)
    while left < right:
        center = (left+right) // 2
        if l[center] == key:
            return True
        elif l[center] < key:
            left = center + 1
        else:
            right = center
    return False
    
ans = 0
for num in map(int, input().split()):
    if binary(S, num):
        ans += 1
        
print(ans)

Solution (Python):
def binarysearch(list,key):
    left = 0
    right = len(list)
    while left < right:
        mid = (left + right)//2
        if list[mid] == key:
            return mid + 1
        elif list[mid] > key:
            right = mid
        else:
            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 range(q):
    if binarysearch(S,T[i]):
        ans += 1
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):
def bisect(lst, isok, ok, ng):
    while(abs(ok-ng)>1):
        mid = (ok+ng)//2
        if isok(lst[mid]):
            ok = mid
        else:
            ng = mid
    return [ok, ng]

n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
m = [int(i) for i in input().split()]

a.sort()
print(sum([a[bisect(a, lambda x:x >= i, n, -1)[0]] == i for i in m]))

Solution (Python):
def main():
    import sys
    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()))
    
    
    def nibutan(x):
        left, right = 0, N-1
        if S[left]==x or S[right]==x:
            
            return 1
        while True:
            mid = (left+right)//2
            if S[mid] < x:
                left = mid
            elif S[mid] > x:
                right = mid
            elif S[mid] == x:
                
                return 1
            if right-left==1:
                return 0
                
            
    
    cnt = 0
    for t in T:
        cnt +=nibutan(t)
    print(cnt)
    



if __name__=='__main__':
    main()

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

    def bisect(item, list):
        cnt = 0
        
        l = 0
        h = len(list) - 1
        while l <= h:
            mid = (l+h) // 2
            tmp = list[mid]
            if item == tmp:
                cnt = 1
                return cnt
            elif tmp < item:
                l = mid + 1
            elif tmp > item:
                h = mid - 1
        return cnt
    
    ans = 0
    for i in t:
        ans += bisect(i, s)
    print(ans)
    
if __name__ == '__main__':
    main()

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

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


count=0
for i in range(K):
    tmp=T[i]
    left=0
    right=N-1
    flag=False
    while left<=right:
        mid=(left+right)//2
        if S[mid]==T[i]:
            count+=1
            break
        elif S[mid]>T[i]:
            right=mid-1
        elif S[mid]<T[i]:
            left=mid+1
        else:
            print("イレギュラーな例につかまりました")
            exit()
        
print(count)

Solution (Python):
def binarysearch(S,x):
    a=0
    b=len(S)
    while b>a+1:
        m=(b+a)//2
        if S[m]>x:
            b=m
        elif S[m]<=x:
            a=m
    if S[a]==x:
        return True
    return False
            

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

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

ans = 0

for t in T:
    
    left = bisect_left(S, t)
    if left < len(S) and S[left] == t:
        ans += 1

print(ans)

Solution (Python):
def binary_search(S,n,a):
    first = 0
    last = n
    
    
    
    
    
    
    
    
    
    
    
    
    

    while first < last:
        mid = (first + last) // 2
        if S[mid] == a:
            return 1
        elif a < S[mid]:
            last = mid
        elif S[mid] < a:
            first = mid + 1

    return 0

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

    for i in range(q):
        count += binary_search(S,n,T[i])

    print(count)