

"""simple docstring"""





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						:   Optional[int]							   =	logging.get_logger(__name__)

__UpperCamelCase						:   int							   =	{
    '''vocab_file''': '''vocab.json''',
    '''merges_file''': '''merges.txt''',
}

__UpperCamelCase						:   Optional[Any]							   =	{
    '''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						:   Optional[Any]							   =	{
    '''Salesforce/codegen-350M-mono''': 2_0_4_8,
}

@lru_cache()
def 						__SCREAMING_SNAKE_CASE						(   ):
	lowerCAmelCase__			:		List[Any]						       =			(
	    list(range(ord('''!'''				)		,  ord('''~'''				) + 1				)				) + list(range(ord('''¡'''				)		,  ord('''¬'''				) + 1				)				) + list(range(ord('''®'''				)		,  ord('''ÿ'''				) + 1				)				)
	)
	lowerCAmelCase__			:		str						       =			bs[:]
	lowerCAmelCase__			:		Any						       =			0
	for b in range(2**8				):
		if b not in bs:
			bs.append(A_				)
			cs.append(2**8 + n				)
			n += 1
	lowerCAmelCase__			:		Union[str, Any]						       =			[chr(A_				) for n in cs]
	return dict(zip(A_		,  A_				)				)

def 						__SCREAMING_SNAKE_CASE						(   A_				):
	lowerCAmelCase__			:		int						       =			set()
	lowerCAmelCase__			:		Union[str, Any]						       =			word[0]
	for char in word[1:]:
		pairs.add((prev_char, char)				)
		lowerCAmelCase__			:		List[str]						       =			char
	return pairs







class        SCREAMING_SNAKE_CASE      (	a_ ):






					"""simple docstring"""



					lowercase__       				= VOCAB_FILES_NAMES
					lowercase__       				= PRETRAINED_VOCAB_FILES_MAP
					lowercase__       				= PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
					lowercase__       				= ["input_ids", "attention_mask"]







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

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

						# Should have added re.IGNORECASE so BPE merges can happen for capitalized versions of contractions
						lowerCAmelCase__			:		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  __lowerCAmelCase				( self    :       Optional[int]	):
						return len(self.encoder	)







					def  __lowerCAmelCase				( self    :       List[Any]	):
						return dict(self.encoder     ,**self.added_tokens_encoder	)







					def  __lowerCAmelCase				( self    :       Dict     ,lowercase_    :       Optional[int]	):
						if token in self.cache:
							return self.cache[token]
						lowerCAmelCase__			:		Any						       =			tuple(lowercase_	)
						lowerCAmelCase__			:		Any						       =			get_pairs(lowercase_	)

						if not pairs:
							return token

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

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







					def  __lowerCAmelCase				( self    :       List[str]     ,lowercase_    :       Dict     ,lowercase_    :       List[Any]=None	):
						if self.add_bos_token:
							lowerCAmelCase__			:		int						       =			[self.bos_token_id]
						else:
							lowerCAmelCase__			:		List[str]						       =			[]

						lowerCAmelCase__			:		List[str]						       =			bos_token_ids + token_ids_a

						if token_ids_a is None:
							return output

						return output + bos_token_ids + token_ids_a







					def  __lowerCAmelCase				( self    :       List[str]     ,lowercase_    :       Union[str, Any]	):
						lowerCAmelCase__			:		Union[str, Any]						       =			[]
						for token in re.findall(self.pat     ,lowercase_	):
							lowerCAmelCase__			:		int						       =			''''''.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(lowercase_	).split(''' '''	)	)
						return bpe_tokens







					def  __lowerCAmelCase				( self    :       Union[str, Any]     ,lowercase_    :       Optional[Any]	):
						return self.encoder.get(lowercase_     ,self.encoder.get(self.unk_token	)	)







					def  __lowerCAmelCase				( self    :       Dict     ,lowercase_    :       Tuple	):
						return self.decoder.get(lowercase_	)







					def  __lowerCAmelCase				( self    :       Any     ,lowercase_    :       int	):
						lowerCAmelCase__			:		Union[str, Any]						       =			''''''.join(lowercase_	)
						lowerCAmelCase__			:		List[str]						       =			bytearray([self.byte_decoder[c] for c in text]	).decode('''utf-8'''     ,errors=self.errors	)
						return text







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

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

						lowerCAmelCase__			:		str						       =			0
						with open(lowercase_     ,'''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 lowercase_	: 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!'''	)
									lowerCAmelCase__			:		List[str]						       =			token_index
								writer.write(''' '''.join(lowercase_	) + '''\n'''	)
								index += 1

						return vocab_file, merge_file







					def  __lowerCAmelCase				( self    :       List[str]     ,lowercase_    :       List[str]     ,lowercase_    :       str=False     ,**lowercase_    :       str	):
						lowerCAmelCase__			:		Union[str, Any]						       =			kwargs.pop('''add_prefix_space'''     ,self.add_prefix_space	)
						if is_split_into_words or add_prefix_space:
							lowerCAmelCase__			:		List[Any]						       =			''' ''' + text
						return (text, kwargs)







					def  __lowerCAmelCase				( self    :       str     ,lowercase_    :       Union[int, List[int], "np.ndarray", "torch.Tensor", "tf.Tensor"]     ,lowercase_    :       bool = False     ,lowercase_    :       bool = None     ,lowercase_    :       Optional[List[str]] = None     ,**lowercase_    :       List[Any]     ,):
						lowerCAmelCase__			:		Tuple						       =			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:
							lowerCAmelCase__			:		str						       =			self.truncate(lowercase_     ,lowercase_	)

						return decoded_text







					def  __lowerCAmelCase				( self    :       Optional[int]     ,lowercase_    :       int     ,lowercase_    :       List[str]	):
						def find_re(lowercase_    :       Dict     ,lowercase_    :       Any     ,lowercase_    :       int	):
							lowerCAmelCase__			:		List[str]						       =			pattern.search(lowercase_     ,lowercase_	)
							return m.start() if m else -1

						lowerCAmelCase__			:		Optional[int]						       =			[re.compile(lowercase_     ,re.MULTILINE	) for pattern in truncate_before_pattern]

						lowerCAmelCase__			:		Dict						       =			list(re.finditer('''^print'''     ,lowercase_     ,re.MULTILINE	)	)

						if len(lowercase_	) > 1:
							lowerCAmelCase__			:		Tuple						       =			completion[: prints[1].start()]

						lowerCAmelCase__			:		str						       =			list(re.finditer('''^def'''     ,lowercase_     ,re.MULTILINE	)	)

						if len(lowercase_	) > 1:
							lowerCAmelCase__			:		Dict						       =			completion[: defs[1].start()]

						lowerCAmelCase__			:		Union[str, Any]						       =			0

						lowerCAmelCase__			:		Tuple						       =			[
						    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







"""simple docstring"""





from itertools import permutations

def 						__SCREAMING_SNAKE_CASE						(   A_ = 5				):
	if gon_side < 3 or gon_side > 5:
		raise ValueError('''gon_side must be in the range [3, 5]'''				)

	# Since it's 16, we know 10 is on the outer ring
	# Put the big numbers at the end so that they are never the first number
	lowerCAmelCase__			:		str						       =			list(range(gon_side + 1		,  0		,  -1				)				)
	lowerCAmelCase__			:		int						       =			list(range(gon_side + 2		,  gon_side * 2 + 1				)				)

	for perm in permutations(small_numbers + big_numbers				):
		lowerCAmelCase__			:		Optional[Any]						       =			generate_gon_ring(A_		,  list(A_				)				)
		if is_magic_gon(A_				):
			return int(''''''.join(str(A_				) for n in numbers				)				)

	lowerCAmelCase__			:		Tuple						       =			f'Magic {gon_side}-gon ring is impossible'
	raise ValueError(A_				)

def 						__SCREAMING_SNAKE_CASE						(   A_		,  A_				):
	lowerCAmelCase__			:		Dict						       =			[0] * (gon_side * 3)
	lowerCAmelCase__			:		Optional[int]						       =			perm[0:3]
	perm.append(perm[1]				)

	lowerCAmelCase__			:		int						       =			1 if gon_side < 5 else 2

	for i in range(1		,  len(A_				) // 3 + magic_number				):
		lowerCAmelCase__			:		List[str]						       =			perm[2 * i + 1]
		lowerCAmelCase__			:		Optional[int]						       =			result[3 * i - 1]
		lowerCAmelCase__			:		List[Any]						       =			perm[2 * i + 2]

	return result

def 						__SCREAMING_SNAKE_CASE						(   A_				):
	if len(A_				) % 3 != 0:
		raise ValueError('''a gon ring should have a length that is a multiple of 3'''				)

	if min(numbers[::3]				) != numbers[0]:
		return False

	lowerCAmelCase__			:		int						       =			sum(numbers[:3]				)

	return all(sum(numbers[i : i + 3]				) == total for i in range(3		,  len(A_				)		,  3				)				)


if __name__ == "__main__":
							print(solution())




