Buggy python submission (verdict: Time Limit Exceeded):
class Sequence:
    def __init__(self,num, seq):
        self.n = num
        self.sequence = seq

def LinearSearch(A, n, key):
    i=0
    A[n] = key
    while A[i] != key:
        i += 1
    if i==n:
        return "NOT_FOUND"
    return i

if __name__ == "__main__":

    n = int(raw_input())
    x =	map(int, raw_input().split())
    x.append(" ")
    A = Sequence(n, x)
    n =	int(raw_input())
    x =	map(int, raw_input().split())
    x.append(" ")
    B = Sequence(n, x)

    C_num = 0

    for i in range(B.n):
        res = LinearSearch(A.sequence, A.n, B.sequence[i])
        if res != "NOT_FOUND":
            C_num += 1

    print(C_num)

Fixed submission:
def BinarySearch(A, n, key):
    #left:left end index                                      
    #right:right end index + 1                                
    left = 0
    right = n

    while left < right:
        mid = (left+right)/2
        if A[mid] == key:
            return mid
        elif key < A[mid]:
            right = mid
        elif key > A[mid]:
            left = mid + 1

    return "NOT_FOUND"


if __name__ == "__main__":
    n1 = int(raw_input())
    x1 = map(int, raw_input().split())
    n2 = int(raw_input())
    x2 = map(int, raw_input().split())

    C_num = 0

    for i in range(n2):
	if BinarySearch(x1, n1, x2[i]) != "NOT_FOUND":
            C_num += 1

    print(C_num)

Buggy python submission (verdict: Time Limit Exceeded):
def BinarySearch(A, n, key):
    left = 0
    right = n

    while left < right:
        mid = (left+right)/2
	if A[mid] == key:
            return mid
	elif key < A[mid]:
            right = mid
	elif key > A[mid]:
            left = mid
    return "NOT_FOUND"


if __name__ == "__main__":
    n1 = int(raw_input())
    x1 = map(int, raw_input().split())
    n2 = int(raw_input())
    x2 = map(int, raw_input().split())

    C_num = 0

    for i in range(n2):
	if BinarySearch(x1, n1, x2[i]) != "NOT_FOUND":
            C_num += 1

    print(C_num)

Fixed submission:
def BinarySearch(A, n, key):
    #left:left end index                                      
    #right:right end index + 1                                
    left = 0
    right = n

    while left < right:
        mid = (left+right)/2
        if A[mid] == key:
            return mid
        elif key < A[mid]:
            right = mid
        elif key > A[mid]:
            left = mid + 1

    return "NOT_FOUND"


if __name__ == "__main__":
    n1 = int(raw_input())
    x1 = map(int, raw_input().split())
    n2 = int(raw_input())
    x2 = map(int, raw_input().split())

    C_num = 0

    for i in range(n2):
	if BinarySearch(x1, n1, x2[i]) != "NOT_FOUND":
            C_num += 1

    print(C_num)

Buggy python submission (verdict: Time Limit Exceeded):
def BinarySearch(A, n, key):
    left = 0
    right = n

    while left < right:
        mid = (left+right)/2
	if A[mid] == key:
            return mid
	elif key < A[mid]:
            right = mid
	elif key > A[mid]:
            left = mid
    return "NOT_FOUND"


if __name__ == "__main__":
    n1 = int(raw_input())
    x1 = map(int, raw_input().split())
    n2 = int(raw_input())
    x2 = map(int, raw_input().split())

    C_num = 0

    for i in range(n2):
	if BinarySearch(x1, n1, x2[i]) != "NOT_FOUND":
            C_num += 1

    print(C_num)

Fixed submission:
def BinarySearch(A, n, key):
    #left:left end index                                      
    #right:right end index + 1                                
    left = 0
    right = n

    while left < right:
        mid = (left+right)/2
        if A[mid] == key:
            return mid
        elif key < A[mid]:
            right = mid
        elif key > A[mid]:
            left = mid + 1

    return "NOT_FOUND"


if __name__ == "__main__":
    n1 = int(raw_input())
    x1 = map(int, raw_input().split())
    n2 = int(raw_input())
    x2 = map(int, raw_input().split())

    C_num = 0

    for i in range(n2):
	if BinarySearch(x1, n1, x2[i]) != "NOT_FOUND":
            C_num += 1

    print(C_num)