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:
import sys

n = input()
s = set([x for x in sys.stdin.readline().split()])
q = input()
t = set([x for x in sys.stdin.readline().split()])
print(len(s & t))

Submission status: Accepted

Solution code:
import sys

input()
s = set([x for x in sys.stdin.readline().split()])
input()
t = set([x for x in sys.stdin.readline().split()])
print(len(s & t))

Submission status: Accepted

Solution code:
def find(target, list):
  l = 0
  r = len(list)-1
  while l < r:
    m = (l + r) / 2
    if list[m] == target:
      return 1
    if target < list[m]:
      r = m
    else:
      l = m + 1
  if list[l] == target:
    return 1
  else:
    return 0

n = int(raw_input())
S = map(int, raw_input().split())
q = int(raw_input())
T = map(int, raw_input().split())
count = 0
for i in xrange(q):
  count += find(T[i], S)
print count

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 as ma

def bs(num, li):
    low, high = 0, len(li)
    if num >= li[low] and num <= li[high-1]:
        while(low <= high):
            center = ma.floor((low + high)/2 )
            if li[center] < num:
                low = center + 1
            elif li[center] > num:
                high = center -1
            else:
                return True
                break

flag = False
cnt = 0

n = int(input())
li1 = list(map(int, input().split()))
m = int(input())
li2 = list(map(int, input().split()))

for i in li2:
    flag = bs(i, li1)
    if flag:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# ALDS1 : Binary Search

def binary_search(S,t,imin,imax):
    if imin>imax:
        return 0
    else:
        imid = imin + (imax - imin)/2
        if S[imid] > t:
            return binary_search(S,t,imin,imid-1)
        elif S[imid]<t:
            return binary_search(S,t,imid+1,imax)
        else:
            return 1

def main():
    n = input()
    S = map(int,raw_input().split())
    q = input()
    T = map(int,raw_input().split())
    ans = 0
    for t in T:
        ans += binary_search(S,t,0,len(S))
    print ans

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
input()
slist = map(int, raw_input().split())
input()
tlist = map(int, raw_input().split())

def func(v, low, high):

    # print "l h = %d %d" % (low, high)
    if low > high:
        return 0

    mid = (low + high)/2
    
    # print "mid %d" % mid
    
    if mid >= len(slist):
        # print "test1"
        return 0
    
    if v > slist[mid]:
        if low == high:
            # print "test2"
            return 0
        # print "test3"
        return func(v, mid+1, high)
        
    elif v == slist[mid]:
        # print "test4"
        return 1
    else:
        if low == high:
            # print "test5"
            return 0

        # print "test6 %d %d" % (v, slist[mid])
        return func(v, low, mid-1)

count = 0
for t in tlist:
    count += func(t, 0, len(slist)-1)
print count

Submission status: Accepted

Solution code:
#coding:UTF-8
def BS(n,S,q,T):
    count=0
    for i in range(q):
        left=0
        right=n
        while left < right:
            mid=int((left+right)/2)
            if S[mid]==T[i]:
                count+=1
                break
            elif T[i]<S[mid]:
                right=mid
            else:
                left=mid+1
        
    print(count)
  
if __name__=="__main__":
    n=int(input())
    S=input().split(" ")
    for i in range(n):
        S[i]=int(S[i])
    q=int(input())
    T=input().split(" ")
    for i in range(q):
        T[i]=int(T[i])
    BS(n,S,q,T)

Submission status: Accepted

Solution code:
# encoding: utf-8


import sys


class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        length_1 = int(self.__input[0])
        array_1 = list(map(int, self.__input[1].split()))
        length_2 = int(self.__input[2])
        array_2 = list(map(int, self.__input[3].split()))

        # assert length_1 == len(array_1) and length_2 == len(array_2)

        count = 0

        for each in array_2:
            if self.binary_search(key=each, array=array_1, array_length=length_1):
                count += 1

        return str(count)

    @staticmethod
    def binary_search(key, array, array_length):
        # print(len(set(array_1).intersection(set(array_2))))
        left, right = 0, array_length
        while left < right:
            mid = (left + right) // 2
            if key == array[mid]:
                return True
            elif key < array[mid]:
                right = mid
            else:
                left = mid + 1
                # return False


if __name__ == '__main__':
    case = Solution()
    print(case.solution)

Submission status: Accepted

Solution code:
# encoding: utf-8


import sys


class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        length_1 = int(self.__input[0])
        array_1 = list(map(int, self.__input[1].split()))
        length_2 = int(self.__input[2])
        array_2 = list(map(int, self.__input[3].split()))

        assert length_1 == len(array_1) and length_2 == len(array_2)

        count = 0

        for each in array_2:
            if self.binary_search(key=each, array=array_1, array_length=length_1):
                count += 1

        return str(count)

    @staticmethod
    def binary_search(key, array, array_length):
        # print(len(set(array_1).intersection(set(array_2))))
        left, right = 0, array_length
        while left < right:
            mid = (left + right) // 2
            if key == array[mid]:
                return True
            elif key < array[mid]:
                right = mid
            else:
                left = mid + 1
        return False


if __name__ == '__main__':
    case = Solution()
    print(case.solution)

Submission status: Accepted

Solution code:

def binary_search_internal(l, r, k, S):
    if l > r:
        return None
    center = (l + r) // 2
    v = S[center]
    if v == k:
        return center
    elif v < k:
        return binary_search_internal(center + 1, r, k, S)
    else:
        return binary_search_internal(l, center - 1, k, S)

def binary_search(k, S):
    return binary_search_internal(0, len(S) - 1, k, S)

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

count = 0
for k in Q:
    index = binary_search(k, S)
    if index != None:
        count += 1

print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
#-*- coding:utf-8 -*-

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

def main():
	Ns = int(raw_input())
	S  = map(int, raw_input().split())
	Nt = int(raw_input())
	T  = map(int, raw_input().split())
	
	total_v = 0
	for key in T:
		if binarySearch(S,key):
			total_v += 1

	print total_v
			
	

#def test():

if __name__ == '__main__':
	main()
	#test()

Submission status: Accepted

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B&lang=jp
#????????¢?´¢
#???????????§???????????°????????????????????¢?????´????????????????????????????????¢?????´???????????¨????????????????????????
def binary_search(list_1, list_2):
    count = 0

    for b in list_2:
        left_index = 0
        right_index = len(list_1)
        
        while left_index < right_index:
            center = int((left_index + right_index) / 2)
            if list_1[center] == b:
                count += 1
                break
            elif b < list_1[center]:
                right_index = center
            elif b > list_1[center]:
                left_index = center + 1
                
    return count

if __name__ == "__main__":
    n_listA = int(input())
    a = sorted(set([n for n in input().split()]))
    n_listB = int(input())
    b = [n for n in input().split()]
    print(binary_search(a,b))

Submission status: Accepted

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B&lang=jp
#????????¢?´¢
#???????????§???????????°????????????????????¢?????´????????????????????????????????¢?????´???????????¨????????????????????????
def binary_search(list_1, list_2):
    count = 0

    for b in list_2:
        left_index = 0
        right_index = len(list_1)
        
        while left_index < right_index:
            center = int((left_index + right_index) / 2)
            if list_1[center] == b:
                count += 1
                break
            elif b < list_1[center]:
                right_index = center
            elif b > list_1[center]:
                left_index = center + 1
                
    return count

if __name__ == "__main__":
    n_listA = int(input())
    a = sorted(set([n for n in input().split()]))
    n_listB = int(input())
    b = set([n for n in input().split()])
    print(binary_search(a,b))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    # ??????????????\???
    S_size = int(input())
    S = set([int(x) for x in input().split(' ')])
    T_size = int(input())
    T = set([int(x) for x in input().split(' ')])
    # S = [1, 2, 3, 4, 5, 1]
    # T = set([3, 4, 1])

    # ????????????
    U = S.intersection(T)

    # ???????????????
    print('{0}'.format(len(U)))

Submission status: Accepted

Solution code:
from bisect import bisect_left



def index(a, x):
    ''' Locate the leftmost value exactly equal to x
    http: // docs.python.jp / 3.5 / library / bisect.html
    '''
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError


if __name__ == '__main__':
    # ??????????????\???
    # S = [1, 2, 3, 4, 5]
    # T = [3, 4, 1]
    num = int(input())
    S = [int(x) for x in input().split(' ')]
    num = int(input())
    T = [int(x) for x in input().split(' ')]

    # ????´¢??????
    found = 0
    for t in T:
        try:
            index(S, t)
        except ValueError:
            pass
        else:
            found += 1

    # ???????????????
    print(found)

Submission status: Accepted

Solution code:
from bisect import bisect_left
#from functools import lru_cache

#@lru_cache(maxsize=None)
def index(a, x):
    ''' Locate the leftmost value exactly equal to x
    http: // docs.python.jp / 3.5 / library / bisect.html
    '''
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError


if __name__ == '__main__':
    # ??????????????\???
    # S = [1, 2, 3, 4, 5]
    # T = [3, 4, 1]
    num = int(input())
    S = tuple(int(x) for x in input().split(' '))
    num = int(input())
    T = [int(x) for x in input().split(' ')]

    # ????´¢??????
    found = 0
    for t in T:
        try:
            index(S, t)
        except ValueError:
            pass
        else:
            found += 1

    # ???????????????
    print(found)

Submission status: Accepted

Solution code:
n = input()
S = set(map(int, input().split()))
q = 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:
# coding: utf-8

n = int(input())
s = tuple(map(int, input().rstrip().split()))
q = int(input())
t = tuple(map(int, input().rstrip().split()))
# print("s:",s)
count = 0

def binary_search(array, value):
    ''' array must be sorted'''
    # print("value:{}".format(value))
    size = len(array)
    start = 0
    end = size - 1
    found = False
    while True:
        middle = (start + end)//2
        # print("s:{0}, e:{1}, m:{2}".format(start, end, middle))
        v = array[middle]
        if v == value:
            # print("v[{}]={} == {}".format(middle, v, value))
            return True
        elif start == end:
            # print("s:{} == e:{}".format(start, end)) 
            return False
        elif v > value:
            # print("v[{}]={} > {}".format(middle, v, value))
            end = middle
        elif v < value:
            # print("v[{}]={} < {}".format(middle, v, value))
            start = middle + 1

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

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

''' ????????¢?´¢ '''

# n??????????´??????????????????????q????????¢?´¢????????£?????´???
# ?¨??????????O(qlogn)


def binary_search(key, A):
    imin, imax = 0, len(S)

    while imin < imax:
        mid = int((imin + imax) / 2)
        if A[mid] == key:
            return True
        elif key < A[mid]:
            imax = mid
        else:
            imin = mid + 1
    return False


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

    count = 0

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

Submission status: Accepted

Solution code:
def binarySearch(l, v):
    stt = 0
    end = len(l)
    while stt < end:
        mid = (stt + end) // 2
        lmid = l[mid]
        if lmid == v:
            return mid
        if lmid > v:
            end = mid
        else:
            stt = mid + 1
    raise ValueError

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

ans = 0
for t in T:
    try:
        binarySearch(S, t)
        ans += 1
    except ValueError:
        pass

print ans

Submission status: Accepted

Solution code:
import math

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

n = int(input())
S = [int(x) for i, x in enumerate(input().split()) if i < n]
q = int(input())
T = [int(x) for i, x in enumerate(input().split()) if i < q]
count = 0
for key in T:
    if binary_search(S, key) > -1:
        count += 1
print(count)

Submission status: Accepted

Solution code:

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

ans=len(set(s)&set(t))

print(ans)

Submission status: Accepted

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

n = int(input())
L = list(map(int, input().split()))
q = int(input())
Key = list(map(int, input().split()))
cnt = 0

for i in range(q):
    if binarySearch(L, n, Key[i]):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
def binary_search(v, arr, s, e):
  if s > e: return False
  m = (e - s) // 2 + s
  if arr[m] == v: return True
  elif arr[m] < v:
    return binary_search(v, arr, m + 1, e)
  else:
    return binary_search(v, arr, s, m - 1)

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 binary_search(t, S, 0, len(S) - 1):
    C += 1
print(C)

Submission status: Accepted

Solution code:

n = int(input())
S = {int(s) for s in input().split()}

q = int(input())
T = {int(t) for t in input().split()}

cnt = sum(t in S for t in T)

print(cnt)

Submission status: Accepted

Solution code:

def BinarySearch(n, S, t):
    """ ????????????????????? """
    left = 0
    right = n - 1

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

        if t > S[center]:
            left = center + 1
        elif t < S[center]:
            right = center - 1
        else:
            return center

    return -1

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

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

cnt = 0

for t in T:
    if BinarySearch(n, S, t) != -1:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import sys

def BinarySearch(S, n, t):
    bottom = 0
    top = n - 1

    while bottom <= top:
        center = (bottom + top) // 2

        if S[center] == t:
            return center
        elif S[center] < t:
            bottom = center + 1
        else:
            top = center - 1

    return -1


n = int(sys.stdin.readline())
S = [int(s) for s in sys.stdin.readline().split()]

q = int(sys.stdin.readline())
T = {int(t) for t in sys.stdin.readline().split()}

ans = sum(BinarySearch(S, n, t) != -1 for t in T)

print(ans)

Submission status: Accepted

Solution code:
def binary_search(A, n, key):
    start = 0
    end = n - 1
    while start + 1 < end:
        mid = (start + end) // 2
        if key > A[mid]:
            start = mid
        elif key < A[mid]:
            end = mid
        else:
            end = mid
    if A[start] == key:
        return True
    elif A[end] == key:
        return True
    else:
        return False

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
count = 0
for i in T:
    if binary_search(S, n, i):
        count += 1


print(count)

Submission status: Accepted

Solution code:
def main():
    input()
    a = set(input().split())
    input()
    b = set(input().split())
    print(len(a.intersection(b)))


if __name__ == "__main__":
    import os
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

count = 0
for i in T:
    if binary_search(S, i, n):
        count += 1
print(count)

Submission status: Accepted

Solution code:
def binarySearch(S, T):
    print(len(S.intersection(T)))
    
n = int(input())
S = set(map(int, input().split()))
q = int(input())
T = set(map(int, input().split()))

binarySearch(S, T)

Submission status: Accepted

Solution code:
def binarySearch():
    n = int(input())
    S = set(map(int, input().split()))
    q = int(input())
    T = set(map(int, input().split()))
    print(len(S.intersection(T)))
    

binarySearch()

Submission status: Accepted

Solution code:
def binarySearch():
    n = int(input())
    S = set(input().split())
    q = int(input())
    T = set(input().split())
    print(len(S.intersection(T)))
    

binarySearch()

Submission status: Accepted

Solution code:
def binarySearch():
    n = int(input())
    S = set(input().split())
    q = int(input())
    T = set(input().split())
    print(len(S & T))
    

binarySearch()

Submission status: Accepted

Solution code:
#!/usr/bin/python
#coding: utf-8
import re
a=raw_input()
s=set(raw_input().split())
b=raw_input()
t=set(raw_input().split())

print len(list(s&t)) if list(s&t) else 0

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
a=input().split()
input()
print(len(set(a)&set(input().split())))

Submission status: Accepted

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

sum = 0
for c in T:
    left = 0
    right = n
    mid = 0
    if c == S[left] or c == S[right-1]:
        sum += 1
    else:
        while left+1 < right:
            mid = int(( left + right ) / 2)
            if c == S[mid]:
                sum += 1
                break
            if c > S[mid]:
                left = mid
                mid = 0
            elif c < S[mid]:
                right = mid
                mid = 0
print(sum)

Submission status: Accepted

Solution code:
import sys
import bisect

def index(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	return -1


#fin = open("test.txt", "r")
fin = sys.stdin

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

ret = 0

for t in T:
	if index(S, t) >= 0:
		ret += 1

print(ret)

Submission status: Accepted

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

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

count = 0
for i in T:
    count += binarySearch(i, S)
    
print(count)

Submission status: Accepted

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

def binarySearch(a,b):
    left = 0
    right = n
    
    while left < right:
        middle = (left + right)//2
        if b[middle] == a:
            return 1
        elif b[middle] < a:
            left = middle + 1
        elif b[middle] > a:
            right = middle 
    return 0

            
for a in t:
    count += binarySearch(a, s)

print(count)

Submission status: Accepted

Solution code:
int(input())
s = set(input().split())
int(input())
t = set(input().split())
print(len(s & t))

Submission status: Accepted

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

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


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

Submission status: Accepted

Solution code:
def do_binary_search(target_value, target_list, target_list_length=None):
    if target_list_length:
        target_list_length = len(target_list)
   

    left = 0
    right = target_list_length

    while right - left > 0:
        mid = (right + left) / 2
        if target_list[mid] == target_value:
            return True
        elif target_value < target_list[mid]:
            right = mid
        else:
            left = mid + 1
    return False



def main():
    s_length = int(raw_input())
    s = [int(x) for x in raw_input().strip().split(' ')]
    t_length = raw_input()
    t = [int(x) for x in raw_input().strip().split(' ')]

    counter = 0
    for value in t:
        counter += int(do_binary_search(value, s, s_length))

    print counter 

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def do_binary_search(target_value, target_list, target_list_length=None):
    left = 0
    right = target_list_length

    while right - left > 0:
        mid = (right + left) / 2
        key = target_list[mid]
        if key == target_value:
            return True
        elif target_value < key:
            right = mid
        else:
            left = mid + 1
    return False



def main():
    s_length = int(raw_input())
    s = [int(x) for x in raw_input().strip().split(' ')]
    t_length = raw_input()
    t = [int(x) for x in raw_input().strip().split(' ')]

    counter = 0
    for value in t:
        counter += int(do_binary_search(value, s, s_length))

    print counter 

if __name__ == '__main__':
    main()

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()]
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:
            left = mid + 1 
        else:
            right = mid
print(C)

Submission status: Accepted

Solution code:
n = list(input())
sList = list(map(int, input().split()))
sList = list(set(sList))
sList.sort()

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

tCount = 0


def middle_idx(tmin, tmax):
    return int((tmin + tmax) / 2)


for tmp_t in tList:
    tmp_min = 0
    tmp_max = len(sList) - 1
    if (tmp_t >= sList[tmp_min] and tmp_t <= sList[tmp_max]):
        while ( tmp_max - tmp_min > 1 ):
            tmp_mid = middle_idx(tmp_max, tmp_min)
            if sList[tmp_mid] > tmp_t:
                tmp_max = tmp_mid
            elif sList[tmp_mid] < tmp_t:
                tmp_min = tmp_mid
            elif sList[tmp_mid] == tmp_t:
                tmp_min = tmp_max
        if(sList[tmp_max] == tmp_t or sList[tmp_min] == tmp_t or sList[tmp_mid] == tmp_t):
            tCount += 1
    else:
        pass

print(tCount)

Submission status: Accepted

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

print(len(s & t))

Submission status: Accepted

Solution code:
import math

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

cnt = 0
left = 0
right = n
for i in t:
    left = 0
    right = n
    while left < right:
        mid = math.floor((left + right) / 2)
        if s[mid] == i:
            cnt += 1
            left = right +1
        elif s[mid] > i:
            right = mid
        else:
            left = mid + 1
print(cnt)

Submission status: Accepted

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


if __name__ == "__main__":
    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):
        if binarySearch(S, n,T[i]):
            cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
S = sorted(set(list(map(int, input().split()))))
q = int(input())
T = list(map(int, input().split()))
cnt = 0
for t in T:
    l, r = 0, len(S)
    while l < r:
        m = (l+r) // 2
        if S[m] == t:
            cnt += 1
            break
        elif t < S[m]:
            r = m
        else:
            l = m+1
print(cnt)

Submission status: Accepted

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

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

ctr = 0



for i in range(Q):
	if BinarySearch(S, T[i]):
		ctr += 1

print(ctr)

Submission status: Accepted

Solution code:
# coding: utf-8

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

res = 0
for t in T:
    left = 0
    right = n # ??????1????????§??????

    while left != right:
        i = (left+right)//2
        if S[i] == t:
            res += 1
            break
        elif t < S[i]:
            right = i
        else:
            left = i+1 # ?????????????????????????????§????????????

print(res)

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
import math
n=int(input())
S=list(map(int,input().split()))

q=int(input())
T=list(map(int,input().split()))
c=0
def biSearch(key):
    left = 0
    right= n
    while left<right:
        mid = math.floor((left+right)/2)
        if S[mid]==key:
            return 1
            
        elif key<S[mid]:
            right=mid
        else:
            left=mid+1
for i in T:
    if biSearch(i):
        c+=1
print(c)

Submission status: Accepted

Solution code:
_ = int(input())
ns = [int(e) for e in input().split()]
_ = int(input())
qs = [int(e) for e in input().split()]


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


def main(ns, qs):
    total = 0
    for q in qs:
        if binary_search(q, ns):
            total += 1
    return total


print(main(ns, qs))

Submission status: Accepted

Solution code:
n = input()
S = set(input().split())
q = input()
T = set(input().split())

print(len(S&T))

Submission status: Accepted

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

#print(len(S&T))
#set:???????????????????????????

cnt = 0

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

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 = [int(x) for x in input().split()]
q = int(input())
T = [int(x) for x in input().split()]

res = 0

for key in T:
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if S[mid] == key:
            res += 1
            right = -1
        elif key < S[mid]:
            right = mid
        else:
            left = mid + 1

print(res)

Submission status: Accepted

Solution code:
c = 0
input()
s = set(input().split())
input()
t = set(input().split())
print(len(s&t))