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:
def main():
    input()
    a = list(input().split())
    input()
    bs = list(input().split())
    count = 0
    for b in bs:
        indicate = len(a)//2
        search_range = len(a)
        while 0 != search_range:
            search_range //= 2
            if a[indicate] < b:
                indicate += search_range
            elif b < a[indicate]:
                indicate -= search_range
            elif a[indicate] == b:
                count += 1
                break

    print(count)



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

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

binarySearch(S, T)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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 list(s&t) if list(s&t) else 0

Submission status: Wrong Answer

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:
            right = mid
        elif b[mid] > a:
            left = mid+1
    return 0

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

Submission status: Wrong Answer

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-1
    return 0

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

Submission status: Wrong Answer

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 = 1
    right = len(b)
    while left < right:
        mid = int((left + right)/2)
        if b[mid-1] == a:
            return 1
        elif b[mid-1] < a:
            left = mid+1
        elif b[mid-1] > a:
            right = mid-1
    return 0

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = set(input())
n = int(input())
t = set(input())
print(len(t&s)-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
input()
S = input().split()
input()
T = 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: Wrong Answer

Solution code:
def binsearch(order, key):                                     
    n = len(order) / 2                                         
    print order, n, key                                        
    if order[n] == key:                                        
        return True, n                                         
    elif len(order) == 1:                                      
        return False, None                                     
    elif order[n] > key:                                       
        return binsearch(order[:n], key)                       
    else:                                                      
        return binsearch(order[n:], key)                       
                                                               
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: Wrong Answer

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

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 = int(n[0]) - 1
    if(tmp_t >= sList[tmp_min]  and tmp_t <= sList[tmp_max] ):
        while(tmp_min != tmp_max):
            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:
                tCount += 1
                tmp_min = tmp_max
            else:
                tmp_min = tmp_max

print(tCount)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = 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 m > t:
            r = m
        elif m < t:
            l = m+1
        else:
            cnt += 1
            break
print(cnt)

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 = set(S)
cnt = 0
for t in T:
    l, r = 0, len(S)
    while l < r:
        m = (l+r) // 2
        if m > t:
            r = m
        elif m < t:
            l = m+1
        else:
            print()
            print(m, t)
            cnt += 1
            break
print(cnt)

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 = set(S)
cnt = 0
for t in T:
    l, r = 0, len(S)
    while l < r:
        m = (l+r) // 2
        if m > t:
            r = m
        elif m < t:
            l = m+1
        else:
            cnt += 1
            break
print(cnt)

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 = sorted(set(S))
cnt = 0
for t in T:
    l, r = 0, len(S)
    while l < r:
        m = (l+r) // 2
        if T[m] == t:
            cnt += 1
            break
        elif t < T[m]:
            r = m
        else:
            l = m+1
print(cnt)

Submission status: Wrong Answer

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

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

ctr = 0

n = N

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

print(ctr)

Submission status: Wrong Answer

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

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

ctr = 0

n = N

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

print(ctr)

Submission status: Wrong Answer

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
        print(i, left, right)
        if S[i] == t:
            res += 1
            print("check")
            break
        elif t < S[i]:
            right = i
        else:
            left = i+1 # ?????????????????????????????§????????????

print(res)

Submission status: Wrong Answer

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
        print(i, left, right)
        if S[i] == t:
            res += 1
            break
        elif t < S[i]:
            right = i
        else:
            left = i+1 # ?????????????????????????????§????????????

print(res)

Submission status: Wrong Answer

Solution code:
# encording: utf-8

_ = 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(qs)
    while left < right:
        mid = (left + right) // 2
        target = ns[mid]
        if q == target:
            return True
        elif q < target:
            right = mid
        else:
            left = mid + 1
    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: Wrong Answer

Solution code:
# encording: utf-8

_ = 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(qs) - 1
    while left < right:
        mid = (left + right) // 2
        target = ns[mid]
        if q == target:
            return True
        elif q < target:
            right = mid
        else:
            left = mid + 1
    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: Wrong Answer

Solution code:
# encording: utf-8

_ = 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(qs)
    while left < right:
        mid = (left + right) // 2
        if q == ns[mid]:
            return True
        elif q < ns[mid]:
            right = mid
        elif ns[mid] < q:
            left = mid + 1
    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: Wrong Answer

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(qs)
    while left < right:
        mid = (left + right) // 2
        if q == ns[mid]:
            return True
        elif q < ns[mid]:
            right = mid
        elif ns[mid] < q:
            left = mid + 1
    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: Wrong Answer

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(qs)
    while left < right:
        mid = (left + right) // 2
        if ns[mid] < q:
            left = mid + 1
        elif q < ns[mid]:
            right = mid
        elif q == ns[mid]:
            return True
    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: Wrong Answer

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

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

findCount = 0

for t in T:
    left = 0
    right = n - 1
    center = right // 2
    preCenter= 0
    while center != preCenter:
        if S[center] == t:
            findCount += 1
            break
        
        if S[center] >= t:
            right = center
        else:
            left = center
        
        preCenter = center
        center = (left + right) // 2

print(findCount)

Submission status: Wrong Answer

Solution code:
def binary_search(t, s_list):
    left = 0
    right = len(s_list) - 1

    while left < right:
        mid = (left + right) // 2
        if s_list[mid] == t:
            return True
        elif s_list[mid] > t:
            right = mid
        else:
            left = mid + 1
    return False


n = int(input())
s_list = list(map(int, input().split()))
q = int(input())
t_list = list(map(int, input().split()))

c = 0
for t in t_list:
    if binary_search(t, s_list):
        c += 1

print(c)

Submission status: Wrong Answer

Solution code:
def main():
    n = input()
    S = map(int,raw_input().split())
    q = input()
    T = map(int,raw_input().split())
    m = 0
    for i in range(q):
        i0 = 0
        i1 = n-1
        t = T.pop()
        while i0 < i1:
            im = int((i0+i1)/2)
            if t == S[im]:
                m += 1
                break
            elif t < S[im]:
                i1 = im-1
            elif t > S[im]:
                i0 = im+1
            
    print m

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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 = 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(m)
print(len(m))

Submission status: Wrong Answer

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 = 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(m)
print(len(m))

Submission status: Wrong Answer

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

Solution code:
#ALDS1_4-B BinarySearch
import heapq
S = []
T = []
n=input()
heapq.heappush(S, input().split())
q=input()
heapq.heappush(T, input().split())
c=0

for t in T:
    if(t in S):
        c+=1

print(c)

Submission status: Wrong Answer

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

cnt = 0
for t in T:
    low = 0
    high = len(S) - 1
    while low < high:
        mid = (low + high) // 2
        if t == S[mid]:
            cnt += 1
            break
        elif t < S[mid]:
            high = mid - 1
        else:
            low = mid + 1
print(cnt)

Submission status: Wrong Answer

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

cnt = 0

def binarysearch(x, l):
	mi = 0
	ma = len(l) - 1
	
	while mi < ma:
		print(mi, ma)
		tmp = (mi + ma) // 2
		
		if l[tmp] == x:
			return tmp
		elif l[tmp] < x:
			mi = tmp + 1
		else:
			ma = tmp - 1
	
	else:
		if mi == ma:
			if x == l[mi]:
				return mi
			else:
				return -1
		else:
			if x == l[mi]:
				return mi
			elif x == l[ma]:
				return ma
			else:
				return -1
	
	

for x in t:
	if binarysearch(x, s) != -1:
		cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
def binarySearch(t):
	left,right = 0,n
	while right > left+1:
		mid = (left+right) // 2
		print(left, right, mid)
		if S[mid] == t:
			return True
		elif S[mid] > t:
			right = mid
		else:
			left = mid
	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([binarySearch(t) for t in T]))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Binary Search
n ????????´??°???????????°??? S ??¨???q ????????°????????´??°???????????°??? T ??????????????????
T ?????????????????´??°????????§ S ?????????????????????????????° C ???????????????????????°????????????????????????????????????
"""
def bsrch(l, a):
    """ ????????????????????? """
    c = int(len(l) / 2)
    if l[c] == a:
        return True
    else:
        if c > 0:
            if l[c] > a:
                return bsrch(l[:c], a)
            elif l[c] < a:
                return bsrch(l[c:], a)
    return False

def main():
    """ ????????? """
    n = int(input())
    S = list(input().split())
    q = int(input())
    T = list(input().split())

    cnt = {}

    for j in range(q):
       x = bsrch(S, T[j])
       if x == True:
           cnt[T[j]] = 1
    print(len(cnt))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def binarySearch(array, target):
    l = len(array)
    first_half = array[:l//2]
    second_half = array[l//2:]
    if first_half == []:
        return False
    if first_half[-1] == target:
        return True
    elif first_half[-1] < target:
        return binarySearch(second_half, target)
    else:
        return binarySearch(first_half, target)

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

Submission status: Wrong Answer

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 = int(n/4)
    flag = 0
    if t[i] < s[0] or t[i] > s[n-1]:
        continue
    else:
        while True:
            if s[tmp] < t[i]:
                tmp = tmp + gap
            elif s[tmp] > t[i]:
                tmp = tmp - gap
            else:
                count += 1
                break
            if gap == 1 and flag == 0:
                flag = 1
                continue
            elif gap < 1:
                break
            gap = int(gap/2)
        
print count

Submission status: Wrong Answer

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):
    #print t[i]
    tmp = int(n/2)
    gap = 1./4
    flag = 0
    if t[i] < s[0] or t[i] > s[n-1]:
        continue
    elif t[i] == s[0] or t[i] == s[n-1]:
        count += 1
        continue
    else:
        while True:
            if s[tmp] < t[i]:
                tmp = tmp + int(n*gap)
                #print 'bigger'
            elif s[tmp] > t[i]:
                #print 'smaller'
                tmp = tmp - int(n*gap)
            else:
                count += 1
                #print 'found'
                break
            if int(gap*n) == 1 and flag == 0:
                flag = 1
                continue
            elif int(gap*n) < 1:
                #print 'fail'
                break
            #print gap, tmp, s[tmp]
            gap *= 1./2
        
print count

Submission status: Wrong Answer

Solution code:
input()
S = set(input().split())
input()
T = set(input().split())
print(len(S and T))

Submission status: Wrong Answer

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 i==25:
            print(b)
            print(j)
    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: Wrong Answer

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

q = input()
q = int(q)
t = input()
t = t.split()
t = [int(x) for x in t]
    
n_unique = len(set(s) - set(t))
n_overlap = len(s) - n_unique
print(n_overlap)

Submission status: Wrong Answer

Solution code:
def binary_search(S, n, index ):
    if S[index] == n:
        return 'eq'
    elif S[index] < n:
        return 'bt'
    elif S[index] > n:
        return 'lt'

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

cnt = 0
for i in T:
    mini = 0
    maxi = len(T) - 1
    while int(maxi - mini) >= 0:
        index = int( mini + maxi )
        rs = binary_search(S, i, index )
        if rs == 'eq':
            cnt += 1
            break
        elif rs == 'bt':
            mini = index + 1
        elif rs == 'lt':
            maxi = index - 1

print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
snum = set(map(int, input().split()))
q = input()
qnum = set(map(int, input().split()))
print(len(snum and qnum))

Submission status: Wrong Answer

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

m, M = S[0], S[n - 1]
for x in T:
    if x < m or M < x:
        continue
    l, r = 0, n - 1
    while l < r:
        m = (l + r) // 2
        if S[m] == x:
            count += 1
            break
        elif S[m] > x:
            r = m - 1
        else:
            l = m + 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()))
count = 0

Sm, SM = S[0], S[n - 1]
for x in T:
    if x < Sm or SM < x:
        continue
    l, r = 0, n - 1
    while l < r:
        m = (l + r) // 2
        if S[m] == x:
            count += 1
            break
        elif S[m] > x:
            r = m
        else:
            l = m + 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()))

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = map(int,raw_input().split())
q = int(input())
T = map(int,raw_input().split())
count = 0
for v in S:
    for i in range(q):
        if T[i] == v:
            count += 1
            break
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()))
count = 0

def binarySearch(x,s):
    left = 0
    right = len(s) - 1

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

for x in t:
    if binarySearch(x,s) != -1:
        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()))

count = 0
for item in t:
    middle = int((n - 1) / 2)
    upper = n - 1
    lower = 0

    while(True):

        if s[middle] == item:
            count += 1
            break
        elif lower >= upper:
            break
        elif s[middle] > item:
            upper = middle
            middle = int((lower + middle) / 2)
        elif s[middle] < item:
            lower = middle + 1
            middle = int((upper + middle) / 2)

print(count)

Submission status: Wrong Answer

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


def binary_search(data, targets, n):
    cnt = 0
    for num in targets:
        small = 0
        big = n - 1
        while 1:
            index = (small + big) >> 1
            if num < data[index]:
                big = index - 1
            elif num > data[index]:
                small = index + 1
            else:
                cnt += 1
                break

            if big == small:
                break
    return cnt


if __name__ == "__main__":
    data = [val.split() for val in sys.stdin.read().splitlines()]
    print(binary_search(data[1], data[3], int(data[0][0])))

Submission status: Wrong Answer

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


def binary_search(data, targets, n):
    cnt = 0
    for num in targets:
        small = 0
        big = n - 1
        while 1:
            index = (small + big) >> 1
            if small < big:
                if num < data[index]:
                    big = index - 1
                if num > data[index]:
                    small = index + 1
                if num == data[index]:
                    cnt += 1
                    break
            else:
                break
    return cnt


if __name__ == "__main__":
    data = [val.split() for val in sys.stdin.read().splitlines()]
    print(binary_search(data[1], data[3], int(data[0][0])))

Submission status: Wrong Answer

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


def binary_search(data, targets, n):
    cnt = 0
    for num in targets:
        small = 0
        big = n - 1
        while small < big:
            index = (small + big) >> 1
            if small < big:
                if num < data[index]:
                    big = index - 1
                if num > data[index]:
                    small = index + 1
                if num == data[index]:
                    cnt += 1
                    break
        if small == big and num == data[small]:
            cnt += 1

    return cnt


if __name__ == "__main__":
    data = [val.split() for val in sys.stdin.read().splitlines()]
    print(binary_search(data[1], data[3], int(data[0][0])))

Submission status: Wrong Answer

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

def lower_bound(lis, target):
    left, right = 0, n-1
    while left<right:
        mid = (left+right)//2
        if lis[mid]==target:
            return True
        elif target<lis[mid]:
            right = mid
        else:
            left = mid+1
    return False

cnt = 0
for i in range(q):
    cnt = cnt+1 if lower_bound(s, t[i]) else cnt
print(cnt)

Submission status: Wrong Answer

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

def lower_bound(lis, target):
    left, right = 0, n  # NOT n-1 !!!!!!!!!!
    while left<right:
        mid = (left+right)//2
        if lis[mid]==target:
            return True
        elif target<lis[mid]:
            right = mid
        else:
            left = mid+1
    return False

cnt = 0
for i in range(q):
    cnt = cnt+1 if lower_bound(s, t[i]) else cnt
print(cnt)

Submission status: Wrong Answer

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

def BinarySearch(list, num):
	left = 0
	right = len(list) - 1
	while left <= right:
		mid = (left + right) / 2
		#print("left = {:}".format(left))
		#print("mid = {:}".format(mid))
		#print("right = {:}".format(right))
		#print("")
		if list[mid] == num:
			return 1
		elif list[mid] < num:
			left = mid + 1
			#print("left = {:}".format(left))
			#print("mid = {:}".format(mid))
			#print("right = {:}".format(right))
			#print("")
		else:
			right = mid - 1
			#print("left = {:}".format(left))
			#print("mid = {:}".format(mid))
			#print("right = {:}".format(right))
			#print("")
	return 0

cnt = 0
for i in T:
	cnt += BinarySearch(S, i)

Submission status: Wrong Answer

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

def b_search(key, n):
    left = 0
    right = n
    while( left < right ) :
        mid = int( (left + right) / 2 )
        if ( key == S[mid]):
            return 1
        if ( key > S[mid] ):
            left = mid + 1
        if ( key < S[mid] ):
            right = mid
    return 0

if __name__ == "__main__":
    ans = 0
    for i in T:
        if b_search(i, n) == 1:
            ans += 1
    
    print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

print(S & T)