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):
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
import time
from bisect import bisect_left, insort_left, bisect_right
import sys
import random
import itertools

input = sys.stdin.readline
_NUMINT_ALL = list(range(10))
_START_TIME = time.time()
INDEX_KETA = 10**12

def main():
    ans = solve()

    if ans is True or ans is False:
        YesNo(ans)
    elif ans is None:
        return

    if isinstance(ans, tuple):
        split_print_space(ans)


def solve():

    N = iip()
    S = iip()
    M = iip()
    T = iip()

    S.sort()

    ans = 0
    for i in T:
        if index_sorted(S, i) is not False:
            ans += 1
    print(ans)









def kiriage_warizan(a, b):
    return -(-a//b)


def iip(listed=False):  
    d = input().rstrip("\n").split()
    try:
        ret = [int(i) for i in d]
    except:
        ret = [int(i) if i in _NUMINT_ALL else i for i in d]
        if len(ret) == 1 and listed is False:
            return ret[0]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iipt(l, listed=True, num_only=True):  
    if isinstance(l, list):
        l = l[0] 
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed))
    return ret


def saidai_kouyakusuu(A):  
    l = len(A)
    while True:
        m = min(A)
        mx = max(A)
        if m == mx:
            return m

        for i in range(l):
            if A[i] % m == 0:
                A[i] = m
            else:
                A[i] %= m


def index_sorted(sorted_list, target):
    idx = bisect_left(sorted_list, target)
    if idx != len(sorted_list) and sorted_list[idx] == target:
        return idx
    else:
        return False


def time_debug_10percent():
    a = random.randint(0, 9)
    if a == 9:
        sys.exit()

def time_debug(t):
    time.sleep(_START_TIME + t - time.time())
    sys.exit()


def make_graph_edge_flat(N):  
    ret = []
    for i in range(N-1):
        a, b, c = iip()
        a -= 1
        b -= 1
        ret[a].append((b, c))
        ret[b].append((a, c))
    return ret


def sort_tuples(l, index):  
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):  
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  
    if index >= len(l):                      
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def sortstr(s):  
    return "".join(sorted(s))


def iip_ord(startcode="a"):  
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  
    for i in s:
        print(i)


def bitall(N):  
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):  
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        
        pass
    return ret


def inv(n, mod):  
    return power(n, mod - 2)


def power(n, p, mod_=mod):  
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


def nibutan_func(func, target, left, right, side="left"): 
    l = left
    r = right
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if func(x) == target:
            return x
        elif func(x) > target:
            r = x
        else:
            l = x

    if side == "left" or func(x) == target:
        return l
    else:
        return r


def nibutan_list(list_, target, side="left"):  
    if not isinstance(list_, list):
        list_ = list(list_)

    l = 0
    r = len(list_)
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if list_[x] == target:
            return x
        elif list_[x] > target:
            r = x
        else:
            l = x

    if side == "left" or list_[x] == target:
        return l
    else:
        return r


class UfTree():
    def __init__(self, maxnum):
        self.parent = list(range(maxnum))
        self._size = [1] * maxnum
        self.rank = [0] * maxnum

    def size(self, a):
        return self._size[self.root(a)]

    def root(self, a):
        rank = 0
        cur = a
        while True:
            if self.parent[cur] == cur:
                
                
                return cur
            else:
                self.parent[cur] = self.parent[self.parent[cur]]
                cur = self.parent[cur]
                rank += 1

    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb:
            return self

        self._size[ra] += self._size[rb]
        self.parent[rb] = ra
        return self

if __name__ == "__main__":
    main()

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



def BinarySearch(A,n, key):
    left  = -1
    right = n
    i = 0
    while left < right:

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

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

print(cnt)

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):
	s_idx = 0
	g_idx = n
	while s_idx != g_idx:
		idx = (s_idx + g_idx) // 2
		if S[idx] == T[i]:
			C += 1
			break
		elif S[idx] < T[i]:
			s_idx = idx + 1
		elif S[idx] > T[i]:
			g_idx = idx

print(C)

Solution (Python):



from bisect import bisect_left
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    n = int(readline())
    S = [int(i) for i in readline().split()]
    q = int(readline())
    T = [int(i) for i in readline().split()]
    
    ans = 0
    for t in T:
        x = bisect_left(S, t)
        if x == n:
            if S[-1] == t:
                ans += 1
        else:
            if S[x] == t:
                ans += 1
    
    print(ans)
    

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

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

Solution (Python):
import math
import copy
import sys
import fractions


import decimal
import heapq
import collections
import itertools
import bisect












def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList




n = int(input())
data = getInputIntList()
t = int(input())
candidate = getInputIntList()

D = set(data)

ans = 0
for c in candidate:
    if c in D:
        ans += 1

print(ans)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip() 
import bisect as bs

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

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

    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
from bisect import bisect_left, bisect_right  

def search(t, i):
    ix = bisect_right(t, i)
    if t[ix-1] != i:
        return False
    return True

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

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

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[-1] or i == S[0]:
        ans += 1
    else:
        left = 0
        right = n-1
        while right-left > 1:
            mid = (left+right)//2
            if S[mid] == i:
                ans += 1
                break
            elif S[mid] < i:
                left = mid
            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()))
ans = 0
def binary_search(S,key):  
    n = len(S)             
    left  = 0
    right = n
    while left < right:
        mid = (left+right) // 2
        if S[mid] == key:
            return mid
        elif S[mid] > key:
            right = mid
        else:
            left = mid + 1
    return -1
for i in range(q):
    if binary_search(S,T[i]) != -1:
        ans += 1
print(ans)

Solution (Python):
from bisect import bisect_left
n = int(input())
S = list(map(int, input().split()))
p = int(input())
T = list(map(int, input().split()))

ans = 0
def sh(num):
    ind = bisect_left(S, num)
    return S[ind] == num

for t in T:
    if sh(t):
        ans += 1
print(ans)

Solution (Python):
from bisect import bisect_left

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

    count = 0
    for t in T:
        i = bisect_left(S, t)
        if i != len(S) and S[i] == t:
            count += 1
    print(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()))

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

Solution (Python):
def binary_search(lst, x):
    left=0
    right=len(lst)
    while left<right:
        m=(left+right)//2
        if lst[m]==x:
            return True
        elif x<lst[m]:
            right=m
        else:
            left=m+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 t in T:
        if binary_search(S,t):
            ans+=1
    print(ans)

main()

Solution (Python):
from bisect import bisect_left

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 ti in t:
    idx = bisect_left(s, ti)
    if s[idx] == ti:
        ans += 1

print(ans)

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

    result = 0
    for t in T:
        l = 0
        r = n - 1
        while l <= r:

            
            c = (l + r) // 2
            if t < S[c]:
                r = c - 1
                continue
            elif t == S[c]:
                result += 1
                break
            elif S[c] < t:
                l = c + 1
                continue
            raise Exception

    print(result)

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

def binary_search(search,list_):
  
  l = 0
  r = len(list_)
  while r-l > 1:
    m = (l+r)//2
    if list_[m] > search: r = m
    elif list_[m] < search: l = m
    else:return m
  if r-l == 1:
    if search == list_[l]: return 0
    else: return -1
ans = 0
for i in t:
  if binary_search(i,s) >= 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()))
cnt = 0

def binary_search(l,num):
    left = 0
    right = n
    flag = 0
    while left < right:
        mid = (left + right)//2
        if l[mid] == num:
            flag = 1
            return(flag)
        elif l[mid] > num:
            right = mid
        else:
            left = mid + 1
    return(flag)
    
for i in T:
    cnt += binary_search(S,i)
print(cnt)

Solution (Python):

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


n = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(i) for i in input().split()]
C = 0
for t in T:
    if binarySearch(S, n, t) != -1:
        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 search(ary, target):
    left = 0
    right = len(ary)
    while (left < right):
        idx = (left+right)//2
        if ary[idx] == target:
            return True
        if ary[idx] < target:
            left = idx + 1
        elif ary[idx] > target:
            right = idx
        else:
            return False
    return False

result = 0;
for i in t:
    if search(s, i):
        result += 1
print(result)

Solution (Python):
import math

def bs(lis,target): 

    result = -1
    left = 0
    right = len(lis) - 1

    while left <= right:
        center = (left + right)//2
        if lis[center] == target:
            result = center
            break
        elif lis[center] < target:
            left = center + 1
        elif lis[center] > target:
            right = center - 1

    return result

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 bs(s,i) != -1:
        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 j in range(q):
	l=-1
	r=n
	while l+1<r:
		m=(l+r)//2
		if S[m]==T[j]:
			c+=1
			break
		elif S[m]<T[j]:
			l=m
		else:
			r=m
print(c)

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


ans = 0
for b in B:
    r = bisect.bisect_right(A, b)
    l = bisect.bisect_left(A, b)
    if r != l:
        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()))

counter = 0

for t in T:
    a = bisect.bisect_left(S, t)
    if a < n:
        if S[a] == t:
            counter += 1

print(counter)

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

def binarySearch(key):
  left = 0
  right = n - 1
  mid = (left + right) // 2
  while S[mid] != key:
    if left == right:
      return 0
    if S[mid] > key:
      right = mid
    elif S[mid] < key:
      left = mid + 1
    mid = (left + right) // 2
  return 1
  
count = 0
for t in T:
  count += binarySearch(t)
print(count)

Solution (Python):

def main():
    n = int(input())
    a = list(map(int,input().split()))
    m = int(input())
    b = list(map(int,input().split()))
    res = 0
    for i in range(m):
        l = 0
        r = n
        while l<r:
            mid = int((l+r)/2)
            if b[i]==a[mid]:
                res+=1
                break
            if b[i]>a[mid]:l = mid+1
            else          :r = mid
    print (res)


if __name__ == '__main__':
    main()

Solution (Python):
from bisect import bisect_left as bisect


def inpl():
    return list(map(int, input().split()))


n = int(input())
S = inpl()
q = int(input())
T = inpl()

S.sort()
S.append(10**11)


print(sum(1 for t in T if S[bisect(S, t)] == t))

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

def bin(a):
    ok=n-1
    ng=-1

    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if s[mid]>=a:
            ok=mid
        else:
            ng=mid
    if s[ok]==a:return 1
    else:return 0

ans=0
for i in t:
    ans+=bin(i)
print(ans)

Solution (Python):
import bisect
N=int(input())
S=list(map(int,input().split()))
Q=int(input())
T=list(map(int,input().split()))
X=0
P=0
for i in range(Q):
  X=bisect.bisect_left(S,T[i])
  if S[X]==T[i]:
    P=P+1
print(P)

Solution (Python):



import sys

def input_lines():
    return sys.stdin.readlines()

def binary_search(l, v):    
    low = 0
    high = len(l) - 1
    while low <= high:
        mid = (low + high) // 2
        if l[mid] == v:
            return mid
        elif l[mid] < v:
            low = mid + 1
        else:
            high = mid - 1
    return -1

def main():
    lines = input_lines()
    s = sorted(set(map(int, lines[1].split())))
    t = sorted(map(int, lines[3].split()))
    
    count = 0
    for v in t:
        res = binary_search(s, v)
        if res != -1:
            count += 1
            s = s[res + 1:]
    print(count)
    
main()

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 i in range(q):
    idx = bisect_left(S, T[i])
    if idx == n:
        continue
    if S[idx] == T[i]:
        cnt += 1
print(cnt)

Solution (Python):
from bisect import bisect_left
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = map(int, input().split())
a = 0
for t in T:
  if S[bisect_left(S, t)]==t:
    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 binary_search(A, key):
    n = len(A)
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            return True
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return False


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

Solution (Python):















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

    ans = 0

    for i in T:
        pl = 0
        pr = n - 1

        while pl <= pr:
            pc = (pl + pr) // 2
            if S[pc] == i:
                ans += 1
                break
            elif i < S[pc]:
                pr = pc - 1
            else:
                pl = pc + 1

    print(ans)


resolve()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
t=int(input())
b=list(map(int,input().split()))
a=sorted(a)

import bisect
cnt=0
for i in b:
    x=bisect.bisect_left(a,i)
    if x!=n and i==a[x]:
        cnt+=1
print(cnt)

Solution (Python):
import math
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):
    left = 0
    right = N-1
    key = T[i]
    
    while left <= right:
        mid =(left+right)//2

        if S[mid] == key:
            ans += 1
            break
        elif S[mid] < key:
            left = mid+1

        else:
            right = mid-1
        
print(ans)

Solution (Python):
from bisect import bisect_left
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
cnt = 0

def find_idx(l, x):
    i = bisect_left(l, x)
    if i != len(l) and l[i] == x:
        return 1
    else:
        return 0

for i in T:
    cnt += find_idx(S, i)

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

print(ans)

Solution (Python):
def findNum(array, target):
    n = len(array)
    l = -1
    r = n  
    while l + 1 < r:
        m = (l + r) // 2
        if array[m] == target:
            return True
        elif array[m] < target:
            l = m
        else:
            r = m

    if r < n and array[r] == target:
        return True
    else:
        return False


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

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

count = 0
for i in range(q):
    if findNum(array, m[i]):
        count += 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):
from bisect import bisect_left
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 t in T:
    idx = bisect_left(S, t)
    if idx != n and S[idx] == t:
        ans += 1
print(ans)

Solution (Python):

import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    S=list(map(int,input().split()))
    Q=int(input())
    T=list(map(int,input().split()))
    ans=0
    for x in T:
        ans+=bool(bisect_right(S,x)-bisect_left(S,x))
    print(ans)

if __name__ == '__main__':
    main()

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

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  
nl = lambda: list(map(int, stdin.readline().split()))

n = ni()
s = na()
q = ni()
t = na()
ans = 0
for x in t:
    d = bisect.bisect_right(s, x) - bisect.bisect_left(s, x)
    if d != 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()))

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

n = int(input())
S = list(map(int,input().split()))
q = int(input())
T = map(int,input().split())
ret = 0
for t in T:
  ok = 0
  ng = n
  while ng-ok > 1:
    mid = (ok+ng)//2
    if t < S[mid]:
      ng = mid
    else:
      ok = mid
  if S[ok]==t:
    ret += 1
print(ret)

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=round((left+right-0.0001)/2)

        if S[mid] == t:
            cnt+=1
            break
        elif S[mid] > t:
            right = mid
        elif S[mid] < t:
            left = mid+1
print(cnt)

Solution (Python):


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


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

S.sort()
count = 0
for i in range(q):
    if binary_search(S, T[i]) != -1:
        count += 1

print(count)

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

def b_search(b, x, l, r):
    while l+1<r:
        m = (l+r)//2
        if b[m]<x:
            l = m
        else:
            r = m
    
    if b[r]==x:
        return True
    else:
        return False
    
s.sort()
cnt = 0
for ai in a:
    if b_search(s, ai, -1, n-1):
        cnt += 1
print(cnt)

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

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

count = 0
for elem in T:
    if binarySearch(elem, S):
        count = count + 1
print(count)

Solution (Python):
from math import floor

def binary_search(A, key):
    left = 0
    right = len(A)

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



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

    ans = 0

    for key in T:
        
        if binary_search(S, key) is not None:
            ans += 1

    print(ans)

            

main()

Solution (Python):
def binary_search(t,S):
  start = 0
  end = len(S)-1
  flag = False
  while start <= end:
    mid = (start + end) //2
    if t == S[mid]:
      flag = True
      break
    elif t < S[mid]:
      end = mid -1
    else:
      start = mid + 1
  if flag:
    return True
  else:
    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(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()))

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

print(cnt)

Solution (Python):
from bisect import bisect_left

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return 1
    return 0

n = ii()
s = li()

q = ii()
t = li()

cnt = 0

for i in t:
    cnt += index(s,i)

print(cnt)

Solution (Python):





def find(S, val):
    left = 0
    right = len(S) - 1
    while left < right:
        mid = (left+right) // 2
        if S[mid] == val:
            return True
        elif S[mid] < val:
            left = mid+1
        else:
            right = mid-1
    return S[left] == val


def solv(S, T):
    count = 0
    for val in T:
        a = find(S, val)
        count += a
    return count


if __name__ == "__main__":

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

    ans = solv(S, T)

    print(ans)

Solution (Python):
def bisearch(li, tgt):
    upper, lower = len(li)-1, 0
    while upper>=lower:
        mid = lower + (upper-lower)//2
        if(li[mid]==tgt):
            return mid
        elif(li[mid]>tgt):
            upper = mid-1
        else:
            lower = mid+1
        
    return -1

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:
    if(bisearch(S, t)!=-1):
        cnt += 1
print(cnt)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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 LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    s = LI()
    q = I()
    t = LI()
    ans = 0
    for i in t:
        j = bisect.bisect_left(s,i)
        if j < n and i == s[j]:
            ans += 1
    print(ans)
    return


if __name__ == "__main__":
    solve()

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

def func(x,btm,top):
  while btm < top:
    ctr = btm + (top-btm)//2 
    if x == S[ctr]:
      return 1
    elif x < S[ctr]:
      top = ctr
    elif x > S[ctr]:
      btm = ctr + 1
  return 0

C = 0
btm = 0
top = n
for i in T:
  C += func(i,btm,top)

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(item,list):
    low=0
    high=len(list)-1
    while low<=high :
        mid=(high+low)//2
        if item == list[mid]:
            return 1
        elif item < list[mid]:
            high=mid-1
        else:
            low=mid+1
    return 0

cnt=0
for i in T:
    cnt+=Binary_Search(i,S)
print(cnt)

Solution (Python):

s_num = int(input())
s = list(map(int, input().split()))
s = set(s)
q_num = int(input())
q = list(map(int ,input().split()))
q = set(q)

r = s & q

print(len(r))