Buggy python submission (verdict: Time Limit Exceeded):
# encoding: utf-8


class Solution:
    @staticmethod
    def binary_search():
        array_length_1 = int(input())
        array_1 = [int(x) for x in input().split()]
        array_length_2 = int(input())
        array_2 = [int(x) for x in input().split()]

        # print(len(set(array_1).intersection(set(array_2))))
        left, right, count = 0, array_length_1, 0
        for each in array_2:
            while left < right:
                mid = (left + right) // 2
                if array_1[mid] == each:
                    count += 1
                elif each < array_1[mid]:
                    right = mid
                else:
                    left = mid + 1

        print(count)


if __name__ == '__main__':
    solution = Solution()
    solution.binary_search()

Fixed submission:
# encoding: utf-8


import sys


class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        length_1 = int(self.__input[0])
        array_1 = list(map(int, self.__input[1].split()))
        length_2 = int(self.__input[2])
        array_2 = list(map(int, self.__input[3].split()))

        assert length_1 == len(array_1) and length_2 == len(array_2)

        count = 0

        for each in array_2:
            if self.binary_search(key=each, array=array_1, array_length=length_1):
                count += 1

        return str(count)

    @staticmethod
    def binary_search(key, array, array_length):
        # print(len(set(array_1).intersection(set(array_2))))
        left, right = 0, array_length
        while left < right:
            mid = (left + right) // 2
            if key == array[mid]:
                return True
            elif key < array[mid]:
                right = mid
            else:
                left = mid + 1
        return False


if __name__ == '__main__':
    case = Solution()
    print(case.solution)

Buggy python submission (verdict: Time Limit Exceeded):
# encoding: utf-8


class Solution:
    @staticmethod
    def binary_search():
        array_length_1 = int(input())
        array_1 = [int(x) for x in input().split()]
        array_length_2 = int(input())
        array_2 = [int(x) for x in input().split()]

        # print(len(set(array_1).intersection(set(array_2))))
        left, right, count = 0, array_length_1, 0
        for each in array_2:
            while left < right:
                mid = int((left + right) / 2)
                if array_1[mid] == each:
                    count += 1
                elif each < array_1[mid]:
                    right = mid
                else:
                    left = mid + 1

        print(count)


if __name__ == '__main__':
    solution = Solution()
    solution.binary_search()

Fixed submission:
# encoding: utf-8


import sys


class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        length_1 = int(self.__input[0])
        array_1 = list(map(int, self.__input[1].split()))
        length_2 = int(self.__input[2])
        array_2 = list(map(int, self.__input[3].split()))

        assert length_1 == len(array_1) and length_2 == len(array_2)

        count = 0

        for each in array_2:
            if self.binary_search(key=each, array=array_1, array_length=length_1):
                count += 1

        return str(count)

    @staticmethod
    def binary_search(key, array, array_length):
        # print(len(set(array_1).intersection(set(array_2))))
        left, right = 0, array_length
        while left < right:
            mid = (left + right) // 2
            if key == array[mid]:
                return True
            elif key < array[mid]:
                right = mid
            else:
                left = mid + 1
        return False


if __name__ == '__main__':
    case = Solution()
    print(case.solution)

Buggy python submission (verdict: Runtime Error):
# encoding: utf-8


class Solution:
    @staticmethod
    def binary_search():
        array_length_1 = int(input())
        array_1 = [int(x) for x in input().split()]
        array_length_2 = int(input())
        array_2 = [int(x) for x in input().split()]

        # print(len(set(array_1).intersection(set(array_2))))
        left, right, count = 0, array_length_1, 0
        for each in array_2:
            while left < right:
                mid = (left + right) // 2
                if array_1[mid] == each:
                    count += 1
                elif each < array_1[mid]:
                    right = mid
                else:
                    left = mid + 1

        print(count)


if __name__ == '__main__':
    solution = Solution()
    solution.binary_search()

Fixed submission:
# encoding: utf-8


import sys


class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        length_1 = int(self.__input[0])
        array_1 = list(map(int, self.__input[1].split()))
        length_2 = int(self.__input[2])
        array_2 = list(map(int, self.__input[3].split()))

        assert length_1 == len(array_1) and length_2 == len(array_2)

        count = 0

        for each in array_2:
            if self.binary_search(key=each, array=array_1, array_length=length_1):
                count += 1

        return str(count)

    @staticmethod
    def binary_search(key, array, array_length):
        # print(len(set(array_1).intersection(set(array_2))))
        left, right = 0, array_length
        while left < right:
            mid = (left + right) // 2
            if key == array[mid]:
                return True
            elif key < array[mid]:
                right = mid
            else:
                left = mid + 1
        return False


if __name__ == '__main__':
    case = Solution()
    print(case.solution)

Buggy python submission (verdict: Time Limit Exceeded):
# encoding: utf-8


class Solution:
    @staticmethod
    def binary_search():
        array_length_1 = int(input())
        array_1 = [int(x) for x in input().split()]
        array_length_2 = int(input())
        array_2 = [int(x) for x in input().split()]

        # print(len(set(array_1).intersection(set(array_2))))
        left, right, count = 0, array_length_1, 0
        for each in array_2:
            while left < right:
                mid = (left + right) // 2
                if array_1[mid] == each:
                    count += 1
                elif each < array_1[mid]:
                    right = mid
                else:
                    left = mid + 1

        print(count)


if __name__ == '__main__':
    solution = Solution()
    solution.binary_search()

Fixed submission:
# encoding: utf-8


import sys


class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        length_1 = int(self.__input[0])
        array_1 = list(map(int, self.__input[1].split()))
        length_2 = int(self.__input[2])
        array_2 = list(map(int, self.__input[3].split()))

        assert length_1 == len(array_1) and length_2 == len(array_2)

        count = 0

        for each in array_2:
            if self.binary_search(key=each, array=array_1, array_length=length_1):
                count += 1

        return str(count)

    @staticmethod
    def binary_search(key, array, array_length):
        # print(len(set(array_1).intersection(set(array_2))))
        left, right = 0, array_length
        while left < right:
            mid = (left + right) // 2
            if key == array[mid]:
                return True
            elif key < array[mid]:
                right = mid
            else:
                left = mid + 1
        return False


if __name__ == '__main__':
    case = Solution()
    print(case.solution)