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 ≤ 109

0 ≤ an element in T ≤ 109

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

Template in C
-->



Sample input:
5
1 2 3 4 5
3
3 4 1


Sample output:
3

Submission status: Accepted

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

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


resolve()

Submission status: Accepted

Solution code:
import sys


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


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


def is_bin_search(l, v):
    left = 0  # 探索範囲の左端
    right = len(l) - 1  # 探索範囲の右端
    mid = (left + right) // 2
    while left <= right:
        mid = (left + right) // 2
        if l[mid] == v:
            return True
        elif v < l[mid]:
            right = mid - 1  # 真ん中の左隣
        else:
            left = mid + 1  # 真ん中の右隣
        mid = (left + right) // 2
    return False


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

print(c)

Submission status: Accepted

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

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

c = 0

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

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

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

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

        else:
            c += 1
            break

print(c)

Submission status: Accepted

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

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


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

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
ans = 0
ansl = []
for t in T:
    l = 0
    r = n
    while l < r:
        i = (l + r)//2
#         print(l, i, r)
        if S[i] > t:
            r = i
        elif S[i] < t:
            l = i + 1
        else:
            ans += 1
            ansl.append(t)
            break
print(ans)

Submission status: Accepted

Solution code:
from typing import List


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

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


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

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

    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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


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


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
        
ans = 0
for t in T:
    if bisect.bisect_left(S, t) != bisect.bisect_right(S, t):
        ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
# ALDS1_4_B.pys

def is_ok(idx,key,target):
########## wirte criteria here ##########
    if target[idx] >= key:
        return True
    return False

def meguru_bisect(key,target):
    left = -1
    right = len(target)
    while (abs(right - left) > 1):
        mid = left + (right - left) // 2
        if is_ok(mid,key,target):
            right = mid
        else:
            left = mid
    if key == target[right]:
        return True
    return False

N = int(input())
S = list(map(int,input().split()))
q = int(input())
T = list(map(int,input().split()))
ans = 0
for i in T:
    if meguru_bisect(i,S):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=list(map(int,input().split()))
q=int(input())
t=list(map(int,input().split()))
ans=0
for i in t:
    if i<s[0] or i>s[-1]: continue 
    lo,hi=0,len(s)
    while hi-lo>1:
        mid=(lo+hi)//2
        if s[mid]<i:
            lo=mid
        else:
            hi=mid
    l=[s[hi],s[lo]]
    if i in l:
        ans+=1
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

        
print(count)

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

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

print(count)

Submission status: Accepted

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

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

    return None

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

Submission status: Accepted

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

    cnt = 0

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

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

Submission status: Accepted

Solution code:
import sys
import copy

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

  C = 0
  
  for i in range(q):
    tmp = T[i]
    L = 0
    R = n - 1
    M = n // 2

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

      M = (R + L) // 2

  print(C)

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

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

Submission status: Accepted

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


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

def binary_search(key):
    OK = N #絶対Trueになるやつ
    NG = -1 #絶対Falseになるやつ
    while abs(OK-NG)>1:
        mid = (OK+NG)//2
        if check(mid,i):
            OK = mid
        else:
            NG = mid
    return lisS[NG] == key

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

print(ans)

Submission status: Accepted

Solution code:
def binary_search(num_list, key):
    left = 0
    right = len(num_list)
    while right > left:
        mid = (left + right)//2
        if num_list[mid] == key:
            return 1
        #前半部分に答えがある
        if num_list[mid] > key:
            right = mid
        #後半部分に答えがある
        elif num_list[mid] < key:
            left = mid + 1            
    return 0
            
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
ans = 0
for i in T:
    ans += binary_search(S, i)
print(ans)

Submission status: Accepted

Solution code:
import bisect

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

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

print(c)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin

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

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

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

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import bisect

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

cnt = 0
#S.sort()
for i in T:
    index = bisect.bisect_left(S, i)
    if index >= len(S):
        continue
    if S[bisect.bisect_left(S, i)] == i:
        cnt += 1
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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



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

Submission status: Accepted

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

Submission status: Accepted

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

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

    if A[left] == q:
        return True

    else:
        return False


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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


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


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


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

Submission status: Accepted

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

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

l=S & T

print(len(l))

Submission status: Accepted

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


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

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

print(total)

Submission status: Accepted

Solution code:
#แบ่งครึ่งข้อมูลในการ search
n=int(input())
s=list(map(int,input().split()))
q=int(input())
count=0
t=list(map(int,input().split()))
for i in range(q):
	l=0
	r=n
	while r>l:
                #แบ่งข้อมูลตรงกลาง
		mid=(l+r)//2
		#ถ้ามีข้อมูลตัวนั้นในลิสข้อมูล count +=1
		if s[mid]==t[i]: 
			count+=1
			break
		#ขยับไปตัวซ้ายถัดไป
		elif s[mid]>t[i]:
			r=mid
                #ขยับไปตัวขวาถัดไป			
		else:
			l=mid+1
print(count)

Submission status: Accepted

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

print(len(S & T))

Submission status: Accepted

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

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

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

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

    return False

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

print(answer)

Submission status: Accepted

Solution code:
from bisect import bisect_left
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
cnt = 0
for t in T:
    id = bisect_left(S, t)
    if S[id] == t:
        cnt += 1

print(cnt)

Submission status: Accepted

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


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

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

print(total)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import deque
import sys
import math

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

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

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

Submission status: Accepted

Solution code:
from bisect import bisect_right, bisect_left

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

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

Submission status: Accepted

Solution code:
def binarySearch(N, S, T):
	cnt = 0  # 一致した数
	left = 0  # 左端
	#	right = N - 1  # 右端
	right = N # 右端
	mid = (left + right) // 2
	while left < right:
#		print('{0} {1} {2} {3}'.format(T, left, right, mid))
		if S[mid] == T:
			cnt = cnt + 1
			return cnt
			# 両隣が一致するかのチェック
			# まずは左
#			temp = 1
#			while mid - temp >= left:
#				if S[mid - temp] == T:
#					cnt = cnt + 1
#				else:
#					break
#				temp = temp + 1
#			# つぎは右
#			temp = 1
#			while mid + temp <= right - 1:
#				if S[mid + temp] == T:
#					cnt = cnt + 1
#				else:
#					break
#				temp = temp + 1
#			return cnt
		elif S[mid] > T:
			left = left
			right = mid
			mid =  (left + right) // 2
		elif S[mid] < T:
			left = mid + 1
			right = right
			mid =  (left + right) // 2
	#		if left == right - 1:
	#			break

	return cnt


n = int(input())  # 8
s = list(map(int, input().split()))  # 1 2 3 4 5 6 7 8
q = int(input())  # 5
t = list(map(int, input().split()))  # 1 2 3 4 5
sum = 0

for i in t:
	sum = sum + binarySearch(n, s, i)
	#	print(n)
	#	print(s)
#	print(' {0} {1}'.format(i, binarySearch(n, s, i)))
print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# ALDS_4_B - 二分探索

import sys

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


def search(i, S):  # i は探索対象 S : 探索する数列
    if S[0] > i:
        return False
    if S[-1] == i:
        return True

    left = 0
    right = len(S) - 1

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

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


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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

# print(n,q)
# print(S_list)
# print(T_list)

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

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

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

    return False

# 重複した要素を削除
S_set = sorted(set(S_list))
# print(S_set)

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

print(cnt)

Submission status: Accepted

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

import bisect
ans = 0

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

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

print(len(s&t))

Submission status: Accepted

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


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

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


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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

    return False

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# 2分探索


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

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

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

    return 1


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

    total = 0

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

    print(total)

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

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

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

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

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import bisect

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

print(count)

Submission status: Accepted

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


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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s_lis = list(map(int, input().split()))
    q = int(input())
    t_lis = list(map(int, input().split()))
    #print(s_lis, t_lis)
    ans = 0

    for t in t_lis:
        low = 0
        high = len(s_lis) - 1
        
        while low <= high:
            mid = (low + high) // 2
            guess = s_lis[mid]
            #print(t, guess)
            if guess == t:
                ans += 1
                break
            elif guess > t:
                high = mid -1
            else:
                low = mid + 1

    print(ans)






if __name__ == "__main__":
    main()