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

Submission status: Wrong Answer

Solution code:
import sys


def binsearch(x, s):
    l = 0
    r = len(s) - 1
    while (l < r):
        m = int((l + r) / 2)
        if s[m] == x:
            return True
        else:
            if s[m] < x:
                l = m + 1
            else:
                r = m
    return False


ns = sys.stdin.readline()
s = sys.stdin.readline().split()
nt = sys.stdin.readline()
t = sys.stdin.readline().split()

out = ""
for x in t:
    if (binsearch(x, s)):
        out += str(x) + " "

print(out.strip())

Submission status: Wrong Answer

Solution code:
import sys


def binsearch(x, s):
    l = 0
    r = len(s) - 1
    while (l < r):
        m = int((l + r) / 2)
        if s[m] == x:
            return True
        else:
            if s[m] < x:
                l = m + 1
            else:
                r = m
    return False


ns = sys.stdin.readline()
s = sys.stdin.readline().split()
nt = sys.stdin.readline()
t = sys.stdin.readline().split()

cnt = 0
for x in t:
    if (binsearch(x, s)):
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys


def binsearch(x, s):
    l = 0
    r = len(s)
    while (l < r):
        m = int((l + r) / 2)
        if s[m] == x:
            return True
        else:
            if s[m] < x:
                l = m + 1
            else:
                r = m
    return False


ns = sys.stdin.readline()
s = sys.stdin.readline().split()
nt = sys.stdin.readline()
t = sys.stdin.readline().split()

cnt = 0
for x in t:
    if (binsearch(x, s)):
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
s=(raw_input()).split(" ")
q=int(raw_input())
t=sorted((raw_input()).split(" "))

s_index=0

rt=0

for i in range(q):
    while s[s_index]<=t[i]:
        if s[s_index]==t[i]:
            rt+=1
            break
        s_index+=1
        if s_index>=n:
            break
    if s_index>=n:
            break

print(rt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    N = int(input())
    S = tuple(map(int, input().split()))
    Q = int(input())
    T = tuple(map(int, input().split()))

    c = Counter(S)
    cnt = 0
    for i in T:
        cnt += c[i]

    print(cnt)

main()

Submission status: Wrong Answer

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

    print(count)


def binary_search(li, key, index, devide=1):
    devide *= 2

    if li[index] == key:
        return True
    elif li[index] < key:
        index += len(li) // devide
    elif li[index] > key:
        index -= len(li) // devide

    if devide > len(li):
        return False
    return binary_search(li, key, index, devide)


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

    return li


main()

Submission status: Wrong Answer

Solution code:
import math
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, len(S) // 2):
            print('kkkkkkkkkkk')
            print(t)
            print('kkkkkkkkkkk')
            count += 1

    print(count)


def binary_search(li, key, index, devide=1):
    devide *= 2

    if li[index] == key:
        return True
    elif li[index] < key:
        index += len(li) // devide
    elif li[index] > key:
        index -= len(li) // devide

    if math.ceil(len(li) / 2) < 2 ** devide:
        return False
    return binary_search(li, key, index, devide)


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

    return li


main()

Submission status: Wrong Answer

Solution code:
import math
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, len(S) // 2):
            count += 1

    print(count)


def binary_search(li, key, index, devide=1):
    devide *= 2

    if li[index] == key:
        return True
    elif li[index] < key:
        index += len(li) // devide
    elif li[index] > key:
        index -= len(li) // devide

    if math.ceil(len(li) / 2) < 2 ** devide:
        return False
    return binary_search(li, key, index, devide)


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

    return li


main()

Submission status: Wrong Answer

Solution code:
def search(target, array):
	start,end=0,len(array)-1
	while (start+1<end):
		mid = (start + end) // 2
		if array[mid] == target:
			return 1
		elif array[mid] < target:
			start = mid
		elif array[mid] > target:
			end = mid
	return 0		

input()
userinput=input()
array=[int(s) for s in userinput.split(' ')]
#print(len(array))
input()
userinput=input()
searcharray=[int(s) for s in userinput.split(' ')]
count =0
for s in searcharray:
	count+=search(s,array)
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    N = int(input())
    S = tuple(map(int, input().split()))
    Q = int(input())
    T = tuple(map(int, input().split()))

    counter = Counter(S)
    cnt = 0
    for i in T:
        cnt += counter[i]
    print(cnt)

main()

Submission status: Wrong Answer

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


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

    return "NOT_FOUND"


if __name__ == '__main__':

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

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

    print(count)

Submission status: Wrong Answer

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

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

#%%
sum = 0

for i in range(q):
    if binarySearch(S,T[i]) == True:
        sum += 1
        
print(sum)

Submission status: Wrong Answer

Solution code:
def main():
    n1 = int(input())
    if n1 > 100000:
        return 
    li1 = [int(x) for x in input().split()]
    if len(li1) > 10**9:
        return 
    n2 = int(input())
    if n1 > 50000:
        return 
    li2 = [int(x) for x in input().split()]
    if len(li2) > 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: Wrong Answer

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

n=int(input())
A=input().split()
input()
print(sum(binarySearch(e) for e in input()))

Submission status: Wrong Answer

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

n=int(input())
A=input().split()
input()
print(sum(binarySearch(e) for e in input().split()))

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
A = list(map(int, input().split()))
input()
k = 0
for e in map(int, input().split()):
    i = bisect.bisect_left(A, e)
    if i < n: k += 1
print(k)

Submission status: Wrong Answer

Solution code:
def binarysearch(ary, num):
    mid = len(ary) // 2

    if mid == 0: return 0

    if num < mid:
        binarysearch(ary[0:mid], num)
    elif num > mid:
        binarysearch(ary[mid+1:mid], num)
    else:
        return mid


n = int(input())
s = list(map(lambda i: int(i), input().split(" ")))
q = int(input())
t = list(map(lambda i: int(i), input().split(" ")))
c = 0

for i in t:
    if binarysearch(s, i) != 0:
        c += 1

print(c)

Submission status: Wrong Answer

Solution code:
def binarysearch(ary, num):
    mid = len(ary) // 2
    if mid == 0: return 0

    if num < mid:
        binarysearch(ary[:mid], num)
    elif num > mid:
        binarysearch(ary[mid+1:], num)
    else:
        return mid


n = int(input())
s = list(map(lambda i: int(i), input().split(" ")))
q = int(input())
t = list(map(lambda i: int(i), input().split(" ")))
c = 0

for i in t:
    if binarysearch(s, i) != None:
        c += 1

print(c)

Submission status: Wrong Answer

Solution code:
def binarysearch(ary, num):
    if len(ary) == 1 and ary[0] != ary: return -1

    mid = len(ary) // 2

    if num < ary[mid]:
        return binarysearch(ary[:mid], num)
    elif num > ary[mid]:
        return binarysearch(ary[mid+1:], num)
    else:
        return ary[mid]

n = int(input())
s = list(map(lambda i: int(i), input().split(" ")))
q = int(input())
t = list(map(lambda i: int(i), input().split(" ")))
c = 0

for i in t:
    if binarysearch(s, i) != -1: c += 1

print(c)

Submission status: Wrong Answer

Solution code:
import sys

if __name__ == '__main__':
    data = []
    count = 0
    for line in sys.stdin:
        data.append(line.split())

    n = int(data[0][0])
    q = int(data[2][0])
    t = list(map(int, data[3]))
    for i in range(0, q - 1):
        head = 0
        tail = n
        s = list(map(int, data[1]))
        while True:
            center = len(s) // 2
            if s[center] == t[i] :
                count = count + 1
                break
            elif s[center] < t[i]:
                head = center + 1
            else :
                tail = center - 1

            s = s[head : tail + 1]

            if head >= tail :
                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

for i in range(q):
    left = 0
    right = n-1
    while left < right:
        mid = (right + left) // 2
        if t[i] == s[mid]:
            count += 1
            break
        elif t[i] < s[mid]:
            right = mid
        elif t[i] > s[mid]:
            left = mid+1

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 i in range(q):
    left = 0
    right = n-1
    while left < right:
        mid = (right + left) // 2
        if t[i] == s[mid]:
            count += 1
            break
        elif t[i] < s[mid]:
            right = mid
        elif t[i] > s[mid]:
            left = mid+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 i in range(Q):
    OK = 0
    NG = N-1
    while abs(OK-NG)>1:
        mid = (OK+NG)//2
        if S[mid]<=T[i]:
            OK = mid
        else:
            NG = mid
    if S[OK] == T[i]:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def binSearch(x,data):
    start = 0
    end = len(data)
    while start <= end:
        mid = int((start + end) / 2)
        if data[mid] == x:
            return 1
        elif data[mid] > x:
            end = mid - 1
        else:
            start = mid + 1
    return 0
l = []
for i in sys.stdin:
    l.append(i)
l[1] = l[1].split()
l[3] = l[3].split()
count = 0
for i in range(0,len(l[3])):
    count += binSearch(l[3][i],l[1])
print(count)

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
center = int(n/2)
shift = int(n/2)
for k in t:
    while True:
        if k == s[center]:
            cnt += 1
            break
        elif k > s[center]:
            shift = int(shift/2)
            center += shift
        elif k < s[center]:
            shift = int(shift/2)
            center -= shift
        else:
            print("ERROR")
        if shift == 0:
            if k == s[0] or k == s[-1]:
                cnt += 1
            break
print(cnt)

Submission status: Wrong Answer

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

for i in t:
    l = 0
    r = n-1
    cen = int((l+r) / 2)
    while r >= l :
        if i > s[cen]:
            l = cen
            cen = int((l+r) / 2)
        elif i < s[cen]:
            r = cen
            cen = int((l+r) / 2)
        if i == s[cen]:
            c += 1
            break
        if l+1 == r-1:
            break
print(c)

Submission status: Wrong Answer

Solution code:
def inarySearch(n,key,A):
    left = 0
    right = n
    while left < right:
        mid =(left + right) / 2
        mid=(int)(mid)
        if A[mid] == key:
            return 1
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return 0
cnt=0
n=int(input())
S=[0 for i in range(n)]
S=input().split()
q=int(input())
T=[0 for i in range(q)]
T=input().split()
for i in range(q):
    a=inarySearch(n,T[i],S)
    if a==1:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
def BinarySearch(n,key,A):
    left = 0
    right = n
    while left < right:
        mid =(left + right)//2
        if A[mid] == key:
            print(key)
            return 1
        elif A[mid]>key:
            right = mid
        else:
            left = mid + 1
            print("a")
    return 2
cnt=0
n=int(input())
S=[0 for i in range(n)]
S=input().split()
q=int(input())
T=[0 for i in range(q)]
T=input().split()
for i in range(q):
    a=BinarySearch(n,T[i],S)
    if a==1:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
def BinarySearch(n,key,A):
    left = 0
    right = n
    while left < right:
        mid =(left + right)//2
        if A[mid] == key:
            return 1
        elif A[mid]>key:
            right = mid
        else:
            left = mid + 1
    return 2
cnt=0
n=int(input())
S=[0 for i in range(n)]
S=input().split()
q=int(input())
T=[0 for i in range(q)]
T=input().split()
for i in range(q):
    a=BinarySearch(n,T[i],S)
    if a==1:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

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

for i in t:
    l = 0
    r = n-1
    cen = int((l+r) / 2)
    while r >= l :
#        print("0:",i,l,r,cen,s[cen])
        if i > s[cen]:
            l = cen
            cen = int((l+r) / 2)
#            print("1:",l,r,cen,s[cen])
        elif i < s[cen]:
            r = cen
            cen = int((l+r) / 2)
#            print("2:",l,r,cen,s[cen])
        if i == s[cen]:
            c += 1
#            print("!")
            break
        if l+1 > r-1:
#            print("!!")
            break
print(c)

Submission status: Wrong Answer

Solution code:
def BinarySearch(n,key,A):
    left = 0
    right = n
    while left<right:
        mid =(left + right)//2
        if A[mid]==key:
            return 0
        elif A[mid]>key:
            right=mid
        else:
            left=mid + 1
    return 1
cnt=0
n=int(input())
S=[0 for i in range(n)]
S=input().split()
q=int(input())
T=[0 for i in range(q)]
T=input().split()
for i in range(q):
    a=BinarySearch(n,T[i],S)
    if a==0:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

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

for i in range(q):
    left=0
    right=n-1
    while left<right:
        mid=int((left+right)/2)
        #print(left,right,mid,s[mid],t[i])
        if s[mid]==t[i]:
            cnt+=1
            break
        elif s[mid]>t[i]:
            right=mid
        else:
            left=mid+1
        
            
            
print(cnt)

Submission status: Wrong Answer

Solution code:
def BinarySearch(n,key,A):
    left=0
    right=n
    while left<right:
        mid=(int)((left+right)/2)
        if A[mid]==key:
            return 0
        elif key<A[mid]:
            right=mid
        else:
            left=mid+1
    return 1
cnt=0
n=int(input())
S=[0 for i in range(n)]
S=input().split()
q=int(input())
T=[0 for i in range(q)]
T=input().split()
for i in range(q):
    a=BinarySearch(n,T[i],S)
    if a==0:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

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


n1=int(input())
l1=list(input().split())

n2=int(input())
l2=list(input().split())

cnt=0

for x in l2:
    if bs(l1,x):
        cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
def bs(l,key):
    left=0
    right=len(l)
    
    while left<right:
        mid=int((left+right)/2)
        print("mid",mid)
        print("l[mid]:",l[mid])
        if l[mid]==key:

            return  True
        elif key<l[mid]:
            right=mid
        else:
            left=mid+1
    
    return False
            


n1=int(input())
l1=list(map(int,input().split()))
n2=int(input())
l2=list(map(int,input().split()))

cnt=0

for x in l2:

    if bs(l1,x):
        cnt+=1

print("cnt",cnt)

Submission status: Wrong Answer

Solution code:
S=[]
T=[]
S_num=int(input())
S=input().split()
T_num=int(input())
T=input().split()
cnt=0

for i in T:
	right=S_num-1
	left=0
	center=int((right+left)/2)
	while left<=center and right>=center:
		if S[center]==i:
			cnt+=1
			break
		elif S[center]>i:
			right=center-1
			center=int((left+right)/2)
		elif S[center]<i:
			left=center+1
			center=int((left+right)/2)
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input().split()

m=int(input())
b=input().split()

a=[int(i) for i in a]
b=[int(i) for i in b]
cnt=0
low=0
high=m
t=int((low+high)/2)
print(t)
i=0
while(low<=high):
  if(b[i]==a[t]):
    i+=1
    cnt+=1
  elif(b[i]>a[t]):
    low=t+1
  elif(b[i]<a[t]):
    high=t-1
  t=int((low+high)/2)
  
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input().split()

m=int(input())
b=input().split()

a=[int(i) for i in a]
b=[int(i) for i in b]
cnt=0
low=0
high=n-1
t=int((low+high)/2)
print(t)
i=0
while(low<=high and i<m):
  if(b[i]==a[t]):
    i+=1
    cnt+=1
    low=0
    high=n
  elif(b[i]>a[t]):
    low=t+1
  elif(b[i]<a[t]):
    high=t-1
  t=int((low+high)/2)
  print("low:",low,"high",high,"t:",t)
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input().split()

m=int(input())
b=input().split()

a=[int(i) for i in a]
b=[int(i) for i in b]
cnt=0
low=0
high=n-1
t=int((low+high)/2)
print(t)
i=0
while(low<=high and i<m):
  if(b[i]==a[t]):
    i+=1
    cnt+=1
    low=0
    high=n
  elif(b[i]>a[t]):
    low=t+1
  elif(b[i]<a[t]):
    high=t-1
  t=int((low+high)/2)
#  print("low:",low,"high",high,"t:",t)
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input().split()

m=int(input())
b=input().split()

a=[int(i) for i in a]
b=[int(i) for i in b]
cnt=0
low=0
high=n-1
t=int((low+high)/2)
print(t)
i=0
while(low<=high and i<m):
  if(b[i]==a[t]):
    i+=1
    cnt+=1
    low=0
    high=n
  elif(b[i]>a[t]):
    low=t+1
  elif(b[i]<a[t]):
    high=t-1
  t=int((low+high)/2)
print(cnt)

Submission status: Wrong Answer

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

Q=list(map(int,Q))
S=list(map(int,S))

cnt=0

for i in range(q):
	left=0
	right=n-1
	while left>=right:
		mid=int((n-1)/2)
		if S[mid]==Q[i]:
			cnt+=1
			break
		elif S[mid]>Q[i]:
			right=mid
		elif S[mid]<Q[i]:
			left=mid

print(cnt)

Submission status: Wrong Answer

Solution code:
#16D8101014F Kurume Ryunosuke 久留米 竜之介 2018/5/14
n=int(input())
S=[]
S=input().split()
q=int(input())
T=[]
T=input().split()
point=0

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

Submission status: Wrong Answer

Solution code:
def binary_search(v,r):
    if len(r)==0:
        return False
    if len(r)==1:
        if v==r[0]:
            return True
        else:
            return False
 
    half=int(len(r)/2)
    if(r[half]==v):
        return True
    else:
        return False
 
    if r[half]>v:
        return binary_search(v,r[:half])
    else:
        return binary_search(v,r[half+1:])
 
n=int(input())
s=[]
l=input()
s=l.split(" ")
for i in range(n):
   s[i]=int(s[i])
 
q=int(input())
l=input()
t=l.split(" ")
for i in range(q):
    t[i]=int(t[i])
 
cnt=0
for i in range(q):
    if binary_search(t[i],s):
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
def half(a,b,low,high): #aは配列,bはソートされてない要素,cはcenter

    if(low > high):
        return 0

    c = int((low+high)/2)

    if(a[c] == b):
        return 1
    elif(a[c] < b):
        return half(a,b,c,high-1)
    elif(a[c] > b):
        return half(a,b,low+1,c)
    else:
        return 1
#############################


n = int(input())
s = list(map(int,input().split()))
q = int(input())
r = list(map(int,input().split()))
cou = 0

for i in range(q):
    cou += half(s,r[i],0,len(s))

print(cou)

Submission status: Wrong Answer

Solution code:
############################
# 再帰的に呼出す関数
def half(a,b,low,high):

    if(low > high):
        return 0

    c = int((low+high)/2)

    if(a[c] == b):
        return 1
    elif(a[c] < b):
        return half(a,b,c+1,high)
    elif(a[c] > b):
        return half(a,b,low,c-1)
#############################


n = int(input())
s = list(map(int,input().split()))
q = int(input())
r = list(map(int,input().split()))
cou = 0

Submission status: Wrong Answer

Solution code:
c=0
n=int(input())
s=input().split()
q=int(input())
t=input().split()
l=list(set(s))
l.sort()
h=0
for i in t:
	for j in l:
		if int(i)==int(j) and h==int(i):
			c +=1
			h=j
			break
print(c)

Submission status: Wrong Answer

Solution code:
c=0
n=int(input())
s=input().split()
q=int(input())
t=input().split()
l=list(set(s))
l.sort()
h=0
for i in t:
	for j in l:
		if int(i)==int(j) and h!=int(i):
			c +=1
			h=j
			break
print(c)

Submission status: Wrong Answer

Solution code:
n_num = int(input())
n_list = list(map(int, input().split()))
q_num = int(input())
q_list = list(map(int, input().split()))

for q in q_list:
	lower = 0
	higher = len(n_list) - 1
	m = (higher - lower) // 2

	while lower <= higher:
		if n_list[m] == q:
			print(q)
			break
		elif n_list[m] > q:
			higher = m - 1
			m = lower + (higher - lower) // 2
		else:
			lower = m + 1
			m = lower + (higher - lower) // 2

Submission status: Wrong Answer

Solution code:
# coding: Shift-JIS
n=int(input())
S=input().split()
q=int(input())
T=input().split()
cnt=0
for t in T:
	l=0
	r=len(S)
	while l<r:
		center=(l+r)//2
		if S[center]==t:
			cnt+=1
			break
		elif t>S[center]:
			l=center+1
		else:
			r=center
print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: Shift-JIS
n=int(input())
S=input().split()
q=int(input())
T=input().split()
cnt=0
for t in T:
	l=0
	r=len(S)
	while l<r:
		center=(l+r)//2
		if S[center]==t:
			cnt+=1
			break
		elif t<S[center]:
			r=center
		else:
			l=center+1
print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: Shift-JIS
n=int(input())
S=input().split()
q=int(input())
T=input().split()
cnt=0
for t in T:
	l=0
	r=len(S)
	while r>=l:
		center=(l+r)//2
		if t==S[center]:
			cnt+=1;
			break
			
		if t>S[center]:
			l=center+1
		else:
			r=center-1

print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: Shift-JIS
n=int(input())
S=input().split()
q=int(input())
T=input().split()
cnt=0
for t in T:
	l=0
	r=len(S)
	while r>=l:
		center=(l+r)//2
		if t==S[center]:
			cnt+=1
			break
		elif t>S[center]:
			l=center+1
		else:
			r=center-1

print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: Shift-JIS
n=int(input())
S=input().split()
q=int(input())
T=input().split()
cnt=0
for t in T:
	l=0
	r=len(S)-1
	while r>=l:
		center=(l+r)//2
		if t==S[center]:
			cnt+=1
			break
		elif t>S[center]:
			l=center+1
		else:
			r=center-1

print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: Shift-JIS
n=int(input())
S=input().split()
q=int(input())
T=input().split()
cnt=0
for t in T:
	l=0
	r=len(S)-1
	center=(l+r)//2
	while l<=r:
		if t==S[center]:
			break
		elif t>S[center]:
			l=center+1
		else:
			r=center-1
		center=(l+r)//2
	if t==S[center]:
		cnt+=1
		
print(cnt)

Submission status: Wrong Answer

Solution code:
S=[]
T=[]
n=int(input())
s=input().split()
for i in range(n):
	S.append(s[i])
q=int(input())
t=input().split()
for j in range(q):
	T.append(t[j])
cnt=0
for i in range(q):
	for j in range(n):
		if T[i]==S[j]:
			cnt+=1
			break
		if S[j+1]==S[j]:
			break
print(cnt)

Submission status: Wrong Answer

Solution code:
S=[]
T=[]
n=int(input())
s=input().split()
for i in range(n):
	S.append(s[i])
q=int(input())
t=input().split()
for j in range(q):
	T.append(t[j])
cnt=0
for i in range(q):
	for j in range(n):
		if T[i]==S[j]:
			cnt+=1
			break
		elif S[j+1]==S[j]:
			break
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
lista=[0 for i in range(n)]
lista=input().split()
n2=int(input())
listb=[0 for i in range(n2)]
listb=input().split()
cnt=0
for i in range(n2):
    x=0
    for j in range(n):
        if listb[i]==lista[j] and x==0:
            x=1
            cnt+=1

Submission status: Wrong Answer

Solution code:
n=int(input())
lista=[0 for i in range(n)]
lista=input().split()
n2=int(input())
listb=[0 for i in range(n2)]
listb=input().split()
cnt=0
cen=lista[int(n/2)]
for i in range(n2):
    x=0
    if cen<listb[i]:
        for j in range(int(n/2),n):
            if listb[i]==lista[j] and x==0:
                x=1
                cnt+=1
    else:
        for j in range(int(n/2)):
            if listb[i]==lista[j] and x==0:
                x=1
                cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
lista=[0 for i in range(n)]
lista=input().split()
n2=int(input())
listb=[0 for i in range(n2)]
listb=input().split()
cnt=0

for i in range(n2):
    x=0
    if lista[int(n/2)]>listb[i]:
        listc=[lista[k] for k in range(int(n/2))]
        for j in range(len(listc)):
            if listb[i]==lista[j] and x==0:
                x=1
                cnt+=1
    else:
        listc=[lista[k] for k in range(int(n/2),n)]
        for j in range(len(listc)):
            if listb[i]==lista[j] and x==0:
                x=1
                cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
lista=[0 for i in range(n)]
lista=input().split()
n2=int(input())
listb=[0 for i in range(n2)]
listb=input().split()
cnt=0

for i in range(n2):
    x=0
    if lista[int(n/2)]>listb[i]:
        listc=[lista[k] for k in range(int(n/2))]
        for j in range(len(listc)):
            if listb[i]==listc[j] and x==0:
                x=1
                cnt+=1
    else:
        listc=[lista[k] for k in range(int(n/2),n)]
        for j in range(len(listc)):
            if listb[i]==listc[j] and x==0:
                x=1
                cnt+=1
print(cnt)

Submission status: Wrong Answer

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

S=[]
T=[]
n=int(input())
s=input().split()
for i in range(n):
	S.append(s[i])
q=int(input())
t=input().split()
for j in range(q):
	T.append(t[j])

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