




"""simple docstring"""





import math

def        _UpperCamelCase     (      UpperCamelCase					,							UpperCamelCase = 0					,							UpperCamelCase = 0				)      ->      list:


			"""simple docstring"""
			__UpperCAmelCase						:			Union[str, Any]												=       end or len(UpperCamelCase				)
			for i in range(UpperCamelCase					,							UpperCamelCase				):
						__UpperCAmelCase						:			List[Any]												=       i
						__UpperCAmelCase						:			Any												=       array[i]
						while temp_index != start and temp_index_value < array[temp_index - 1]:
									__UpperCAmelCase						:			Dict												=       array[temp_index - 1]
									temp_index -= 1
						__UpperCAmelCase						:			str												=       temp_index_value
			return array

def        _UpperCamelCase     (      UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase				)      ->      None:  # Max Heap


			"""simple docstring"""
			__UpperCAmelCase						:			Optional[Any]												=       index
			__UpperCAmelCase						:			List[str]												=       2 * index + 1  # Left Node
			__UpperCAmelCase						:			Union[str, Any]												=       2 * index + 2  # Right Node

			if left_index < heap_size and array[largest] < array[left_index]:
						__UpperCAmelCase						:			Tuple												=       left_index

			if right_index < heap_size and array[largest] < array[right_index]:
						__UpperCAmelCase						:			int												=       right_index

			if largest != index:
						__UpperCAmelCase						,  __UpperCAmelCase						:			List[str]												=       array[largest], array[index]
						heapify(UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase				)

def        _UpperCamelCase     (      UpperCamelCase				)      ->      list:


			"""simple docstring"""
			__UpperCAmelCase						:			List[Any]												=       len(UpperCamelCase				)

			for i in range(n // 2					,							-1					,							-1				):
						heapify(UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase				)

			for i in range(n - 1					,							0					,							-1				):
						__UpperCAmelCase						,  __UpperCAmelCase						:			int												=       array[0], array[i]
						heapify(UpperCamelCase					,							0					,							UpperCamelCase				)

			return array

def        _UpperCamelCase     (      UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase				)      ->      int:


			"""simple docstring"""
			if (array[first_index] > array[middle_index]) != (
			    array[first_index] > array[last_index]
			):
						return array[first_index]
			elif (array[middle_index] > array[first_index]) != (
			    array[middle_index] > array[last_index]
			):
						return array[middle_index]
			else:
						return array[last_index]

def        _UpperCamelCase     (      UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase				)      ->      int:


			"""simple docstring"""
			__UpperCAmelCase						:			Optional[Any]												=       low
			__UpperCAmelCase						:			List[str]												=       high
			while True:
						while array[i] < pivot:
									i += 1
						j -= 1
						while pivot < array[j]:
									j -= 1
						if i >= j:
									return i
						__UpperCAmelCase						,  __UpperCAmelCase						:			Optional[int]												=       array[j], array[i]
						i += 1

def        _UpperCamelCase     (      UpperCamelCase				)      ->      list:


			"""simple docstring"""
			if len(UpperCamelCase				) == 0:
						return array
			__UpperCAmelCase						:			Optional[int]												=       2 * math.ceil(math.loga(len(UpperCamelCase				)				)				)
			__UpperCAmelCase						:			List[Any]												=       16
			return intro_sort(UpperCamelCase					,							0					,							len(UpperCamelCase				)					,							UpperCamelCase					,							UpperCamelCase				)

def        _UpperCamelCase     (      UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase				)      ->      list:


			"""simple docstring"""
			while end - start > size_threshold:
						if max_depth == 0:
									return heap_sort(UpperCamelCase				)
						max_depth -= 1
						__UpperCAmelCase						:			List[Any]												=       median_of_a(UpperCamelCase					,							UpperCamelCase					,							start + ((end - start) // 2) + 1					,							end - 1				)
						__UpperCAmelCase						:			Union[str, Any]												=       partition(UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase				)
						intro_sort(UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase				)
						__UpperCAmelCase						:			Optional[Any]												=       p
			return insertion_sort(UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase				)


if __name__ == "__main__":
					import doctest

					doctest.testmod()

					A				=							input("""Enter numbers separated by a comma : """).strip()
					A				=							[float(item) for item in user_input.split(""",""")]
					print(sort(unsorted))




"""simple docstring"""




import operator



def     __magic_name__		(					UpperCamelCase     :		list							,		UpperCamelCase     :		bool = False							,		UpperCamelCase     :		list | None = None     )     ->						list:
    a__		=			operator.lt if reverse else operator.gt
    a__		=			solution or []

    if not arr:
        return solution

    a__		=			[arr.pop(0     )]
    for i, item in enumerate(UpperCamelCase     ):
        if _operator(UpperCamelCase							,		sublist[-1]     ):
            sublist.append(UpperCamelCase     )
            arr.pop(UpperCamelCase     )

    #  merging sublist into solution list
    if not solution:
        solution.extend(UpperCamelCase     )
    else:
        while sublist:
            a__		=			sublist.pop(0     )
            for i, xx in enumerate(UpperCamelCase     ):
                if not _operator(UpperCamelCase							,		UpperCamelCase     ):
                    solution.insert(UpperCamelCase							,		UpperCamelCase     )
                    break
            else:
                solution.append(UpperCamelCase     )

    strand_sort(UpperCamelCase							,		UpperCamelCase							,		UpperCamelCase     )
    return solution


if __name__ == "__main__":
    assert strand_sort([4, 3, 5, 1, 2]) == [1, 2, 3, 4, 5]
    assert strand_sort([4, 3, 5, 1, 2], reverse=True) == [5, 4, 3, 2, 1]


