


'''simple docstring'''



from multiprocessing import Lock, Pipe, Process

# lock used to ensure that two processes do not access a pipe at the same time
__A		=Lock()







def 			_UpperCamelCase					(						UpperCamelCase__       ,					UpperCamelCase__       ,					UpperCamelCase__       ,					UpperCamelCase__       ,					UpperCamelCase__       ,					UpperCamelCase__       ,					UpperCamelCase__    ):
			global process_lock

			# we perform n swaps since after n swaps we know we are sorted
			# we *could* stop early if we are sorted already, but it takes as long to
			# find out we are sorted as it does to sort the list with this algorithm
			for i in range(0       ,					1_0    ):
						if (i + position) % 2 == 0 and r_send is not None:
									# send your value to your right neighbor
									process_lock.acquire()
									r_send[1].send(__lowerCAmelCase    )
									process_lock.release()

									# receive your right neighbor's value
									process_lock.acquire()
									UpperCAmelCase__     :    Union[str, Any]         =   rr_cv[0].recv()
									process_lock.release()

									# take the lower value since you are on the left
									UpperCAmelCase__     :    Optional[int]         =   min(__lowerCAmelCase       ,					__lowerCAmelCase    )
						elif (i + position) % 2 != 0 and l_send is not None:
									# send your value to your left neighbor
									process_lock.acquire()
									l_send[1].send(__lowerCAmelCase    )
									process_lock.release()

									# receive your left neighbor's value
									process_lock.acquire()
									UpperCAmelCase__     :    Tuple         =   lr_cv[0].recv()
									process_lock.release()

									# take the higher value since you are on the right
									UpperCAmelCase__     :    Union[str, Any]         =   max(__lowerCAmelCase       ,					__lowerCAmelCase    )
    # after all swaps are performed, send the values back to main
			result_pipe[1].send(__lowerCAmelCase    )







def 			_UpperCamelCase					(						UpperCamelCase__    ):
			UpperCAmelCase__     :    Tuple         =   []
			UpperCAmelCase__     :    str         =   []
			# initialize the list of pipes where the values will be retrieved
			for _ in arr:
						result_pipe.append(Pipe()    )
			# creates the processes
			# the first and last process only have one neighbor so they are made outside
			# of the loop
			UpperCAmelCase__     :    Dict         =   Pipe()
			UpperCAmelCase__     :    str         =   Pipe()
			process_array_.append(
			    Process(
			        target=__lowerCAmelCase       ,					args=(0, arr[0], None, temp_rs, None, temp_rr, result_pipe[0])       ,					)    )
			UpperCAmelCase__     :    List[str]         =   temp_rs
			UpperCAmelCase__     :    str         =   temp_rr

			for i in range(1       ,					len(__lowerCAmelCase    ) - 1    ):
						UpperCAmelCase__     :    Dict         =   Pipe()
						UpperCAmelCase__     :    Optional[Any]         =   Pipe()
						process_array_.append(
						    Process(
						        target=__lowerCAmelCase       ,					args=(i, arr[i], temp_ls, temp_rs, temp_lr, temp_rr, result_pipe[i])       ,					)    )
						UpperCAmelCase__     :    List[Any]         =   temp_rs
						UpperCAmelCase__     :    Union[str, Any]         =   temp_rr

			process_array_.append(
			    Process(
			        target=__lowerCAmelCase       ,					args=(
			            len(__lowerCAmelCase    ) - 1,
			            arr[len(__lowerCAmelCase    ) - 1],
			            temp_ls,
			            None,
			            temp_lr,
			            None,
			            result_pipe[len(__lowerCAmelCase    ) - 1],
			        )       ,					)    )

			# start the processes
			for p in process_array_:
						p.start()

			# wait for the processes to end and write their values to the list
			for p in range(0       ,					len(__lowerCAmelCase    )    ):
						UpperCAmelCase__     :    Dict         =   result_pipe[p][0].recv()
						process_array_[p].join()
			return arr







def 			_UpperCamelCase					(						):
			UpperCAmelCase__     :    Optional[Any]         =   list(range(1_0       ,					0       ,					-1    )    )
			print("""Initial List"""    )
			print(*__lowerCAmelCase    )
			UpperCAmelCase__     :    List[Any]         =   odd_even_transposition(__lowerCAmelCase    )
			print("""Sorted List\n"""    )
			print(*__lowerCAmelCase    )


if __name__ == "__main__":
		main()



import sys

from .dependency_versions_table import deps
from .utils.versions import require_version, require_version_core


# define which module versions we always want to check at run time
# (usually the ones defined in `install_requires` in setup.py)
#
# order specific notes:
# - tqdm must be checked before tokenizers

snake_case							:       List[str]     			=      '''python tqdm regex requests packaging filelock numpy tokenizers'''.split()
if sys.version_info < (3, 7):
						pkgs_to_check_at_runtime.append('''dataclasses''')
if sys.version_info < (3, 8):
						pkgs_to_check_at_runtime.append('''importlib_metadata''')

for pkg in pkgs_to_check_at_runtime:
						if pkg in deps:
												if pkg == "tokenizers":
																		# must be loaded here, or else tqdm check may fail
																		from .utils import is_tokenizers_available

																		if not is_tokenizers_available():
																								continue  # not required, check version only if installed

												require_version_core(deps[pkg])
						else:
												raise ValueError(f"""can't find {pkg} in {deps.keys()}, check dependency_versions_table.py""")






def 							__lowercase   ( __lowerCAmelCase							:				Optional[Any]					,    __lowerCAmelCase							:				Tuple=None   ):
							require_version(deps[pkg]					,    __lowerCAmelCase   )




