
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


lowercase  :					Optional[int]						    =							logging.get_logger(__name__)

lowercase  :					str						    =							"""▁"""

lowercase  :					List[str]						    =							{"""vocab_file""": """sentencepiece.bpe.model"""}

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

lowercase  :					Dict						    =							{
    """facebook/xglm-564M""": 2048,
}

class __snake_case		(      lowerCAmelCase     ):
    _a		:						Optional[Any]=				VOCAB_FILES_NAMES
    _a		:						str=				PRETRAINED_VOCAB_FILES_MAP
    _a		:						str=				PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    _a		:						Dict=				["input_ids", "attention_mask"]
    def __init__(  self		,snake_case		,snake_case="<s>"		,snake_case="</s>"		,snake_case="</s>"		,snake_case="<s>"		,snake_case="<unk>"		,snake_case="<pad>"		,snake_case = None		,**snake_case		,):



           '''simple docstring'''







           lowercase							:     int       	=      {} if sp_model_kwargs is None else sp_model_kwargs

           # Compatibility with the original tokenizer
           lowercase							:     Optional[int]       	=      7
           lowercase							:     Union[str, Any]       	=      [f"<madeupword{i}>" for i in range(self.num_madeup_words      )]

           lowercase							:     Optional[Any]       	=      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=snake_case		,eos_token=snake_case		,unk_token=snake_case		,sep_token=snake_case		,cls_token=snake_case		,pad_token=snake_case		,sp_model_kwargs=self.sp_model_kwargs		,**snake_case		,)

           lowercase							:     Optional[int]       	=      spm.SentencePieceProcessor(**self.sp_model_kwargs      )
           self.sp_model.Load(str(snake_case      )      )
           lowercase							:     List[str]       	=      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
           lowercase							:     Any       	=      1

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

           lowercase							:     Optional[Any]       	=      len(self.sp_model      )
           lowercase							:     Tuple       	=      {f"<madeupword{i}>": sp_size + i + self.fairseq_offset for i in range(self.num_madeup_words      )}
           self.fairseq_tokens_to_ids.update(snake_case      )

           lowercase							:     Union[str, Any]       	=      {v: k for k, v in self.fairseq_tokens_to_ids.items()}
    def __getstate__(  self      ):



           '''simple docstring'''







           lowercase							:     Optional[Any]       	=      self.__dict__.copy()
           lowercase							:     Union[str, Any]       	=      None
           lowercase							:     List[str]       	=      self.sp_model.serialized_model_proto()
           return state
    def __setstate__(  self		,snake_case      ):



           '''simple docstring'''







           lowercase							:     Union[str, Any]       	=      d

           # for backward compatibility
           if not hasattr(self		,"""sp_model_kwargs"""      ):
                  lowercase							:     List[str]       	=      {}

           lowercase							:     Optional[int]       	=      spm.SentencePieceProcessor(**self.sp_model_kwargs      )
           self.sp_model.LoadFromSerializedProto(self.sp_model_proto      )
    def       _SCREAMING_SNAKE_CASE       (  self		,snake_case		,snake_case = None      ):



           '''simple docstring'''







           if token_ids_a is None:
                  return [self.sep_token_id] + token_ids_a
           lowercase							:     Any       	=      [self.sep_token_id]
           return sep + token_ids_a + sep + sep + token_ids_a
    def       _SCREAMING_SNAKE_CASE       (  self		,snake_case		,snake_case = None		,snake_case = False      ):



           '''simple docstring'''







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

           if token_ids_a is None:
                  return [1] + ([0] * len(snake_case      ))
           return [1] + ([0] * len(snake_case      )) + [1, 1] + ([0] * len(snake_case      ))
    def       _SCREAMING_SNAKE_CASE       (  self		,snake_case		,snake_case = None      ):



           '''simple docstring'''







           lowercase							:     List[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      ):



           '''simple docstring'''







           return len(self.sp_model      ) + self.fairseq_offset + self.num_madeup_words
    def       _SCREAMING_SNAKE_CASE       (  self      ):



           '''simple docstring'''







           lowercase							:     List[Any]       	=      {self.convert_ids_to_tokens(snake_case      ): i for i in range(self.vocab_size      )}
           vocab.update(self.added_tokens_encoder      )
           return vocab
    def       _SCREAMING_SNAKE_CASE       (  self		,snake_case      ):



           '''simple docstring'''







           return self.sp_model.encode(snake_case		,out_type=snake_case      )
    def       _SCREAMING_SNAKE_CASE       (  self		,snake_case      ):



           '''simple docstring'''







           if token in self.fairseq_tokens_to_ids:
                  return self.fairseq_tokens_to_ids[token]
           lowercase							:     str       	=      self.sp_model.PieceToId(snake_case      )

           # 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		,snake_case      ):



           '''simple docstring'''







           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		,snake_case      ):



           '''simple docstring'''







           lowercase							:     Optional[int]       	=      """""".join(snake_case      ).replace(snake_case		,""" """      ).strip()
           return out_string
    def       _SCREAMING_SNAKE_CASE       (  self		,snake_case		,snake_case = None      ):



           '''simple docstring'''







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

           if os.path.abspath(self.vocab_file      ) != os.path.abspath(snake_case      ) and os.path.isfile(self.vocab_file      ):
                  copyfile(self.vocab_file		,snake_case      )
           elif not os.path.isfile(self.vocab_file      ):
                  with open(snake_case		,"""wb"""      ) as fi:
                         lowercase							:     int       	=      self.sp_model.serialized_model_proto()
                         fi.write(snake_case      )

           return (out_vocab_file,)







from itertools import permutations



def _a				(	lowerCamelCase:   tuple )	->						bool:







      '''simple docstring'''






      if num[3] % 2 != 0:
            return False

      if (num[2] + num[3] + num[4]) % 3 != 0:
            return False

      if num[5] % 5 != 0:
            return False

      __A          =				[7, 11, 13, 17]
      for i, test in enumerate(lowerCamelCase ):
            if (num[i + 4] * 1_00 + num[i + 5] * 10 + num[i + 6]) % test != 0:
                  return False
      return True



def _a				(	lowerCamelCase:   int = 10 )	->						int:







      '''simple docstring'''






      return sum(
          int(''''''.join(map(lowerCamelCase					,				lowerCamelCase ) ) )
          for num in permutations(range(lowerCamelCase ) )
          if is_substring_divisible(lowerCamelCase ) )


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





