def partition_helper(a, first, last):
    """
    A left_mark index are initiated at the leftmost index available (ie
    not the pivot) and a right_mark at the rightmost. The left_mark is shifted
    right as long as a[left_mark] < pivot and the right_mark left as long as
    a[right_mark] > pivot. If left_mark < right_mark, the values at which the
    marks are stopped are swapped and the process continues until they cross.
    At this point, a[right_mark] and the pivot are swapped and the index of the
    right_mark is returned.
    """
    pivot_value = a[first]
    left_mark = first + 1
    right_mark = last

    done = False
    while not done:

        while right_mark >= left_mark and a[left_mark] <= pivot_value:
            left_mark += 1

        while right_mark >= left_mark and a[right_mark] >= pivot_value:
            right_mark -= 1

        if right_mark < left_mark:
            done = True
        else:
            a[left_mark], a[right_mark] = a[right_mark], a[left_mark]

    a[first], a[right_mark] = a[right_mark], a[first]
    return right_mark