def bsearch(arr, tgt):
    lo = 0
    hi = len(arr)
    while lo <= hi:
        mid = (lo + hi) / 2
        if arr[mid] < tgt:
            lo = mid + 1
        else:
            hi = mid - 1
    return (lo + hi) / 2


def bsearch(arr, tgt):
    lo = 0
    hi = len(arr)
    while lo != hi:
        mid = (lo + hi) / 2
        if arr[mid] < tgt:
            lo = mid + 1
        else:
            hi = mid - 1
    return (lo + hi) / 2

Search for an element in an array using the binary search algorithm.


def bsearch(a, q):
    low = 0
    high = len(a) - 1
    while True:
        if high < low:
            return -1
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        elif a[mid] > q:
            high = mid - 1
        else:
            return mid


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] <= q:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid and mid < high
        if a[mid] < q:
            low = mid + 1
            assert a[low - 1] < q
        else:
            high = mid
            assert q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while True:
        if high < low:
            return -1
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        elif a[mid] > q:
            high = mid - 1
        else:
            return mid


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if q > a[mid]:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(arr, tgt):
    lo = 0
    hi = len(arr)
    while lo <= hi and (low + hi) / 2 < len(arr):
        mid = (lo + hi) / 2
        if arr[mid] < tgt:
            lo = mid + 1
        else:
            hi = mid - 1
    return (lo + hi) / 2


def bsearch(arr, tgt):
    lo = 0
    hi = len(arr)
    while lo <= hi and (lo + hi) / 2 < len(arr):
        mid = (lo + hi) / 2
        if arr[mid] < tgt:
            lo = mid + 1
        else:
            hi = mid - 1
    return (lo + hi) / 2


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (high + low) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    mid = 0
    i = 0
    if q in a:
        while a[i] != q:
            i += 1
        print(i)
    else:
        while low != high:
            mid = (high + low) / 2
            if a[mid] < low:
                high = mid
            else:
                low = mid
            print(low)


def bsearch(a, q):
    low = 0
    high = len(a) - 1
    while True:
        if high < low:
            return -1
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            return mid


def bsearch(arr, tgt):
    lo = 0
    hi = len(arr)
    while lo <= hi and (lo + hi) / 2 < len(arr):
        mid = (lo + hi) / 2
        if arr[mid] < tgt:
            lo = mid + 1
        else:
            hi = mid - 1
    return (lo + hi) / 2 + 1


def bsearch(a, q):
    low = 0
    high = len(a)
    i = 0
    if q in a:
        while a[i] != q:
            i += 1
        print(i)


def bsearch(a, q):
    A = False
    found = A
    newSet = q
    while found != True or newSet > 0:
        midpoint = int(len(newSet) / 2)
        if a < newSet[midpoint]:
            found = A
            newSet = newSet[:midpoint]
        elif a > newSet[midpoint]:
            found = A
            newSet = newSet[midpoint:]
        elif a == newSet[midpoint]:
            found = True
    return found


def bsearch(a, q):
    low = 0
    high = len(a)
    i = 0
    if q in a:
        while a[i] != q:
            i += 1
        print(i)
    else:
        while low != high:
            mid = (high + low) / 2
            if a[mid] < low:
                high = mid
            else:
                low = mid
            return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
        return low


def bsearch(a, q):
    low = 0
    high = len(a)
    i = 0
    while low != high:
        mid = (high + low) / 2
        if a[mid] < low:
            high = mid
        else:
            low = mid
        return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low == 0 and a[low - 1] < q
        if a[mid] < q:
            low = mid + 1
            assert a[low - 1] < q
        else:
            high = mid
            assert q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid and mid < high
        if a[mid] < q:
            low = mid + 1
            assert a[low - 1] < q
        else:
            high = mid
            assert q <= a[high]
            return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = low
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    i = 0
    while low != high:
        mid = (high + low) / 2
        if a[mid] < q:
            high = mid
        else:
            low = mid
        return low


def bsearch(a, q):
    low = 0
    high = len(a) - 1
    while low != high:
        if high < low:
            return -1
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            return mid


def bsearch(a, t):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < t:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    i = 0
    while low != high:
        mid = (high + low) / 2
        if a[mid] < q:
            high = mid
        else:
            low = mid
    return low


def bsearch(a, t):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < t:
            low = mid + 1
        else:
            high = mid - 1
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (high + low) / 2
        if a[mid] < q:
            assert low == 0 or a[low - 1] < q
            assert high == len(a) or q <= a[high]
        else:
            mid = low


def bsearch(a, q):
    low = 0
    high = len(a) - 1
    while low != high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            return mid


def bsearch(a, q):
    low = 0
    high = len(a) - 1
    while low != high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = low + 1
        else:
            return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid and mid < high
        if a[mid] < q:
            low = mid + 1
            assert a[low - 1] < q
        else:
            high = mid
            assert q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (high + low) / 2
        if a[mid + 1] < q:
            assert low == 0 or a[low - 1] < q
            assert high == len(a) or q <= a[high]
        else:
            mid = low


def bsearch(a, q):
    high = len(a)
    low = 0
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (high + low) / 2
        if low < q:
            low = mid + 1
        else:
            high = mid
    print(low)


def bsearch(a, q):
    low = 0
    high = len(a)
    while low != high:
        m = (low + high) / 2
        if a[m] < q:
            low = m + 1
        else:
            high = m
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low != high:
        mid = (high + low) / 2
        if a[mid] < q:
            low = mid
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = low + (high - low) / 2
        if a[mid] < q:
            low = mid + 1
        elif a[mid] >= q:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (high + low) / 2
        if low < q:
            low = low + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid < high
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
        return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid and mid < high
        if a[mid] < q:
            low = mid + 1
            assert a[low - 1] < q
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid < high
        if a[mid] < q:
            low = mid + 1
            assert a[low - 1] < a
        else:
            high = mid
            assert q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (high + low) / 2
        assert low <= mid < high
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (high + low) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid < high
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid < high
        if a[mid] < q:
            low = mid + 1
            assert low == 0 or a[low - 1] < q
        else:
            high = mid
            assert high == len(a) or q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (high + low) / 2
        if low < q:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid and mid < high
        if a[mid] < q:
            low = mid + 1
            assert a[low - 1] < q
        else:
            high = mid
            assert q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = low + (high - low) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
        return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid < high
        if a[mid] < q:
            low = mid + 1
            assert a[low - 1] < q
        else:
            high = mid
            assert q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid and mid < high
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
            assert q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = low + (high - low) / 2
        if a[mid] < q:
            low = mid
        else:
            high = mid + 1
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a) - 1
    mid = 0
    while low < len(a) and a[low] < q:
        mid = (high + low) // 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    print(q)
    print(a, len(a))
    print(low, high)
    while low != high:
        mid = (low + high) / 2
        if a[mid] < q:
            0
        else:
            0
        print(q)
        print(a, len(a))
        print(low, mid, high)
        assert low == 0 or a[low - 1] < q
        assert high == len(a) or q <= a[high]
        low = high
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    print(q)
    print(a, len(a))
    print(low, high)
    while low != high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
        print(q)
        print(a, len(a))
        print(low, mid, high)
        assert low == 0 or a[low - 1] < q
        assert high == len(a) or q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low != high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
        print(q)
        print(a, len(a))
        print(low, mid, high)
        assert low == 0 or a[low - 1] < q
        assert high == len(a) or q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low != high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
        assert low == 0 or a[low - 1] < q
        assert high == len(a) or q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid < high
    if a[mid] < q:
        low = mid + 1
        assert low == 0 or a[low - 1] < q
    else:
        high = mid
        assert q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (high + low) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
    if a[mid] < q:
        low = mid + 1
    else:
        high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
    if a[mid] < q:
        low = mid
    else:
        high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = low + high / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        middle = (low + high) / 2
        if a[mid] < q:
            low = mid
            assert low == 0 or a[low - 1] < q
        else:
            high = mid
            assert high == len(a) or q <= a[high]


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        middle = (low + high) / 2
        if a[middle] < q:
            low = middle
            assert low == 0 or a[low - 1] < q
        else:
            high = middle
            assert high == len(a) or q <= a[high]


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (high + low) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
    return high


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = low + (high - low) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        middle = (low + high) / 2
        if a[middle] < q:
            low = middle
            assert low == 0 or a[low - 1] < q
        else:
            high = middle
            assert high == len(a) or q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        middle = (low + high) / 2
        if a[middle] < q:
            low = middle
            assert low == 0 or a[low - 1] < q
        else:
            high = middle
            assert high == len(a) or q <= a[high]
        return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid < high
        if a[mid] < q:
            low = mid + 1
            assert low == 0 or a[low - 1] < q
        else:
            high = mid
            assert high == len(a) or q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        middle = (low + high) / 2
        if a[middle] < q:
            low = middle
            assert low == 0 or a[low - 1] < q
        else:
            high = middle
            assert high == len(a) or q <= a[high]
        return low[i]


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid and mid < high
        if a[mid] < q:
            low = mid + 1
            assert a[low - 1] < q
        else:
            high = mid
            assert q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid
            assert low == 0 or a[low - 1] < q
        else:
            high = mid
            assert high == len(a) or q <= a[high]


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid
            assert low == 0 or a[low - 1] < q
        else:
            high = mid
            assert high == len(a) or q <= a[high]
        return low, high


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid
            assert low == 0 or a[low - 1] < q
        else:
            high = mid
            assert high == len(a) or q <= a[high]
        return mid


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid
            assert low == 0 or a[low - 1] < q
        else:
            high = mid
            assert high == len(a) or q <= a[high]
        return high - low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid
            assert low == 0 or a[low - 1] < q
        else:
            high = mid
            assert high == len(a) or q <= a[high]
        return len(a)


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        middle = (low + high) / 2
        if a[middle] < q:
            low = middle + 1
            assert low == 0 or a[low - 1] < q
        else:
            high = middle
            assert high == len(a) or q <= a[high]
        return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid
            assert low == 0 or a[low - 1] < q
        else:
            high = mid
            assert high == len(a) or q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid
            assert low == 0 or a[low - 1] < q
        else:
            high = mid
            assert high == len(a) or q <= a[high]
        return high


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid
            assert low == 0 or a[low - 1] < q
        else:
            high = mid
            assert high == len(a) or q <= a[high]
        return high - mid


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid < high
        if a[mid] < q:
            low = mid + 1
            assert a[low - 1] < q or low == 0
        else:
            high = mid
            assert q <= a[high] or high == len(a)
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        middle = (low + high) / 2
        if a[middle] < q:
            low = middle + 1
        else:
            high = middle
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid and mid < high
    if a[mid] < q:
        low = mid + 1
        assert a[low - 1] < q
    elif a[mid] == q:
        return mid
    else:
        high = mid
        assert q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid and mid < high
        if a[mid] < q:
            low = mid + 1
            assert a[low - 1] < q
        elif a[mid] == q:
            return mid
        else:
            high = mid
            assert q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid < high
        if a[mid] < q:
            low = mid + 1
            assert a[low - 1] < q
        else:
            high = mid
            assert q <= a[high]
        return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid < high
        if a[mid] < q:
            low = mid + 1
            assert a[low - 1] < q
        else:
            high = mid
            assert q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid and mid < high
        if a[mid] < q:
            low = mid + 1
            assert a[low - 1] < q
        elif a[mid] == q:
            return mid
        else:
            high = mid
            assert q <= a[high]
    assert low == 0 or a[low - 1] < q
    assert high == len(a) or q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid and mid < high
        if a[mid] < q:
            low = mid + 1
            assert a[low - 1] < q
        else:
            high = mid
            assert q <= a[high]
    assert low == 0 or a[low - 1] < q
    assert high == len(a) or q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
            assert low == 0 or a[low - 1] < q
        else:
            high = mid
            assert high == len(a) or q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid and mid < high
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
            assert q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid < high
        if a[mid] < q:
            low = mid + 1
            assert low == 0 or a[low - 1] < q
        else:
            high = mid
            assert high == len(a) or q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while high != low:
        search = (high + low) / 2
        if a[search] == q:
            return True
        elif a[search] > q:
            high = search
        else:
            low = search
            if low == search:
                low += 1
    return False


def bsearch(a, q):
    low = 0
    high = len(a)
    while high != low:
        search = (high + low) / 2
        if a[search] == q:
            return search
        elif a[search] > q:
            high = search
        else:
            low = search
            if low == search:
                low += 1
    return search


def bsearch(a, q):
    low = 0
    high = len(a)
    search = (high + low) / 2
    while high != low and a[search] != q:
        search = (high + low) / 2
        if a[search] > q:
            high = search
        else:
            low = search
            if low == search:
                low += 1
    return search


def bsearch(a, q):
    low = 0
    high = len(a)
    while high != low:
        search = (high + low) / 2
        if a[search] == q and a[search - 1] != q:
            return search
        elif a[search] > q:
            high = search
        else:
            low = search
            if low == search:
                low += 1
    return search


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        search = (high + low) / 2
        assert low <= search < high
        if a[search] < q:
            low = search + 1
            assert a[low - 1] < q
        else:
            high = search
            assert q <= a[high]
    return low


def intersection(a, b):
    seen = {}
    appended = {}
    c = []
    i = 0
    while i < len(a):
        seen[a[i]] = True
        i = i + 1
    i = 0
    while i < len(b):
        if b[i] in seen and b[i] not in appended:
            c.append(b[i])
            appended[b[i]] = True
        i = i + 1
    return c

Return the elements which are in both lists.


def union(a, b):
    a = a + b
    seen = {}
    c = []
    i = 0
    while i < len(a):
        if a[i] not in seen:
            c.append(a[i])
            seen[a[i]] = True
        i = i + 1
    return c

Merge two lists into a single one.


Merge two lists into a single one.


def walkback(a, q, i):
    while i > 1 and a[i - 1] == q:
        i -= 1
    return i

def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        guess = low + (high - low) / 2
        if a[guess] == q:
            return walkback(a, q, guess)
        elif a[guess] < q:
            low = guess + 1
        else:
            high = guess - 1
    return low


def walkback(a, q, i):
    while i > 1 and a[i - 1] == q:
        i -= 1
    return i

def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        guess = low + (high - low) // 2
        if a[guess] == q:
            return walkback(a, q, guess)
        elif a[guess] < q:
            low = guess + 1
        else:
            high = guess
    return low


def walkback(a, q, i):
    while i > 0 and a[i - 1] == q:
        i -= 1
    return i

def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        guess = low + (high - low) // 2
        if a[guess] == q:
            return walkback(a, q, guess)
        elif a[guess] < q:
            low = guess + 1
        else:
            high = guess
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid < high
        if a[mid] < q:
            low = mid + 1
            assert a[low - 1] < a
        else:
            high = mid
            assert q <= a[high]
    return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
        return low


def reverse(a):
    i = 0
    j = len(a) - 1
    while i < len(a) / 2:
        tmp = a[i]
        a[i] = a[j]
        a[j] = tmp
        i = i + 1
        j = j - 1

Reverse a list of elements.


Reverse a list of elements.


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        assert low <= mid < high
        if a[mid] < q:
            low = mid + 1
            assert a[low - 1] < q
        else:
            high = mid
            assert q <= a[high]
    return low


def reverse(a):
    a = a[::-1]
    return a

Reverse a list of elements.


def selection_sort(a):
    i = 0
    while i < len(a):
        p = i
        j = i + 1
        while j < len(a):
            if a[j] < a[p]:
                p = j
            j = j + 1
        tmp = a[p]
        a[p] = a[i]
        a[i] = tmp
        i = i + 1

Repeatedly move minimimum of remaining sublist to front.


def swap(a, i, j):
    tmp = a[j]
    a[j] = a[i]
    a[i] = tmp
    return

def reverse(a):
    return swap(a, 2, 3)

Reverse a list of elements.


def swap(a, i, j):
    tmp = a[j]
    a[j] = a[i]
    a[i] = tmp
    return

def reverse(a):
    i = 0
    while i < len(a) / 2:
        swap(a, i, len(a) - 1 - i)
        i = i + 1

Reverse a list of elements.


def swap(a, i, j):
    tmp = a[i]
    a[i] = a[j]
    a[j] = tmp
    return a

def reverse(a):
    i = 0
    while i < len(a) / 2:
        swap(a, a[i], a[len(a) - i - 1])
    return a

Reverse a list of elements.


def swap(a, i, j):
    tmp = a[j]
    a[j] = a[i]
    a[i] = tmp
    return a

def reverse(a):
    i = 0
    while i < len(a) / 2:
        swap(a, a[i], a[len(a) - i - 1])
    return a

Reverse a list of elements.


def swap(a, i, j):
    tmp = a[j]
    a[j] = a[i]
    a[i] = tmp
    return a

def reverse(a):
    i = 0
    while i < len(a) / 2:
        j = len(a) - i - 1
        swap(a, i, j)
        i = i + 1
    return a

Reverse a list of elements.


def selection_sort(a):
    i = 0
    while i < len(a):
        j = i + 1
        min_ind = i
        while j < len(a):
            if a[j] < a[min_ind]:
                min_ind = j
            j += 1
        tmp = a[i]
        a[i] = a[min_ind]
        a[min_ind] = tmp
        i += 1


def reverse(a):
    i = 0
    while i < len(a):
        print(len(a) - i)

Reverse a list of elements.


def reverse(a):
    i = 0
    while i < len(a):
        print(len(a) - i)
    i = i + 1

Reverse a list of elements.


def reverse(a):
    i = 0
    while i < len(a):
        print(len(a) - i)
        i = i + 1

Reverse a list of elements.


def reverse(a):
    i = 1
    while i < len(a):
        print(len(a) - i)
        i = i + 1

Reverse a list of elements.


def selection_sort(a):
    p = i
    j = i + 1
    while j < len(a):
        if a[j] < a[p]:
            p = j
        j = j + 1
    tmp = a[p]
    a[p] = a[i]
    a[i] = tmp
    i = i + 1
    return a


def selection_sort(a):
    i = 0
    while i < len(a):
        p = i
        j = i + 1
        while j < len(a):
            if a[j] < a[p]:
                p = j
            j = j + 1
        tmp = a[p]
        a[p] = a[i]
        a[i] = tmp
        i = i + 1
    return a


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
        return low


def bsearch(a, q):
    low = 0
    high = len(a)
    while low < high:
        mid = (low + high) / 2
        if a[mid] < q:
            low = mid + 1
        else:
            high = mid
    return low


def swap(a, i, j):
    tmp = a[j]
    a[j] = a[i]
    a[i] = tmp

def reverse(a):
    i = 0
    while i < len(a) / 2:
        swap(a, i, len(a) - 1 - i)
        i = i + 1

Reverse a list of elements.


Reverse a list of elements.


def swap(a, i, j):
    tmp = a[i]
    a[i] = a[j]
    a[j] = tmp

def reverse(a):
    i = 0
    j = len(a) - 1
    while i < len(a) / 2:
        swap(a, i, j)
        i = i + 1
        j = j - 1

Reverse a list of elements.


def reverse(a, i):
    p = i
    j = i + 1
    while j < len(a):
        if int(a[j]) > int(a[p]):
            p = j
        j = j + 1
    return p

Reverse a list of elements.


def reverse(a):
    p = i
    j = i + 1
    while j < len(a):
        if int(a[j]) > int(a[p]):
            p = j
        j = j + 1
    return p

Reverse a list of elements.


def reverse(a):
    i = 0
    j = len(a) - 1
    while i < len(a) / 2:
        tmp = a[i]
        a[i] = a[j]
        a[j] = tmp
        i = i + 1
        j = j - 1

Reverse a list of elements.


def swap(a, i, j):
    tmp = a[i]
    a[i] = a[j]
    a[j] = tmp

def selection_sort(a):
    i = 0
    while i < len(a):
        p = i
        j = i + 1
        while j < len(a):
            if a[j] < a[p]:
                p = j
            j = j + 1
        swap(a, i, p)
        i = i + 1


def swap(a, i, j):
    tmp = a[i]
    a[i] = a[j]
    a[j] = tmp

def reverse(a):
    i = 0
    while i < len(a) / 2:
        swap(a, i, len(a) - 1 - i)
        i = i + 1

Reverse a list of elements.


def swap(a, i, j):
    tmp = a[i]
    a[i] = a[j]
    a[j] = tmp

def reverse(a):
    i = 0
    while i < len(a) / 2:
        swap(a, i, len(a) - i - 1)
        i = i + 1

Reverse a list of elements.


def swap(a, i, j):
    tmp = a[i]
    a[i] = a[j]
    a[j] = tmp

def reverse(a):
    i = 0
    while i < len(a) / 2:
        j = len(a) - i - 1
        swap(a, i, j)
        i = i + 1

Reverse a list of elements.


def selection_sort(a):
    i = 0
    j = i + 1
    while i < len(a):
        if a[j] < a[i]:
            tmp = a[j]
            a[j] = a[i]
            a[i] = tmp
        j = j + 1
    i = i + 1
    return a


def selection_sort(a):
    i = 0
    j = i + 1
    while i < len(a):
        j = i + 1
        while j < len(a):
            if a[j] < a[i]:
                tmp = a[j]
                a[j] = a[i]
                a[i] = tmp
        j = j + 1
    i = i + 1
    return a


def selection_sort(a):
    i = 0
    j = i + 1
    while i < len(a):
        j = i + 1
        while j < len(a):
            if a[j] < a[i]:
                tmp = a[j]
                a[j] = a[i]
                a[i] = tmp
            j = j + 1
        i = i + 1
        return a


def selection_sort(a):
    i = 0
    while i < len(a):
        j = i + 1
        while j < len(a):
            if a[j] < a[i]:
                tmp = a[j]
                a[j] = a[i]
                a[i] = tmp
            j = j + 1
        i = i + 1
        return a


def swap(a, i, j):
    tmp = a[i]
    a[i] = a[j]
    a[j] = tmp

def selection_sort(a):
    i = 0
    while i < len(a):
        p = i
        j = i + 1
        while j < len(a):
            if a[p] < a[j]:
                j = p
            j = j + 1
        i = i + 1
    swap(a, i, p)


def swap(a, i, j):
    tmp = a[i]
    a[i] = a[j]
    a[j] = tmp

def smallest_element(a, i):
    p = i
    j = i + 1
    while j < len(a):
        if a[p] < a[j]:
            p = j
        j = j + 1
    return p

def selection_sort(a):
    i = 0
    while i < len(a):
        smallest_element(a, i)
        swap(a, i, j)
        i = i + 1


def swap(a, i, j):
    tmp = a[i]
    a[i] = a[j]
    a[j] = tmp

def smallest_element(a, i):
    p = i
    j = i + 1
    while j < len(a):
        if a[p] < a[j]:
            p = j
        j = j + 1
    return p

def selection_sort(a):
    i = 0
    while i < len(a):
        p = smallest_element(a, i)
        swap(a, i, j)
        i = i + 1


def swap(a, i, j):
    tmp = a[i]
    a[i] = a[j]
    a[j] = tmp

def smallest_element(a, i):
    p = i
    j = i + 1
    while j < len(a):
        if a[p] < a[j]:
            p = j
        j = j + 1
    return p

def selection_sort(a):
    i = 0
    while i < len(a):
        p = smallest_element(a, i)
        swap(a, i, p)
        i = i + 1


def swap(a, i, j):
    tmp = a[i]
    a[i] = a[j]
    a[j] = tmp

def smallest_element(a, i):
    p = i
    j = i + 1
    while j < len(a):
        if a[p] < a[j]:
            j = p
        j = j + 1
    return p

def selection_sort(a):
    i = 0
    while i < len(a):
        p = smallest_element(a, i)
        swap(a, i, p)
        i = i + 1


def swap(a, i, j):
    tmp = a[i]
    a[i] = a[j]
    a[j] = tmp

def smallest_element(a, i):
    p = i
    j = i + 1
    while j < len(a):
        if a[j] < a[p]:
            p = j
        j = j + 1
    return p

def selection_sort(a):
    i = 0
    while i < len(a):
        p = smallest_element(a, i)
        swap(a, i, p)
        i = i + 1


def swap(a, i, j):
    tmp = a[i]
    a[i] = a[j]
    a[j] = tmp

def reverse(a):
    i = 0
    while i < len(a) / 2:
        swap(a, i, -i - 1)
        i += 1

Reverse a list of elements.


Reverse a list of elements.


def selection_sort(a):
    i = 0
    while i < len(a):
        p = i
        j = i + 1
        while j < len(a):
            if a[j] < a[p]:
                p = j
            j += 1
        tmp = a[p]
        a[p] = a[i]
        a[i] = tmp
        i += 1