
import os
import unicodedata
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


UpperCamelCase_   	=	logging.get_logger(__name__)
UpperCamelCase_   	=	{"vocab_file": "spiece.model"}

UpperCamelCase_   	=	{
    "vocab_file": {
        "albert-base-v1": "https://huggingface.co/albert-base-v1/resolve/main/spiece.model",
        "albert-large-v1": "https://huggingface.co/albert-large-v1/resolve/main/spiece.model",
        "albert-xlarge-v1": "https://huggingface.co/albert-xlarge-v1/resolve/main/spiece.model",
        "albert-xxlarge-v1": "https://huggingface.co/albert-xxlarge-v1/resolve/main/spiece.model",
        "albert-base-v2": "https://huggingface.co/albert-base-v2/resolve/main/spiece.model",
        "albert-large-v2": "https://huggingface.co/albert-large-v2/resolve/main/spiece.model",
        "albert-xlarge-v2": "https://huggingface.co/albert-xlarge-v2/resolve/main/spiece.model",
        "albert-xxlarge-v2": "https://huggingface.co/albert-xxlarge-v2/resolve/main/spiece.model",
    }
}

UpperCamelCase_   	=	{
    "albert-base-v1": 5_1_2,
    "albert-large-v1": 5_1_2,
    "albert-xlarge-v1": 5_1_2,
    "albert-xxlarge-v1": 5_1_2,
    "albert-base-v2": 5_1_2,
    "albert-large-v2": 5_1_2,
    "albert-xlarge-v2": 5_1_2,
    "albert-xxlarge-v2": 5_1_2,
}

UpperCamelCase_   	=	"▁"

class       a		(   __UpperCAmelCase					):
							lowercase_		:						Dict   							=  VOCAB_FILES_NAMES
							lowercase_		:						Union[str, Any]   							=  PRETRAINED_VOCAB_FILES_MAP
							lowercase_		:						Optional[int]   							=  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES







							def __init__(						self  :  str      ,				snake_case__  :  List[Any]      ,				snake_case__  :  List[str]=True      ,				snake_case__  :  Optional[int]=True      ,				snake_case__  :  Dict=False      ,				snake_case__  :  Union[str, Any]="[CLS]"      ,				snake_case__  :  Optional[int]="[SEP]"      ,				snake_case__  :  Union[str, Any]="<unk>"      ,				snake_case__  :  Any="[SEP]"      ,				snake_case__  :  List[Any]="<pad>"      ,				snake_case__  :  int="[CLS]"      ,				snake_case__  :  str="[MASK]"      ,				snake_case__  :  Optional[Dict[str, Any]] = None      ,				**snake_case__  :  Optional[Any]      ,				):
								"""simple docstring"""







								__lowerCAmelCase         =							(
								    AddedToken(snake_case__      ,				lstrip=snake_case__      ,				rstrip=snake_case__      ,				normalized=snake_case__ )
								    if isinstance(snake_case__      ,				snake_case__ )
								    else mask_token
								)

								__lowerCAmelCase         =							{} if sp_model_kwargs is None else sp_model_kwargs

								super().__init__(
								    do_lower_case=snake_case__      ,				remove_space=snake_case__      ,				keep_accents=snake_case__      ,				bos_token=snake_case__      ,				eos_token=snake_case__      ,				unk_token=snake_case__      ,				sep_token=snake_case__      ,				pad_token=snake_case__      ,				cls_token=snake_case__      ,				mask_token=snake_case__      ,				sp_model_kwargs=self.sp_model_kwargs      ,				**snake_case__      ,				)

								__lowerCAmelCase         =							do_lower_case
								__lowerCAmelCase         =							remove_space
								__lowerCAmelCase         =							keep_accents
								__lowerCAmelCase         =							vocab_file

								__lowerCAmelCase         =							spm.SentencePieceProcessor(**self.sp_model_kwargs )
								self.sp_model.Load(snake_case__ )







							@property
							def       UpperCAmelCase__					(						self  :  str ):
								"""simple docstring"""







								return len(self.sp_model )







							def       UpperCAmelCase__					(						self  :  Optional[int] ):
								"""simple docstring"""







								__lowerCAmelCase         =							{self.convert_ids_to_tokens(snake_case__ ): i for i in range(self.vocab_size )}
								vocab.update(self.added_tokens_encoder )
								return vocab







							def __getstate__(						self  :  Optional[Any] ):
								"""simple docstring"""







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







							def __setstate__(						self  :  int      ,				snake_case__  :  Any ):
								"""simple docstring"""







								__lowerCAmelCase         =							d

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

								__lowerCAmelCase         =							spm.SentencePieceProcessor(**self.sp_model_kwargs )
								self.sp_model.Load(self.vocab_file )







							def       UpperCAmelCase__					(						self  :  str      ,				snake_case__  :  int ):
								"""simple docstring"""







								if self.remove_space:
									__lowerCAmelCase         =							" ".join(inputs.strip().split() )
								else:
									__lowerCAmelCase         =							inputs
								__lowerCAmelCase         =							outputs.replace("``"      ,				"\"" ).replace("''"      ,				"\"" )

								if not self.keep_accents:
									__lowerCAmelCase         =							unicodedata.normalize("NFKD"      ,				snake_case__ )
									__lowerCAmelCase         =							"".join([c for c in outputs if not unicodedata.combining(snake_case__ )] )
								if self.do_lower_case:
									__lowerCAmelCase         =							outputs.lower()

								return outputs







							def       UpperCAmelCase__					(						self  :  Any      ,				snake_case__  :  str ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.preprocess_text(snake_case__ )
								__lowerCAmelCase         =							self.sp_model.encode(snake_case__      ,				out_type=snake_case__ )
								__lowerCAmelCase         =							[]
								for piece in pieces:
									if len(snake_case__ ) > 1 and piece[-1] == str("," ) and piece[-2].isdigit():
										__lowerCAmelCase         =							self.sp_model.EncodeAsPieces(piece[:-1].replace(snake_case__      ,				"" ) )
										if piece[0] != SPIECE_UNDERLINE and cur_pieces[0][0] == SPIECE_UNDERLINE:
											if len(cur_pieces[0] ) == 1:
												__lowerCAmelCase         =							cur_pieces[1:]
											else:
												__lowerCAmelCase         =							cur_pieces[0][1:]
										cur_pieces.append(piece[-1] )
										new_pieces.extend(snake_case__ )
									else:
										new_pieces.append(snake_case__ )

								return new_pieces







							def       UpperCAmelCase__					(						self  :  Optional[Any]      ,				snake_case__  :  int ):
								"""simple docstring"""







								return self.sp_model.PieceToId(snake_case__ )







							def       UpperCAmelCase__					(						self  :  Optional[Any]      ,				snake_case__  :  Any ):
								"""simple docstring"""







								return self.sp_model.IdToPiece(snake_case__ )







							def       UpperCAmelCase__					(						self  :  Tuple      ,				snake_case__  :  Optional[int] ):
								"""simple docstring"""







								__lowerCAmelCase         =							[]
								__lowerCAmelCase         =							""
								__lowerCAmelCase         =							False
								for token in tokens:
									# make sure that special tokens are not decoded using sentencepiece model
									if token in self.all_special_tokens:
										if not prev_is_special:
											out_string += " "
										out_string += self.sp_model.decode(snake_case__ ) + token
										__lowerCAmelCase         =							True
										__lowerCAmelCase         =							[]
									else:
										current_sub_tokens.append(snake_case__ )
										__lowerCAmelCase         =							False
								out_string += self.sp_model.decode(snake_case__ )
								return out_string.strip()







							def       UpperCAmelCase__					(						self  :  Optional[int]      ,				snake_case__  :  List[int]      ,				snake_case__  :  Optional[List[int]] = None ):
								"""simple docstring"""







								__lowerCAmelCase         =							[self.sep_token_id]
								__lowerCAmelCase         =							[self.cls_token_id]
								if token_ids_a is None:
									return cls + token_ids_a + sep
								return cls + token_ids_a + sep + token_ids_a + sep







							def       UpperCAmelCase__					(						self  :  List[Any]      ,				snake_case__  :  List[int]      ,				snake_case__  :  Optional[List[int]] = None      ,				snake_case__  :  bool = 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 not None:
									return [1] + ([0] * len(snake_case__ )) + [1] + ([0] * len(snake_case__ )) + [1]
								return [1] + ([0] * len(snake_case__ )) + [1]







							def       UpperCAmelCase__					(						self  :  List[Any]      ,				snake_case__  :  List[int]      ,				snake_case__  :  Optional[List[int]] = None ):
								"""simple docstring"""







								__lowerCAmelCase         =							[self.sep_token_id]
								__lowerCAmelCase         =							[self.cls_token_id]

								if token_ids_a is None:
									return len(cls + token_ids_a + sep ) * [0]
								return len(cls + token_ids_a + sep ) * [0] + len(token_ids_a + sep ) * [1]







							def       UpperCAmelCase__					(						self  :  str      ,				snake_case__  :  str      ,				snake_case__  :  Optional[str] = None ):
								"""simple docstring"""







								if not os.path.isdir(snake_case__ ):
									logger.error(F"Vocabulary path ({save_directory}) should be a directory" )
									return
								__lowerCAmelCase         =							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:
										__lowerCAmelCase         =							self.sp_model.serialized_model_proto()
										fi.write(snake_case__ )

								return (out_vocab_file,)








from __future__ import annotations

from math import ceil, floor, sqrt






def 		_UpperCAmelCase   (	UpperCamelCase:     int = 2_0_0_0_0_0_0  ):






	"""simple docstring"""


	__lowerCAmelCase         =							[0]
	__lowerCAmelCase         =							42

	for idx in range(1			,							ceil(sqrt(target * 2  ) * 1.1  )  ):
		triangle_numbers.append(triangle_numbers[-1] + idx  )

	# we want this to be as close as possible to target
	__lowerCAmelCase         =							0
	# the area corresponding to the grid that gives the product closest to target
	__lowerCAmelCase         =							0
	# an estimate of b, using the quadratic formula
	__lowerCAmelCase         =							42
	# the largest integer less than b_estimate
	__lowerCAmelCase         =							42
	# the largest integer less than b_estimate
	__lowerCAmelCase         =							42
	# the triangle number corresponding to b_floor
	__lowerCAmelCase         =							42
	# the triangle number corresponding to b_ceil
	__lowerCAmelCase         =							42

	for idx_a, triangle_a in enumerate(triangle_numbers[1:]			,							1  ):
		__lowerCAmelCase         =							(-1 + sqrt(1 + 8 * target / triangle_a  )) / 2
		__lowerCAmelCase         =							floor(UpperCamelCase  )
		__lowerCAmelCase         =							ceil(UpperCamelCase  )
		__lowerCAmelCase         =							triangle_numbers[b_floor]
		__lowerCAmelCase         =							triangle_numbers[b_ceil]

		if abs(target - triangle_b_first_guess * triangle_a  ) < abs(
		    target - best_product  ):
			__lowerCAmelCase         =							triangle_b_first_guess * triangle_a
			__lowerCAmelCase         =							idx_a * b_floor

		if abs(target - triangle_b_second_guess * triangle_a  ) < abs(
		    target - best_product  ):
			__lowerCAmelCase         =							triangle_b_second_guess * triangle_a
			__lowerCAmelCase         =							idx_a * b_ceil

	return area


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






