





'''simple docstring'''



import os
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


_SCREAMING_SNAKE_CASE   =      logging.get_logger(__name__)


_SCREAMING_SNAKE_CASE   =      '''▁'''

_SCREAMING_SNAKE_CASE   =      {'''vocab_file''': '''spiece.model'''}

_SCREAMING_SNAKE_CASE   =      {
    '''vocab_file''': {
        '''google/reformer-crime-and-punishment''': (
            '''https://huggingface.co/google/reformer-crime-and-punishment/resolve/main/spiece.model'''
        )
    }
}

_SCREAMING_SNAKE_CASE   =      {
    '''google/reformer-crime-and-punishment''': 5_2_4_2_8_8,
}






class 							__lowercase    ( lowerCAmelCase__  ):







	'''simple docstring'''

	a      :			List[str]     =    VOCAB_FILES_NAMES
	a      :			List[Any]     =    PRETRAINED_VOCAB_FILES_MAP
	a      :			str     =    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	a      :			Any     =    ["input_ids", "attention_mask"]


	def __init__(self       ,_lowerCamelCase       ,_lowerCamelCase="</s>"       ,_lowerCamelCase="<unk>"       ,_lowerCamelCase=[]       ,_lowerCamelCase = None       ,**_lowerCamelCase       ,)							->							None:







				'''simple docstring'''





				__lowercase			  =							{} if sp_model_kwargs is None else sp_model_kwargs

				super().__init__(
				    eos_token=_lowerCamelCase       ,unk_token=_lowerCamelCase       ,additional_special_tokens=_lowerCamelCase       ,sp_model_kwargs=self.sp_model_kwargs       ,**_lowerCamelCase       ,)

				__lowercase			  =							vocab_file
				__lowercase			  =							spm.SentencePieceProcessor(**self.sp_model_kwargs	)
				self.sp_model.Load(_lowerCamelCase	)


	@property
	def   _UpperCAmelCase       (self	)							->							Union[str, Any]:







				'''simple docstring'''





				return self.sp_model.get_piece_size()


	def   _UpperCAmelCase       (self	)							->							Dict[str, int]:







				'''simple docstring'''





				__lowercase			  =							{self.convert_ids_to_tokens(_lowerCamelCase	): i for i in range(self.vocab_size	)}
				vocab.update(self.added_tokens_encoder	)
				return vocab


	def __getstate__(self	)							->							Any:







				'''simple docstring'''





				__lowercase			  =							self.__dict__.copy()
				__lowercase			  =							None
				return state


	def __setstate__(self       ,_lowerCamelCase	)							->							List[Any]:







				'''simple docstring'''





				__lowercase			  =							d

				# for backward compatibility
				if not hasattr(self       ,'''sp_model_kwargs'''	):
							__lowercase			  =							{}

				__lowercase			  =							spm.SentencePieceProcessor(**self.sp_model_kwargs	)
				self.sp_model.Load(self.vocab_file	)


	def   _UpperCAmelCase       (self       ,_lowerCamelCase	)							->							List[str]:







				'''simple docstring'''





				return self.sp_model.encode(_lowerCamelCase       ,out_type=_lowerCamelCase	)


	def   _UpperCAmelCase       (self       ,_lowerCamelCase	)							->							List[Any]:







				'''simple docstring'''





				return self.sp_model.piece_to_id(_lowerCamelCase	)


	def   _UpperCAmelCase       (self       ,_lowerCamelCase	)							->							List[Any]:







				'''simple docstring'''





				if index < self.sp_model.get_piece_size():
							__lowercase			  =							self.sp_model.IdToPiece(_lowerCamelCase	)
				return token


	def   _UpperCAmelCase       (self       ,_lowerCamelCase	)							->							Union[str, Any]:







				'''simple docstring'''





				__lowercase			  =							[]
				__lowercase			  =							''''''
				for token in tokens:
							# make sure that special tokens are not decoded using sentencepiece model
							if token in self.all_special_tokens:
										out_string += self.sp_model.decode(_lowerCamelCase	) + token
										__lowercase			  =							[]
							else:
										current_sub_tokens.append(_lowerCamelCase	)
				out_string += self.sp_model.decode(_lowerCamelCase	)
				return out_string.strip()


	def   _UpperCAmelCase       (self       ,_lowerCamelCase       ,_lowerCamelCase = None	)							->							Tuple[str]:







				'''simple docstring'''





				if not os.path.isdir(_lowerCamelCase	):
							logger.error(f"Vocabulary path ({save_directory}) should be a directory"	)
							return
				__lowercase			  =							os.path.join(
				    _lowerCamelCase       ,(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']	)

				if os.path.abspath(self.vocab_file	) != os.path.abspath(_lowerCamelCase	) and os.path.isfile(self.vocab_file	):
							copyfile(self.vocab_file       ,_lowerCamelCase	)
				elif not os.path.isfile(self.vocab_file	):
							with open(_lowerCamelCase       ,'''wb'''	) as fi:
										__lowercase			  =							self.sp_model.serialized_model_proto()
										fi.write(_lowerCamelCase	)

				return (out_vocab_file,)












'''simple docstring'''



def 				_lowerCAmelCase  (			lowerCamelCase_     :					Union[str, Any]			):
			__lowercase			  =							1
			__lowercase			  =							2
			while i * i <= n:
						__lowercase			  =							0
						while n % i == 0:
									n //= i
									multiplicity += 1
						n_divisors *= multiplicity + 1
						i += 1
			if n > 1:
						n_divisors *= 2
			return n_divisors




def 				_lowerCAmelCase  (			):
			__lowercase			  =							1
			__lowercase			  =							1

			while True:
						i += 1
						t_num += i

						if count_divisors(lowerCamelCase_			) > 5_0_0:
									break

			return t_num


if __name__ == "__main__":
	print(solution())





