Buggy python submission (verdict: Time Limit Exceeded):
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 > 0):
        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)

print(answer)
    


Fixed submission:
n = int(input())
sinput = input().split()
s=[]
for i in range(n):
    s.append(int(sinput[i]))

q = int(input())
tinput = input().split()
t=[]
for i in range(q):
    t.append(int(tinput[i]))
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]):
            if(tn == s[smax]):
                answer = answer + 1
                break
            smin = c
            c = math.floor((smin + smax) / 2) 
        elif(tn < s[c]):
            if(tn == s[smin]):
                answer = answer + 1
                break
            smax = c
            c = math.floor((smin + smax) / 2)

print(answer)

Buggy python submission (verdict: Runtime Error):
count_n = int(input())
N = []
n = input()
N = n.split()
N = list(map(lambda x: int(x), N)).sort()


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


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

Fixed submission:
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 p in P:
    if b(p, N):
        answer += 1
print (answer)

Buggy python submission (verdict: Runtime Error):
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

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

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

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

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

Buggy python submission (verdict: Runtime Error):
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

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

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

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

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

Buggy python submission (verdict: Runtime Error):
n = int(input())
S = [int(s) for s in input().split()]
q = int(input())
T = [int(t) for t in input().split()]

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

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

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

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