
"""simple docstring"""







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


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

_SCREAMING_SNAKE_CASE	       =      {
    "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",
    }
}

_SCREAMING_SNAKE_CASE	       =      {
    "albert-base-v1": 512,
    "albert-large-v1": 512,
    "albert-xlarge-v1": 512,
    "albert-xxlarge-v1": 512,
    "albert-base-v2": 512,
    "albert-large-v2": 512,
    "albert-xlarge-v2": 512,
    "albert-xxlarge-v2": 512,
}

_SCREAMING_SNAKE_CASE	       =      "▁"







class 							__magic_name__     (		lowercase__   ):
					_SCREAMING_SNAKE_CASE       :					int     							=   VOCAB_FILES_NAMES
					_SCREAMING_SNAKE_CASE       :					int     							=   PRETRAINED_VOCAB_FILES_MAP
					_SCREAMING_SNAKE_CASE       :					int     							=   PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES





					def __init__(				self   :							Any							,						snake_case_   :							Union[str, Any]							,						snake_case_   :							Optional[int]=True							,						snake_case_   :							Union[str, Any]=True							,						snake_case_   :							Union[str, Any]=False							,						snake_case_   :							Union[str, Any]="[CLS]"							,						snake_case_   :							List[str]="[SEP]"							,						snake_case_   :							Optional[int]="<unk>"							,						snake_case_   :							Optional[Any]="[SEP]"							,						snake_case_   :							str="<pad>"							,						snake_case_   :							Optional[Any]="[CLS]"							,						snake_case_   :							List[str]="[MASK]"							,						snake_case_   :							Optional[Dict[str, Any]] = None							,						**snake_case_   :							Optional[int]							,						):
												__snake_case     			=       (
												    AddedToken(__lowerCamelCase							,						lstrip=__lowerCamelCase							,						rstrip=__lowerCamelCase							,						normalized=__lowerCamelCase    )
												    if isinstance(__lowerCamelCase							,						__lowerCamelCase    )
												    else mask_token
												)

												__snake_case     			=       {} if sp_model_kwargs is None else sp_model_kwargs

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

												__snake_case     			=       do_lower_case
												__snake_case     			=       remove_space
												__snake_case     			=       keep_accents
												__snake_case     			=       vocab_file

												__snake_case     			=       spm.SentencePieceProcessor(**self.sp_model_kwargs    )
												self.sp_model.Load(__lowerCamelCase    )





					@property
					def 							lowerCAmelCase      (				self   :							int    ):
												return len(self.sp_model    )





					def 							lowerCAmelCase      (				self   :							str    ):
												__snake_case     			=       {self.convert_ids_to_tokens(__lowerCamelCase    ): i for i in range(self.vocab_size    )}
												vocab.update(self.added_tokens_encoder    )
												return vocab





					def __getstate__(				self   :							Optional[Any]    ):
												__snake_case     			=       self.__dict__.copy()
												__snake_case     			=       None
												return state





					def __setstate__(				self   :							Tuple							,						snake_case_   :							Optional[int]    ):
												__snake_case     			=       d

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

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





					def 							lowerCAmelCase      (				self   :							List[Any]							,						snake_case_   :							Tuple    ):



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

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

												return outputs





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

												return new_pieces





					def 							lowerCAmelCase      (				self   :							List[str]							,						snake_case_   :							List[Any]    ):
												return self.sp_model.PieceToId(__lowerCamelCase    )





					def 							lowerCAmelCase      (				self   :							int							,						snake_case_   :							int    ):
												return self.sp_model.IdToPiece(__lowerCamelCase    )





					def 							lowerCAmelCase      (				self   :							Tuple							,						snake_case_   :							List[str]    ):
												__snake_case     			=       []
												__snake_case     			=       ""
												__snake_case     			=       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(__lowerCamelCase    ) + token
																										__snake_case     			=       True
																										__snake_case     			=       []
																			else:
																										current_sub_tokens.append(__lowerCamelCase    )
																										__snake_case     			=       False
												out_string += self.sp_model.decode(__lowerCamelCase    )
												return out_string.strip()





					def 							lowerCAmelCase      (				self   :							Dict							,						snake_case_   :							List[int]							,						snake_case_   :							Optional[List[int]] = None    ):
												__snake_case     			=       [self.sep_token_id]
												__snake_case     			=       [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 							lowerCAmelCase      (				self   :							Union[str, Any]							,						snake_case_   :							List[int]							,						snake_case_   :							Optional[List[int]] = None							,						snake_case_   :							bool = False    ):



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

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





					def 							lowerCAmelCase      (				self   :							Tuple							,						snake_case_   :							List[int]							,						snake_case_   :							Optional[List[int]] = None    ):
												__snake_case     			=       [self.sep_token_id]
												__snake_case     			=       [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 							lowerCAmelCase      (				self   :							List[str]							,						snake_case_   :							str							,						snake_case_   :							Optional[str] = None    ):



												if not os.path.isdir(__lowerCamelCase    ):
																			logger.error(F'''Vocabulary path ({save_directory}) should be a directory'''    )
																			return
												__snake_case     			=       os.path.join(
												    __lowerCamelCase							,						(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]    )

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

												return (out_vocab_file,)


"""simple docstring"""







from __future__ import annotations

from itertools import permutations
from random import randint
from timeit import repeat
def   __UpperCamelCase   (					)  ->     tuple[list[int], int]:







							"""simple docstring"""


							__snake_case     			=       [randint(-10_00							,    10_00 ) for i in range(10 )]
							__snake_case     			=       randint(-50_00							,    50_00 )
							return (arr, r)


_SCREAMING_SNAKE_CASE	       =      make_dataset()
def   __UpperCamelCase   (					SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE )  ->     tuple[int, ...]:







							"""simple docstring"""


							for triplet in permutations(SCREAMING_SNAKE_CASE							,    3 ):
														if sum(SCREAMING_SNAKE_CASE ) == target:
																					return tuple(sorted(SCREAMING_SNAKE_CASE ) )
							return (0, 0, 0)
def   __UpperCamelCase   (					SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE )  ->     tuple[int, int, int]:







							"""simple docstring"""


							arr.sort()
							__snake_case     			=       len(SCREAMING_SNAKE_CASE )
							for i in range(n - 1 ):
														__snake_case			,   __snake_case     			=       i + 1, n - 1
														while left < right:
																					if arr[i] + arr[left] + arr[right] == target:
																												return (arr[i], arr[left], arr[right])
																					elif arr[i] + arr[left] + arr[right] < target:
																												left += 1
																					elif arr[i] + arr[left] + arr[right] > target:
																												right -= 1
							return (0, 0, 0)
def   __UpperCamelCase   (					)  ->     tuple[float, float]:







							"""simple docstring"""


							__snake_case     			=       "\nfrom __main__ import dataset, triplet_sum1, triplet_sum2\n"
							__snake_case     			=       "\ntriplet_sum1(*dataset)\n"
							__snake_case     			=       "\ntriplet_sum2(*dataset)\n"
							__snake_case     			=       repeat(setup=SCREAMING_SNAKE_CASE							,    stmt=SCREAMING_SNAKE_CASE							,    repeat=5							,    number=1_00_00 )
							__snake_case     			=       repeat(setup=SCREAMING_SNAKE_CASE							,    stmt=SCREAMING_SNAKE_CASE							,    repeat=5							,    number=1_00_00 )
							return (min(SCREAMING_SNAKE_CASE ), min(SCREAMING_SNAKE_CASE ))


if __name__ == "__main__":
		from doctest import testmod

		testmod()
		_SCREAMING_SNAKE_CASE	       =      solution_times()
		print(F"""The time for naive implementation is {times[0]}.""")
		print(F"""The time for optimized implementation is {times[1]}.""")
