def solve(self, cipher):
        """
        Boarder detection
        Binary search for coordinates.

        Python time out, use C++ instead.
        :param cipher: the cipher
        """
        r2, k = cipher

        required = 0
        r = r2 ** 0.5

        for x in xrange(0, int(r) + 1):
            # binary search
            low = 0
            high = int(r) + 1
            while low <= high:
                mid = (low + high) / 2
                if x * x + mid * mid == r2:
                    if mid == 0 or x == 0:
                        required += 2
                    else:
                        required += 4
                    if required > k: return "impossible"
                    break
                elif x * x + mid * mid < r2:
                    low = mid + 1
                else:
                    high = mid - 1

        if required > k: return "impossible"
        return "possible"
dataset/ETHPy150Open algorhythms/HackerRankAlgorithms/Circle City.py/Solution.solve/original