# Path: pyalgs/algorithms/commons/util.py
# def is_sorted(a):
#     if len(a) <= 1:
#         return True
#     for i in range(1, len(a)):
#         if less(a[i], a[i - 1]):
#             return False
#     return True
# 
# def less(a, b):
#     return cmp(a, b) < 0


from pyalgs.algorithms.commons.util import is_sorted, less


class BinarySelection(object):
    @staticmethod
    def index_of(a, x, lo=None, hi=None):
        if not is_sorted(a):
            raise ValueError('array must be sorted before running selection')

        if lo is None:
            lo = 0
        if hi is None:
            hi = len(a) - 1

        while lo <= hi:
            mid = lo + (hi - lo) // 2
            if less(x, a[mid]):
                hi = mid - 1

# Path: pyalgs/algorithms/commons/util.py
# def is_sorted(a):
#     if len(a) <= 1:
#         return True
#     for i in range(1, len(a)):
#         if less(a[i], a[i - 1]):
#             return False
#     return True
# 
# def less(a, b):
#     return cmp(a, b) < 0


# Path: pyalgs/algorithms/commons/selecting.py
from pyalgs.algorithms.commons.util import is_sorted, less



class BinarySelection(object):
    @staticmethod
    def index_of(a, x, lo=None, hi=None):
        if not is_sorted(a):
            raise ValueError('array must be sorted before running selection')

        if lo is None:
            lo = 0
        if hi is None:
            hi = len(a) - 1

        while lo <= hi:
            mid = lo + (hi - lo) // 2
            if less(x, a[mid]):
                hi = mid - 1

            elif less(a[mid], x):