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: Runtime Error

Solution code:
def gost(lis,ky,r,l):
    
    lens=l-r+1
    
    if lens <= 5:
        print("key = "+str(ky))
        print(lis)
        if ky in lis[r:l]:
            return True
        else:
            return False
    
    if ky <= lis[(lens//2)-1]:
        return gost(lis,ky,r,r+(lens//2))
    else:
        return gost(lis,ky,l-(lens//2),l)
    

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

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


i = 0
for it in t:
    if gost(s,it):
        i = i+1
print(i)

Submission status: Runtime Error

Solution code:
def gost(lis,ky,r,l):
    
    lens=l-r+1
    
    if lens <= 5:
        if ky in lis[r:l]:
            return True
        else:
            return False
    
    if ky <= lis[(lens//2)-1]:
        return gost(lis,ky,r,r+(lens//2))
    else:
        return gost(lis,ky,l-(lens//2),l)
    

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

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


i = 0
for it in t:
    if gost(s,it):
        i = i+1
print(i)

Submission status: Runtime Error

Solution code:
def gost(lis,ky,r,l):
    
    lens=l-r+1
    
    if lens <= 5:
        if ky in lis[r:l]:
            return True
        else:
            return False
    
    if ky <= lis[(lens//2)-1]:
        return gost(lis,ky,r,r+(lens//2))
    else:
        return gost(lis,ky,l-(lens//2),l)
    

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

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


i = 0
for it in t:
    if gost(s,it,0,int(a)-1):
        i = i+1
print(i)

Submission status: Runtime Error

Solution code:
n = input()

S = map(int, raw_input().split())

q = input()

T = map(int, raw_input().split())

S.append(0)
cnt = 0
for j in range(q):
    left = 0
    right = n
    while left < right:
        mid = (left + right) / 2
        if S[mid] == T[j]:
            cnt = cnt + 1
        else if T[j] < S[mid]:
            right = mid
        else:
            left = mid + 1

Submission status: Runtime Error

Solution code:
n = input()

S = map(int, raw_input().split())

q = input()

T = map(int, raw_input().split())

S.append(0)
cnt = 0
for j in range(q):
    left = 0
    right = n
    while left < right:
        mid = (left + right) / 2
        if S[mid] == T[j]:
            cnt = cnt + 1
        else if T[j] < S[mid]:
            right = mid
        else:
            left = mid + 1

print cnt

Submission status: Runtime Error

Solution code:
n = input()

S = map(int, raw_input().split())

q = input()

T = map(int, raw_input().split())

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

print cnt

Submission status: Runtime Error

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


# print(sum(i in s for i in t))

def binary_search(i):
    global n, s
    l, r = 0, n
    while l < r:
        m = (l + r) // 2
        sm = s[m]
        if sm == i:
            return 1
        elif i < sm:
            r = m
        else:
            l = m + 1
    return 0


print(sum(binary_search(i) for i in t))

Submission status: Runtime Error

Solution code:
def binarySearch(key, lst):
    while len(lst) != 1:
        i = len(lst) / 2
        if lst[i] > key:
            lst = lst[:i]
        elif lst[i] < key:
            lst = lst[i + 1:]
        else:
            return True

    if lst[0] == key:
        return True
    else:
        return False

if __name__ == "__main__":
    input()
    S = map(int, raw_input().split())
    input()
    T = map(int, raw_input().split())

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

Submission status: Runtime Error

Solution code:
ef binarySearch(S,t):
    if len(S) == 1:
        return S[0] == t
    m = len(S)//2
    if S[m] == t:
        return True
    if S[m] > t:
        return binarySearch(S[:m],t)
    if len(S) > 2:
        return binarySearch(S[m+1:],t)
    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 t in T: cnt += binarySearch(S,t)
    print(cnt)

Submission status: Runtime Error

Solution code:
count_n = int(input())
N = []
n = input()
N = n.split()
N = list(map(lambda x: int(x), N)).sort()


count_p = int(input())
P = []
p = input()
P = p.split()
P = list(map(lambda x: int(x), P)).sort()


def b(i, l):
    left = 0
    right = len(l)
    while left < right:
        mid = int((left + right) / 2)
        if l[mid] > i:
            right = mid
        elif l[mid] < i:
            left = mid + 1
        elif l[mid] == i:
            return True
    return False
answer = 0
for n in N:
    if b(n, P):
        answer += 1
print (answer)

Submission status: Runtime Error

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

def func(v, low, high):

    mid = (low + high)/2
    
    if mid >= len(slist):
        return False
    
    if v > slist[mid]:
        if low == high:
            return False
        return func(v, mid+1, high)
    elif v == slist[mid]:
        return True
    else:
        if low == high:
            return False
        return func(v, low, mid-1)

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

print count

Submission status: Runtime Error

Solution code:
30
0 0 0 0 2 3 3 3 4 5 6 7 8 8 8 9 9 9 10 11 11 12 12 12 12 13 13 7000000 500000000 1000000000
16
2 0 5 11 3 16 4 6 1 10 7 14 15 7000000 9 5555555

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

@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 = [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: Runtime Error

Solution code:
# coding: utf-8
import numpy as np
n = int(input())
s = np.array(list(map(int, input().rstrip().split())))
q = int(input())
t = np.array(list(map(int, input().rstrip().split())))
# print("s:",s)
count = 0

def binary_search(array, value):
    ''' array must be sorted'''
    # print("value:{}".format(value))
    size = array.size
    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: Runtime Error

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

def binary_search(A, key):
left = 0
right = n
while left < right:
    mid = int((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 T:
    if binary_search(S, i):
        cnt += 1
print(cnt)

Submission status: Runtime Error

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

def binary_search(A, key):
left = 0
right = n
while left < right:
    mid = int((left + right)/2)
    if A[mid] == key:
        return True
    elif key < A[mid]:
        right = mid
    else:
        left = mid + 1 return False
t = 0
for i in T:
    if binary_search(S, i):
        t += 1
print(t)

Submission status: Runtime Error

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):
left = 0
right = n
while left < right:
    mid = int((left + right)/2)
    if A[mid] == key:
        return True
    elif key < A[mid]:
        right = mid
    else:
        left = mid + 1 return False
t = 0
for i in T:
    if binary_search(S, i):
        t += 1
print(t)

Submission status: Runtime Error

Solution code:
def binsearch(order, key):                                     
    n = len(order) / 2                                         
    if order[n] == key:                                        
        return True, n                                         
    elif order[n] > key:                                       
        return binsearch(order[:n], key)                       
    else:                                                      
        return binsearch(order[n:], key)                       
                                                               
    return False                                               
                                                               
n = raw_input()                                                
l = map(int, raw_input().split())                              
n = raw_input()                                                
s = map(int, raw_input().split())                              
                                                               
sum = 0                                                        
for i in s:                                                    
    isfind, pos = binsearch(l, i)                              
    if isfind:                                                 
        sum += 1                                               
print sum

Submission status: Runtime Error

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

print(len(S&T)

Submission status: Runtime Error

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

print(len(S&T))

Submission status: Runtime Error

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

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

cnt = 0

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

Submission status: Runtime Error

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

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

cnt = 0

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

Submission status: Runtime Error

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

if __name__ == '__main__':
	linear_search()

Submission status: Runtime Error

Solution code:
def binary_search(S, a):
    leng = len(S)
    mid = leng // 2
    if S[mid] == a:
        return True
    elif leng < 2:
        return False
    elif S[mid] < a:
        return binary_search(S[mid+1:], a)
    else:
        return binary_search(S[:mid], a)
        
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 T:
        if binary_search(S, i):
            ans += 1
    print(ans)

Submission status: Runtime Error

Solution code:
n1 = int(input())
s = (input()).split()
n2 = int(input())
t = (input()).split()
m = []

for i in range(0, n2):
      left = 0
      right = n1
      key = int(t[i])
      while left < right:
            mid = int((left + right)/2)
            if s[mid] == key:
                  m.append(key)
                  break
            elif key < s[mid]:
                  right = mid
            else:
                  left = mid + 1
print(len(m))

Submission status: Runtime Error

Solution code:
n1 = int(input())
s = (input()).split()
n2 = int(input())
t = (input()).split()
m = []

for i in range(0, n2):
      left = 0
      right = n1
      key = int(t[i])
      while left < right:
            mid = int((left + right)/2)
            if int(s[mid]) == key:
                  m.append(key)
                  break
            elif int(key) < s[mid]:
                  right = mid
            else:
                  left = mid + 1
print(len(m))

Submission status: Runtime Error

Solution code:
def binarySeach(t):
	left,right = 0,n
	while right > left:
		mid = (left+right) // 2
		if S[mid] == t:
			return True
		elif S[mid] > t:
			mid = right
		else:
			mid = left
	return False

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

print(sum([binarySerch(t) for t in T]))

Submission status: Runtime Error

Solution code:
n = int(raw_input())
if n > 1:
    s = map(int, raw_input().split())
else:
    s = int(raw_input())
    
q = int(raw_input())
if q > 1:
    t = map(int, raw_input().split())
else:
    t = [int(raw_input())]

count = 0
for i in range(q):
    tmp = int(n/2)
    gap = 1./2
    flag = 0
    if t[i] < s[0] or t[i] > s[n-1]:
        continue
    else:
        while True:
            if s[tmp] < t[i]:
                tmp = tmp + int(n*gap)
            elif s[tmp] > t[i]:
                tmp = tmp - int(n*gap)
            else:
                count += 1
                break
            if int(gap*n) == 1 and flag == 0:
                flag = 1
                continue
            elif int(gap*n) < 1:
                break
            gap *= 1./2
        
print count

Submission status: Runtime Error

Solution code:
# your code goes here
#binary
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 range(q):
    j=n//2
    b=n//2+1
    while T[i]!=S[j] and b>1:
        if b%2==1:
            b+=1
        b//=2
        if T[i]>S[j]:
            j+=b
        elif T[i]<S[j]:
            j-=b
    if T[i]==S[j]:
        C+=1
    else:
        if T[i]>S[j]:
            j+=b
        else:
            j-=b
        if T[i]==S[j]:
            C+=1
 #   print(j)
print(C)

Submission status: Runtime Error

Solution code:
# your code goes here
#binary
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 range(q):
    j=n//2
    b=n//2
    while T[i]!=S[j] and b>1:
        if b%2==1:
            b+=1
        b//=2
        if T[i]>S[j]:
            j+=b
        elif T[i]<S[j]:
            j-=b
    if T[i]==S[j]:
        C+=1
    else:
        if T[i]>S[j]:
            j+=b
        else:
            j-=b
        if T[i]==S[j]:
            C+=1
 #   print(j)
print(C)

Submission status: Runtime Error

Solution code:
import sys

def binary_search(array, num, left, right):
    if right < left:
        return False
    center = (right + left) / 2
    if array[center] == num:
        return True
    elif array[center] < num:
        return binary_search(array, num, center + 1, right)
    elif array[center] > num:
        return binary_search(array, num, left, center)

n = int(sys.stdin.readline().strip())
S = map(lambda x: int(x), sys.stdin.readline().strip().split(" "))
n = int(sys.stdin.readline().strip())
T = map(lambda x: int(x), sys.stdin.readline().strip().split(" "))

res = 0

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

print res

Submission status: Runtime Error

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

def BinarySearch(list, num):
	#print list
	l = len(list)
	if l == 1 and list[0] != num:
		#print("*0")
		return 0
	else:
		if list[l/2] == num:
			#print("*1")
			return 1
		elif list[l/2] < num:
			#print("*2")
			return BinarySearch(list[l/2+1:], num)
		else:
			#print("*3")
			return BinarySearch(list[:l/2], num)

cnt = 0
for i in T:
	#print("*4")
	#print BinarySearch(S, i)
	cnt += BinarySearch(S, i)
	#print cnt

print cnt

Submission status: Runtime Error

Solution code:
n = int(input())

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

q = int(input())

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

def binary_search(target, key):
    left = 0
    right = len(S)

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

    return False

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

print(cnt)

Submission status: Runtime Error

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

print(len(S&T))

Submission status: Runtime Error

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

print(len(S&T))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

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

Submission status: Runtime Error

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

def binary_search(lindex, rindex, key):
    while lindex <= rindex:
        if lindex == rindex:
            if S[lindex] == key:
                return True
            break
        midindex = (lindex + rindex) / 2
        if S[midindex] == key:
            return True
        else:
            if S[midindex] < key:
                lindex = midindex + 1
            else:
                rindex = midindex
            
C = 0

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

print(C)

Submission status: Runtime Error

Solution code:
import sys

ERROR_INPUT = 'input is invalid'
ERROR_INPUT_NOT_UNIQUE = 'input is not unique'


def main():
    S = get_input1()
    T = get_input2()

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

    print(count)


def binary_search(li, key, left, right, mid):
    if li[mid] == key:
        return True
    elif li[mid] < key:
        left = mid + 1
    elif li[mid] > key:
        right = mid

    if left > right:
        return False
    mid = (left + right) / 2
    return binary_search(li, key, left, right, mid)


def get_input1():
    n = int(input())
    if n > 100000:
        print(ERROR_INPUT)
        sys.exit(1)

    li = []
    for x in input().split(' '):
        if int(x) < 0 or int(x) > 10 ** 9:
            print(ERROR_INPUT)
            sys.exit(1)
        li.append(int(x))

    return li


def get_input2():
    n = int(input())
    if n > 50000:
        print(ERROR_INPUT)
        sys.exit(1)

    li = []
    for x in input().split(' '):
        if int(x) < 0 or int(x) > 10 ** 9:
            print(ERROR_INPUT)
            sys.exit(1)
        elif int(x) in li:
            print(ERROR_INPUT_NOT_UNIQUE)
            sys.exit(1)
        li.append(int(x))

    return li


main()

Submission status: Runtime Error

Solution code:
import sys

ERROR_INPUT = 'input is invalid'
ERROR_INPUT_NOT_UNIQUE = 'input is not unique'


def main():
    S = get_input1()
    T = get_input2()

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

    print(count)


def binary_search(li, key, left, right, mid):
    if li[mid] == key:
        return True
    elif li[mid] < key:
        left = mid + 1
    elif li[mid] > key:
        right = mid

    if left > right:
        return False
    mid = (left + right) // 2
    return binary_search(li, key, left, right, mid)


def get_input1():
    n = int(input())
    if n > 100000:
        print(ERROR_INPUT)
        sys.exit(1)

    li = []
    for x in input().split(' '):
        if int(x) < 0 or int(x) > 10 ** 9:
            print(ERROR_INPUT)
            sys.exit(1)
        li.append(int(x))

    return li


def get_input2():
    n = int(input())
    if n > 50000:
        print(ERROR_INPUT)
        sys.exit(1)

    li = []
    for x in input().split(' '):
        if int(x) < 0 or int(x) > 10 ** 9:
            print(ERROR_INPUT)
            sys.exit(1)
        elif int(x) in li:
            print(ERROR_INPUT_NOT_UNIQUE)
            sys.exit(1)
        li.append(int(x))

    return li


main()

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(50000)
ERROR_INPUT = 'input is invalid'
ERROR_INPUT_NOT_UNIQUE = 'input is not unique'


def main():
    S = get_input1()
    T = get_input2()

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

    print(count)


def binary_search(li, key, left, right, mid):
    if li[mid] == key:
        return True
    elif li[mid] < key:
        left = mid + 1
    elif li[mid] > key:
        right = mid

    if left > right:
        return False
    mid = (left + right) // 2
    return binary_search(li, key, left, right, mid)


def get_input1():
    n = int(input())
    if n > 100000:
        print(ERROR_INPUT)
        sys.exit(1)

    li = []
    for x in input().split(' '):
        if int(x) < 0 or int(x) > 10 ** 9:
            print(ERROR_INPUT)
            sys.exit(1)
        li.append(int(x))

    return li


def get_input2():
    n = int(input())
    if n > 50000:
        print(ERROR_INPUT)
        sys.exit(1)

    li = []
    for x in input().split(' '):
        if int(x) < 0 or int(x) > 10 ** 9:
            print(ERROR_INPUT)
            sys.exit(1)
        elif int(x) in li:
            print(ERROR_INPUT_NOT_UNIQUE)
            sys.exit(1)
        li.append(int(x))

    return li


main()

Submission status: Runtime Error

Solution code:
first_set_count = int(input());
first_set = [int(n) for n in input().split()];
second_set_count = int(input());
second_set = [int(n) for n in input().split()];

def binary_search(num, s, start, end):
    if start == end:
        if s[start] == num:
            return True;
        else:
            return False;
    else:
        mid = (start + end) // 2;
        if s[mid] == num:
            return True;
        elif num > s[mid]:
            start = mid + 1;
            return binary_search(num, s, start, end);
        else:
            end = mid - 1;
            return binary_search(num, s, start, end);

count = 0;
for num in second_set:
    if binary_search(num, first_set, 0, len(first_set) - 1):
        count += 1;
print(count);

Submission status: Runtime Error

Solution code:
_ = input()
li1 = [int(x) for x in input().split()]
_ = input()
li2 = [int(x) for x in input().split()]
count = 0

for l in li2:
    if binary_search(li1, l):
        count += 1
        
print(count)
    
def binary_search(li, x):
    if len(li) == 0:
        return False
    
    mid = len(li)//2
    
    k = li[mid]
    if k == x:
        return True
    elif k > x:
        li = li[:mid]
    else:
        li = li[mid+1:]
        
    return binary_search(li, x)

Submission status: Runtime Error

Solution code:
def main()
    _ = input()
    li1 = [int(x) for x in input().split()]
    _ = input()
    li2 = [int(x) for x in input().split()]
    count = 0

    for l in li2:
        if binary_search(li1, l):
            count += 1

    print(count)


def binary_search(li, x):
    if len(li) == 0:
        return False
    
    mid = len(li)//2
    
    k = li[mid]
    if k == x:
        return True
    elif k > x:
        li = li[:mid]
    else:
        li = li[mid+1:]
        
    return binary_search(li, x)

if __name__='__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    _ = input()
    li1 = [int(x) for x in input().split()]
    _ = input()
    li2 = [int(x) for x in input().split()]
    count = 0

    for l in li2:
        if binary_search(li1, l):
            count += 1

    print(count)


def binary_search(li, x):
    if len(li) == 0:
        return False
    
    mid = len(li)//2
    
    k = li[mid]
    if k == x:
        return True
    elif k > x:
        li = li[:mid]
    else:
        li = li[mid+1:]
        
    return binary_search(li, x)

if __name__='__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    n1 = input()
    if n1 > 100000:
        return 
    li1 = [int(x) for x in input().split()]
    n2 = input()
    if n1 > 50000:
        return 
    li2 = [int(x) for x in input().split()]
    count = 0

    for l in li2:
        if binary_search(li1, l):
            count += 1

    print(count)


def binary_search(li, x):
    if len(li) == 0:
        return False
    
    mid = len(li)//2
    
    k = li[mid]
    if k == x:
        return True
    elif k > x:
        li = li[:mid]
    else:
        li = li[mid+1:]
        
    return binary_search(li, x)

if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    n1 = int(input())
    if n1 > 100000:
        return 
    li1 = [int(x) for x in input().split()]
    if len(l1) > 10**9:
        return 
    n2 = int(input())
    if n1 > 50000:
        return 
    li2 = [int(x) for x in input().split()]
    if len(l2) > 10**9:
        return
    count = 0

    for l in li2:
        if binary_search(li1, l):
            count += 1

    print(count)


def binary_search(li, x):
    if len(li) == 0:
        return False
    
    mid = len(li)//2
    
    k = li[mid]
    if k == x:
        return True
    elif k > x:
        li = li[:mid]
    else:
        li = li[mid+1:]
        
    return binary_search(li, x)

if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
data = []
for line in sys.stdin:
	data.append(line.split())

S = []
T = []
ans = []
S = data[1]
T = data[3]

for t in T:
    l = 0
    r = len(S)

    while l < r :
        i = (l + r) / 2
        if int(S[i]) < int(t) :
            l = i + 1
        elif int(S[i]) > int(t):
            r = i
        else :
            print(int(t))
            break

Submission status: Runtime Error

Solution code:
[n, k] = map(int, input().split(' '))
wi = list(map(int, [input() for i in range(n)]))

def isAllocatable(p):
  kw, ki = 0, 1
  for w in wi:
    if w > p: return False
    kw += w
    if kw <= p: continue
    ki += 1
    if k < ki: return False
    kw = w
  return True

l = 0
r = sum(wi)
while l + 1 < r:
  p = int((l + r) / 2)
  if isAllocatable(p): r = p
  else: l = p
print(r)

Submission status: Runtime Error

Solution code:
#coding: UTF-8
#@document_it
import numpy as np

def document_it(func):
  def new_function(*args,**kwargs):
    print('Running function:', func.__name__)
    print('Positional arguments:', args)
    print('Kewword arguments:', kwargs)
    result = func(*args,**kwargs)
    print('Result:', result)
    return result
  return new_function

#@document_it
def bsearch(v,list,l=None):
  if l == 0 or list == []:
    return False
  if l==None:
    l = len(list)
  
  import math
  T = math.ceil(math.log2(l))
  t = 0
  wid = l
  offset = 0
  while t <= T:
    if wid == 0:
        return False
    pos = wid//2 + offset
    w = list[pos]
    if wid == 1:
        if v == w:
            return True
        else:
            return False
    else:
        if v == w:
            return True
        elif v < w:
            wid = wid//2
        else:
            wid = wid//2 - 1 + wid%2
            offset = pos + 1
    t+=1



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

    for t in T:
        if bsearch(t,S,n):
            ans += 1

    print(ans)

if __name__ == '__main__':
    exe()