






import json
from typing import Iterator, List, Union

from tokenizers import AddedToken, Regex, Tokenizer, decoders, normalizers, pre_tokenizers, trainers
from tokenizers.implementations.base_tokenizer import BaseTokenizer
from tokenizers.models import Unigram
from tokenizers.processors import TemplateProcessing

class 				lowerCAmelCase_	(		SCREAMING_SNAKE_CASE__			):


				def __init__(					self ,						_lowerCAmelCase = "▁" ,						_lowerCAmelCase = True ,						_lowerCAmelCase = "<unk>" ,						_lowerCAmelCase = "</s>" ,						_lowerCAmelCase = "<pad>" ,						):
											_lowercase							:   Optional[Any] 							=   {
											    'pad': {'id': 0, 'token': pad_token},
											    'eos': {'id': 1, 'token': eos_token},
											    'unk': {'id': 2, 'token': unk_token},
											}

											_lowercase							:   Optional[Any] 							=   [None] * len(self.special_tokens      )
											for token_dict in self.special_tokens.values():
																		_lowercase							:   str 							=   token_dict['token']

											_lowercase							:   List[Any] 							=   Tokenizer(Unigram()      )

											_lowercase							:   Any 							=   normalizers.Sequence(
											    [
											        normalizers.Nmt(),
											        normalizers.NFKC(),
											        normalizers.Replace(Regex(' {2,}'      ) ,						' '      ),
											        normalizers.Lowercase(),
											    ]      )
											_lowercase							:   Optional[int] 							=   pre_tokenizers.Sequence(
											    [
											        pre_tokenizers.Metaspace(replacement=snake_case__ ,						add_prefix_space=snake_case__      ),
											        pre_tokenizers.Digits(individual_digits=snake_case__      ),
											        pre_tokenizers.Punctuation(),
											    ]      )
											_lowercase							:   int 							=   decoders.Metaspace(replacement=snake_case__ ,						add_prefix_space=snake_case__      )

											_lowercase							:   List[Any] 							=   TemplateProcessing(
											    single=F"""$A {self.special_tokens['eos']['token']}""" ,						special_tokens=[(self.special_tokens['eos']['token'], self.special_tokens['eos']['id'])] ,						)

											_lowercase							:   List[Any] 							=   {
											    'model': 'SentencePieceUnigram',
											    'replacement': replacement,
											    'add_prefix_space': add_prefix_space,
											}

											super().__init__(snake_case__ ,						snake_case__      )


				def 						__a					(					self ,						_lowerCAmelCase ,						_lowerCAmelCase = 8_0_0_0 ,						_lowerCAmelCase = True ,						):
											_lowercase							:   List[Any] 							=   trainers.UnigramTrainer(
											    vocab_size=snake_case__ ,						special_tokens=self.special_tokens_list ,						show_progress=snake_case__ ,						)

											if isinstance(snake_case__ ,						snake_case__      ):
																		_lowercase							:   int 							=   [files]
											self._tokenizer.train(snake_case__ ,						trainer=snake_case__      )

											self.add_unk_id()


				def 						__a					(					self ,						_lowerCAmelCase ,						_lowerCAmelCase = 8_0_0_0 ,						_lowerCAmelCase = True ,						):
											_lowercase							:   int 							=   trainers.UnigramTrainer(
											    vocab_size=snake_case__ ,						special_tokens=self.special_tokens_list ,						show_progress=snake_case__ ,						)

											self._tokenizer.train_from_iterator(snake_case__ ,						trainer=snake_case__      )

											self.add_unk_id()


				def 						__a					(					self      ):
											_lowercase							:   str 							=   json.loads(self._tokenizer.to_str()      )

											_lowercase							:   Dict 							=   self.special_tokens['unk']['id']

											_lowercase							:   List[Any] 							=   Tokenizer.from_str(json.dumps(snake_case__      )      )










def 					_a							(					lowerCAmelCase    ,						lowerCAmelCase )->	List[str]:
		SCREAMING_SNAKE_CASE_					      =							[1]
		for i in range(2    ,						lowerCAmelCase ):
				factorials.append(factorials[-1] * i )
		assert 0 <= k < factorials[-1] * n, "k out of bounds"

		SCREAMING_SNAKE_CASE_					      =							[]
		SCREAMING_SNAKE_CASE_					      =							list(range(lowerCAmelCase ) )

		# Find permutation
		while factorials:
				SCREAMING_SNAKE_CASE_					      =							factorials.pop()
				SCREAMING_SNAKE_CASE_      ,				SCREAMING_SNAKE_CASE_					      =							divmod(lowerCAmelCase    ,						lowerCAmelCase )
				permutation.append(elements[number] )
				elements.remove(elements[number] )
		permutation.append(elements[0] )

		return permutation


if __name__ == "__main__":
						import doctest

						doctest.testmod()