






'''simple docstring'''







import contextlib
from multiprocessing import Pool, RLock

from tqdm.auto import tqdm

from ..utils import experimental, logging


UpperCamelCase     :   Optional[Any]	      =		logging.get_logger(__name__)




class 		UpperCamelCase__     :




		'''simple docstring'''





		_UpperCamelCase						=       None



@experimental
def     A__      (					__lowerCAmelCase		:      str ,     __lowerCAmelCase		:      Any ,     __lowerCAmelCase		:      Union[str, Any] ,     __lowerCAmelCase		:      Optional[int] ,     __lowerCAmelCase		:      Optional[Any] ,     __lowerCAmelCase		:      Optional[Any] ,     __lowerCAmelCase		:      Tuple    ):
						if ParallelBackendConfig.backend_name is None:
												return _map_with_multiprocessing_pool(
												    __lowerCAmelCase ,     __lowerCAmelCase ,     __lowerCAmelCase ,     __lowerCAmelCase ,     __lowerCAmelCase ,     __lowerCAmelCase ,     __lowerCAmelCase    )

						return _map_with_joblib(__lowerCAmelCase ,     __lowerCAmelCase ,     __lowerCAmelCase ,     __lowerCAmelCase ,     __lowerCAmelCase ,     __lowerCAmelCase ,     __lowerCAmelCase    )
def     A__      (					__lowerCAmelCase		:      int ,     __lowerCAmelCase		:      List[str] ,     __lowerCAmelCase		:      Tuple ,     __lowerCAmelCase		:      List[str] ,     __lowerCAmelCase		:      int ,     __lowerCAmelCase		:      str ,     __lowerCAmelCase		:      List[str]    ):
						lowerCamelCase__								=	num_proc if num_proc <= len(__lowerCAmelCase    ) else len(__lowerCAmelCase    )
						lowerCamelCase__								=	[]  # We organize the splits ourselve (contiguous splits)
						for index in range(__lowerCAmelCase    ):
												lowerCamelCase__								=	len(__lowerCAmelCase    ) // num_proc
												lowerCamelCase__								=	len(__lowerCAmelCase    ) % num_proc
												lowerCamelCase__								=	div * index + min(__lowerCAmelCase ,     __lowerCAmelCase    )
												lowerCamelCase__								=	start + div + (1 if index < mod else 0)
												split_kwds.append((function, iterable[start:end], types, index, disable_tqdm, desc)    )

						if len(__lowerCAmelCase    ) != sum(len(i[1]    ) for i in split_kwds    ):
												raise ValueError(
												    F'''Error dividing inputs iterable among processes. '''
												    F'''Total number of objects {len(__lowerCAmelCase    )}, '''
												    F'''length: {sum(len(i[1]    ) for i in split_kwds    )}'''    )

						logger.info(
						    F'''Spawning {num_proc} processes for {len(__lowerCAmelCase    )} objects in slices of {[len(i[1]    ) for i in split_kwds]}'''    )
						lowerCamelCase__							,      lowerCamelCase__								=	None, None
						if not disable_tqdm:
												lowerCamelCase__							,      lowerCamelCase__								=	(RLock(),), tqdm.set_lock
						with Pool(__lowerCAmelCase ,     initargs=__lowerCAmelCase ,     initializer=__lowerCAmelCase    ) as pool:
												lowerCamelCase__								=	pool.map(__lowerCAmelCase ,     __lowerCAmelCase    )
						logger.info(F'''Finished {num_proc} processes'''    )
						lowerCamelCase__								=	[obj for proc_res in mapped for obj in proc_res]
						logger.info(F'''Unpacked {len(__lowerCAmelCase    )} objects'''    )

						return mapped
def     A__      (					__lowerCAmelCase		:      str ,     __lowerCAmelCase		:      str ,     __lowerCAmelCase		:      Tuple ,     __lowerCAmelCase		:      Tuple ,     __lowerCAmelCase		:      str ,     __lowerCAmelCase		:      Dict ,     __lowerCAmelCase		:      Optional[int]    ):
						# progress bar is not yet supported for _map_with_joblib, because tqdm couldn't accurately be applied to joblib,
						# and it requires monkey-patching joblib internal classes which is subject to change
						import joblib

						with joblib.parallel_backend(ParallelBackendConfig.backend_name ,     n_jobs=__lowerCAmelCase    ):
												return joblib.Parallel()(
												    joblib.delayed(__lowerCAmelCase    )((function, obj, types, None, True, None)    ) for obj in iterable    )





@experimental
@contextlib.contextmanager
def     A__      (					__lowerCAmelCase		:      str    ):
						lowerCamelCase__								=	backend_name

						if backend_name == "spark":
												from joblibspark import register_spark

												register_spark()

												# TODO: call create_cache_and_write_probe if "download" in steps
												# TODO: raise NotImplementedError when Dataset.map etc is called

						try:
												yield
						finally:
												lowerCamelCase__								=	None





'''simple docstring'''


from __future__ import annotations







def      snake_case_  (    SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__	):







				"""simple docstring"""





				if len(SCREAMING_SNAKE_CASE__	) <= 1 or n <= 1:
								return

				insert_next(SCREAMING_SNAKE_CASE__				, n - 1	)
				rec_insertion_sort(SCREAMING_SNAKE_CASE__				, n - 1	)







def      snake_case_  (    SCREAMING_SNAKE_CASE__				, SCREAMING_SNAKE_CASE__	):







				"""simple docstring"""





				if index >= len(SCREAMING_SNAKE_CASE__	) or collection[index - 1] <= collection[index]:
								return

				# Swaps adjacent elements since they are not in ascending order
				_SCREAMING_SNAKE_CASE						,			_SCREAMING_SNAKE_CASE					:			List[Any]							= (
				    collection[index],
				    collection[index - 1],
				)

				insert_next(SCREAMING_SNAKE_CASE__				, index + 1	)


if __name__ == "__main__":
				UpperCAmelCase_						:  List[str]				  =						input('Enter integers separated by spaces: ')
				UpperCAmelCase_						:  list[int]				  =						[int(num) for num in numbers.split()]
				rec_insertion_sort(number_list, len(number_list))
				print(number_list)




