def find_insertion_index(el, list):
    """
    Assuming list is a sorted list, looks for the right index where
    el should be inserted. The search is exaustive for lists with less
    than 6 elements, otherwise it's done with a bisection algorithm.

    Input:
        el          The element to look the insertion index for
        list        An already sorted list (eventually [])

    Output:
        An integer in the range 0...len(list)

    Remarks:
        Used by shanks, autoshanks, pohlighellman.
    """
    if len(list)==0: return 0
    if len(list)==1:
        if el<list[0]: return 0
        return 1
    if len(list)<=5:
        candidate=len(list)
        while el<list[candidate-1] and candidate>0:
            candidate-=1
        return candidate
    # binary search
    a=0; b=len(list); m=b//2
    while True:
        # compare with the middle element
        if el<list[m]:
            b=m
        else:
            a=m+1
        m=(a+b)//2

        if a==b:
            if a==len(list) or el<list[a]:
                return a
            return a+1
        elif a+1==b:
            if el<list[a]: return a
            if b==len(list) or el<list[b]:
                return b
            return b+1