
"""simple docstring"""
from ..utils import DummyObject, requires_backends
class       lowerCAmelCase_		(				metaclass=_lowercase ):



							'''simple docstring'''





							_snake_case						      =		['torch', 'scipy']




							def __init__( self    ,				*snake_case_    ,				**snake_case_				)       ->  Dict:
													requires_backends(self    ,				["""torch""", """scipy"""]				)




							@classmethod
							def    A__						( cls    ,				*snake_case_    ,				**snake_case_				)       ->  str:
													requires_backends(cls    ,				["""torch""", """scipy"""]				)




							@classmethod
							def    A__						( cls    ,				*snake_case_    ,				**snake_case_				)       ->  Dict:
													requires_backends(cls    ,				["""torch""", """scipy"""]				)


"""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]


