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:
from typing import  Any, Sequence

def binarySearch(A: Sequence, Key: int) -> int:
    global cnt
    left = 0
    right = len(A)
    while True:
        mid = (left + right) // 2
        if A[mid] == Key:
            cnt += 1
            return cnt
        elif A[mid] < Key:
            left = mid + 1
        else:
            right = mid - 1
        if left > right:
            break
    return  0

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

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

cnt = 0

for i in T:

    binarySearch(S, i)

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()))
C = 0

for t in T:
    start = 0
    end = n
    while start < end:
        half = (start + end) // 2
        if t == S[half]:
            C += 1
            break
        elif t < S[half]:
            end = half
        else:
            start = half + 1
        
print(C)

Submission status: Accepted

Solution code:
from sys import stdin

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

def main():
    n = stdin.readline()
    s = list(map(int, stdin.readline().split()))
    q = stdin.readline()
    t = list(map(int, stdin.readline().split()))
    print(sum([1 for v in t if binarySearch(s, v)]))
        
main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def Search2(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

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

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

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()))
cou = 0
def find(x,a):
  #xにリスト,aに値　あったら1なかったら0
  k = bisect_left(x,a)
  if k!= len(x) and x[k]==a:
    return 1
  else:
    return 0
  
for i in t:
  cou += find(s,i)
print(cou)

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
for i in t:
    if s[bisect.bisect_left(s, i)] == i:
        cnt += 1
print(cnt)

Submission status: Accepted

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

ans = 0
for i in range(len(t)):
    low = 0
    high = len(q) - 1
    item = t[i]

    while low <= high:
        mid = (low + high) //2
        guess = q[mid]
        if guess == item:
            break
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    
    if q[mid] == t[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 binary_search(S, t):
    l = 0
    r = len(S)
    mid = (l+r)//2
    if S[l] == t or S[r-1] == t:
        return True
    while r - mid > 0 and l - mid < 0:
        if S[mid] == t:
            return True
        if S[mid] <= t:
            l = mid
            mid = (l+r)//2
        else:
            r = mid
            mid = (l+r)//2

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

print(cnt)

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
for ti in t:
    x = bisect.bisect_left(s, ti)
    if x < n and s[x] == ti:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
n = I()
S = LI()
q = I()
T = LI()
ans = 0
def is_ok(i):
    return x>=S[i]
def binarysearch(x):
    ok,ng = -1,n
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return S[max(ok,0)]
for x in T:
    if x==binarysearch(x):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B&lang=ja
# 二分探索を用いた解法
from bisect import bisect_left as bil

N = int(input())
*S, = map(int, input().split())
q = int(input())
*T, = map(int, input().split())

ans = 0
for t in T:
    l = bil(S, t)
    if S[l] == t:
        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 binarySearch(key):
  left = 0
  right = n

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

cnt = 0
for t in T:
  idx = binarySearch(t)
  if idx != 'Not Found':
    cnt += 1
    
print(cnt)

Submission status: Accepted

Solution code:
def bin_search(num, array):
    low = 0
    high = len(array) - 1

    while low <= high:
        mid = (low + high) // 2
        # print(mid)
        if array[mid] == num:
            return mid
        
        elif array[mid] > num:
            high = mid - 1
        
        elif array[mid] < num:
            low = mid + 1
    
    return -1

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

ans = 0
for i in T:
    # print("i = ",i)
    if bin_search(i, S) != -1:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
S = list(map(int,readline().rstrip().split()))
Q = int(readline())
T = list(map(int,readline().rstrip().split()))
cnt = 0
for i in range(Q):
    low = 0
    high = N-1
    while low <= high:
        mid = (low+high)//2
        guess = S[mid]
        if T[i] == guess:
            cnt += 1
            break
        elif T[i] < S[mid]:
            high = mid-1
        else:
            low = mid+1
print(cnt)

Submission status: Accepted

Solution code:
def binarySearch(l, key):
    left = 0
    right = len(l)
    while left < right:
        mid = (left + right) // 2
        if key == l[mid]:
            return True 
            
        if key < l[mid]:
            right = mid 
        else:
            left = mid + 1
    return False
    
input()
S = list(map(int, input().split()))
input()
T = map(int, input().split())

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

print(count)

Submission status: Accepted

Solution code:
import bisect

def binarySearch(lis, snum):
    a = bisect.bisect_left(lis, snum)
    if a == len(lis):
        return -1
    if not lis[a] == snum:
        return -1
    return a

n = int(input())
s = [int(_) for _ in input().split()]
q = int(input())
t = [int(_) for _ in input().split()]

ans = 0
for i in range(q):
    if binarySearch(s, t[i]) >= 0:
        ans += 1
    else:
        pass
print(ans)

Submission status: Accepted

Solution code:
cin = open(0).read().strip().split('\n')
n = int(cin[0])
s = list(map(int, cin[1].split(' ')))
q = int(cin[2])
t = list(map(int, cin[3].split(' ')))

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

    return None

ret = 0
for i in t:
    if binary_search(s, i) is not None:
        ret += 1

print(ret)

Submission status: Accepted

Solution code:
def solve():
    import bisect

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

    S = set(S)
    T = set(T)
    C = 0
    for s in S:
        if s in T:
            C += 1
    print(C)





if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import math
n = int(input())
s = []
s = input().split()
s = list(map(int,s))
q = int(input())
t = []
t = input().split()
t = list(map(int,t))
cnt = 0

def binalySearch(s,key):
    first = 0
    last = n
    while first < last:
        dist = math.floor((last + first)/2)
        if s[dist] == key:
            return 1
        elif key < s[dist]:
            last = dist
        else:
            first = dist + 1
    return 0

for i in range(q):
    cnt = cnt + binalySearch(s,t[i])


print(cnt)

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:
  x=bisect.bisect_left(S,t)
  if S[x]==t:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces


def BinarySearch(num, nums):
    if len(nums) == 0:
        print("Erorr : list has no element")
        return
    left,right = 0,len(nums)
    while left < right:
        mid  = (left+right)//2
        if num < nums[mid]:
            right = mid
        else:
            left = mid + 1
    return right


def main():
    n = ni()
    s = na()
    q = ni()
    t = na()
    ans = 0
    for ti in t:
        if ti == s[BinarySearch(ti, s)-1]:
            ans += 1
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
n = int(input())
li_s = list(map(int, input().split()))
q = int(input())
li_t = list(map(int, input().split()))
li_s.sort()
ans = 0
for i in li_t:
    left = bisect_left(li_s, i)
    right = bisect_right(li_s, i)
    k = right - left
    if k >= 1:
        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 range(q):
    bot = -1
    top = n
    x = t[i]
    while top - bot > 1:
        mid = (top+bot)//2
        if s[mid] >= x:top = mid
        else:bot = mid
    if top < n and s[top] == x:ans += 1
print(ans)

Submission status: Accepted

Solution code:
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()))

cnt = 0
for j in range(q):
    if binarySearch(S,T[j]):
        cnt += 1
        continue

print(str(cnt))

Submission status: Accepted

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

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
cnt = 0
for i in T:
  if type(binarySearch(S, i)) == int:
    cnt += 1
print(cnt)

Submission status: Accepted

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

counter=[]
for i in range(q):
    left,right=0,len(S)
    while left<right:
        mid=math.floor((left+right)/2)
        if T[i]==S[mid]:
            counter.append(T[i])
            break
        elif S[mid]<T[i]:
            left=mid+1
        elif T[i]<S[mid]:
            right=mid
            
print(len(set(counter)))

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 range(q):
    L = 0
    R = n
    key = T[i]
    while R-L >= 1:
        i = int((L+R)/2)
        if S[i] == key:
            ans += 1
            break
        elif  S[i] > key:
            R = i
        else:
            L = i+1

print(ans)

Submission status: Accepted

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

cnt = 0
for i in T:
    left = 0
    right = len(S) - 1
    while left < right:
        mid = (left + right) // 2
        #print(i, S[mid], S[left:right+1])
        if i == S[mid]:
            cnt += 1
            #print('found!')
            break
        elif i < S[mid]:
            if i < S[left]:
                break
            elif i == S[left]:
                cnt += 1
                break
            else:
                right = mid - 1
        else:
            if i > S[right]:
                break
            elif i == S[right]:
                cnt += 1
                break
            else:
                left = mid + 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
for x in t:
    low,up = 0,n
    while up - low > 1:
        mid = (up + low) // 2
        if s[mid] <= x:
            low = mid
        else:
            up = mid
    ans += (x == s[low])
print(ans)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline

def main():
    n = int(input())
    S = list(map(int, readline().split()))
    q = int(input())
    T = list(map(int, readline().split()))
    ans = 0
    for i in range(q):
        target = T[i]
        upper = len(S)-1
        lower = 0
        middle = (upper + lower) // 2
        while lower <= upper:
            if target == S[middle]:
                ans += 1
                break
            elif target < S[middle]:
                upper = middle - 1
            else:
                lower = middle + 1
            middle = (upper + lower) // 2

    print(ans)        


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

ctr = 0
for i in range(q):
    ctr += binarySearch(T[i],n,S)
        
        
print(ctr)

Submission status: Accepted

Solution code:
from bisect import bisect_right

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

ans = 0
for i in range(Q):
  x = bisect_right(S, T[i])
  if(S[x-1] == T[i]):
    ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
import math

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

q = int(input())
T = list(map(int,input().split()))
result= []
#print(T)
i = 0
right = 0
left = len(S)
for i in range(q):
    right = 0
    left = len(S)
    #print(result)
    while right<left:
        mid = (left+right)/2
        mid = math.floor(mid)
        if S[mid] == T[i]:
            result.append(T[i])
            break
        elif S[mid]<T[i]:
            right = mid+1
        else:
            left = mid
print(len(result))

Submission status: Accepted

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

def binary_search(a, key):
  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 None

count = 0

for key in t:
  if binary_search(s, key) != None:
    count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n = int(sys.stdin.readline()[:-1])
S = [int(x) for x in (sys.stdin.readline()[:-1].split())]
q = int(sys.stdin.readline()[:-1])
T = [int(x) for x in (sys.stdin.readline()[:-1].split())]

count = 0
for t in T:
    l = 0
    h = n - 1
    while l <= h:
        half = (h + l) // 2
        if S[half] == t:
            count += 1
            break
        elif S[half] < t:
            l = half + 1
        else:
            h = half - 1

print(count)

Submission status: Accepted

Solution code:
import math
n = int(input())
s = input().split()
q = input()
t = input().split()
cnt = 0
for x in t:
    left = 0
    right = n
    while (left < right):
        mid = math.floor((left + right) / 2)
        if s[mid] == x:
            cnt += 1
            break
        elif int(x) < int(s[mid]):
            right = mid
        else:
            left = mid + 1
print(cnt)

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

S.sort() # 昇順にソート

# binaryserch
def binarySearch(A, key):
	left, right = 0, 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

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

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = sorted([int(s) for s in input().split()])
Q = int(input())
T = sorted([int(t) for t in input().split()])

cnt = 0
for t in T:
    left = 0
    right = len(S)
    while left < right:
        mid = int((left + right) / 2)
        if t < S[mid]:
            right = mid
        elif S[mid] < t:
            left = mid + 1
        elif t == S[mid]:
            cnt += 1
            break

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(' ')))
r = 0

S.sort()


def binary_search(S, left, right, t):
    m = (left + right) // 2
    if S[m] == t:
        return True
    if left >= right:
        return False
    if S[m] > t:
        return binary_search(S, left, m, t)
    else:
        return binary_search(S, m + 1, right, t)


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

print(r)

Submission status: Accepted

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

def bin_search(t):
    l=0
    r=n-1
    if S[r]==t:
        return 1
    else:
        while r-l > 1:
            m=(l+r)//2
            if S[m] > t:
                r=m
            else:
                l=m
        if S[l] == t:
            return 1
        else:
            return 0
cnt=0
for t in T:
    cnt += bin_search(t)

print(cnt)

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()]
#print(s)
c=0
for i in t:
    if i in s:
        c+=1
print(c)
"""
n=int(input())
s=[int(x) for x in input().split()]
q=int(input())
t=[int(x) for x in input().split()]
#binary search
a=0
for i in range(q):
    L=0
    R=n-1#探索する方の配列(s)はソート済みでないといけない
    while L<=R:
        M=(L+R)//2
        if s[M]<t[i]:
            L=M+1
        elif s[M]>t[i]:
            R=M-1
        else:
            a+=1
            break
print(a)

Submission status: Accepted

Solution code:
n = int(input())
s = sorted(list(map(int,input().split())))
q = int(input())
t = list(map(int,input().split()))
c = 0
import bisect
for i in t:
    ind = bisect.bisect_left(s,i)
    if ind<n and s[ind]==i:
        c += 1
print(c)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
def main():
    n = int(readline())
    s = set([int(i) for i in readline().split()])
    q = int(readline())
    t = [int(i) for i in readline().split()]
    ans = 0
    for i in t:
        if i in s:
            ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect as bs
def find(x):
    n = bs.bisect_left(S,x)
    if n != len(S) and x == S[n]: return True
    else: return False

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):
    if find(T[i]): ans += 1
print(ans)

Submission status: Accepted

Solution code:
# 二分探索
# ALDS1_4_B

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


def binarySearch(t, S, n1, n2):
    ret = False
    n3 = n1 + int((n2 - n1)/2)
    if n3 >= len(S) or n2 < n1:
        return False
    elif t == S[n3]:
        return True
    elif n1 == n2:
        return False
    elif t > S[n3]:
        ret = binarySearch(t, S, n3 + 1, n2)
    elif t < S[n3]:
        ret = binarySearch(t, S, n1, n3 - 1)
    return ret


cnt = 0
for t in T:
    if binarySearch(t, S, 0, len(S) - 1):
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

# 遅い
def rec_binary_search(x, ss):
    len_s = len(ss)
    half = len_s // 2
    if len_s <= 10:
        return int(x in ss)
    if x < ss[half]:
        ss = ss[:half]
    else:
        ss = ss[half:]
    return rec_binary_search(x, ss)

def binary_search(x, ss):
    L = 0
    R = len(ss)
    half = (L+R) // 2
    while L<=R:
        if R-L < 2:
            return int(x in ss[L:R+1])
        if x < ss[half]:
            R = half-1
        elif x > ss[half]:
            L = half + 1
        else:
            return 1
        half = (L+R) // 2

n = int(input())
ss = list(map(int, input().split()))
m = int(input())
ts = list(map(int, input().split()))

ans = 0
for x in ts:
    ans += binary_search(x, ss)

print(ans)

Submission status: Accepted

Solution code:
import math

def binary_search(l, key):
    n = len(l)
    minindex = 0
    maxindex = n

    while minindex < maxindex:
        halfindex = math.floor(minindex + (maxindex - minindex) / 2)
        if key == l[halfindex]:
            return True
        elif key > l[halfindex]:
            minindex = halfindex + 1
        elif key < l[halfindex]:
            maxindex = halfindex

    return False


if __name__ == "__main__":
    import sys
    input = sys.stdin.readline # faster input

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

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

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

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 i in T:
    if s[bisect_left(s,i)]==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()))

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 True
        if guess > item:
            high = mid - 1
        else:
            low = mid + 1
    return False

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

S.sort()

cnt = 0
for t in T:
    b = bisect.bisect_left(S, t)
    if S[b] == t:
        cnt += 1

print(cnt)

Submission status: Accepted

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

T.sort()
# print(T)
count = 0

S = set(S)
for s in S:
    # print(s)
    high = len(T) - 1
    low = 0
    while high >= low:
        mid = (high + low) //2
        # print(mid,high,low,s)
        if T[mid] ==  s:
            count += 1
            break
        elif T[mid] > s:
            high = mid -1
        else:
            low = mid +1

print(count)

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 range(q):
    tmp=bisect.bisect_left(s,t[i])
    if s[tmp]==t[i]:
        ans+=1

print(ans)

Submission status: Accepted

Solution code:
s_num = int(input())
s_list = list(map(int,input().split()))
q_num = int(input())
q_list = list(map(int,input().split()))



def binary_search(A,x):

    low = 0
    high = len(A)
    mid = len(A)//2

    while 1:
        if low > high: return False
        if A[mid] == x: return True
        elif A[mid] > x: high = mid-1
        elif A[mid] < x: low = mid + 1
        mid = (low+high) //2

count = 0
for x in q_list:
    if binary_search(s_list,x):
        count += 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int,input().split()))
s = set(s)
q = int(input())
t = list(map(int,input().split()))
ans = 0
for i in t:
    if i in s:
        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()))
c = 0

for i in T:
  if i in S:
    c += 1
    
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()))

ans = 0
for i in t:
    ind = bisect.bisect_left(s, i)
    if ind<n and s[ind]==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()))

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

Submission status: Accepted

Solution code:
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]
    L = 0
    R = len(S)-1
    mid = (L+R) // 2

    while L <= R:
        if S[mid] == key:
            cnt += 1
            break
        elif S[mid] > key:
            R = mid - 1
        elif S[mid] < key:
            L = mid + 1
        mid = (L+R) // 2

print(cnt)

Submission status: Accepted

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

count = 0
for i in 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)

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

ans = 0
for key in T:
    ans+=binary_search(S,key)
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()))

cnt = 0

def binary_search(S, n):
    high = len(S)-1
    low = 0
    
    while(high >= low):
        mid = (high+low)//2
        if(S[mid] == n):
            return mid
        elif(S[mid] < n):
            low = mid+1
        else:
            high = mid -1
    return False
    
for i in range(q):
    if(binary_search(S, T[i])):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
def bs(a,s):
    l = 0
    r = len(s)
    while l < r:
        m = (l+r)//2
        if s[m] == a:
            return True
        elif s[m] > a:
            r = m
        else:
            l = m + 1
    return False

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

ans = 0
for x in X:
    if bs(x,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()))


def search(a, X):
  l = 0
  r = len(X) 
  while l < r:
    m = (l + r ) // 2
    if a == X[m]:
      return m
    elif a > X[m]:
      l = m + 1
    elif a < X[m]:
      r = m
  return None
    

s = 0
for t in T:
  if search(t,S) is not None:
    s += 1
print(s)

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

def solve(x):
    l = 0
    r = n - 1
    while l <= r:
        mid = (l + r) // 2
        # print(S[mid], n)
        if S[mid] == x:
            return True
        if S[mid] < x:
            l = mid + 1
        else:
            r = mid - 1

    return False

for i in range(q):
    if solve(T[i]):
        # print(T[i])
        ans += 1

print(ans)