def lowerBound(sortedCollection, item, key=lambda x: x):
    """
    Given a sorted collection, perform binary search to find element x for which
    the following holds: item > key(x) and the value key(x) is the largest.
    Returns index of such an element.
    """
    lo = 0
    hi = len(sortedCollection)
    while lo < hi:
        mid = (lo + hi) // 2
        if item > key(sortedCollection[mid]):
            lo = mid + 1
        else:
            hi = mid
    return lo - 1