





import io
import os
import unicodedata
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

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


UpperCamelCase__      =logging.get_logger(__name__)

UpperCamelCase__      ='▁'

UpperCamelCase__      ={'vocab_file': 'vocab.txt', 'sentencepiece_model_ckpt': 'sentencepiece.bpe.model'}

UpperCamelCase__      ={
    'sentencepiece_model_file': 'sentencepiece.bpe.model',
    'vocab_file': 'vocab.txt',
}

UpperCamelCase__      ={
    'vocab_file': {
        'ernie-m-base': 'https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/vocab.txt',
        'ernie-m-large': 'https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/vocab.txt',
    },
    'sentencepiece_model_file': {
        'ernie-m-base': 'https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/sentencepiece.bpe.model',
        'ernie-m-large': 'https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/sentencepiece.bpe.model',
    },
}

UpperCamelCase__      ={
    'ernie-m-base': 514,
    'ernie-m-large': 514,
}

UpperCamelCase__      ={
    'ernie-m-base': {'do_lower_case': False},
    'ernie-m-large': {'do_lower_case': False},
}





class 			lowerCAmelCase__( __lowercase    ):






       '''simple docstring'''


       __snake_case 			=    ["input_ids"]

       __snake_case 			=    VOCAB_FILES_NAMES
       __snake_case 			=    PRETRAINED_INIT_CONFIGURATION
       __snake_case 			=    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
       __snake_case 			=    PRETRAINED_VOCAB_FILES_MAP
       __snake_case 			=    RESOURCE_FILES_NAMES




       def __init__(      self    ,						__lowerCamelCase    ,						__lowerCamelCase=None    ,						__lowerCamelCase=False    ,						__lowerCamelCase="utf8"    ,						__lowerCamelCase="[UNK]"    ,						__lowerCamelCase="[SEP]"    ,						__lowerCamelCase="[PAD]"    ,						__lowerCamelCase="[CLS]"    ,						__lowerCamelCase="[MASK]"    ,						__lowerCamelCase = None    ,						**__lowerCamelCase    ,						)			->     None:
            # Mask token behave like a normal word, i.e. include the space before it and
            # is included in the raw text, there should be a match in a non-normalized sentence.

            _SCREAMING_SNAKE_CASE       :	Any						    =							{} if sp_model_kwargs is None else sp_model_kwargs
            super().__init__(
                do_lower_case=__lowerCamelCase    ,						unk_token=__lowerCamelCase    ,						sep_token=__lowerCamelCase    ,						pad_token=__lowerCamelCase    ,						cls_token=__lowerCamelCase    ,						mask_token=__lowerCamelCase    ,						vocab_file=__lowerCamelCase    ,						encoding=__lowerCamelCase    ,						sp_model_kwargs=self.sp_model_kwargs    ,						**__lowerCamelCase    ,						)
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							do_lower_case
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							sentencepiece_model_ckpt
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							spm.SentencePieceProcessor(**self.sp_model_kwargs							)
            self.sp_model.Load(__lowerCamelCase							)

            # to mimic paddlenlp.transformers.ernie_m.tokenizer.ErnieMTokenizer functioning
            if vocab_file is not None:
                 _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							self.load_vocab(filepath=__lowerCamelCase							)
            else:
                 _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							{self.sp_model.id_to_piece(__lowerCamelCase							): id for id in range(self.sp_model.get_piece_size()							)}
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							{v: k for k, v in self.vocab.items()}




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase							)			->     int:
            if text is None:
                 return None

            _SCREAMING_SNAKE_CASE       :	str						    =							self.tokenize(__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE       :	int						    =							"", []

            for i, ch in enumerate(__lowerCamelCase							):
                 if ch in self.SP_CHAR_MAPPING:
                      _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							self.SP_CHAR_MAPPING.get(__lowerCamelCase							)
                 else:
                      _SCREAMING_SNAKE_CASE       :	str						    =							unicodedata.normalize("NFKC"    ,						__lowerCamelCase							)
                 if self.is_whitespace(__lowerCamelCase							):
                      continue
                 normalized_text += ch
                 char_mapping.extend([i] * len(__lowerCamelCase							)							)

            _SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE       :	Optional[int]						    =							normalized_text, [], 0

            if self.do_lower_case:
                 _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							text.lower()

            for token in split_tokens:
                 if token[:1] == "▁":
                      _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							token[1:]
                 _SCREAMING_SNAKE_CASE       :	Dict						    =							text[offset:].index(__lowerCamelCase							) + offset
                 _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							start + len(__lowerCamelCase							)

                 token_mapping.append((char_mapping[start], char_mapping[end - 1] + 1)							)
                 _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							end
            return token_mapping




       @property
       def     UpperCamelCase_			(      self							)			->     int:
            return len(self.vocab							)




       def     UpperCamelCase_			(      self							)			->     Optional[int]:
            return dict(self.vocab    ,						**self.added_tokens_encoder							)




       def __getstate__(      self							)			->     Optional[Any]:
            _SCREAMING_SNAKE_CASE       :	Any						    =							self.__dict__.copy()
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							None
            return state




       def __setstate__(      self    ,						__lowerCamelCase							)			->     List[Any]:
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							d

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

            _SCREAMING_SNAKE_CASE       :	int						    =							spm.SentencePieceProcessor(**self.sp_model_kwargs							)
            self.sp_model.Load(self.sentencepiece_model_ckpt							)




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase							)			->     Dict:
            return "".join((self.SP_CHAR_MAPPING.get(__lowerCamelCase    ,						__lowerCamelCase							) for c in text)							)




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase    ,						__lowerCamelCase=False    ,						__lowerCamelCase=6_4    ,						__lowerCamelCase=0.1							)			->     Optional[int]:

            if self.sp_model_kwargs.get("enable_sampling"							) is True:
                 _SCREAMING_SNAKE_CASE       :	int						    =							True
            if self.sp_model_kwargs.get("alpha"							) is not None:
                 _SCREAMING_SNAKE_CASE       :	Any						    =							self.sp_model_kwargs.get("alpha"							)
            if self.sp_model_kwargs.get("nbest_size"							) is not None:
                 _SCREAMING_SNAKE_CASE       :	Any						    =							self.sp_model_kwargs.get("nbest_size"							)

            if not enable_sampling:
                 _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							self.sp_model.EncodeAsPieces(__lowerCamelCase							)
            else:
                 _SCREAMING_SNAKE_CASE       :	Tuple						    =							self.sp_model.SampleEncodeAsPieces(__lowerCamelCase    ,						__lowerCamelCase    ,						__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							[]
            for pi, piece in enumerate(__lowerCamelCase							):
                 if piece == SPIECE_UNDERLINE:
                      if not pieces[pi + 1].startswith(__lowerCamelCase							) and pi != 0:
                           new_pieces.append(__lowerCamelCase							)
                           continue
                      else:
                           continue
                 _SCREAMING_SNAKE_CASE       :	Tuple						    =							0
                 for i, chunk in enumerate(__lowerCamelCase							):
                      if chunk == SPIECE_UNDERLINE:
                           continue
                      if self.is_ch_char(__lowerCamelCase							) or self.is_punct(__lowerCamelCase							):
                           if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
                                new_pieces.append(piece[lst_i:i]							)
                           new_pieces.append(__lowerCamelCase							)
                           _SCREAMING_SNAKE_CASE       :	Dict						    =							i + 1
                      elif chunk.isdigit() and i > 0 and not piece[i - 1].isdigit():
                           if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
                                new_pieces.append(piece[lst_i:i]							)
                           _SCREAMING_SNAKE_CASE       :	str						    =							i
                      elif not chunk.isdigit() and i > 0 and piece[i - 1].isdigit():
                           if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
                                new_pieces.append(piece[lst_i:i]							)
                           _SCREAMING_SNAKE_CASE       :	str						    =							i
                 if len(__lowerCamelCase							) > lst_i:
                      new_pieces.append(piece[lst_i:]							)
            return new_pieces




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase							)			->     str:
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							"".join(__lowerCamelCase							).replace(__lowerCamelCase    ,						" "							).strip()
            return out_string




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase							)			->     Optional[Any]:
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							self.convert_ids_to_tokens(__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							"".join(__lowerCamelCase							).replace(__lowerCamelCase    ,						" "							).strip()
            return out_string




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase							)			->     str:
            return self.vocab.get(__lowerCamelCase    ,						self.vocab.get(self.unk_token							)							)




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase							)			->     Union[str, Any]:
            return self.reverse_vocab.get(__lowerCamelCase    ,						self.unk_token							)




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase    ,						__lowerCamelCase=None							)			->     List[Any]:
            if token_ids_a is None:
                 return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							[self.cls_token_id]
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							[self.sep_token_id]
            return _cls + token_ids_a + _sep + _sep + token_ids_a + _sep




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase    ,						__lowerCamelCase=None							)			->     List[Any]:
            if offset_mapping_a is None:
                 return [(0, 0)] + offset_mapping_a + [(0, 0)]

            return [(0, 0)] + offset_mapping_a + [(0, 0), (0, 0)] + offset_mapping_a + [(0, 0)]




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase    ,						__lowerCamelCase=None    ,						__lowerCamelCase=False							)			->     Any:

            if already_has_special_tokens:
                 if token_ids_a is not None:
                      raise ValueError(
                          "You should not supply a second sequence if the provided sequence of "
                          "ids is already formatted with special tokens for the model."							)
                 return [1 if x in [self.sep_token_id, self.cls_token_id] else 0 for x in token_ids_a]

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




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase    ,						__lowerCamelCase = None							)			->     List[int]:
            # called when `add_special_tokens` is True, so align with `build_inputs_with_special_tokens` method
            if token_ids_a is None:
                 # [CLS] X [SEP]
                 return (len(__lowerCamelCase							) + 2) * [0]

            # [CLS] A [SEP] [SEP] B [SEP]
            return [0] * (len(__lowerCamelCase							) + 1) + [1] * (len(__lowerCamelCase							) + 3)




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase							)			->     int:
            if "\u4e00" <= char <= "\u9fff":
                 return True
            return False




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase							)			->     Dict:
            if ("a" <= char <= "z") or ("A" <= char <= "Z"):
                 return True
            return False




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase							)			->     Any:
            if char in ",;:.?!~，；：。？！《》【】":
                 return True
            return False




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase							)			->     Optional[Any]:
            if char == " " or char == "\t" or char == "\n" or char == "\r":
                 return True
            if len(__lowerCamelCase							) == 1:
                 _SCREAMING_SNAKE_CASE       :	Dict						    =							unicodedata.category(__lowerCamelCase							)
                 if cat == "Zs":
                      return True
            return False




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase							)			->     Union[str, Any]:
            _SCREAMING_SNAKE_CASE       :	Any						    =							{}
            with io.open(__lowerCamelCase    ,						"r"    ,						encoding="utf-8"							) as f:
                 for index, line in enumerate(__lowerCamelCase							):
                      _SCREAMING_SNAKE_CASE       :	str						    =							line.rstrip("\n"							)
                      _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							int(__lowerCamelCase							)

            return token_to_idx







       def     UpperCamelCase_			(      self    ,						__lowerCamelCase    ,						__lowerCamelCase = None							)			->     Tuple[str]:
            _SCREAMING_SNAKE_CASE       :	Any						    =							0
            if os.path.isdir(__lowerCamelCase							):
                 _SCREAMING_SNAKE_CASE       :	Tuple						    =							os.path.join(
                     __lowerCamelCase    ,						(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]							)
            else:
                 _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							(filename_prefix + "-" if filename_prefix else "") + save_directory
            with open(__lowerCamelCase    ,						"w"    ,						encoding="utf-8"							) as writer:
                 for token, token_index in sorted(self.vocab.items()    ,						key=lambda __lowerCamelCase							: kv[1]							):
                      if index != token_index:
                           logger.warning(
                               F"""Saving vocabulary to {vocab_file}: vocabulary indices are not consecutive."""
                               " Please check that the vocabulary is not corrupted!"							)
                           _SCREAMING_SNAKE_CASE       :	Tuple						    =							token_index
                      writer.write(token + "\n"							)
                      index += 1

            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							os.path.join(__lowerCamelCase    ,						"sentencepiece.bpe.model"							)
            with open(__lowerCamelCase    ,						"wb"							) as fi:
                 _SCREAMING_SNAKE_CASE       :	Any						    =							self.sp_model.serialized_model_proto()
                 fi.write(__lowerCamelCase							)

            return (vocab_file,)






from __future__ import annotations

UpperCamelCase__      =[True] * 100_0001
UpperCamelCase__      =2
while i * i <= 100_0000:
       if seive[i]:
              for j in range(i * i, 100_0001, i):
                     UpperCamelCase__      =False
       i += 1






def     lowerCamelCase__			(__lowerCamelCase	):
     return seive[n]






def     lowerCamelCase__			(__lowerCamelCase	):
     return any(digit in "02468" for digit in str(__lowerCamelCase	)	)






def     lowerCamelCase__			(__lowerCamelCase = 1000000	):
     _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							[2]  # result already includes the number 2.
     for num in range(3,       limit + 1,       2	):
          if is_prime(__lowerCamelCase	) and not contains_an_even_digit(__lowerCamelCase	):
               _SCREAMING_SNAKE_CASE       :	List[Any]						    =							str(__lowerCamelCase	)
               _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							[int(str_num[j:] + str_num[:j]	) for j in range(len(__lowerCamelCase	)	)]
               if all(is_prime(__lowerCamelCase	) for i in list_nums	):
                    result.append(__lowerCamelCase	)
     return result






def     lowerCamelCase__			():
     return len(find_circular_primes()	)


if __name__ == "__main__":
       print(f"{len(find_circular_primes()) = }")