def insertion_sort(arr):
    """
    Returns the list 'arr' sorted in nondecreasing order in O(n^2) time.
    """

    for i in range(1,len(arr)):
        key = arr[i]
        j = i-1
        while j >= 0 and arr[j] > key:
            arr[j+1] = arr[j]
            j = j-1
        arr[j+1] = key
    return arr