




import json
import re
from typing import TYPE_CHECKING, List, Optional, Tuple, Union

import numpy as np

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 tokenizers import pre_tokenizers

from ...tokenization_utils_base import BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_codegen import CodeGenTokenizer


lowercase__				:     List[Any] 		=						logging.get_logger(__name__)

lowercase__				:     str 		=						{"vocab_file": "vocab.json", "merges_file": "merges.txt", "tokenizer_file": "tokenizer.json"}

lowercase__				:     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",
    },
    "tokenizer_file": {
        "Salesforce/codegen-350M-mono": (
            "https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/tokenizer.json"
        ),
    },
}

lowercase__				:     Optional[int] 		=						{
    "Salesforce/codegen-350M-mono": 2048,
}
class 		UpperCAmelCase   (				UpperCAmelCase__			):







						'''simple docstring'''





						lowerCAmelCase_     		=   VOCAB_FILES_NAMES
						lowerCAmelCase_     		=   PRETRAINED_VOCAB_FILES_MAP
						lowerCAmelCase_     		=   PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						lowerCAmelCase_     		=   ['''input_ids''', '''attention_mask''']
						lowerCAmelCase_     		=   CodeGenTokenizer






						def __init__(						self							:     Union[str, Any]       ,	__lowercase							:     Any=None       ,	__lowercase							:     Any=None       ,	__lowercase							:     Union[str, Any]=None       ,	__lowercase							:     Dict="<|endoftext|>"       ,	__lowercase							:     Dict="<|endoftext|>"       ,	__lowercase							:     Any="<|endoftext|>"       ,	__lowercase							:     List[Any]=False       ,	**__lowercase							:     List[Any]       ,	):






							"""simple docstring"""






							super().__init__(
							    __lowercase       ,	__lowercase       ,	tokenizer_file=__lowercase       ,	unk_token=__lowercase       ,	bos_token=__lowercase       ,	eos_token=__lowercase       ,	add_prefix_space=__lowercase       ,	**__lowercase       ,	)

							if kwargs.pop("add_bos_token"       ,	__lowercase						):
								snake_case_		    =     kwargs.pop("name_or_path"       ,	""						)
								raise ValueError(
								    "Currenty GPT2's fast tokenizer does NOT support adding a BOS token."
								    "Instead you should use GPT2's slow tokenizer class `CodeGenTokenizer` as follows: \n"
								    f"`CodeGenTokenizer.from_pretrained('{model_id}')`\nor\n"
								    f"`AutoTokenizer.from_pretrained('{model_id}', use_fast=False)`\n"
								    "This issue will be fixed soon, see: https://github.com/huggingface/tokenizers/pull/1005."
								    " so that the fast tokenizer works correctly."						)

							snake_case_		    =     json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()						)
							if pre_tok_state.get("add_prefix_space"       ,	__lowercase						) != add_prefix_space:
								snake_case_		    =     getattr(__lowercase       ,	pre_tok_state.pop("type"						)						)
								snake_case_		    =     add_prefix_space
								snake_case_		    =     pre_tok_class(**__lowercase						)

							snake_case_		    =     add_prefix_space






						def        snake_case__						(						self							:     Optional[Any]       ,	*__lowercase							:     Optional[int]       ,	**__lowercase							:     List[Any]						):






							"""simple docstring"""






							snake_case_		    =     kwargs.get("is_split_into_words"       ,	__lowercase						)
							assert self.add_prefix_space or not is_split_into_words, (
							    f"You need to instantiate {self.__class__.__name__} with add_prefix_space=True "
							    "to use it with pretokenized inputs."
							)

							return super()._batch_encode_plus(*__lowercase       ,	**__lowercase						)






						def        snake_case__						(						self							:     Tuple       ,	*__lowercase							:     Optional[int]       ,	**__lowercase							:     Optional[int]						):






							"""simple docstring"""






							snake_case_		    =     kwargs.get("is_split_into_words"       ,	__lowercase						)

							assert self.add_prefix_space or not is_split_into_words, (
							    f"You need to instantiate {self.__class__.__name__} with add_prefix_space=True "
							    "to use it with pretokenized inputs."
							)

							return super()._encode_plus(*__lowercase       ,	**__lowercase						)






						def        snake_case__						(						self							:     Optional[int]       ,	__lowercase							:     str       ,	__lowercase							:     Optional[str] = None						):






							"""simple docstring"""






							snake_case_		    =     self._tokenizer.model.save(__lowercase       ,	name=__lowercase						)
							return tuple(__lowercase						)






						def        snake_case__						(						self							:     List[str]       ,	__lowercase							:     Union[int, List[int], "np.ndarray", "torch.Tensor", "tf.Tensor"]       ,	__lowercase							:     bool = False       ,	__lowercase							:     bool = None       ,	__lowercase							:     Optional[List[str]] = None       ,	**__lowercase							:     Any       ,	):






							"""simple docstring"""






							snake_case_		    =     super().decode(
							    token_ids=__lowercase       ,	skip_special_tokens=__lowercase       ,	clean_up_tokenization_spaces=__lowercase       ,	**__lowercase       ,	)

							if truncate_before_pattern is not None and len(__lowercase						) > 0:
								snake_case_		    =     self.truncate(__lowercase       ,	__lowercase						)

							return decoded_text






						def        snake_case__						(						self							:     Optional[Any]       ,	__lowercase							:     Union[str, Any]       ,	__lowercase							:     str						):






							"""simple docstring"""






							def find_re(__lowercase							:     Tuple       ,	__lowercase							:     int       ,	__lowercase							:     int						):
								snake_case_		    =     pattern.search(__lowercase       ,	__lowercase						)
								return m.start() if m else -1

							snake_case_		    =     [re.compile(__lowercase       ,	re.MULTILINE						) for pattern in truncate_before_pattern]

							snake_case_		    =     list(re.finditer("^print"       ,	__lowercase       ,	re.MULTILINE						)						)

							if len(__lowercase						) > 1:
								snake_case_		    =     completion[: prints[1].start()]

							snake_case_		    =     list(re.finditer("^def"       ,	__lowercase       ,	re.MULTILINE						)						)

							if len(__lowercase						) > 1:
								snake_case_		    =     completion[: defs[1].start()]

							snake_case_		    =     0

							snake_case_		    =     [
							    pos for pos in [find_re(__lowercase       ,	__lowercase       ,	__lowercase						) for terminal in terminals] if pos != -1
							]

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






from __future__ import annotations


def 						lowerCamelCase__    (		_A							):







	'''simple docstring'''





	snake_case_		    =     str(_A							)
	return len(_A							) == 9 and set(_A							) == set("123456789"							)


def 						lowerCamelCase__    (		):







	'''simple docstring'''





	for base_num in range(9999     ,	4999     ,	-1							):
		snake_case_		    =     100002 * base_num
		if is_9_pandigital(_A							):
			return candidate

	for base_num in range(333     ,	99     ,	-1							):
		snake_case_		    =     1002003 * base_num
		if is_9_pandigital(_A							):
			return candidate

	return None


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