Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
cnt = 0
for i in t:
    if i in s:
        cnt += 1
print(cnt)


Fixed submission:
def binarySearch(array, key):
    left = 0
    right = len(array)
    while left < right:
        mid = int((left + right) / 2)
        if key == array[mid]:
            return True
        elif key > array[mid]:
            left = mid + 1
        elif key < array[mid]:
            right = mid
        else:
            print("ERROR")
    return False


n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
a = [x for x in t if binarySearch(s, x)]
print(len(a))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
cnt = 0
y = None
for x in s:
    if x == y:
        continue
    else:
        if x in t:
            cnt += 1
            y = x
        else:
            continue
print(cnt)


Fixed submission:
def binarySearch(array, key):
    left = 0
    right = len(array)
    while left < right:
        mid = int((left + right) / 2)
        if key == array[mid]:
            return True
        elif key > array[mid]:
            left = mid + 1
        elif key < array[mid]:
            right = mid
        else:
            print("ERROR")
    return False


n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
a = [x for x in t if binarySearch(s, x)]
print(len(a))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n = int(input())
s = deque([int(x) for x in input().split()])
q = int(input())
t = [int(x) for x in input().split()]
cnt = 0

for i in t:
    if i in s:
        cnt += 1
        while i in s:
            s.remove(i)
    else:
        continue
print(cnt)


Fixed submission:
def binarySearch(array, key):
    left = 0
    right = len(array)
    while left < right:
        mid = int((left + right) / 2)
        if key == array[mid]:
            return True
        elif key > array[mid]:
            left = mid + 1
        elif key < array[mid]:
            right = mid
        else:
            print("ERROR")
    return False


n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
a = [x for x in t if binarySearch(s, x)]
print(len(a))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
a = list(filter(lambda x: x in s, t))
print(len(a))


Fixed submission:
def binarySearch(array, key):
    left = 0
    right = len(array)
    while left < right:
        mid = int((left + right) / 2)
        if key == array[mid]:
            return True
        elif key > array[mid]:
            left = mid + 1
        elif key < array[mid]:
            right = mid
        else:
            print("ERROR")
    return False


n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
a = [x for x in t if binarySearch(s, x)]
print(len(a))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
a = list(filter(lambda x: x in s, [int(y) for y in input().split()]))
print(len(a))


Fixed submission:
def binarySearch(array, key):
    left = 0
    right = len(array)
    while left < right:
        mid = int((left + right) / 2)
        if key == array[mid]:
            return True
        elif key > array[mid]:
            left = mid + 1
        elif key < array[mid]:
            right = mid
        else:
            print("ERROR")
    return False


n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
a = [x for x in t if binarySearch(s, x)]
print(len(a))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
a = [x for x in t if x in s]
print(len(a))


Fixed submission:
def binarySearch(array, key):
    left = 0
    right = len(array)
    while left < right:
        mid = int((left + right) / 2)
        if key == array[mid]:
            return True
        elif key > array[mid]:
            left = mid + 1
        elif key < array[mid]:
            right = mid
        else:
            print("ERROR")
    return False


n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
a = [x for x in t if binarySearch(s, x)]
print(len(a))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
cnt = 0
for k in t:
    center = int(n/2)
    shift = int(n/2)
    j = 0
    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:
            j += 1
            if j == 2:
                if k in s[:center] or k in s[center:]:
                    cnt += 1
                break
print(cnt)


Fixed submission:
def binarySearch(array, key):
    left = 0
    right = len(array)
    while left < right:
        mid = int((left + right) / 2)
        if key == array[mid]:
            return True
        elif key > array[mid]:
            left = mid + 1
        elif key < array[mid]:
            right = mid
        else:
            print("ERROR")
    return False


n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
a = [x for x in t if binarySearch(s, x)]
print(len(a))

Buggy python submission (verdict: Runtime Error):
def binarySearch(array, key):
    left = 0
    right = len(array)
    while left < right:
        mid = (left + right) / 2
        if key == array[mid]:
            return True
        elif key > array[mid]:
            left = mid + 1
        elif key < array[mid]:
            right = mid
        else:
            print("ERROR")
    return False


n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
a = [x for x in t if binarySearch(s, x)]
print(len(a))


Fixed submission:
def binarySearch(array, key):
    left = 0
    right = len(array)
    while left < right:
        mid = int((left + right) / 2)
        if key == array[mid]:
            return True
        elif key > array[mid]:
            left = mid + 1
        elif key < array[mid]:
            right = mid
        else:
            print("ERROR")
    return False


n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
a = [x for x in t if binarySearch(s, x)]
print(len(a))