






"""simple docstring"""



def 						lowercase    (				__snake_case				: Union[str, Any]		,					__snake_case				: Tuple	):
		lowercase_ : Tuple							       =   [1]
		for i in range(2		,					__snake_case	):
				factorials.append(factorials[-1] * i	)
		assert 0 <= k < factorials[-1] * n, "k out of bounds"

		lowercase_ : str							       =   []
		lowercase_ : str							       =   list(range(__snake_case	)	)

		# Find permutation
		while factorials:
				lowercase_ : int							       =   factorials.pop()
				lowercase_       ,					lowercase_ : List[Any]							       =   divmod(__snake_case		,					__snake_case	)
				permutation.append(elements[number]	)
				elements.remove(elements[number]	)
		permutation.append(elements[0]	)

		return permutation


if __name__ == "__main__":
						import doctest

						doctest.testmod()







"""simple docstring"""







from __future__ import annotations




def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_ = None  ,						lowerCAmelCase_ = None   ):




					'''simple docstring'''


					if start is None:
										__SCREAMING_SNAKE_CASE						   =				0

					if end is None:
										__SCREAMING_SNAKE_CASE						   =				len(lowerCAmelCase_   ) - 1

					if start >= end:
										return

					__SCREAMING_SNAKE_CASE						   =				(start + end) // 2

					slowsort(lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_   )
					slowsort(lowerCAmelCase_  ,						mid + 1  ,						lowerCAmelCase_   )

					if sequence[end] < sequence[mid]:
										__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				sequence[mid], sequence[end]

					slowsort(lowerCAmelCase_  ,						lowerCAmelCase_  ,						end - 1   )


if __name__ == "__main__":
		from doctest import testmod

		testmod()
