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: Wrong Answer

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

def binary_search(target_num, head, tail):
    while head < tail:
        idx = int((head+tail)/2)
        if target_num == S[idx]:
            return True
        elif target_num < S[idx]:
            tail = idx -1
        else:
            head = idx + 1
    return False


match_count = 0
for target_num in T:
    if binary_search(target_num, 0, len(S)-1):
        match_count += 1

print(str(match_count))

Submission status: Wrong Answer

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

def binary_search(target_num, head, tail):
    while head <= tail:
        idx = int((head+tail)/2)
        if target_num == S[idx]:
            print(target_num)
            return True
        elif target_num < S[idx]:
            tail = idx - 1
        else:
            head = idx + 1
    return False


match_count = 0
for target_num in T:
    if binary_search(target_num, 0, len(S)-1):
        match_count += 1

print(str(match_count))

Submission status: Wrong Answer

Solution code:
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
s = []
for i in range(1,max(S) + 1):
    if i in S:
        s.append(s)
c = 0
for i in T:
    if (i in s):
        c += 1
    
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
s = []
for i in range(1,max(S) + 1):
    if i in S:
        s.append(i)
c = 0
for i in T:
    if (i in s):
        c += 1
    
print(c)

Submission status: Wrong Answer

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

c = 0
for i in T:
    c += S.count(i)
    
print(c)

Submission status: Wrong Answer

Solution code:
iipt=lambda:int(input())
miipt=lambda:list(map(int,input().split(" ")))
import bisect
 
N=iipt()
c=miipt()
M=iipt()
qu=miipt()
ans=0
for q in qu:
    a=0
    b=N-1
    while b-a>1:
        x=(a+b)//2
        if c[a]==q or c[b]==q:
            ans+=1
            break
        if c[x]<q:
            a=x
        else:
            b=x
    else:
        if c[a]==q or c[b]==q:
            ans+=1
            break
    """        
    if a==-1 or b==N:
        print(q,a,b)
        ans-=1"""

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input().split()
for sn in s:
    sn = int(sn)

q = int(input())
t = input().split()
for tn in t:
    tn = int(tn)

answer = 0

import math
for tn in t:
    smin = 0
    smax = n - 1
    c = math.floor(n - 1 / 2)
    while(smax - smin > 1):
        if(tn == s[c]):
            answer = answer + 1
            break
        elif(tn > s[c]):
            smin = c
            c = math.floor((smin + smax) / 2) 
        elif(tn < s[c]):
            smax = c
            c = math.floor((smin + smax) / 2)
        if(smax - smin <= 1):
            if(tn == s[smax] or tn == s[smin]):
                answer = answer + 1
            break

print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input().split()
for sn in s:
    sn = int(sn)

q = int(input())
t = input().split()
for tn in t:
    tn = int(tn)

answer = 0

import math
for tn in t:
    smin = 0
    smax = n - 1
    c = math.floor(n - 1 / 2)
    while(smax - smin > 1):
        if(tn == s[c] or tn == s[smin] or tn == s[smax]):
            answer = answer + 1
            break
        elif(tn > s[c]):
            smin = c
            c = math.floor((smin + smax) / 2) 
        elif(tn < s[c]):
            smax = c
            c = math.floor((smin + smax) / 2)
print(answer)

Submission status: Wrong Answer

Solution code:
def binary_search(array, tgt_no): #  arrayは昇順にソートされているものとする

    def compare_midpoint(tgt, array, start, end):
        midpoint = (end + start)//2
        if tgt == array[midpoint]:
            return True, None, None
        elif tgt < array[midpoint]:
            return False, start, midpoint
        elif tgt > array[midpoint]:
            return False, midpoint, end

    start = 0
    end = len(array)
    while True:
        ret, start, end = compare_midpoint(tgt_no, array, start, end)
        if ret:
            return True
        if end - start <= 1:
            return tgt_no == array[start]


def main():
    _ = input()
    array_A = input().split()
    _ = input()
    array_B = input().split()

    cnt = 0
    for integer_B in array_B:
        if binary_search(array_A, integer_B):
            cnt += 1

    print(cnt)
    return


main()

Submission status: Wrong Answer

Solution code:
def main():
    input()
    s = [int(i) for i in input().split()]
    input()
    t = [int(i) for i in input().split()]
    number = 0
    for ti in t:
        start, stop = 0, len(s)-1
        while stop - start > 1:
            center = int((start + stop) / 2)
            if ti < s[center]:
                stop = center
            elif ti > s[center]:
                start = center
            else:
                number += 1
                break
        else:
            if ti == s[start]:
                number += 1
    print(number)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def search(l, n):
    left = 0
    right = len(l) - 1
    m = (left + right) // 2

    # while right - left > 1:
    while left < right:
        if n == l[m]:
            return True
        elif n < l[m]:
            right = m - 1
        elif n > l[m]:
            left = m + 1
        else:
            raise Exception()

        m = (left + right) // 2


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 ti in t:
    if search(s, ti):
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
def search(l, n):
    left = 0
    right = len(l) - 1
    m = (left + right) // 2

    # while right - left > 1:
    while left < right:
        if n == l[m]:
            return True
        elif n < l[m]:
            right = m
        elif n > l[m]:
            left = m + 1
        else:
            raise Exception()

        m = (left + right) // 2


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 ti in t:
    if search(s, ti):
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
# your code goes here

n = int(raw_input())
S_str = raw_input().split(" ")
S = map(lambda x : int(x), S_str)

m = int(raw_input())
T_str = raw_input().split(" ")
T = map(lambda x : int(x), T_str)

count = 0

for s in S:
	if s in T:
		count += 1
		
print count

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
S_str = raw_input().split(" ")
S = map(lambda x : int(x), S_str)

m = int(raw_input())
T_str = raw_input().split(" ")
T = map(lambda x : int(x), T_str)

count = 0

for s in S:
	if s in T:
		count += 1
		
print count

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
S_str = raw_input().split(" ")
S = map(lambda x : int(x), S_str)

m = int(raw_input())
T_str = raw_input().split(" ")
T = map(lambda x : int(x), T_str)

count = 0
"""
for t in T:
	index = 0
	for s in S:
		if s == t:
			count += 1
			break
"""
pre = None
for s in S:
	if not pre:
		pre = (s, s in T)
		if pre[1]:
			count += 1
		continue
	else:
		if pre[0] == s:
			count += 1
			continue
		else:
			pre = (s, s in T)
			if pre[1]:
				count += 1
			continue
	
print count

Submission status: Wrong Answer

Solution code:

n = int(raw_input())
S_str = raw_input().split(" ")
S = map(lambda x : int(x), S_str)

m = int(raw_input())
T_str = raw_input().split(" ")
T = map(lambda x : int(x), T_str)

count = 0

pre = None
for s in S:
	if pre is None:
		pre = (s, s in T)
		if pre[1]:
			count += 1
		continue
	else:
		if pre[0] == s:
			if pre[1]:
				count += 1
				continue
		else:
			pre = (s, s in T)
			if pre[1]:
				count += 1
			continue
	
print count

Submission status: Wrong Answer

Solution code:
      
def binary_search(A,n):
    # sequence A, item n
    l=len(A)
    if l==0:
        return False
    elif A[l/2] > n:
        return binary_search(A[:l/2],n)
    elif A[l/2] == n:
        return True
    elif A[l/2]<n:
        return binary_search(A[(l/2)+1:],n)

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

C = 0
for k in range(len(T)):
    if binary_search(S,S[k]):
        C += 1
print C

Submission status: Wrong Answer

Solution code:
      
def binary_search(A,n):
    # sequence A, item n
    l=len(A)
    if l==0:
        return False
    elif A[l/2] > n:
        return binary_search(A[:l/2],n)
    elif A[l/2] == n:
        return True
    elif A[l/2]<n:
        return binary_search(A[(l/2)+1:],n)

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

C = 0
for k in range(len(T)):
    if binary_search(S,T[k]):
        C += 1
print C

Submission status: Wrong Answer

Solution code:
n = int( input( ) )
s = [ int( val ) for val in input( ).split( " " ) ]
q = int( input( ) )
t = [ int( val ) for val in input( ).split( " " ) ]
t.sort( )
print( t )
cnt = 0
for ti in t:
	low = 0
	high = n - 1
	while low <= high:
		m = ( low+high )//2
		if ti < s[m]:
			high = m - 1
		elif s[m] < ti:
			low = m + 1
		else:
			cnt += 1
			break

print( cnt )

Submission status: Wrong Answer

Solution code:
def binarySearch(x, S):
    mid = len(S) / 2
    if mid < 2:
        return x in S
    if S[mid] == x:
        return True
    elif S[mid] > x:

        left = S[:mid - 1]
        return binarySearch(x, left)
    else:
        right = S[mid + 1:]
        return binarySearch(x, right)

n = int(raw_input())
S = map(int, raw_input().split())
q = int(raw_input())
T = map(int, raw_input().split())
count = 0
for x in T:
    if binarySearch(x, S):
        count += 1
print count

Submission status: Wrong Answer

Solution code:
n = input()
S = map(int,raw_input().split())
m = input()
T = map(int,raw_input().split())
C=0
def binarySearch(A,p):
    lens = len(A)
    ll = -1
    ul = lens-1
    ms=(ll+ul)/2
    while (ll+1<ul):
        if ll == ul and A[ll] != p:
            return False
        elif A[ll] > p:
            ul =ms
        elif A[ll] < p:
            ll=ms
	return True
 
for item in T:
    if binarySearch(S,item):
        C += 1
print C

Submission status: Wrong Answer

Solution code:
n = input()
S = map(int,raw_input().split())
m = input()
T = map(int,raw_input().split())
C=0
def binarySearch(A,p):
    lens = len(A)
    ll = 0
    ul = lens-1
    ms=(ll+ul)/2
    while (ll+1<ul):
        if ll == ul and A[ll] != p:
            return False
        elif A[ll] > p:
            ul =ms
        elif A[ll] < p:
            ll=ms
	return True
 
for item in T:
    if binarySearch(S,item):
        C += 1
print C

Submission status: Wrong Answer

Solution code:
n = input()
S = map(int,raw_input().split())
m = input()
T = map(int,raw_input().split())
C=0
def binarySearch(A,p):
    lens = len(A)
    ll = -1
    ul = lens-1
    ms=(ll+ul)/2
    while (ll+1<ul):
    	ms=(ll+ul)/2
        if A[ms] >= p:
            ul =ms
        elif A[ms] < p:
            ll =ms
	return A[ul]==p

for item in T:
    if binarySearch(S,item):
        C += 1
print C

Submission status: Wrong Answer

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

    return -1 #not found
ans = 0
input()
A = []
q = []
A = list(map(int, input().split()))
input()
q = list(map(int, input().split()))

for x in q:
    tmp = binarySearch(A, x)
    if(tmp != -1):
        ans += 1

print(ans)

Submission status: Wrong Answer

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

    return -1 #not found

ans = 0
n = int(input())
A = [int(x) for x in input().split()] 
z = int(input())
q = [int(x) for x in input().split()]
for x in q:
    tmp = binarySearch(A, x)
    if(tmp != -1):
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
# encoding: utf-8


def main():
    input()
    s = map(int, raw_input().split())
    input()
    t = map(int, raw_input().split())

    sum = 0
    for n in s:
        sum += 1 if n in t else 0

    print sum

main()

Submission status: Wrong Answer

Solution code:
# encoding: utf-8


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

    sum = 0
    for n in s:
        sum += 1 if n in t else 0

    print sum

main()

Submission status: Wrong Answer

Solution code:
# encoding: utf-8


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

    sum = 0
    for n in t:
        sum += s.count(n)

    print sum

main()

Submission status: Wrong Answer

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


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

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 (S,i):
        count += 1

print (count)

Submission status: Wrong Answer

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

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: Wrong Answer

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

left = 0
right = n

for key in T:
 while left<right:
  mid = (right + left)/2
  if key==S[mid]:
   C += 1
   break
  elif key<S[mid]:
   right = mid
  elif key>S[mid]:
   left = mid+1

print C

Submission status: Wrong Answer

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

left = 0
right = n

for key in T:
 while left<right:
  mid = int((right + left)/2)
  if key==S[mid]:
   C += 1
   break
  elif key<S[mid]:
   right = mid
  elif key>S[mid]:
   left = mid+1

print C

Submission status: Wrong Answer

Solution code:
n, s, q, t = 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 s
    l, r = 0, len(s)
    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: Wrong Answer

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

count   = 0
isExist = False
low     = 0
high    = n - 1
middle  = 0

for j in range(q):
    search = T[j]
    for i in range(10):
        middle = (high - low)/2
        if S[middle] == search:
            isExist = True
            break
        elif middle == -1:
            break
        elif S[middle] < search:
            high = middle - 1
        elif S[middle] > search:
            low = middle + 1
    if isExist:
        count = count + 1

print count

Submission status: Wrong Answer

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

count    = 0
isBroken = False
low      = 1 - 1
high     = n - 1
middle   = 0

for j in range(q):
    search = T[j]
    while True:
        middle = (high + low)/2
        if S[middle] == search:
            count = count + 1
            isBroken = True
        elif middle == 0:
            isBroken = True
        elif search < S[middle]:
            high = middle - 1
        elif S[middle] < search:
            low = middle + 1

        if isBroken:
            break

print count

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
def 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=input() 
    S=input().split()
    q=input() 
    T=input().split()
    cnt = 0
    for t in T: cnt += binarySearch(S,t)
    print(cnt)

Submission status: Wrong Answer

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


def binary_search(n, A):
    count = 0
    left = 0
    right = len(A)
    while left < right:
        mid = int((left + right) / 2)
        print '%d, %d, %d' % (left, mid, right)
        if A[mid] == n:
            return True
        elif A[mid] > n:
            right = mid
        else:
            left = mid + 1
    return False


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

    count = 0
    for i in xrange(len(T)):
        if binary_search(T[i], S):
            count += 1
    print count

Submission status: Wrong Answer

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


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

N.sort()
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: Wrong Answer

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


def binarysearch(key, a, length):
    left = 0
    right = length-1
    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 binarysearch(i, S, n):
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [int(i) for i in input().split()]
S = sorted(set(s), key=s.index)
q = int(input())
t = [int(i) for i in input().split()]
T = sorted(set(t))

print(S)
print(T)

count = 0
for v in T:
    if v in S:
        count += 1
        S[:] = S[S.index(v)+1:]
        print(S)

print(count)

Submission status: Wrong Answer

Solution code:
import sys


def binary_search(a, t, n):
    low = 0
    high = n - 1
    while low <= high:
        mid = low + (high - low) // 2
        if a[mid] == t:
            return True
        elif a[mid] < t:
            low = mid + 1
        else:
            high = mid - 1
    return False


def main():
    n = int(sys.stdin.readline())
    s = sys.stdin.readline().split()
    q = int(sys.stdin.readline())
    t = sys.stdin.readline().split()
    cnt = 0

    for i in t:
        if binary_search(s, i, n):
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys


def binary_search(a, t, n):
    low = 0
    high = n - 1
    while low < high:
        mid = low + (high - low) // 2
        if a[mid] == t:
            return True
        elif a[mid] < t:
            low = mid + 1
        else:
            high = mid - 1
    return False


def main():
    n = int(sys.stdin.readline())
    s = sys.stdin.readline().split()
    q = int(sys.stdin.readline())
    t = sys.stdin.readline().split()
    cnt = 0

    for i in t:
        if binary_search(s, i, n):
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys


def binary_search(a, t, n):
    low = 0
    high = n - 1
    while low <= high:
        mid = (high + low) // 2
        if a[mid] == t:
            return True
        elif a[mid] < t:
            low = mid + 1
        else:
            high = mid - 1
    return False


def main():
    n = int(sys.stdin.readline())
    s = sys.stdin.readline().split()
    q = int(sys.stdin.readline())
    t = sys.stdin.readline().split()
    cnt = 0

    for i in t:
        if binary_search(s, i, n):
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def find(target, list):
  l = 0
  r = len(list)-1
  m = (l + r) / 2
  while l < r:
    if list[m] == target:
      return 1
    if list[m] < target:
      l = m + 1
      m = (l + r) / 2
    else:
      r = m
      m = (l + r) / 2
  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: Wrong Answer

Solution code:
import math as ma

def bs(num, li):
    low, high = 0, len(li)
    if num > min(li) and num < max(li):
        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: Wrong Answer

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

def func(v, low, high):
    mid = (low + high)/2

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

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

print count

Submission status: Wrong Answer

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

def func(v, low, high):

    if low > high:
        return False

    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: Wrong Answer

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 T[i]==S[mid]:
                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(" ")
    q=int(input())
    T=input().split(" ")
    BS(n,S,q,T)

Submission status: Wrong Answer

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 = self.__input[1].split()
        length_2 = int(self.__input[2])
        array_2 = self.__input[3].split()

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

        left, right, count = 0, length_1, 0

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

        return str(count)

    @staticmethod
    def binary_search(key, array):
        # print(len(set(array_1).intersection(set(array_2))))
        left, right = 0, len(array)
        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: Wrong Answer

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

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

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 0 < binarySearch(S, key):
			total_v += 1

	print total_v
			
	

#def test():

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

Submission status: Wrong Answer

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

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

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) > 0:
			total_v += 1

	print total_v
			
	

#def test():

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

Submission status: Wrong Answer

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

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

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) > 0:
			total_v += 1

	print total_v
			
	

#def test():

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

Submission status: Wrong Answer

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 = list(set([n for n in input().split()]))
    n_listB = int(input())
    b = list(set([n for n in input().split()]))
    print(binary_search(a,b))

Submission status: Wrong Answer

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 = [n for n in input().split()]
    n_listB = int(input())
    b = [n for n in input().split()]
    print(binary_search(a,b))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = map(int, input().rstrip().split())
q = int(input())
t = map(int, input().rstrip().split())
count = 0
for x in t:
    if x in s:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

n = int(input())
s = map(int, input().rstrip().split())
q = int(input())
t = map(int, input().rstrip().split())
count = 0
for x in t:
    if x in s:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:

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



def search(s,T):
    left = 0 ; right = len(T)-1
    while left < right:
        mid = (left + right)//2
        if T[mid]==s: return True
        elif T[mid]>s: right = mid
        else: left = mid+1

count = 0
for s in S:
    if search(s,T): count+=1


print(count)