from __future__ import annotations






def 					SCREAMING_SNAKE_CASE_			(		lowerCAmelCase_: list[int]     ):
      if not list_of_ints:
            return []

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

      snake_case_     :			str       =       max(len(bin(lowerCAmelCase_     )[2:]     ) for x in list_of_ints     )
      return _msd_radix_sort(lowerCAmelCase_ ,	lowerCAmelCase_     )






def 					SCREAMING_SNAKE_CASE_			(		lowerCAmelCase_: list[int] ,	lowerCAmelCase_: int     ):
      if bit_position == 0 or len(lowerCAmelCase_     ) in [0, 1]:
            return list_of_ints

      snake_case_     :			Any       =       []
      snake_case_     :			Union[str, Any]       =       []
      # 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(lowerCAmelCase_     )
            else:
                  # number has a zero at bit bit_position
                  zeros.append(lowerCAmelCase_     )

    # recursively split both lists further
      snake_case_     :			int       =       _msd_radix_sort(lowerCAmelCase_ ,	bit_position - 1     )
      snake_case_     :			Optional[Any]       =       _msd_radix_sort(lowerCAmelCase_ ,	bit_position - 1     )

      # recombine lists
      snake_case_     :			List[Any]       =       zeros
      res.extend(lowerCAmelCase_     )

      return res






def 					SCREAMING_SNAKE_CASE_			(		lowerCAmelCase_: list[int]     ):
      snake_case_     :			str       =       len(lowerCAmelCase_     )
      if not list_of_ints or length == 1:
            return

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

      snake_case_     :			Optional[int]       =       max(len(bin(lowerCAmelCase_     )[2:]     ) for x in list_of_ints     )
      _msd_radix_sort_inplace(lowerCAmelCase_ ,	lowerCAmelCase_ ,	0 ,	lowerCAmelCase_     )






def 					SCREAMING_SNAKE_CASE_			(		lowerCAmelCase_: list[int] ,	lowerCAmelCase_: int ,	lowerCAmelCase_: int ,	lowerCAmelCase_: int     ):
      if bit_position == 0 or end_index - begin_index <= 1:
            return

      bit_position -= 1

      snake_case_     :			Dict       =       begin_index
      snake_case_     :			Optional[Any]       =       end_index - 1
      while i <= j:
            snake_case_     :			Any       =       False
            if not (list_of_ints[i] >> bit_position) & 1:
                  # found zero at the beginning
                  i += 1
                  snake_case_     :			Optional[Any]       =       True
            if (list_of_ints[j] >> bit_position) & 1:
                  # found one at the end
                  j -= 1
                  snake_case_     :			Union[str, Any]       =       True

            if changed:
                  continue

            snake_case_  ,snake_case_     :			Optional[Any]       =       list_of_ints[j], list_of_ints[i]
            j -= 1
            if j != i:
                  i += 1

      _msd_radix_sort_inplace(lowerCAmelCase_ ,	lowerCAmelCase_ ,	lowerCAmelCase_ ,	lowerCAmelCase_     )
      _msd_radix_sort_inplace(lowerCAmelCase_ ,	lowerCAmelCase_ ,	lowerCAmelCase_ ,	lowerCAmelCase_     )


if __name__ == "__main__":
     import doctest

     doctest.testmod()




from __future__ import annotations

UpperCAmelCase							=       "Alexander Joslin"






def 					SCREAMING_SNAKE_CASE_			(		lowerCAmelCase_: int     ):

      if number <= 0:
            snake_case_     :			Dict       =       f"n must be greater than 0. Got n = {number}"
            raise ValueError(lowerCAmelCase_     )

      snake_case_     :			Tuple       =       [number + 1] * (number + 1)

      # starting position
      snake_case_     :			Union[str, Any]       =       0
      for i in range(1 ,	lowerCAmelCase_     ):
            snake_case_     :			int       =       min(table[i + 1] ,	table[i] + 1     )
            # check if out of bounds
            if i * 2 <= number:
                  snake_case_     :			Tuple       =       min(table[i * 2] ,	table[i] + 1     )
            # check if out of bounds
            if i * 3 <= number:
                  snake_case_     :			Dict       =       min(table[i * 3] ,	table[i] + 1     )
      return table[number]


if __name__ == "__main__":
     import doctest

     doctest.testmod()



