def findFirst(L, pred):
    """
    Returns the first element in L that satisfies a given predicate with binary search.
    L must be a list of elements that DO NOT satisfy the predicate followed by a list of ones that DO satisfy pred.
    Returns 0 if there is no element satisfying pred.
    """
    left, right = 0, len(L) - 1
    ans = 0
    while left <= right:
        mid = left + (right - left) // 2
        if pred(L[mid]):
            ans = L[mid]
            right = mid - 1
        else:
            left = mid + 1

    return ans