






import json
import os
from pathlib import Path
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple, Union

import sentencepiece

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


UpperCamelCase								=		logging.get_logger(__name__)

UpperCamelCase								=		"▁"

UpperCamelCase								=		{
    "vocab_file": "vocab.json",
    "spm_file": "sentencepiece.bpe.model",
}

UpperCamelCase								=		{
    "vocab_file": {
        "facebook/s2t-small-librispeech-asr": (
            "https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/vocab.json"
        ),
    },
    "spm_file": {
        "facebook/s2t-small-librispeech-asr": (
            "https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/sentencepiece.bpe.model"
        )
    },
}

UpperCamelCase								=		{
    "facebook/s2t-small-librispeech-asr": 1_024,
}

UpperCamelCase								=		["pt", "fr", "ru", "nl", "ro", "it", "es", "de"]

UpperCamelCase								=		{"mustc": MUSTC_LANGS}

class 				lowerCAmelCase_	(		__snake_case			):
				_UpperCamelCase					:       Optional[Any]							       = VOCAB_FILES_NAMES
				_UpperCamelCase					:       int							       = PRETRAINED_VOCAB_FILES_MAP
				_UpperCamelCase					:       List[str]							       = MAX_MODEL_INPUT_SIZES
				_UpperCamelCase					:       Optional[int]							       = ['''input_ids''', '''attention_mask''']

				_UpperCamelCase					:       List[int]							       = []


				def __init__(					self ,						_lowerCAmelCase ,						_lowerCAmelCase ,						_lowerCAmelCase="<s>" ,						_lowerCAmelCase="</s>" ,						_lowerCAmelCase="<pad>" ,						_lowerCAmelCase="<unk>" ,						_lowerCAmelCase=False ,						_lowerCAmelCase=False ,						_lowerCAmelCase=None ,						_lowerCAmelCase=None ,						_lowerCAmelCase = None ,						**_lowerCAmelCase ,						):
											_lowercase							:   Union[str, Any] 							=   {} if sp_model_kwargs is None else sp_model_kwargs

											super().__init__(
											    bos_token=_lowerCAmelCase ,						eos_token=_lowerCAmelCase ,						unk_token=_lowerCAmelCase ,						pad_token=_lowerCAmelCase ,						do_upper_case=_lowerCAmelCase ,						do_lower_case=_lowerCAmelCase ,						tgt_lang=_lowerCAmelCase ,						lang_codes=_lowerCAmelCase ,						sp_model_kwargs=self.sp_model_kwargs ,						**_lowerCAmelCase ,						)
											_lowercase							:   Any 							=   do_upper_case
											_lowercase							:   Tuple 							=   do_lower_case

											_lowercase							:   List[Any] 							=   load_json(_lowerCAmelCase      )
											_lowercase							:   List[str] 							=   {v: k for k, v in self.encoder.items()}
											_lowercase							:   str 							=   spm_file
											_lowercase							:   str 							=   load_spm(_lowerCAmelCase ,						self.sp_model_kwargs      )

											if lang_codes is not None:
																		_lowercase							:   int 							=   lang_codes
																		_lowercase							:   Optional[int] 							=   LANGUAGES[lang_codes]
																		_lowercase							:   Union[str, Any] 							=   [F"""<lang:{lang}>""" for lang in self.langs]
																		_lowercase							:   List[str] 							=   {lang: self.sp_model.PieceToId(F"""<lang:{lang}>"""      ) for lang in self.langs}

																		_lowercase							:   Optional[int] 							=   self.lang_tokens
																		_lowercase							:   str 							=   tgt_lang if tgt_lang is not None else self.langs[0]

																		self.set_tgt_lang_special_tokens(self._tgt_lang      )
											else:
																		_lowercase							:   Any 							=   {}


				@property
				def 						__a					(					self      ):
											return len(self.encoder      )


				@property
				def 						__a					(					self      ):
											return self._tgt_lang


				@tgt_lang.setter
				def 						__a					(					self ,						_lowerCAmelCase      ):
											_lowercase							:   str 							=   new_tgt_lang
											self.set_tgt_lang_special_tokens(_lowerCAmelCase      )


				def 						__a					(					self ,						_lowerCAmelCase      ):
											_lowercase							:   Union[str, Any] 							=   self.lang_code_to_id[tgt_lang]
											_lowercase							:   Optional[Any] 							=   [lang_code_id]


				def 						__a					(					self ,						_lowerCAmelCase      ):
											return self.sp_model.encode(_lowerCAmelCase ,						out_type=_lowerCAmelCase      )


				def 						__a					(					self ,						_lowerCAmelCase      ):
											return self.encoder.get(_lowerCAmelCase ,						self.encoder[self.unk_token]      )


				def 						__a					(					self ,						_lowerCAmelCase      ):
											return self.decoder.get(_lowerCAmelCase ,						self.unk_token      )


				def 						__a					(					self ,						_lowerCAmelCase      ):
											_lowercase							:   Union[str, Any] 							=   []
											_lowercase							:   Any 							=   ''
											for token in tokens:
																		# make sure that special tokens are not decoded using sentencepiece model
																		if token in self.all_special_tokens:
																									_lowercase							:   Dict 							=   self.sp_model.decode(_lowerCAmelCase      )
																									out_string += (decoded.upper() if self.do_upper_case else decoded) + token + " "
																									_lowercase							:   Tuple 							=   []
																		else:
																									current_sub_tokens.append(_lowerCAmelCase      )
											_lowercase							:   Union[str, Any] 							=   self.sp_model.decode(_lowerCAmelCase      )
											out_string += decoded.upper() if self.do_upper_case else decoded
											return out_string.strip()


				def 						__a					(					self ,						_lowerCAmelCase ,						_lowerCAmelCase=None      ):


											if token_ids_a is None:
																		return self.prefix_tokens + token_ids_a + [self.eos_token_id]
											# We don't expect to process pairs, but leave the pair logic for API consistency
											return self.prefix_tokens + token_ids_a + token_ids_a + [self.eos_token_id]


				def 						__a					(					self ,						_lowerCAmelCase ,						_lowerCAmelCase = None ,						_lowerCAmelCase = False      ):


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

											_lowercase							:   int 							=   [1] * len(self.prefix_tokens      )
											_lowercase							:   Tuple 							=   [1]
											if token_ids_a is None:
																		return prefix_ones + ([0] * len(_lowerCAmelCase      )) + suffix_ones
											return prefix_ones + ([0] * len(_lowerCAmelCase      )) + ([0] * len(_lowerCAmelCase      )) + suffix_ones


				def 						__a					(					self      ):
											_lowercase							:   Union[str, Any] 							=   self.encoder.copy()
											vocab.update(self.added_tokens_encoder      )
											return vocab


				def __getstate__(					self      ):
											_lowercase							:   List[str] 							=   self.__dict__.copy()
											_lowercase							:   List[str] 							=   None
											return state


				def __setstate__(					self ,						_lowerCAmelCase      ):
											_lowercase							:   Union[str, Any] 							=   d

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

											_lowercase							:   int 							=   load_spm(self.spm_file ,						self.sp_model_kwargs      )


				def 						__a					(					self ,						_lowerCAmelCase ,						_lowerCAmelCase = None      ):
											_lowercase							:   Optional[int] 							=   Path(_lowerCAmelCase      )
											assert save_dir.is_dir(), F"""{save_directory} should be a directory"""
											_lowercase							:   List[str] 							=   save_dir / (
											    (filename_prefix + '-' if filename_prefix else '') + self.vocab_files_names['vocab_file']
											)
											_lowercase							:   Union[str, Any] 							=   save_dir / (
											    (filename_prefix + '-' if filename_prefix else '') + self.vocab_files_names['spm_file']
											)

											save_json(self.encoder ,						_lowerCAmelCase      )

											if os.path.abspath(self.spm_file      ) != os.path.abspath(_lowerCAmelCase      ) and os.path.isfile(self.spm_file      ):
																		copyfile(self.spm_file ,						_lowerCAmelCase      )
											elif not os.path.isfile(self.spm_file      ):
																		with open(_lowerCAmelCase ,						'wb'      ) as fi:
																									_lowercase							:   List[str] 							=   self.sp_model.serialized_model_proto()
																									fi.write(_lowerCAmelCase      )

											return (str(_lowerCAmelCase      ), str(_lowerCAmelCase      ))






def    __magic_name__    (	SCREAMING_SNAKE_CASE     ,     SCREAMING_SNAKE_CASE				)     ->    Optional[Any]:
							_lowercase							:   Any 							=   sentencepiece.SentencePieceProcessor(**SCREAMING_SNAKE_CASE				)
							spm.Load(str(SCREAMING_SNAKE_CASE				)				)
							return spm






def    __magic_name__    (	SCREAMING_SNAKE_CASE				)     ->    int:







							with open(SCREAMING_SNAKE_CASE     ,     'r'				) as f:
														return json.load(SCREAMING_SNAKE_CASE				)






def    __magic_name__    (	SCREAMING_SNAKE_CASE     ,     SCREAMING_SNAKE_CASE				)     ->    Tuple:







							with open(SCREAMING_SNAKE_CASE     ,     'w'				) as f:
														json.dump(SCREAMING_SNAKE_CASE     ,     SCREAMING_SNAKE_CASE     ,     indent=2				)










'''simple docstring'''







def 						_A      ( UpperCAmelCase						):






   '''simple docstring'''







   A__       =     0
   while num > 0:
      digit_sum += num % 10
      num //= 10
   return digit_sum







def 						_A      ( UpperCAmelCase = 100						):






   '''simple docstring'''







   A__       =     1
   A__       =     2

   for i in range(2      ,max_n + 1						):
      A__       =     pre_numerator
      A__       =     2 * i // 3 if i % 3 == 0 else 1
      A__       =     cur_numerator
      A__       =     e_cont * pre_numerator + temp

   return sum_digits(UpperCAmelCase						)


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


