



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


snake_case__					:     Any    		=   logging.get_logger(__name__)

snake_case__					:     Union[str, Any]    		=   """▁"""

snake_case__					:     Dict    		=   {"""vocab_file""": """vocab.txt""", """sentencepiece_model_ckpt""": """sentencepiece.bpe.model"""}

snake_case__					:     Optional[Any]    		=   {
    """sentencepiece_model_file""": """sentencepiece.bpe.model""",
    """vocab_file""": """vocab.txt""",
}

snake_case__					:     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""",
    },
}

snake_case__					:     Union[str, Any]    		=   {
    """ernie-m-base""": 5_14,
    """ernie-m-large""": 5_14,
}

snake_case__					:     Optional[int]    		=   {
    """ernie-m-base""": {"""do_lower_case""": False},
    """ernie-m-large""": {"""do_lower_case""": False},
}

class   _A   ( _lowercase	):


						'''simple docstring'''





						_snake_case			:     List[str]      							=      ["input_ids"]

						_snake_case			:     Union[str, Any]      							=      VOCAB_FILES_NAMES
						_snake_case			:     Dict      							=      PRETRAINED_INIT_CONFIGURATION
						_snake_case			:     int      							=      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						_snake_case			:     List[str]      							=      PRETRAINED_VOCAB_FILES_MAP
						_snake_case			:     List[str]      							=      RESOURCE_FILES_NAMES



						def __init__(	self	:							Optional[Any]							,      lowerCamelCase	:							str							,      lowerCamelCase	:							List[str]=None							,      lowerCamelCase	:							int=False							,      lowerCamelCase	:							List[Any]="utf8"							,      lowerCamelCase	:							Optional[int]="[UNK]"							,      lowerCamelCase	:							List[str]="[SEP]"							,      lowerCamelCase	:							int="[PAD]"							,      lowerCamelCase	:							List[str]="[CLS]"							,      lowerCamelCase	:							Optional[Any]="[MASK]"							,      lowerCamelCase	:							Optional[Dict[str, Any]] = None							,      **lowerCamelCase	:							List[str]							,      ):






							'''simple docstring'''



							__lowercase		       =			{} 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							,      )
							__lowercase		       =			do_lower_case
							__lowercase		       =			sentencepiece_model_ckpt
							__lowercase		       =			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:
								__lowercase		       =			self.load_vocab(filepath=lowerCamelCase	)
							else:
								__lowercase		       =			{self.sp_model.id_to_piece(lowerCamelCase	): id for id in range(self.sp_model.get_piece_size()	)}
							__lowercase		       =			{v: k for k, v in self.vocab.items()}



						def     _snake_case	(	self	:							str							,      lowerCamelCase	:							Optional[int]	):






							'''simple docstring'''



							if text is None:
								return None

							__lowercase		       =			self.tokenize(lowerCamelCase	)
							__lowercase       ,    __lowercase		       =			"", []

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

							__lowercase       ,    __lowercase       ,    __lowercase		       =			normalized_text, [], 0

							if self.do_lower_case:
								__lowercase		       =			text.lower()

							for token in split_tokens:
								if token[:1] == "▁":
									__lowercase		       =			token[1:]
								__lowercase		       =			text[offset:].index(lowerCamelCase	) + offset
								__lowercase		       =			start + len(lowerCamelCase	)

								token_mapping.append((char_mapping[start], char_mapping[end - 1] + 1)	)
								__lowercase		       =			end
							return token_mapping



						@property
						def     _snake_case	(	self	:							Any	):






							'''simple docstring'''



							return len(self.vocab	)



						def     _snake_case	(	self	:							Union[str, Any]	):






							'''simple docstring'''



							return dict(self.vocab							,      **self.added_tokens_encoder	)



						def __getstate__(	self	:							Optional[int]	):






							'''simple docstring'''



							__lowercase		       =			self.__dict__.copy()
							__lowercase		       =			None
							return state



						def __setstate__(	self	:							str							,      lowerCamelCase	:							Optional[Any]	):






							'''simple docstring'''



							__lowercase		       =			d

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

							__lowercase		       =			spm.SentencePieceProcessor(**self.sp_model_kwargs	)
							self.sp_model.Load(self.sentencepiece_model_ckpt	)



						def     _snake_case	(	self	:							int							,      lowerCamelCase	:							List[str]	):






							'''simple docstring'''



							return "".join((self.SP_CHAR_MAPPING.get(lowerCamelCase							,      lowerCamelCase	) for c in text)	)



						def     _snake_case	(	self	:							List[str]							,      lowerCamelCase	:							Optional[int]							,      lowerCamelCase	:							int=False							,      lowerCamelCase	:							Tuple=64							,      lowerCamelCase	:							Optional[int]=0.1	):






							'''simple docstring'''



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

							if not enable_sampling:
								__lowercase		       =			self.sp_model.EncodeAsPieces(lowerCamelCase	)
							else:
								__lowercase		       =			self.sp_model.SampleEncodeAsPieces(lowerCamelCase							,      lowerCamelCase							,      lowerCamelCase	)
							__lowercase		       =			[]
							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
								__lowercase		       =			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	)
										__lowercase		       =			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]	)
										__lowercase		       =			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]	)
										__lowercase		       =			i
								if len(lowerCamelCase	) > lst_i:
									new_pieces.append(piece[lst_i:]	)
							return new_pieces



						def     _snake_case	(	self	:							Any							,      lowerCamelCase	:							Optional[Any]	):






							'''simple docstring'''



							__lowercase		       =			"".join(lowerCamelCase	).replace(lowerCamelCase							,      " "	).strip()
							return out_string



						def     _snake_case	(	self	:							Union[str, Any]							,      lowerCamelCase	:							Optional[int]	):






							'''simple docstring'''



							__lowercase		       =			self.convert_ids_to_tokens(lowerCamelCase	)
							__lowercase		       =			"".join(lowerCamelCase	).replace(lowerCamelCase							,      " "	).strip()
							return out_string



						def     _snake_case	(	self	:							Tuple							,      lowerCamelCase	:							List[str]	):






							'''simple docstring'''



							return self.vocab.get(lowerCamelCase							,      self.vocab.get(self.unk_token	)	)



						def     _snake_case	(	self	:							List[Any]							,      lowerCamelCase	:							List[Any]	):






							'''simple docstring'''



							return self.reverse_vocab.get(lowerCamelCase							,      self.unk_token	)



						def     _snake_case	(	self	:							List[Any]							,      lowerCamelCase	:							List[str]							,      lowerCamelCase	:							List[str]=None	):






							'''simple docstring'''



							if token_ids_a is None:
								return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
							__lowercase		       =			[self.cls_token_id]
							__lowercase		       =			[self.sep_token_id]
							return _cls + token_ids_a + _sep + _sep + token_ids_a + _sep



						def     _snake_case	(	self	:							Optional[int]							,      lowerCamelCase	:							Optional[Any]							,      lowerCamelCase	:							str=None	):






							'''simple docstring'''



							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     _snake_case	(	self	:							List[str]							,      lowerCamelCase	:							Union[str, Any]							,      lowerCamelCase	:							int=None							,      lowerCamelCase	:							List[str]=False	):






							'''simple docstring'''



							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     _snake_case	(	self	:							Union[str, Any]							,      lowerCamelCase	:							List[int]							,      lowerCamelCase	:							Optional[List[int]] = None	):






							'''simple docstring'''



							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     _snake_case	(	self	:							Any							,      lowerCamelCase	:							int	):






							'''simple docstring'''



							if "\u4e00" <= char <= "\u9fff":
								return True
							return False



						def     _snake_case	(	self	:							List[str]							,      lowerCamelCase	:							Any	):






							'''simple docstring'''



							if ("a" <= char <= "z") or ("A" <= char <= "Z"):
								return True
							return False



						def     _snake_case	(	self	:							List[str]							,      lowerCamelCase	:							Union[str, Any]	):






							'''simple docstring'''



							if char in ",;:.?!~，；：。？！《》【】":
								return True
							return False



						def     _snake_case	(	self	:							Optional[int]							,      lowerCamelCase	:							Union[str, Any]	):






							'''simple docstring'''



							if char == " " or char == "\t" or char == "\n" or char == "\r":
								return True
							if len(lowerCamelCase	) == 1:
								__lowercase		       =			unicodedata.category(lowerCamelCase	)
								if cat == "Zs":
									return True
							return False



						def     _snake_case	(	self	:							Optional[Any]							,      lowerCamelCase	:							Dict	):






							'''simple docstring'''



							__lowercase		       =			{}
							with io.open(lowerCamelCase							,      "r"							,      encoding="utf-8"	) as f:
								for index, line in enumerate(lowerCamelCase	):
									__lowercase		       =			line.rstrip("\n"	)
									__lowercase		       =			int(lowerCamelCase	)

							return token_to_idx



						def     _snake_case	(	self	:							List[Any]							,      lowerCamelCase	:							str							,      lowerCamelCase	:							Optional[str] = None	):






							'''simple docstring'''



							__lowercase		       =			0
							if os.path.isdir(lowerCamelCase	):
								__lowercase		       =			os.path.join(
								    lowerCamelCase							,      (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]	)
							else:
								__lowercase		       =			(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!"	)
										__lowercase		       =			token_index
									writer.write(token + "\n"	)
									index += 1

							__lowercase		       =			os.path.join(lowerCamelCase							,      "sentencepiece.bpe.model"	)
							with open(lowerCamelCase							,      "wb"	) as fi:
								__lowercase		       =			self.sp_model.serialized_model_proto()
								fi.write(lowerCamelCase	)

							return (vocab_file,)








from __future__ import annotations

import bisect



def    snake_case_				(    _SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE = 0  ,	_SCREAMING_SNAKE_CASE = -1   ):
	if hi < 0:
		__lowercase		       =			len(_SCREAMING_SNAKE_CASE   )

	while lo < hi:
		__lowercase		       =			lo + (hi - lo) // 2
		if sorted_collection[mid] < item:
			__lowercase		       =			mid + 1
		else:
			__lowercase		       =			mid

	return lo



def    snake_case_				(    _SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE = 0  ,	_SCREAMING_SNAKE_CASE = -1   ):
	if hi < 0:
		__lowercase		       =			len(_SCREAMING_SNAKE_CASE   )

	while lo < hi:
		__lowercase		       =			lo + (hi - lo) // 2
		if sorted_collection[mid] <= item:
			__lowercase		       =			mid + 1
		else:
			__lowercase		       =			mid

	return lo



def    snake_case_				(    _SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE = 0  ,	_SCREAMING_SNAKE_CASE = -1   ):
	sorted_collection.insert(bisect_left(_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE   )  ,	_SCREAMING_SNAKE_CASE   )



def    snake_case_				(    _SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE = 0  ,	_SCREAMING_SNAKE_CASE = -1   ):
	sorted_collection.insert(bisect_right(_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE   )  ,	_SCREAMING_SNAKE_CASE   )



def    snake_case_				(    _SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE   ):
	__lowercase		       =			0
	__lowercase		       =			len(_SCREAMING_SNAKE_CASE   ) - 1

	while left <= right:
		__lowercase		       =			left + (right - left) // 2
		__lowercase		       =			sorted_collection[midpoint]
		if current_item == item:
			return midpoint
		elif item < current_item:
			__lowercase		       =			midpoint - 1
		else:
			__lowercase		       =			midpoint + 1
	return None



def    snake_case_				(    _SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE   ):
	__lowercase		       =			bisect.bisect_left(_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE   )
	if index != len(_SCREAMING_SNAKE_CASE   ) and sorted_collection[index] == item:
		return index
	return None



def    snake_case_				(    _SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE   ):
	if right < left:
		return None

	__lowercase		       =			left + (right - left) // 2

	if sorted_collection[midpoint] == item:
		return midpoint
	elif sorted_collection[midpoint] > item:
		return binary_search_by_recursion(_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	midpoint - 1   )
	else:
		return binary_search_by_recursion(_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	midpoint + 1  ,	_SCREAMING_SNAKE_CASE   )


if __name__ == "__main__":
	snake_case__					:     Optional[Any]    		=   input("""Enter numbers separated by comma:\n""").strip()
	snake_case__					:     Any    		=   sorted(int(item) for item in user_input.split(""","""))
	snake_case__					:     Any    		=   int(input("""Enter a single number to be found in the list:\n"""))
	snake_case__					:     List[Any]    		=   binary_search(collection, target)
	if result is None:
		print(F'''{target} was not found in {collection}.''')
	else:
		print(F'''{target} was found at position {result} in {collection}.''')



