def minArea(self, image: List[List[str]], x: int, y: int) -> int:
    if ((not image) or (not image[0])):
        return 0
    (n, m) = (len(image), len(image[0]))

    def search_column(l: int, r: int, up: bool) -> int:
        k = (r if up else l)
        while (l <= r):
            (mid, mid_k) = (((l + r) >> 1), 0)
            for i in range(m):
                if (image[mid][i] == '1'):
                    mid_k = 1
                    break
            if mid_k:
                k = (min(k, mid) if up else max(k, mid))
            if (mid_k ^ up):
                l = (mid + 1)
            else:
                r = (mid - 1)
        return k

    def search_row(l: int, r: int, up: bool) -> int:
        k = (r if up else l)
        while (l <= r):
            (mid, mid_k) = (((l + r) >> 1), 0)
            for i in range(n):
                if (image[i][mid] == '1'):
                    mid_k = 1
                    break
            if mid_k:
                k = (min(k, mid) if up else max(k, mid))
            if (mid_k ^ up):
                l = (mid + 1)
            else:
                r = (mid - 1)
        return k
    a = search_column(0, x, True)
    b = search_row(0, y, True)
    c = search_column(x, (n - 1), False)
    d = search_row(y, (m - 1), False)
    return (((c + 1) - a) * ((d + 1) - b))
def minArea(self, image: List[List[str]], x: int, y: int) -> int:
    if ((not image) or (not image[0])):
        return 0
    (n, m) = (len(image), len(image[0]))

    def search_column(l: int, r: int, up: bool) -> int:
        k = (r if up else l)
        while (l <= r):
            (mid, mid_k) = (((l + r) >> 1), 0)
            for i in range(m):
                if (image[mid][i] == '1'):
                    mid_k = 1
                    break
            if mid_k:
                k = (min(k, mid) if up else max(k, mid))
            if (mid_k ^ up):
                l = (mid + 1)
            else:
                r = (mid - 1)
        return k

    def search_row(l: int, r: int, up: bool) -> int:
        k = (r if up else l)
        while (l <= r):
            (mid, mid_k) = (((l + r) >> 1), 0)
            for i in range(n):
                if (image[i][mid] == '1'):
                    mid_k = 1
                    break
            if mid_k:
                k = (min(k, mid) if up else max(k, mid))
            if (mid_k ^ up):
                l = (mid + 1)
            else:
                r = (mid - 1)
        return k
    a = search_column(0, x, True)
    b = search_row(0, y, True)
    c = search_column(x, (n - 1), False)
    d = search_row(y, (m - 1), False)
    return (((c + 1) - a) * ((d + 1) - b))