Buggy python submission (verdict: Time Limit Exceeded):
def search(l, n):
    l = l.copy()
    l.append(n)
    i = 0
    while l[i] != n:
        i += 1

    if i == len(l) - 1:
        print("NOT FOUND")
    else:
        print("FOUND")


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 ti in s:
        ans += 1

print(ans)


Fixed submission:
def search(l, n):
    left = 0
    right = len(l) - 1
    while right - left > 1:
        m = (left + right) // 2
        if n == l[m]:
            return True
        elif n < l[m]:
            right = m
        else:
            left = m

    # print(left, right)
    if l[left] == n or l[right] == n:
        return True
    else:
        return False


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)

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

        m = (left + right) // 2

    # if l[left] == n or l[right] == n:
    #     return True
    # else:
    #     return False


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)



Fixed submission:
def search(l, n):
    left = 0
    right = len(l) - 1
    while right - left > 1:
        m = (left + right) // 2
        if n == l[m]:
            return True
        elif n < l[m]:
            right = m
        else:
            left = m

    # print(left, right)
    if l[left] == n or l[right] == n:
        return True
    else:
        return False


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)

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



Fixed submission:
def search(l, n):
    left = 0
    right = len(l) - 1
    while right - left > 1:
        m = (left + right) // 2
        if n == l[m]:
            return True
        elif n < l[m]:
            right = m
        else:
            left = m

    # print(left, right)
    if l[left] == n or l[right] == n:
        return True
    else:
        return False


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)