





import json
import os
from functools import lru_cache
from typing import TYPE_CHECKING, List, Optional, Tuple, Union

import numpy as np
import regex as re

from ...utils import is_tf_available, is_torch_available, logging


if TYPE_CHECKING:
			if is_torch_available():
						import torch
			if is_tf_available():
						import tensorflow as tf

from ...tokenization_utils import AddedToken, PreTrainedTokenizer


__UpperCamelCase:  Tuple   =   logging.get_logger(__name__)

__UpperCamelCase:  Any   =   {
    """vocab_file""": """vocab.json""",
    """merges_file""": """merges.txt""",
}

__UpperCamelCase:  Tuple   =   {
    """vocab_file""": {
        """Salesforce/codegen-350M-mono""": """https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/vocab.json""",
    },
    """merges_file""": {
        """Salesforce/codegen-350M-mono""": """https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/merges.txt""",
    },
}

__UpperCamelCase:  Dict   =   {
    """Salesforce/codegen-350M-mono""": 2_0_4_8,
}


@lru_cache()
def 			SCREAMING_SNAKE_CASE__     (					)      ->       Optional[Any]:




		'''simple docstring'''
		lowercase__				:			List[str]            =		(
		    list(range(ord('!' )      ,						ord('~' ) + 1 ) ) + list(range(ord('¡' )      ,						ord('¬' ) + 1 ) ) + list(range(ord('®' )      ,						ord('ÿ' ) + 1 ) )
		)
		lowercase__				:			Optional[int]            =		bs[:]
		lowercase__				:			List[Any]            =		0
		for b in range(2**8 ):
				if b not in bs:
						bs.append(_lowercase )
						cs.append(2**8 + n )
						n += 1
		lowercase__				:			Tuple            =		[chr(_lowercase ) for n in cs]
		return dict(zip(_lowercase      ,						_lowercase ) )


def 			SCREAMING_SNAKE_CASE__     (					_lowercase    :   int )      ->       Dict:




		'''simple docstring'''
		lowercase__				:			Optional[int]            =		set()
		lowercase__				:			Optional[Any]            =		word[0]
		for char in word[1:]:
				pairs.add((prev_char, char) )
				lowercase__				:			str            =		char
		return pairs





class 			__lowerCAmelCase				(					_SCREAMING_SNAKE_CASE			):


	'''simple docstring'''





	_A       	=							VOCAB_FILES_NAMES
	_A       	=							PRETRAINED_VOCAB_FILES_MAP
	_A       	=							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	_A       	=							['input_ids', 'attention_mask']

	def __init__(	self:	Optional[Any],				lowerCamelCase_:	Optional[int],				lowerCamelCase_:	Any,				lowerCamelCase_:	List[str]="replace",				lowerCamelCase_:	Dict="<|endoftext|>",				lowerCamelCase_:	Tuple="<|endoftext|>",				lowerCamelCase_:	Optional[Any]="<|endoftext|>",				lowerCamelCase_:	Tuple=None,				lowerCamelCase_:	Tuple=False,				lowerCamelCase_:	Tuple=False,				**lowerCamelCase_:	List[Any],				):
			lowercase__				:			Tuple            =		AddedToken(UpperCamelCase__,				lstrip=UpperCamelCase__,				rstrip=UpperCamelCase__ ) if isinstance(UpperCamelCase__,				UpperCamelCase__ ) else bos_token
			lowercase__				:			Union[str, Any]            =		AddedToken(UpperCamelCase__,				lstrip=UpperCamelCase__,				rstrip=UpperCamelCase__ ) if isinstance(UpperCamelCase__,				UpperCamelCase__ ) else eos_token
			lowercase__				:			Dict            =		AddedToken(UpperCamelCase__,				lstrip=UpperCamelCase__,				rstrip=UpperCamelCase__ ) if isinstance(UpperCamelCase__,				UpperCamelCase__ ) else unk_token
			lowercase__				:			List[str]            =		AddedToken(UpperCamelCase__,				lstrip=UpperCamelCase__,				rstrip=UpperCamelCase__ ) if isinstance(UpperCamelCase__,				UpperCamelCase__ ) else pad_token
			super().__init__(
			    errors=UpperCamelCase__,				unk_token=UpperCamelCase__,				bos_token=UpperCamelCase__,				eos_token=UpperCamelCase__,				pad_token=UpperCamelCase__,				add_prefix_space=UpperCamelCase__,				add_bos_token=UpperCamelCase__,				**UpperCamelCase__,				)
			lowercase__				:			List[Any]            =		add_bos_token

			with open(UpperCamelCase__,				encoding='utf-8' ) as vocab_handle:
					lowercase__				:			str            =		json.load(UpperCamelCase__ )
			lowercase__				:			Tuple            =		{v: k for k, v in self.encoder.items()}
			lowercase__				:			int            =		errors  # how to handle errors in decoding
			lowercase__				:			Tuple            =		bytes_to_unicode()
			lowercase__				:			Optional[int]            =		{v: k for k, v in self.byte_encoder.items()}
			with open(UpperCamelCase__,				encoding='utf-8' ) as merges_handle:
					lowercase__				:			Tuple            =		merges_handle.read().split('\n' )[1:-1]
			lowercase__				:			Union[str, Any]            =		[tuple(merge.split() ) for merge in bpe_merges]
			lowercase__				:			Optional[int]            =		dict(zip(UpperCamelCase__,				range(len(UpperCamelCase__ ) ) ) )
			lowercase__				:			List[Any]            =		{}
			lowercase__				:			Union[str, Any]            =		add_prefix_space

			# Should have added re.IGNORECASE so BPE merges can happen for capitalized versions of contractions
			lowercase__				:			Tuple            =		re.compile(r'\'s|\'t|\'re|\'ve|\'m|\'ll|\'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+' )

	@property
	def       snake_case__(	self:	Union[str, Any] ):
			return len(self.encoder )

	def       snake_case__(	self:	Tuple ):
			return dict(self.encoder,				**self.added_tokens_encoder )

	def       snake_case__(	self:	str,				lowerCamelCase_:	str ):
			if token in self.cache:
					return self.cache[token]
			lowercase__				:			str            =		tuple(UpperCamelCase__ )
			lowercase__				:			Optional[Any]            =		get_pairs(UpperCamelCase__ )

			if not pairs:
					return token

			while True:
					lowercase__				:			str            =		min(UpperCamelCase__,				key=lambda lowerCamelCase_ : self.bpe_ranks.get(UpperCamelCase__,				float('inf' ) ) )
					if bigram not in self.bpe_ranks:
							break
					lowercase__      ,							lowercase__				:			List[str]            =		bigram
					lowercase__				:			int            =		[]
					lowercase__				:			List[str]            =		0
					while i < len(UpperCamelCase__ ):
							try:
									lowercase__				:			Optional[Any]            =		word.index(UpperCamelCase__,				UpperCamelCase__ )
							except ValueError:
									new_word.extend(word[i:] )
									break
							else:
									new_word.extend(word[i:j] )
									lowercase__				:			str            =		j

							if word[i] == first and i < len(UpperCamelCase__ ) - 1 and word[i + 1] == second:
									new_word.append(first + second )
									i += 2
							else:
									new_word.append(word[i] )
									i += 1
					lowercase__				:			Tuple            =		tuple(UpperCamelCase__ )
					lowercase__				:			Tuple            =		new_word
					if len(UpperCamelCase__ ) == 1:
							break
					else:
							lowercase__				:			Optional[Any]            =		get_pairs(UpperCamelCase__ )
			lowercase__				:			List[str]            =		' '.join(UpperCamelCase__ )
			lowercase__				:			Any            =		word
			return word

	def       snake_case__(	self:	int,				lowerCamelCase_:	int,				lowerCamelCase_:	Any=None ):
			if self.add_bos_token:
					lowercase__				:			Dict            =		[self.bos_token_id]
			else:
					lowercase__				:			Optional[Any]            =		[]

			lowercase__				:			Optional[int]            =		bos_token_ids + token_ids_a

			if token_ids_a is None:
					return output

			return output + bos_token_ids + token_ids_a

	def       snake_case__(	self:	Optional[int],				lowerCamelCase_:	List[str] ):
			lowercase__				:			List[Any]            =		[]
			for token in re.findall(self.pat,				UpperCamelCase__ ):
					lowercase__				:			Tuple            =		''.join(
					    self.byte_encoder[b] for b in token.encode('utf-8' ) )  # Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case)
					bpe_tokens.extend(bpe_token for bpe_token in self.bpe(UpperCamelCase__ ).split(' ' ) )
			return bpe_tokens

	def       snake_case__(	self:	Dict,				lowerCamelCase_:	List[Any] ):
			return self.encoder.get(UpperCamelCase__,				self.encoder.get(self.unk_token ) )

	def       snake_case__(	self:	List[Any],				lowerCamelCase_:	Dict ):
			return self.decoder.get(UpperCamelCase__ )

	def       snake_case__(	self:	Union[str, Any],				lowerCamelCase_:	Optional[int] ):
			lowercase__				:			Dict            =		''.join(UpperCamelCase__ )
			lowercase__				:			Union[str, Any]            =		bytearray([self.byte_decoder[c] for c in text] ).decode('utf-8',				errors=self.errors )
			return text

	def       snake_case__(	self:	Tuple,				lowerCamelCase_:	str,				lowerCamelCase_:	Optional[str] = None ):
			if not os.path.isdir(UpperCamelCase__ ):
					logger.error(F"""Vocabulary path ({save_directory}) should be a directory""" )
					return
			lowercase__				:			Optional[Any]            =		os.path.join(
			    UpperCamelCase__,				(filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file'] )
			lowercase__				:			int            =		os.path.join(
			    UpperCamelCase__,				(filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['merges_file'] )

			with open(UpperCamelCase__,				'w',				encoding='utf-8' ) as f:
					f.write(json.dumps(self.encoder,				indent=2,				sort_keys=UpperCamelCase__,				ensure_ascii=UpperCamelCase__ ) + '\n' )

			lowercase__				:			List[str]            =		0
			with open(UpperCamelCase__,				'w',				encoding='utf-8' ) as writer:
					writer.write('#version: 0.2\n' )
					for bpe_tokens, token_index in sorted(self.bpe_ranks.items(),				key=lambda lowerCamelCase_ : kv[1] ):
							if index != token_index:
									logger.warning(
									    F"""Saving vocabulary to {merge_file}: BPE merge indices are not consecutive."""
									    ' Please check that the tokenizer is not corrupted!' )
									lowercase__				:			List[str]            =		token_index
							writer.write(' '.join(UpperCamelCase__ ) + '\n' )
							index += 1

			return vocab_file, merge_file

	def       snake_case__(	self:	Dict,				lowerCamelCase_:	Dict,				lowerCamelCase_:	Optional[int]=False,				**lowerCamelCase_:	List[Any] ):
			lowercase__				:			Optional[Any]            =		kwargs.pop('add_prefix_space',				self.add_prefix_space )
			if is_split_into_words or add_prefix_space:
					lowercase__				:			Optional[int]            =		' ' + text
			return (text, kwargs)

	def       snake_case__(	self:	List[str],				lowerCamelCase_:	Union[int, List[int], "np.ndarray", "torch.Tensor", "tf.Tensor"],				lowerCamelCase_:	bool = False,				lowerCamelCase_:	bool = None,				lowerCamelCase_:	Optional[List[str]] = None,				**lowerCamelCase_:	int,				):
			lowercase__				:			Any            =		super()._decode(
			    token_ids=UpperCamelCase__,				skip_special_tokens=UpperCamelCase__,				clean_up_tokenization_spaces=UpperCamelCase__,				**UpperCamelCase__,				)

			if truncate_before_pattern is not None and len(UpperCamelCase__ ) > 0:
					lowercase__				:			Tuple            =		self.truncate(UpperCamelCase__,				UpperCamelCase__ )

			return decoded_text





	def       snake_case__(	self:	Dict,				lowerCamelCase_:	Dict,				lowerCamelCase_:	List[Any] ):
			def find_re(lowerCamelCase_:	Optional[Any],				lowerCamelCase_:	str,				lowerCamelCase_:	List[Any] ):
					lowercase__				:			Optional[Any]            =		pattern.search(UpperCamelCase__,				UpperCamelCase__ )
					return m.start() if m else -1

			lowercase__				:			int            =		[re.compile(UpperCamelCase__,				re.MULTILINE ) for pattern in truncate_before_pattern]

			lowercase__				:			Optional[int]            =		list(re.finditer('^print',				UpperCamelCase__,				re.MULTILINE ) )

			if len(UpperCamelCase__ ) > 1:
					lowercase__				:			Union[str, Any]            =		completion[: prints[1].start()]

			lowercase__				:			Optional[Any]            =		list(re.finditer('^def',				UpperCamelCase__,				re.MULTILINE ) )

			if len(UpperCamelCase__ ) > 1:
					lowercase__				:			int            =		completion[: defs[1].start()]

			lowercase__				:			Optional[int]            =		0

			lowercase__				:			int            =		[
			    pos for pos in [find_re(UpperCamelCase__,				UpperCamelCase__,				UpperCamelCase__ ) for terminal in terminals] if pos != -1
			]

			if len(UpperCamelCase__ ) > 0:
					return completion[: min(UpperCamelCase__ )]
			else:
					return completion






def 			SCREAMING_SNAKE_CASE__     (					_lowercase    :   int )      ->       bool:




		'''simple docstring'''
		lowercase__				:			Optional[int]            =		9

		while num > 0:
				if num % 10 != digit:
						return False
				num //= 100
				digit -= 1

		return True


def 			SCREAMING_SNAKE_CASE__     (					)      ->       int:




		'''simple docstring'''
		lowercase__				:			List[str]            =		138_902_663

		while not is_square_form(num * num ):
				if num % 10 == 3:
						num -= 6  # (3 - 6) % 10 = 7
				else:
						num -= 4  # (7 - 4) % 10 = 3

		return num * 10


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


