Problem:
Search II You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S. Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers are given. Output Print C in a line. Constraints  Elements in S is sorted in ascending order  n ≤ 100000  q ≤ 50000  0 ≤ an element in S ≤ 10 9  0 ≤ an element in T ≤ 10 9  Sample Input 1 5
1 2 3 4 5
3
3 4 1 Sample Output 1 3 Sample Input 2 3
1 2 3
1
5 Sample Output 2 0 Sample Input 3 5
1 1 2 2 3
2
1 2 Sample Output 3 2 Notes

Solution (Python):

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

print(point)

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

Solution (Python):
n=input()
A=set(input().split())
m=input()
B=set(input().split())
print(len(A&B))

Solution (Python):


def half(a,b,low,high): 

    if(low > high):
        return 0

    c = int((low+high)/2)

    if(a[c] == b):
        return 1
    elif(a[c] < b):
        return half(a,b,c+1,high)
    elif(a[c] > b):
        return half(a,b,low,c-1)
    else:
        return 1



n = int(input())
s = list(map(int,input().split()))
q = int(input())
r = list(map(int,input().split()))
cou = 0

for i in range(q):
    cou += half(s,r[i],0,len(s))

print(cou)

Solution (Python):


def half(a,b,low,high):

    if(low > high):
        return 0

    c = int((low+high)/2)

    if(a[c] == b):
        return 1
    elif(a[c] < b):
        return half(a,b,c+1,high)
    elif(a[c] > b):
        return half(a,b,low,c-1)



n = int(input())
s = list(map(int,input().split()))
q = int(input())
r = list(map(int,input().split()))
cou = 0

for i in range(q):
    cou += half(s,r[i],0,n-1)

print(cou)

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

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

Solution (Python):
n_num = int(input())
n_list = list(map(int, input().split()))
q_num = int(input())
q_list = list(map(int, input().split()))

count = 0
for q in q_list:
	lower = 0
	higher = len(n_list) - 1
	m = (higher - lower) // 2

	while lower <= higher:
		if n_list[m] == q:
			count += 1
			break
		elif n_list[m] > q:
			higher = m - 1
			m = lower + (higher - lower) // 2
		else:
			lower = m + 1
			m = lower + (higher - lower) // 2

print(count)

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

Solution (Python):
def binarySearch(array, key):
    left = 0
    right = len(array)
    while left < right:
        mid = int((left + right) / 2)
        if key == array[mid]:
            return True
        elif key > array[mid]:
            left = mid + 1
        elif key < array[mid]:
            right = mid
        else:
            print("ERROR")
    return False
 
 
n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
a = [x for x in t if binarySearch(s, x)]
print(len(a))

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

Solution (Python):

def bs(A, n):
    l=0
    r=len(A)
    while l<r:
        mid=int((l+r)/2)
        if A[mid]==n:
            return mid
        else:
            if n<A[mid]:
                r=mid
            else:
                l=mid+1

    return -1

S=int(input())
A=[int(i) for i in input().split()]

T=int(input())
B=[int(j) for j in input().split()]

A.sort()

cnt=0
for i in range(T):
    x=bs(A,B[i])
    if x!=(-1):
        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()))

def binarySearch(list, key):
    left = 0
    right = len(list)

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

    return False

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

Solution (Python):
def binary_search(l, t):
    left = 0
    right = len(l) - 1

    while left <= right:
        mid = (left + right)//2
        if l[mid] < t:
            left = mid + 1
        elif t < l[mid]:
            right = mid - 1
        else:
            return True

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

    cnt = 0
    for et in t:
        bl = binary_search(s, et)
        if bl:
            cnt += 1

    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
def binary_search(l, t):
    left = 0
    right = len(l)

    while left < right:
        mid = (left + right)//2
        if l[mid] < t:
            left = mid + 1
        elif t < l[mid]:
            right = mid
        else:
            return True

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

    cnt = 0
    for et in t:
        bl = binary_search(s, et)
        if bl:
            cnt += 1

    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
n = int(input())
S = list(map(int, input().split(' ')))
q = int(input())
T = list(map(int, input().split(' ')))
counter = 0
def binary_search(A, left, right, t):
    if(left > right):
        return
    global counter
    center = (right + left) // 2
    if(A[center] == t):
        counter += 1
        return
    elif(A[center] < t):
        binary_search(A, center+1, right, t)
    else:
        binary_search(A, left, center-1, t)

for t in T:
    binary_search(S, 0, n, t)
print(counter)

Solution (Python):















def binary_search(ary, target):

    left = 0
    right = len(ary)

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

        if ary[mid] == target:
            return True
        elif ary[mid] < target:
            left = mid + 1
        else:
            right = mid

    return False


if __name__ == '__main__':

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

    for target in T:
        if binary_search(S, target):
            cnt += 1

    print(cnt)

Solution (Python):



def intinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def binary_search(S, k):
    a = 0; b = len(S) - 1
    if b == 0: return S[0] == k
    while b - a > 1:
        c = (a + b) // 2
        if k <= S[c]: b = c
        else: a = c
    return S[a] == k or S[b] == k
    
def main():
    n = int(input())
    S = intinput()
    q = int(input())
    T = intinput()
    count = 0
    for k in T:
        if binary_search(S, k): 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()))

def binary_search(imin, imax, target):
    n = int(imax - imin + 1)
    if n == 1:
        if S[imin] == target:
            return 1
        else:
            return 0
            
        
    if n % 2 == 0:
        c = int(imin + n/2)
        if target >= S[c]:
            imin = c
            return binary_search(imin, imax, target)

        else:
            imax = c-1
            return binary_search(imin, imax, target)



    else:
        n = (n-1)/2
        c = int(imin + n)
        if target >= S[c]:
            imin = c
            return binary_search(imin, imax, target)

        else:
            imax = c-1
            return binary_search(imin, imax, target)


        

def judge(array, target, imin, imax,c):
    if target >= array[c]:
        imin = c
        return binary_search(imin, imax, target)

    else:
        imax = c-1
        return binary_search(imin, imax, target)



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

print(cnt)

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

c = 0
len_s = len(s)
for x in t:
    l = 0
    r = len_s
    while l < r:
        if s[(l + r) // 2] == x:
            c += 1
            break
        elif s[(l + r) // 2] < x:
            l = (l + r) // 2 + 1
        else:
            r = (l + r) // 2

print(c)

Solution (Python):
def binary_search(key):
    left = 0; right = n
    cnt = 0
    while left < right:
        mid = (left + right) // 2
        if key == S[mid]:
            cnt += 1
            break
        elif key < S[mid]:
            right = mid
        else:
            left = mid + 1
    return cnt

n = int(input())
S = [int(e) for e in input().split()]
q = int(input())
T = [int(e) for e in input().split()]
cnt = 0
for key in T:
    cnt += binary_search(key)
print(cnt)

Solution (Python):
def main():
    n = int(stdinput())
    S = [*map(int, stdinput().split())]
    q = int(stdinput())
    T = [*map(int, stdinput().split())]

    S = sorted(S)

    c = 0
    for t in T:
        if binary_search(S, len(S), t):
            c += 1
    
    print(c)

def binary_search(S, n, t):
    left = 0
    right = n - 1
    
    

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

        
        
        
        if S[mid] == t:
            return True
        elif S[mid] > t:
            right = mid - 1
        else:
            left = mid + 1
    
    return False

def stdinput():
    from sys import stdin
    return stdin.readline().strip()

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
s.append(10000000000)
for i in range(q):
    l = 0
    r = n + 1
    while r - l > 1:
        m = (l + r) // 2
        if s[m] > t[i]:
            r = m
        else:
            l = m
    if r > 0 and s[r - 1] == t[i]:
        ans += 1
print(ans)

Solution (Python):
n=int(input())
S=[int(i) for i in input().split()]
q=int(input())
T=[int(i) for i in input().split()]
s=0
S.append(10**10)
for i in range(q):
    l=0
    r=n+1
    while r-l>1:
        m=(l+r)//2
        if S[m]>T[i]:
            r=m
        else:
            l=m
    if S[l]==T[i]:
        s+=1    
print(s)

Solution (Python):
def main():
    N = int(input())
    S = sorted([int(_) for _ in input().split()])
    Q = int(input())
    T = sorted([int(_) for _ in input().split()])

    ans = 0

    for t in T:
        left = 0
        right = len(S) - 1

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

            if left > right:
                break

    print(ans)

main()

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

print(count)

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


N1 = int(input())
arr1 = [int(n) for n in input().split()]
N2 = int(input())
arr2 = [int(n) for n in input().split()]

print(sum([binarySearch(key, arr1, N1) for key in arr2]))

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

print(count)

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


N1 = int(input())
arr1 = [int(n) for n in input().split()]
N2 = int(input())
arr2 = [int(n) for n in input().split()]

print(sum([binarySearch(key, arr1, N1) for key in arr2]))

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


N1 = int(input())
arr1 = [int(n) for n in input().split()]
N2 = int(input())
arr2 = [int(n) for n in input().split()]

print(sum([binarySearch(key, arr1, N1) for key in arr2]))

Solution (Python):


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


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

for j in range(q):
    if T[j] in S1:
        count+=1
    
        
print(count)

Solution (Python):
import math
a = int(input())
listA = list(map(int, input().split()))

b = int(input())
listB = list(map(int, input().split()))

count = 0
for i in range(b):
    key = listB[i]
    left = 0
    right = a
    while left < right:
        mid = math.floor((left+right)/2)
        if listA[mid] == key:
            count += 1
            break
        elif key < listA[mid]:
            right = mid
        else:
            left = mid + 1

print(count)

Solution (Python):


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

Solution (Python):
N = int(input())
L = input().split()
L = [int(s) for s in L]
n = int(input())
l = input().split()
l = [int(s) for s in l]
ans = 0
for i in range(n):
    j = 0
    k = N-1
    while(1):
    
        a =  int((j + k)/2)
        if l[i] == L[a] or l[i] ==L[j] or l[i] ==L[k]:
            ans += 1
            break
        elif k == j+1:
            break
        elif l[i] > L[a]:
            j = a
        elif l[i] < L[a]:
            k = a
        
        
print(ans)

Solution (Python):
from bisect import bisect_left

n = int(input())
S = [int(t) for t in input().split()]
q = int(input())
T = [int(t) for t in input().split()]
assert n == len(S) and q == len(T)

def isin(t, S):
    i = bisect_left(S, t)
    return i < len(S) and S[i] == t

print(sum(1 for t in T if isin(t, S)))

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 sys
from sys import stdin
input = stdin.readline

n = int(input())
s = set(map(int, input().split()))
q = int(input())
t = set(map(int, input().split()))
print(len(s & t))

Solution (Python):



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

Solution (Python):
n = int(input())
S =list(map(int,input().split(" ")))
l =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):
n = input()
S = set([int(s) for s in raw_input().split()])
m = input()
T = set([int(s) for s in raw_input().split()])
print len(T & S)

Solution (Python):
def f():
    return raw_input()
def f2():
    return set(raw_input().split())

n = f()
S = f2()
q = f()
T = f2()

print len(S & T)

Solution (Python):

from __future__ import division, print_function
from sys import stdin
stdin.readline()
s = {int(s) for s in stdin.readline().split()}
stdin.readline()
s.intersection_update((int(s) for s in stdin.readline().split()))
print(len(s))

Solution (Python):



import time
import sys
import io
import re
import math
start = time.clock()
i = 0
n=input()
S=map(int, raw_input().split())
q=input()
T=map(int, raw_input().split())

print len(set(S)&set(T))

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

Solution (Python):
n = int(raw_input())
T = set(raw_input().split())
n = int(raw_input())
S = set(raw_input().split())
print len(T&S)

Solution (Python):
a = [raw_input() for i in range(4)]
print len(set(a[1].split())&set(a[3].split()))

Solution (Python):
a = [raw_input() for i in range(4)]
print len(set(a[1].split())&set(a[3].split()))

Solution (Python):
n1 = int(input())
s1 = set(map(int, input().strip().split()))
n2 = int(input())
s2 = set(map(int, input().strip().split()))
print(len(s1 & s2))

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(lis,item):
    l = 0
    r = len(lis) - 1
    while l <= r:
        mid = (l+r)//2
        guess = lis[mid]
        if guess == item:
            return 1
        if guess > item:
            r = mid -1
        else:
            l = mid + 1
    return 0
for i in T:
    ans += binary_search(S,i)
print(ans)

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

import bisect
ans=0

for t in T:
    b=bisect.bisect(S,t)
    
    if b!=0 and t==S[b-1]:
        ans+=1
print(ans)

Solution (Python):
num1 = int(input())
a1 = list(map(int,input().split()))

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

count = 0

for i in range(num2):
    left = 0
    right = num1
    
    while left < right:
        mid = int((left + right) /2)
        
        if a1[mid] == a2[i]:
            count +=1
            break
        
        elif a2[i] < a1[mid]:
            right = mid
        else:
            left = mid +1
        

print(count)

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


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


for i in T:
    if (BinarySearch(S, i)):
        c += 1

print(c)

Solution (Python):
def bisearch(x,L):
    left = 0
    right = len(L)
    
    while left < right:
        mid = (left+right)//2
        
        if L[mid] == x:
            return True
        elif L[mid] > x:
            right = mid
        else:
            left = mid + 1
    
    return False
    

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

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

Solution (Python):
def binary_search(a, tgt):
    low = 0
    high = len(a) - 1
    while low <= high:
        mid = (low + high) // 2
        cand = a[mid]
        
        if cand == tgt:
            return mid
        if cand > tgt:
            high = mid - 1
        else:
            low = mid + 1
    
    return -1

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

cnt = 0
for tgt in t:
    flag = binary_search(s, tgt)
    if flag >= 0:
        cnt += 1

print(cnt)

Solution (Python):
N = int(input())
S_L = list(map(int, input().split()))
Q = int(input())
T_L = list(map(int, input().split()))


def bisect(a_l, x):
    _l = 0
    _r = len(a_l)-1
    while _r - _l > 1:
        _c = (_l + _r)//2
        _tmp = a_l[_c]
        if _tmp == x:
            return _c
        elif _tmp > x:
            _r = _c
        else:
            _l = _c
    if a_l[_l] == x:
        return _l
    elif a_l[_r] == x:
        return _r
    else:
        return False


ans = 0
for i in range(Q):
    if bisect(S_L, T_L[i]) is not False:
        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(S, key):
    left = 0
    right = N
    while left < right:
        mid = (left + right) // 2
        if S[mid] < key:
            left = mid + 1
        elif S[mid] > key:
            right = mid
        else:
            return True
    return False
cnt = 0
for t in T:
    if binary_search(S, t):
        cnt += 1
print(cnt)

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
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())

n = I()
S = LI()
q = I()
T = LI()
ans = 0
for t in T:
    a = 0
    for i in range(1, 10 * math.ceil(math.log(2, n)) + 10):
        if S[a] == t:
            ans += 1
            break
        elif S[a] < t:
            a += math.ceil(n / pow(2, i))
            if a >= n - 1:
                a = n - 1
        else:
            a -= math.ceil(n / pow(2, i))
            if a <= 0:
                a = 0
print(ans)

Solution (Python):
from sys import stdin

def BinarySearch(x):
    l, r = 0, n
    while l < r:
        mid = (l + r) // 2
        a = x - S[mid]
        if a == 0:
            return True
        elif a > 0:
            l = mid + 1
        elif a < 0:
            r = mid
    return False

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

cnt = 0
for x in T:
    if BinarySearch(x):
        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 binarySearch(A, key, n):
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            return 1
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return 0

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

Solution (Python):
def binary_search(A, n, key):
    left = 0
    right = n
    while left < right:
        mid = int((left + right) / 2)
        if key == A[mid]:
            return True
        elif key > A[mid]:
            left = mid + 1
        elif key < A[mid]:
            right = mid
    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(S, n, t):
        ans += 1
print(ans)

Solution (Python):
import bisect

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

C = 0

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

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


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


ans = []
for j in range(q):
    if binarySearch(S, T[j]) > -1:
        ans.append(binarySearch(S, T[j]))
print(len(ans))

Solution (Python):
def binary_search(n, S, T):
    count = 0
    for t in T:
        left = 0
        right = n
        while left <= right:
            middle = (left + right)//2
            center = S[middle]
            if t == center:
                count += 1
                break
            elif t < center:
                right = middle - 1
            else:
                left = middle + 1
    return count


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

    print(binary_search(n, S, T))


if __name__ == "__main__":
    main()

Solution (Python):
_, s, _, t = [set(o.split()) for o in open(0)]
print(len(s & t))

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

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

ans = 0

def binarySearch(key,array):
    left = 0
    right = len(array)

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

        if array[mid] == key:
            return True
        else:
            if key < array[mid]:
                right = mid
            else:
                left = mid+1

    return False


for i in range(q):
    key = T[i]

    if binarySearch(key,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()))


count = 0
for t in T:
    bottom = 0
    top = n  
    while top - bottom > 0:
        middle = (top + bottom) // 2
        
        if t == S[middle]:
            count += 1
            break

        if t > S[middle]:
            bottom = middle + 1
        if t < S[middle]:
            top = middle

print(count)

Solution (Python):
from bisect import bisect_right as bisect

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

s.sort()

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

print(c)

Solution (Python):
def main():
    import sys
    import math

    asa =  sys.stdin.readline
    n = int(input())
    s = list(map(int, asa().split()))
    q = int(input())
    t = list(map(int, asa().split()))
    c = 0

    stopper = math.log2(n) + 1

    for i in t: 
        time = 0
        middle = int(n/2)
        small = 0
        large = n
        time = 0

        while s[middle] != i and time < stopper:
            if s[middle] > i:
                large = middle
                middle = int((middle + small) / 2)

            else:
                small = middle
                middle = int((middle + large) / 2)

            time += 1
        if s[middle] == i:
            c += 1

    print(c)

if __name__ == '__main__':
    main()

Solution (Python):
_, S = input(), [*map(int, input().split())]
_, T = input(), [*map(int, input().split())]

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

print(sum(binary_search(S, t) for t in T))

Solution (Python):
n=int(input())
s=list(map(int, input().split()))
s=sorted(s)
q=int(input())
t=list(map(int, input().split()))
frt=0
end=n
def src(x:list, y:int):
  frt=0
  end=len(x)-1
  while end>=frt:
    cent=(frt+end)//2
    if x[cent]==y:
      return 1
    elif x[cent]<y:
      frt=cent+1
    else:
      end=cent-1
  return 0
ans=0
for i in t:
  ans+=src(s, 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 range(q):
    t = T[i]
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if S[mid] == t:
            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 = list(map(int,input().split()))

cnt = 0
for x in t:
    l = 0
    r = n
    while l<r:
        mid = (l+r)//2
        if s[mid]!=x:
            if s[mid]<x:
                l = mid + 1
            else:
                r = mid
        else:
            cnt += 1
            break
print(cnt)

Solution (Python):


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

def binarySearch(x,lst):
    left=0
    right=(len(lst))
    while left<right:
        mid=(left+right)//2
        if lst[mid]==x:
            return True
        elif x<lst[mid]:
            right=mid
        else:
            left=mid+1
    return False
a=(list(map(lambda x:binarySearch(x,S),T)))
print(a.count(True))

Solution (Python):
N=int(input())
*S,=map(int,input().split())
Q=int(input())
*T,=map(int,input().split())






def bs(key, l):
    low=0
    high=len(l)-1 
    while low<=high: 
        mid = (low+high)//2
        if l[mid] == key:
            return True
        elif key < l[mid]: 
            high = mid-1 
        else:
            low = mid+1  
    else:
        return False
cnt=0
for i in T:
    if bs(i, S):
        cnt+=1
print(cnt)

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


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

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

count = 0
for key in T:
    if BinarySearch(S,key):
        count += 1
print(count)

Solution (Python):
import sys

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


n = inp()
S = inpl()
q = inp()
T = inpl()

S.sort()
T.sort()



def binary_search(num):
    left = 0
    right = n-1
    while right - left > 1:
        mid = (right + left) // 2
        if S[mid] >= num:
            right = mid
        else:
            left = mid
    if S[right] == num:
        return right
    else:
        return -1

def dup_count(idx):
    for i in range(idx, n-1):
        if S[idx] == S[i]:
            pass
        else:
            break
    return i - idx + 1

ans = 0
for i in T:
    idx = binary_search(i)
    if idx >= 0:
        ans += 1
        
print(ans)

Solution (Python):

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


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