



class       _lowerCAmelCase :






			"""simple docstring"""





			class       _lowerCAmelCase :






						"""simple docstring"""





						lowercase__   :	str  			=      """_prev""", """_data""", """_next"""





						def __init__(					self						:							Optional[int]      ,  lowercase						:							List[str]      ,  lowercase						:							Dict      ,  lowercase						:							Dict )    ->       str:
												"""simple docstring"""







												__lowercase											=					link_p
												__lowercase											=					element
												__lowercase											=					link_n







						def 		snake_case__      (					self						:							Union[str, Any] )    ->       str:
												"""simple docstring"""







												return (
												    F" Prev -> {self._prev is not None}, Next -> {self._next is not None}"
												)





			def __init__(					self						:							int )    ->       Tuple:
									"""simple docstring"""







									__lowercase											=					self._Node(lowercase      ,  lowercase      ,  lowercase )
									__lowercase											=					self._Node(lowercase      ,  lowercase      ,  lowercase )
									__lowercase											=					self._trailer
									__lowercase											=					self._header
									__lowercase											=					0





			def __len__(					self						:							Union[str, Any] )    ->       str:
									"""simple docstring"""







									return self._size





			def 		snake_case__      (					self						:							Tuple )    ->       Dict:
									"""simple docstring"""







									return self.__len__() == 0





			def 		snake_case__      (					self						:							Optional[Any]      ,  lowercase						:							Optional[int]      ,  lowercase						:							Optional[Any]      ,  lowercase						:							Any )    ->       Union[str, Any]:
									"""simple docstring"""







									__lowercase											=					self._Node(lowercase      ,  lowercase      ,  lowercase )
									__lowercase											=					new_node
									__lowercase											=					new_node
									self._size += 1
									return self







			def 		snake_case__      (					self						:							List[Any]      ,  lowercase						:							int )    ->       int:
									"""simple docstring"""







									__lowercase											=					node._prev
									__lowercase											=					node._next

									__lowercase											=					successor
									__lowercase											=					predecessor
									self._size -= 1
									__lowercase											=					node._data
									__lowercase											=					__lowercase											=					__lowercase											=					None
									del node
									return temp





class       _lowerCAmelCase (			_DoublyLinkedBase      ):






			"""simple docstring"""





			def 		snake_case__      (					self						:							str )    ->       Optional[Any]:
									"""simple docstring"""







									if self.is_empty():
															raise Exception("""List is empty""" )
									return self._header._next._data





			def 		snake_case__      (					self						:							Any )    ->       str:
									"""simple docstring"""







									if self.is_empty():
															raise Exception("""List is empty""" )
									return self._trailer._prev._data





			def 		snake_case__      (					self						:							List[str]      ,  lowercase						:							Optional[Any] )    ->       List[str]:
									"""simple docstring"""







									return self._insert(self._header      ,  lowercase      ,  self._header._next )





			def 		snake_case__      (					self						:							List[str]      ,  lowercase						:							Any )    ->       Optional[Any]:
									"""simple docstring"""







									return self._insert(self._trailer._prev      ,  lowercase      ,  self._trailer )





			def 		snake_case__      (					self						:							Optional[Any] )    ->       Optional[Any]:
									"""simple docstring"""







									if self.is_empty():
															raise IndexError("""remove_first from empty list""" )
									return self._delete(self._header._next )







			def 		snake_case__      (					self						:							List[Any] )    ->       List[Any]:
									"""simple docstring"""







									if self.is_empty():
															raise IndexError("""remove_first from empty list""" )
									return self._delete(self._trailer._prev )










from __future__ import annotations






def 			UpperCAmelCase__     (     lowercase__ )			->   list[int]:
						if not list_of_ints:
												return []

						if min(lowercase__ ) < 0:
												raise ValueError("""All numbers must be positive""" )

						__lowercase											=					max(len(bin(lowercase__ )[2:] ) for x in list_of_ints )
						return _msd_radix_sort(lowercase__    ,							lowercase__ )






def 			UpperCAmelCase__     (     lowercase__    ,							lowercase__ )			->   list[int]:
						if bit_position == 0 or len(lowercase__ ) in [0, 1]:
												return list_of_ints

						__lowercase											=					[]
						__lowercase											=					[]
						# Split numbers based on bit at bit_position from the right
						for number in list_of_ints:
												if (number >> (bit_position - 1)) & 1:
																		# number has a one at bit bit_position
																		ones.append(lowercase__ )
												else:
																		# number has a zero at bit bit_position
																		zeros.append(lowercase__ )

    # recursively split both lists further
						__lowercase											=					_msd_radix_sort(lowercase__    ,							bit_position - 1 )
						__lowercase											=					_msd_radix_sort(lowercase__    ,							bit_position - 1 )

						# recombine lists
						__lowercase											=					zeros
						res.extend(lowercase__ )

						return res






def 			UpperCAmelCase__     (     lowercase__ )			->   List[Any]:
						__lowercase											=					len(lowercase__ )
						if not list_of_ints or length == 1:
												return

						if min(lowercase__ ) < 0:
												raise ValueError("""All numbers must be positive""" )

						__lowercase											=					max(len(bin(lowercase__ )[2:] ) for x in list_of_ints )
						_msd_radix_sort_inplace(lowercase__    ,							lowercase__    ,							0    ,							lowercase__ )






def 			UpperCAmelCase__     (     lowercase__    ,							lowercase__    ,							lowercase__    ,							lowercase__ )			->   Optional[Any]:
						if bit_position == 0 or end_index - begin_index <= 1:
												return

						bit_position -= 1

						__lowercase											=					begin_index
						__lowercase											=					end_index - 1
						while i <= j:
												__lowercase											=					False
												if not (list_of_ints[i] >> bit_position) & 1:
																		# found zero at the beginning
																		i += 1
																		__lowercase											=					True
												if (list_of_ints[j] >> bit_position) & 1:
																		# found one at the end
																		j -= 1
																		__lowercase											=					True

												if changed:
																		continue

												__lowercase						,      __lowercase											=					list_of_ints[j], list_of_ints[i]
												j -= 1
												if j != i:
																		i += 1

						_msd_radix_sort_inplace(lowercase__    ,							lowercase__    ,							lowercase__    ,							lowercase__ )
						_msd_radix_sort_inplace(lowercase__    ,							lowercase__    ,							lowercase__    ,							lowercase__ )


if __name__ == "__main__":
			import doctest

			doctest.testmod()





