



from .imports import is_tqdm_available


if is_tqdm_available():
				from tqdm.auto import tqdm as _tqdm

from ..state import PartialState






def      _A				(UpperCamelCase		:      bool = True      ,			*UpperCamelCase		:      Union[str, Any]      ,			**UpperCamelCase		:      Tuple )  ->str:



			'''simple docstring'''







			if not is_tqdm_available():
						raise ImportError("""Accelerate's `tqdm` module requires `tqdm` to be installed. Please run `pip install tqdm`.""" )
			lowerCamelCase__ :      Tuple								=		False
			if main_process_only:
						lowerCamelCase__ :      List[str]								=		PartialState().local_process_index == 0
			return _tqdm(*_A      ,			**_A      ,			disable=_A )








def      _A				(UpperCamelCase		:      List[Any]      ,			UpperCamelCase		:      Dict )  ->List[str]:



			'''simple docstring'''







			lowerCamelCase__ :      int								=		[1]
			for i in range(2      ,			UpperCamelCase ):
						factorials.append(factorials[-1] * i )
			assert 0 <= k < factorials[-1] * n, "k out of bounds"

			lowerCamelCase__ :      Union[str, Any]								=		[]
			lowerCamelCase__ :      Optional[Any]								=		list(range(UpperCamelCase ) )

			# Find permutation
			while factorials:
						lowerCamelCase__ :      Union[str, Any]								=		factorials.pop()
						lowerCamelCase__							,lowerCamelCase__ :      Union[str, Any]								=		divmod(UpperCamelCase      ,			UpperCamelCase )
						permutation.append(elements[number] )
						elements.remove(elements[number] )
			permutation.append(elements[0] )

			return permutation


if __name__ == "__main__":
				import doctest

				doctest.testmod()



