


'''simple docstring'''






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


__A	:	Dict     =     logging.get_logger(__name__)

__A	:	Dict     =     '▁'

__A	:	Union[str, Any]     =     {'vocab_file': 'vocab.txt', 'sentencepiece_model_ckpt': 'sentencepiece.bpe.model'}

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

__A	:	Union[str, Any]     =     {
    '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',
    },
}

__A	:	Union[str, Any]     =     {
    'ernie-m-base': 514,
    'ernie-m-large': 514,
}

__A	:	Tuple     =     {
    'ernie-m-base': {'do_lower_case': False},
    'ernie-m-large': {'do_lower_case': False},
}
class 						__UpperCamelCase	(						lowercase__							):
							lowercase			:		List[str]   		=  ["input_ids"]

							lowercase			:		Optional[int]   		=  VOCAB_FILES_NAMES
							lowercase			:		List[Any]   		=  PRETRAINED_INIT_CONFIGURATION
							lowercase			:		List[str]   		=  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							lowercase			:		List[Any]   		=  PRETRAINED_VOCAB_FILES_MAP
							lowercase			:		Union[str, Any]   		=  RESOURCE_FILES_NAMES





							def __init__(  self		:List[str]  ,_UpperCamelCase		:Union[str, Any]  ,_UpperCamelCase		:List[str]=None  ,_UpperCamelCase		:Optional[Any]=False  ,_UpperCamelCase		:Any="utf8"  ,_UpperCamelCase		:Optional[Any]="[UNK]"  ,_UpperCamelCase		:Any="[SEP]"  ,_UpperCamelCase		:Dict="[PAD]"  ,_UpperCamelCase		:Union[str, Any]="[CLS]"  ,_UpperCamelCase		:List[str]="[MASK]"  ,_UpperCamelCase		:Optional[Dict[str, Any]] = None  ,**_UpperCamelCase		:str  ,):
									# 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.

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

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





							def 		a__   (  self		:Optional[Any]  ,_UpperCamelCase		:Union[str, Any]			):
									if text is None:
											return None

									snake_case_		:							Tuple			       =						self.tokenize(_UpperCamelCase			)
									snake_case_       ,      snake_case_		:							Optional[Any]			       =						"""""", []

									for i, ch in enumerate(_UpperCamelCase			):
											if ch in self.SP_CHAR_MAPPING:
													snake_case_		:							Dict			       =						self.SP_CHAR_MAPPING.get(_UpperCamelCase			)
											else:
													snake_case_		:							List[Any]			       =						unicodedata.normalize("""NFKC"""  ,_UpperCamelCase			)
											if self.is_whitespace(_UpperCamelCase			):
													continue
											normalized_text += ch
											char_mapping.extend([i] * len(_UpperCamelCase			)			)

									snake_case_       ,      snake_case_       ,      snake_case_		:							str			       =						normalized_text, [], 0

									if self.do_lower_case:
											snake_case_		:							List[Any]			       =						text.lower()

									for token in split_tokens:
											if token[:1] == "▁":
													snake_case_		:							Dict			       =						token[1:]
											snake_case_		:							int			       =						text[offset:].index(_UpperCamelCase			) + offset
											snake_case_		:							List[Any]			       =						start + len(_UpperCamelCase			)

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





							@property
							def 		a__   (  self		:Any			):
									return len(self.vocab			)





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





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





							def __setstate__(  self		:Union[str, Any]  ,_UpperCamelCase		:Dict			):
									snake_case_		:							List[Any]			       =						d

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

									snake_case_		:							Union[str, Any]			       =						spm.SentencePieceProcessor(**self.sp_model_kwargs			)
									self.sp_model.Load(self.sentencepiece_model_ckpt			)





							def 		a__   (  self		:Optional[Any]  ,_UpperCamelCase		:List[Any]			):
									return "".join((self.SP_CHAR_MAPPING.get(_UpperCamelCase  ,_UpperCamelCase			) for c in text)			)





							def 		a__   (  self		:List[Any]  ,_UpperCamelCase		:int  ,_UpperCamelCase		:Tuple=False  ,_UpperCamelCase		:Any=6_4  ,_UpperCamelCase		:List[Any]=0.1			):

									if self.sp_model_kwargs.get("""enable_sampling"""			) is True:
											snake_case_		:							List[str]			       =						True
									if self.sp_model_kwargs.get("""alpha"""			) is not None:
											snake_case_		:							str			       =						self.sp_model_kwargs.get("""alpha"""			)
									if self.sp_model_kwargs.get("""nbest_size"""			) is not None:
											snake_case_		:							Union[str, Any]			       =						self.sp_model_kwargs.get("""nbest_size"""			)

									if not enable_sampling:
											snake_case_		:							Union[str, Any]			       =						self.sp_model.EncodeAsPieces(_UpperCamelCase			)
									else:
											snake_case_		:							Optional[int]			       =						self.sp_model.SampleEncodeAsPieces(_UpperCamelCase  ,_UpperCamelCase  ,_UpperCamelCase			)
									snake_case_		:							List[str]			       =						[]
									for pi, piece in enumerate(_UpperCamelCase			):
											if piece == SPIECE_UNDERLINE:
													if not pieces[pi + 1].startswith(_UpperCamelCase			) and pi != 0:
															new_pieces.append(_UpperCamelCase			)
															continue
													else:
															continue
											snake_case_		:							List[Any]			       =						0
											for i, chunk in enumerate(_UpperCamelCase			):
													if chunk == SPIECE_UNDERLINE:
															continue
													if self.is_ch_char(_UpperCamelCase			) or self.is_punct(_UpperCamelCase			):
															if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
																	new_pieces.append(piece[lst_i:i]			)
															new_pieces.append(_UpperCamelCase			)
															snake_case_		:							List[Any]			       =						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]			)
															snake_case_		:							List[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]			)
															snake_case_		:							Dict			       =						i
											if len(_UpperCamelCase			) > lst_i:
													new_pieces.append(piece[lst_i:]			)
									return new_pieces





							def 		a__   (  self		:int  ,_UpperCamelCase		:int			):
									snake_case_		:							Optional[int]			       =						"""""".join(_UpperCamelCase			).replace(_UpperCamelCase  ,""" """			).strip()
									return out_string





							def 		a__   (  self		:Any  ,_UpperCamelCase		:Union[str, Any]			):
									snake_case_		:							Any			       =						self.convert_ids_to_tokens(_UpperCamelCase			)
									snake_case_		:							str			       =						"""""".join(_UpperCamelCase			).replace(_UpperCamelCase  ,""" """			).strip()
									return out_string





							def 		a__   (  self		:Tuple  ,_UpperCamelCase		:int			):
									return self.vocab.get(_UpperCamelCase  ,self.vocab.get(self.unk_token			)			)





							def 		a__   (  self		:int  ,_UpperCamelCase		:List[str]			):
									return self.reverse_vocab.get(_UpperCamelCase  ,self.unk_token			)





							def 		a__   (  self		:Tuple  ,_UpperCamelCase		:int  ,_UpperCamelCase		:Tuple=None			):
									if token_ids_a is None:
											return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
									snake_case_		:							Dict			       =						[self.cls_token_id]
									snake_case_		:							Tuple			       =						[self.sep_token_id]
									return _cls + token_ids_a + _sep + _sep + token_ids_a + _sep





							def 		a__   (  self		:List[Any]  ,_UpperCamelCase		:Tuple  ,_UpperCamelCase		:List[str]=None			):
									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 		a__   (  self		:Tuple  ,_UpperCamelCase		:Any  ,_UpperCamelCase		:List[Any]=None  ,_UpperCamelCase		:List[str]=False			):

									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(_UpperCamelCase			)) + [1, 1] + ([0] * len(_UpperCamelCase			)) + [1]
									return [1] + ([0] * len(_UpperCamelCase			)) + [1]





							def 		a__   (  self		:Tuple  ,_UpperCamelCase		:List[int]  ,_UpperCamelCase		:Optional[List[int]] = None			):
									# 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(_UpperCamelCase			) + 2) * [0]

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





							def 		a__   (  self		:Tuple  ,_UpperCamelCase		:str			):
									if "\u4e00" <= char <= "\u9fff":
											return True
									return False





							def 		a__   (  self		:Tuple  ,_UpperCamelCase		:Any			):
									if ("a" <= char <= "z") or ("A" <= char <= "Z"):
											return True
									return False





							def 		a__   (  self		:int  ,_UpperCamelCase		:List[Any]			):
									if char in ",;:.?!~，；：。？！《》【】":
											return True
									return False





							def 		a__   (  self		:List[str]  ,_UpperCamelCase		:Dict			):
									if char == " " or char == "\t" or char == "\n" or char == "\r":
											return True
									if len(_UpperCamelCase			) == 1:
											snake_case_		:							List[str]			       =						unicodedata.category(_UpperCamelCase			)
											if cat == "Zs":
													return True
									return False





							def 		a__   (  self		:Any  ,_UpperCamelCase		:List[Any]			):
									snake_case_		:							Dict			       =						{}
									with io.open(_UpperCamelCase  ,"""r"""  ,encoding="""utf-8"""			) as f:
											for index, line in enumerate(_UpperCamelCase			):
													snake_case_		:							Dict			       =						line.rstrip("""\n"""			)
													snake_case_		:							List[Any]			       =						int(_UpperCamelCase			)

									return token_to_idx





							def 		a__   (  self		:List[Any]  ,_UpperCamelCase		:str  ,_UpperCamelCase		:Optional[str] = None			):
									snake_case_		:							Union[str, Any]			       =						0
									if os.path.isdir(_UpperCamelCase			):
											snake_case_		:							List[str]			       =						os.path.join(
											    _UpperCamelCase  ,(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]			)
									else:
											snake_case_		:							List[Any]			       =						(filename_prefix + """-""" if filename_prefix else """""") + save_directory
									with open(_UpperCamelCase  ,"""w"""  ,encoding="""utf-8"""			) as writer:
											for token, token_index in sorted(self.vocab.items()  ,key=lambda _UpperCamelCase			: 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!"""			)
															snake_case_		:							Optional[Any]			       =						token_index
													writer.write(token + """\n"""			)
													index += 1

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

									return (vocab_file,)



'''simple docstring'''






from __future__ import annotations





def      UpperCAmelCase      (		lowerCamelCase_  :int ):







		'''simple docstring'''
		snake_case_		:							List[str]			       =						[True] * limit
		snake_case_		:							Union[str, Any]			       =						False
		snake_case_		:							List[str]			       =						False
		snake_case_		:							Any			       =						True

		for i in range(3				,      int(limit**0.5 + 1 )				,      2 ):
				snake_case_		:							Tuple			       =						i * 2
				while index < limit:
						snake_case_		:							Any			       =						False
						snake_case_		:							Optional[Any]			       =						index + i

		snake_case_		:							List[str]			       =						[2]

		for i in range(3				,      lowerCamelCase_				,      2 ):
				if is_prime[i]:
						primes.append(lowerCamelCase_ )

		return primes





def      UpperCAmelCase      (		lowerCamelCase_  :int = 1_00_00_00 ):







		'''simple docstring'''
		snake_case_		:							Optional[int]			       =						prime_sieve(lowerCamelCase_ )
		snake_case_		:							Optional[Any]			       =						0
		snake_case_		:							Optional[int]			       =						0

		for i in range(len(lowerCamelCase_ ) ):
				for j in range(i + length				,      len(lowerCamelCase_ ) ):
						snake_case_		:							Optional[int]			       =						sum(primes[i:j] )
						if sol >= ceiling:
								break

						if sol in primes:
								snake_case_		:							Optional[Any]			       =						j - i
								snake_case_		:							Tuple			       =						sol

		return largest


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