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):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']



show_flg = False


def f(a, x):
    return a[x]



def main():
    N = I()
    S = LI()
    Q = I()
    T = LI()
    ans = 0

    for i in range(Q):
        s = 0
        t = N
        ok = s - 1
        ng = t
        target = T[i]
        while ng - ok > 1:
            mid = (ng + ok) // 2
            
            if f(S, mid) <= target:
                ok = mid
            else:
                ng = mid

        ans += 1 if target == S[ok] else 0

    print(ans)


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 bs(t,s,e):

    while e-s > 1:
        
        m = (s+e)//2
        if S[m] <= t:
            s = m
        else:
            e = m
    if S[s] == t or S[e] == t:
        return True
    else:
        return False

ans = 0
for t in T:
    if bs(t,0,n-1):
        ans += 1
print(ans)

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

Solution (Python):
import bisect

if __name__ == "__main__":
    N = int(input())
    num_list = list(map(int, input().split()))
    M = int(input())
    target_list = list(map(int, input().split()))

    count = 0
    for target in target_list:
        target_idx = bisect.bisect_left(num_list, target)
        if(num_list[target_idx] == target):
            count += 1
    print(count)

Solution (Python):
def bs(a, key):
    left = -1
    right = len(a)

    while right - left > 1:
        mid = left + (right - left) // 2

        if a[mid] >= key:
            right = mid
        else:
            left = mid

    return a[right] == key


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

print(sum([bs(S, t) for t in T]))

Solution (Python):
_ = int(input())

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

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



def binary_search(num_list, num, left, right):
    mid = (left + right) // 2
    
    if num_list[mid] == num:
        
        return True
    if left >= right:
        return False
    elif num_list[mid] > num:
        return binary_search(num_list, num, left, mid - 1)
    else:
        return binary_search(num_list, num, mid + 1, right)


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

print(count)

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 range(q):

    left = 0
    right = n-1

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

        if t[i] < s[mid]:
            right = mid -1
        elif t[i] > s[mid]:
            left = mid + 1
        else:
            ans += 1
            break

print(ans)

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

c = 0
for i in range(len(T)):
    lo = 0
    hi = n
    while lo < hi:
        mid = (lo + hi) // 2
        if S[mid] == T[i]:
            c += 1
            break
        elif T[i] < S[mid]:
            hi = mid
        else:
            lo = mid+1
print(c)

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

def binary(lft,rgt,m):
    global s,n
    while lft <= rgt:
        mid = (rgt+lft)//2
        if s[mid] == m:
            return True
        elif s[mid] > m:
            rgt = mid - 1
        else:
            lft = mid + 1
    return False
    
     

for i in t:
    if binary(0,n-1,i) and (s[0]<=i and s[n-1]>=i):
        cnt += 1
print(cnt)

Solution (Python):
def b_search(A, a, left=None, right=None):
    if left is None:
        left = 0
    if right is None:
        right = len(A)
    if left == right:
        return False
    mid = (left + right) // 2
    if a == A[mid]:
        return True
    elif a > A[mid]:
        return b_search(A, a, mid + 1, right)
    else:
        return b_search(A, a, left, mid)


N = int(input())
S = list(map(int, input().split()))
Q = int(input())
T = list(map(int, input().split()))
ans = 0
for t in T:
    ans += b_search(S, t)
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):
    key = t[i]
    left = 0
    right = n
    mid = (left + right) // 2
    while left <= right:
        if s[mid] == key:
            ans += 1
            break
        elif s[mid] < key:
            left = mid + 1
        else:
            right = mid - 1
        mid = (left + right) // 2
print(ans)

Solution (Python):
import bisect

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

count = 0
for t in T:
    l, r = bisect.bisect_left(S, t), bisect.bisect_right(S, t)
    if l < r:
        count += 1
print(count)

Solution (Python):
import bisect

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

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

print(C)

Solution (Python):
import bisect
N = int(input())
S = [int(item) for item in input().split()]
q = int(input())
T = [int(item) for item in input().split()]

cnt = 0


for i in range(q):
    temp_index = bisect.bisect_left(S, T[i])
    if len(S) != temp_index:
        if T[i] == S[temp_index]:
            cnt += 1
print(cnt)

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

def linearSearch(A,key,n):
    i=0
    B=copy.copy(A)
    B.append(key)
    while B[i] != key:
        i=i+1
    if i==n:
        return 0
    return 1

def BinarySearch(A,key,start,end):
    if start==end:
        if A[start]!=key:
            return 0
        else:
            return 1
    mid=(start+end)//2
    if A[mid]>=key:
        return BinarySearch(A,key,start,mid)
    else:
        return BinarySearch(A,key,mid+1,end)

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

print(ans)

Solution (Python):
n, s = int(input()), list(set(map(int, input().split())))
q, t = int(input()), list(set(map(int, input().split())))
l = set()
tl = set()
for tt in (t):
    if tt in tl:
        l.add(tt)
        continue
    mi, md, ma = 0, len(s) // 2, len(s) - 1
    for i in range(mi, ma, 1):
        tl.add(s[mi])
        tl.add(s[md])
        tl.add(s[ma])
        if tt in tl:
            l.add(tt)
            break
        elif mi == md or md == ma:
            break
        elif s[md] < tt:
            mi = md
            md = md + ((ma - md) // 2)
        elif s[md] > tt:
            ma = md
            md = md - ((md - mi) // 2)
print(len(l))

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

def f(i,s):
    r=n-1
    l=0
    m=(r+l)//2
    while r-l>-1:
        if s[m]==i:
            return True
        elif s[m]>i:
            r=m-1
            m=(r+l)//2
        else:
            l=m+1
            m=(r+l)//2
for i in t:
    if f(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()))

def bs(ken,lst):
    left=0
    right=len(lst)
    while (left<right):
        middle=(left+right)//2
        if lst[middle]==ken:
            return 1
        elif lst[middle]<ken:
            left=middle+1
        elif lst[middle]>ken:
            right=middle
    else: return 0

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

Solution (Python):
def binary_search(s, t):
    top = 0
    tail = len(s)
    while top < tail:
        mid = (top + tail) // 2
        if s[mid] == t:
            return True
        elif s[mid] < t:
            top = mid + 1
        else:
            tail = mid
    return False

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

count = 0

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

print(count)

Solution (Python):
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from bisect import bisect_left 


sys.setrecursionlimit(10**7)
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))


T.sort()
setS = set(S)

cnt = 0
for t in T:
    if t in setS:
        cnt += 1
print(cnt)

Solution (Python):
import bisect

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

A = S & T
print(len(A))

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

ans = 0
for i in t:
    up_index = bisect.bisect_left(s,i)
    if up_index != n:
        if s[up_index] == i:
            ans += 1
    
print(ans)

Solution (Python):
import sys
import math
import copy
from typing import Tuple, List, Union
input = sys.stdin.readline


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


def main():
    n = int(input())
    S = tuple(map(int, input().split()))
    q = int(input())
    T = tuple(map(int, input().split()))
    return [binary_search(t, S) for t in T]



if __name__ == '__main__':
    print(sum(main()))

Solution (Python):
def search(s:list, target:int) -> int:
    left=0
    right=len(s)
    while left < right:
        mid = int((left+right)/2)
        if s[mid] == target:
            return mid
        if target > s[mid]:
            left=mid+1
        elif target < s[mid]:
            right=mid
    return -1

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 search(s, _t) != -1:
        ans+=1

print(ans)

Solution (Python):
def nibu(a,A): 
    mi = 0
    ma = len(A)-1
    while ma-mi>1:
        mid = (ma+mi)//2
        if a < A[mid]:
            ma = mid
        else:
            mi = mid
    if A[ma]==a:
        return True
    elif A[mi]==a:
        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 i in range(q):
    if nibu(T[i],S):
        ans +=1
print(ans)

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

    n=int(input())
    s=set(map(int,input().split()))
    q=int(input())
    t=list(map(int,input().split()))
    
    ans=0
    for num in t:
      if num in s:
        ans+=1
    print(ans)
if __name__=='__main__':
    main()

Solution (Python):
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

def SI():
    return int(readline())
def MI():
    return map(int, readline().split())
def MLI():
    return map(int, open(0).read().split())

inf = float("inf")


def main():
    n = int(input())
    S = [i for i in MI()]
    
    q = int(input())
    T = [i for i in MI()]
    
    ret = 0
    for t in T:
        index = bisect.bisect_left(S, t)
        if index < n and S[index] == t:
            ret += 1
            
    print(ret)

if __name__ == "__main__":
    main()

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

import bisect

ans = 0
s = set()
for i in S:
    if i not in s:
        idx_left = bisect.bisect_left(T, i)
        idx_right = bisect.bisect_right(T, i)
        ans += idx_right - idx_left
        s.add(i)

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

print(count)

Solution (Python):
def func(A, x, lower, upper):
    if lower+1 == upper:
        if (A[lower] == x)or(A[upper] == x):
            return 1
        else:
            return 0
    idx = (upper+lower)//2
    if x < A[idx]:
        return func(A, x, lower, idx)
    else:
        return func(A, x, idx, upper)


N = int(input())
S = list(map(int, input().split()))
Q = int(input())
T = list(map(int, input().split()))
ans = 0
for t in T:
    ans += func(S, t, 0, N)
print(ans)

Solution (Python):


def binary_search(a, x, lo=0, hi=None):
    """Return True if list a in item x, assuming a is sorted.
    """
    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if a[mid] < x:
            lo = mid+1
        elif a[mid] > x:
            hi = mid
        else:
            return True
    return False

same_num_count = 0
firstlist_num = int(input())
sorted_firstlist = sorted(set(input().split()))
secondlist_num = int(input())
secondlist = set(input().split())

for n in secondlist:
    if binary_search(sorted_firstlist, n):
        same_num_count += 1
print(same_num_count)

Solution (Python):
n = int(input())
S = set(list(map(int,input().split())))
q = int(input())
T = list(map(int,input().split()))
c = 0
for t in T:
  if t in S:
    c += 1
print(c)

Solution (Python):
import sys
import math
import fractions
import itertools
from collections import deque
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()
n = int(input())
S = set(map(int,input().split()))
q = int(input())
T = list(map(int,input().split()))
ans = 0
for i in T:
    if i in S:
        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(" ")))

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

Solution (Python):
import bisect

n=int(input())
arr=list(map(int,input().split()))
q=int(input())
arr2=list(map(int,input().split()))
ans=0
for i in range(q):
  pos=bisect.bisect_left(arr,arr2[i])
  if pos==n:
    continue
  else:
    if arr[pos]==arr2[i]:
      ans+=1
print(ans)

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

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

cnt = 0
for x in t:
    c = bisect_left(s,x)
    if s[c] == x:
        cnt += 1












print (cnt)

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

print(len(set(s) & set(t)))

Solution (Python):
def binary():
    
    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 - 1
        while left <= right:
            mid = (left + right) // 2
            if s[mid] == t[i]:
                count += 1
                break
            elif s[mid] > t[i]:
                right = mid - 1
            else:
                left = mid + 1
    print(count)

if __name__ == "__main__":
    binary()

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

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

    count = 0

    for t in T:
        l = 0
        r = n

        while l < r:
            m = int((l + r) / 2)

            if S[m] == t:
                count += 1
                break
            elif S[m] < t:
                l = m + 1
            elif S[m] > t:
                r = m

    print(count)    

main()

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

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

count = 0
for i in T:
    if (binarySerch(S, i)) == True:
        count += 1

print(count)

Solution (Python):






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

    return -1


def main():
    number_of_A = int(input())
    A = [int(a) for a in input().split(" ")]

    number_of_B = int(input())
    B = [int(b) for b in input().split(" ")]

    num = 0
    for b in B:
        result = binary_search(A, b)
        if result != -1:
            num += 1

    print(num)


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 binary_search (a, key):
    left = 0
    right = len(a)
    while left < right:
        mid = (left + right) // 2
        if a[mid] == key:
            return True
        elif key < a[mid]:
            right = mid
        else:
            left = mid + 1
    return False

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

Solution (Python):

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


n_number = int(input())
n_list = list(map(int, input().split()))
q_number = int(input())
q_list = list(map(int, input().split()))
result = 0


for i in range(q_number):
        result += binarySearch(n_list, q_list[i])


print(result)

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

Solution (Python):


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

S.sort()
T.sort()
ans = 0

i = 0
for elm in S:
    if elm > T[i]:
        while i < q-1 and elm > T[i]:
            i += 1
        
        if elm == T[i]:
            ans += 1
    elif elm == T[i]:
        ans += 1
    elif elm < T[i]:
        pass

print(ans)

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

Solution (Python):
import math

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

count = 0

for v in T:
  top = 0
  tail = len(S)
  while top < tail:
    i = math.floor((top + tail)/2)
    if v == S[i]:
      count += 1
      break
    elif v > S[i]:
      top = i + 1
    else :
      tail = i

print (count)

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

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


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

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

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

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

Solution (Python):

from bisect import bisect_left

def main():
  n = int(input())
  S = list(map(int, input().split()))
  m = int(input())
  T = list(map(int, input().split()))
  count = 0
  for i in T:
    index = bisect_left(S, i)
    if index != len(S) and S[index] == i:
      count += 1
  print(count)

main()

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


n = int(input())
count = 0

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

Solution (Python):
n=int(input())
A=list(map(int, input().split()))
q=int(input())
Key = list(map(int, input().split()))
def BinarySearch(A, n, key):
	left = 0
	right = n
	while (left < right):
		mid = (left + right) // 2
		if (key == A[mid]):
			return 1
		if (key > A[mid]):
			left = mid + 1
		elif (key < A[mid]):
			right = mid
	return 0
cnt = 0
for i in range(q):
	if (BinarySearch(A, n, Key[i])):
		cnt+=1
print(cnt)

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

count = 0
for t in T:
    index = bisect_left(S, t)
    if index < len(S) and S[index] == t:
        count += 1

print(count)

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

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

ans=0
for i in range(len(t)):
    ind=binarySearch(s, t[i])
    if(ind!=-1):
        ans+=1
print(ans)

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

count = 0
for t in T:
    min_idx = 0
    max_idx = len(S) - 1
    while min_idx <= max_idx:
        mid_idx = (min_idx+max_idx) // 2
        if t < S[mid_idx]:
            max_idx = mid_idx - 1
        elif t > S[mid_idx]:
            min_idx = mid_idx + 1
        else:
            count += 1
            break
print(count)

Solution (Python):
n = int(input())
s = [int(_) for _ in input().split()]
q = int(input())
t = [int(_) for _ in input().split()]
dic = {}
for i in s:
    if i not in dic:
        dic[i] = 1

c = 0
for i in t:
    if i in dic:
        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 i in range(q):
    l = 0
    r = n
    while r - l > 1:
        m = (r + l) // 2
        if T[i] <= S[m]:
            r = m
        else:
            l = m
    if (T[i] == S[l]) or (T[i] == S[r]):
        C += 1
print(C)

Solution (Python):

num_s = int(input())

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

num_t = int(input())

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



def binary_search(array, x):
    imin = 0
    imax = len(array) - 1
    
    while imin <= imax:
        imid = imin + int((imax - imin) / 2)
        if x > array[imid]:
            imin = imid + 1
        elif x < array[imid]:
            imax = imid - 1
        else:
            return True
    return False

counter = 0
for t in T:
    if binary_search(S, t):
        counter += 1

print(counter)

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

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 type(binarysearch(S,t))==int:
        ans+=1
    
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
m=int(input())
b=list(map(int,input().split()))
ans=0
for x in b:
    l=-1
    r=n
    while r-l>1:
        mid=(l+r)//2
        if a[mid]>=x:
            r=mid
        else:
            l=mid
    lb=r
    l=-1
    r=n
    while r-l>1:
        mid=(l+r)//2
        if a[mid]>x:
            r=mid
        else:
            l=mid
    ub=r
    ans+=ub>lb
print(ans)

Solution (Python):
import bisect


def bisect_find(s, i):
    index = bisect.bisect_left(s, i)
    if s[index] == i:
        return True
    return False


input()
s = [int(i) for i in input().split()]
input()
t = [int(i) for i in input().split()]
ans = len([i for i in t if bisect_find(s, i)])
print(ans)

Solution (Python):
def binarySearch(A,n,key):
    
    left = 0
    right = n
    while(left < right):
        mid = (left + right)//2
        if(key == A[mid]):
            return 1
        if(key > A[mid]):
            left = mid + 1
        elif(key < A[mid]):
            right = mid
            
    return 0
    
if __name__ == '__main__':
    
    n = int(input())
    L = list(map(int,input().split()))
    q = int(input())
    key = list(map(int,input().split()))
    
    count = 0
    for i in range(q):
        if(binarySearch(L,n,key[i])):
            count += 1
            
    print(count)

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


input()
S = [int(i) for i in input().split()]
input()
T = [int(i) for i in input().split()]
count = 0

for k in T:
    if binarySearch(S, k) is not None:
        count += 1

print(count)

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

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

cnt = 0

for i in range(q):
    key = T[i]
    cnt += BinarySearch(S,key) 

print(cnt)

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

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

Solution (Python):
import sys

n = int(input())
s = tuple(map(int, sys.stdin.readline().split()))   
q = int(input())
t = tuple(map(int, sys.stdin.readline().split()))

result = 0
for x in t:
    first = 0
    last = n - 1
    while first <= last:
        middle = first + (last - first) // 2
        if x == s[middle]:
            result += 1
            break
        elif x < s[middle]:
            last = middle - 1
        else:
            first = middle + 1
print(result)

Solution (Python):
"""
二分探索
"""
def BinaraySearch(A, key):
    count = 0
    left = 0
    right = len(A)
    while left < right:
        mid = int((left + right) / 2)
        if A[mid] == key:
            count += 1
            return count
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    else:
        return count

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):
    ans += BinaraySearch(s, t[i])

print(ans)

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

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

count=0
for i in t:
    if binarySearch(s,i):
        count+=1
        

print(count)

Solution (Python):

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

    return False



sum = 0
t = int(input())
A = list(map(int,input().split()))
b = int(input())
C = list(map(int,input().split()))

for res in C:
    if binarySearch(A,res):
        sum += 1

print(sum)

Solution (Python):
n = int(input())

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

q = int(input())

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

C = 0

for i in range(q):
  left = 0

  right = n

  while left < right:
    mid = (left + right) // 2
    if S[mid] == T[i]:
      C += 1
      break
    elif T[i] < S[mid]:
      right = mid
    else:
      left = mid + 1

print(C)