






"""simple docstring"""
def        snake_case   (     A__		):
			UpperCAmelCase_  :				Dict      =      0
			while num > 0:
						digit_sum += num % 10
						num //= 10
			return digit_sum

def        snake_case   (     A__ = 1_00		):
			UpperCAmelCase_  :				List[Any]      =      1
			UpperCAmelCase_  :				Union[str, Any]      =      2

			for i in range(2			,max_n + 1		):
						UpperCAmelCase_  :				List[str]      =      pre_numerator
						UpperCAmelCase_  :				Union[str, Any]      =      2 * i // 3 if i % 3 == 0 else 1
						UpperCAmelCase_  :				int      =      cur_numerator
						UpperCAmelCase_  :				Dict      =      e_cont * pre_numerator + temp

			return sum_digits(__snake_case		)


if __name__ == "__main__":
			print(f'{solution() = }')











"""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


lowerCamelCase_       			=   logging.get_logger(__name__)

lowerCamelCase_       			=   '''▁'''

lowerCamelCase_       			=   {'''vocab_file''': '''sentencepiece.bpe.model'''}

lowerCamelCase_       			=   {
    '''vocab_file''': {
        '''facebook/xglm-564M''': '''https://huggingface.co/facebook/xglm-564M/resolve/main/sentencepiece.bpe.model''',
    }
}

lowerCamelCase_       			=   {
    '''facebook/xglm-564M''': 2048,
}







class     UpperCamelCase_ (__A  ):
	__magic_name__			   =       VOCAB_FILES_NAMES
	__magic_name__			   =       PRETRAINED_VOCAB_FILES_MAP
	__magic_name__			   =       PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	__magic_name__			   =       ['''input_ids''', '''attention_mask''']





	def __init__(   self      :				int			,			lowerCAmelCase_      :				Dict			,			lowerCAmelCase_      :				Union[str, Any]="<s>"			,			lowerCAmelCase_      :				Any="</s>"			,			lowerCAmelCase_      :				Tuple="</s>"			,			lowerCAmelCase_      :				List[str]="<s>"			,			lowerCAmelCase_      :				Union[str, Any]="<unk>"			,			lowerCAmelCase_      :				Any="<pad>"			,			lowerCAmelCase_      :				Optional[Dict[str, Any]] = None			,			**lowerCAmelCase_      :				List[str]			,			)		->    None:
				UpperCAmelCase_  :				Any      =      {} if sp_model_kwargs is None else sp_model_kwargs

				# Compatibility with the original tokenizer
				UpperCAmelCase_  :				Any      =      7
				UpperCAmelCase_  :				Dict      =      [f"""<madeupword{i}>""" for i in range(self.num_madeup_words		)]

				UpperCAmelCase_  :				Optional[int]      =      kwargs.get("additional_special_tokens"			,			[]		)
				kwargs["additional_special_tokens"] += [
				    word for word in madeup_words if word not in kwargs["additional_special_tokens"]
				]

				super().__init__(
				    bos_token=lowerCAmelCase_			,			eos_token=lowerCAmelCase_			,			unk_token=lowerCAmelCase_			,			sep_token=lowerCAmelCase_			,			cls_token=lowerCAmelCase_			,			pad_token=lowerCAmelCase_			,			sp_model_kwargs=self.sp_model_kwargs			,			**lowerCAmelCase_			,			)

				UpperCAmelCase_  :				int      =      spm.SentencePieceProcessor(**self.sp_model_kwargs		)
				self.sp_model.Load(str(lowerCAmelCase_		)		)
				UpperCAmelCase_  :				Union[str, Any]      =      vocab_file

				# Original fairseq vocab and spm vocab must be "aligned":
				# Vocab    |    0    |    1    |   2    |    3    |  4  |  5  |  6  |   7   |   8   |  9
				# -------- | ------- | ------- | ------ | ------- | --- | --- | --- | ----- | ----- | ----
				# fairseq  | '<s>'   | '<pad>' | '</s>' | '<unk>' | ',' | '.' | '▁' | 's'   | '▁de' | '-'
				# spm      | '<unk>' | '<s>'   | '</s>' | ','     | '.' | '▁' | 's' | '▁de' | '-'   | '▁a'

				# The first "real" token "," has position 4 in the original fairseq vocab and position 3 in the spm vocab
				UpperCAmelCase_  :				int      =      1

				# Mimic fairseq token-to-id alignment for the first 4 token
				UpperCAmelCase_  :				Tuple      =      {"<s>": 0, "<pad>": 1, "</s>": 2, "<unk>": 3}

				UpperCAmelCase_  :				List[str]      =      len(self.sp_model		)
				UpperCAmelCase_  :				List[Any]      =      {f"""<madeupword{i}>""": sp_size + i + self.fairseq_offset for i in range(self.num_madeup_words		)}
				self.fairseq_tokens_to_ids.update(lowerCAmelCase_		)

				UpperCAmelCase_  :				Tuple      =      {v: k for k, v in self.fairseq_tokens_to_ids.items()}





	def __getstate__(   self      :				Tuple		)		->    Union[str, Any]:
				UpperCAmelCase_  :				Tuple      =      self.__dict__.copy()
				UpperCAmelCase_  :				Dict      =      None
				UpperCAmelCase_  :				Optional[Any]      =      self.sp_model.serialized_model_proto()
				return state





	def __setstate__(   self      :				Optional[Any]			,			lowerCAmelCase_      :				Any		)		->    Any:
				UpperCAmelCase_  :				Tuple      =      d

				# for backward compatibility
				if not hasattr(self			,			"sp_model_kwargs"		):
							UpperCAmelCase_  :				int      =      {}

				UpperCAmelCase_  :				int      =      spm.SentencePieceProcessor(**self.sp_model_kwargs		)
				self.sp_model.LoadFromSerializedProto(self.sp_model_proto		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Optional[int]			,			lowerCAmelCase_      :				List[int]			,			lowerCAmelCase_      :				Optional[List[int]] = None		)		->    List[int]:

				if token_ids_a is None:
							return [self.sep_token_id] + token_ids_a
				UpperCAmelCase_  :				Optional[Any]      =      [self.sep_token_id]
				return sep + token_ids_a + sep + sep + token_ids_a





	def   _SCREAMING_SNAKE_CASE   (   self      :				List[Any]			,			lowerCAmelCase_      :				List[int]			,			lowerCAmelCase_      :				Optional[List[int]] = None			,			lowerCAmelCase_      :				bool = False		)		->    List[int]:

				if already_has_special_tokens:
							return super().get_special_tokens_mask(
							    token_ids_a=lowerCAmelCase_			,			token_ids_a=lowerCAmelCase_			,			already_has_special_tokens=lowerCAmelCase_		)

				if token_ids_a is None:
							return [1] + ([0] * len(lowerCAmelCase_		))
				return [1] + ([0] * len(lowerCAmelCase_		)) + [1, 1] + ([0] * len(lowerCAmelCase_		))





	def   _SCREAMING_SNAKE_CASE   (   self      :				int			,			lowerCAmelCase_      :				List[int]			,			lowerCAmelCase_      :				Optional[List[int]] = None		)		->    List[int]:
				UpperCAmelCase_  :				str      =      [self.sep_token_id]

				if token_ids_a is None:
							return len(sep + token_ids_a		) * [0]
				return len(sep + token_ids_a + sep + sep + token_ids_a		) * [0]





	@property
	def   _SCREAMING_SNAKE_CASE   (   self      :				Tuple		)		->    Any:
				return len(self.sp_model		) + self.fairseq_offset + self.num_madeup_words





	def   _SCREAMING_SNAKE_CASE   (   self      :				Dict		)		->    Union[str, Any]:
				UpperCAmelCase_  :				Union[str, Any]      =      {self.convert_ids_to_tokens(lowerCAmelCase_		): i for i in range(self.vocab_size		)}
				vocab.update(self.added_tokens_encoder		)
				return vocab





	def   _SCREAMING_SNAKE_CASE   (   self      :				int			,			lowerCAmelCase_      :				str		)		->    List[str]:
				return self.sp_model.encode(lowerCAmelCase_			,			out_type=lowerCAmelCase_		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Dict			,			lowerCAmelCase_      :				Optional[Any]		)		->    Optional[int]:
				if token in self.fairseq_tokens_to_ids:
							return self.fairseq_tokens_to_ids[token]
				UpperCAmelCase_  :				Optional[int]      =      self.sp_model.PieceToId(lowerCAmelCase_		)

				# Need to return unknown token if the SP model returned 0
				return spm_id + self.fairseq_offset if spm_id else self.unk_token_id





	def   _SCREAMING_SNAKE_CASE   (   self      :				Union[str, Any]			,			lowerCAmelCase_      :				Union[str, Any]		)		->    Any:
				if index in self.fairseq_ids_to_tokens:
							return self.fairseq_ids_to_tokens[index]
				return self.sp_model.IdToPiece(index - self.fairseq_offset		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Dict			,			lowerCAmelCase_      :				Tuple		)		->    Optional[int]:
				UpperCAmelCase_  :				Any      =      "".join(lowerCAmelCase_		).replace(lowerCAmelCase_			,			" "		).strip()
				return out_string





	def   _SCREAMING_SNAKE_CASE   (   self      :				Tuple			,			lowerCAmelCase_      :				str			,			lowerCAmelCase_      :				Optional[str] = None		)		->    Tuple[str]:
				if not os.path.isdir(lowerCAmelCase_		):
							logger.error(f"""Vocabulary path ({save_directory}) should be a directory"""		)
							return
				UpperCAmelCase_  :				List[Any]      =      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:
										UpperCAmelCase_  :				str      =      self.sp_model.serialized_model_proto()
										fi.write(lowerCAmelCase_		)

				return (out_vocab_file,)



