






'''simple docstring'''





import json
import os
import re
import warnings
from pathlib import Path
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple, Union

import sentencepiece

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


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

_UpperCamelCase		:		Optional[Any]								=			{
    'source_spm': 'source.spm',
    'target_spm': 'target.spm',
    'vocab': 'vocab.json',
    'target_vocab_file': 'target_vocab.json',
    'tokenizer_config_file': 'tokenizer_config.json',
}

_UpperCamelCase		:		Optional[Any]								=			{
    'source_spm': {
        'Helsinki-NLP/opus-mt-en-de': 'https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/source.spm'
    },
    'target_spm': {
        'Helsinki-NLP/opus-mt-en-de': 'https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/target.spm'
    },
    'vocab': {
        'Helsinki-NLP/opus-mt-en-de': 'https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/vocab.json'
    },
    'tokenizer_config_file': {
        'Helsinki-NLP/opus-mt-en-de': (
            'https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/tokenizer_config.json'
        )
    },
}

_UpperCamelCase		:		Any								=			{'Helsinki-NLP/opus-mt-en-de': 512}
_UpperCamelCase		:		int								=			{}


class 				snake_case__     (			_UpperCAmelCase):
					a_       =			VOCAB_FILES_NAMES
					a_       =			PRETRAINED_VOCAB_FILES_MAP
					a_       =			PRETRAINED_INIT_CONFIGURATION
					a_       =			PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
					a_       =			["input_ids", "attention_mask"]
					a_       =			re.compile(">>.+<<")  # type: re.Pattern




					def __init__(       self       :						Tuple							,				_A       :						str							,				_A       :						Tuple							,				_A       :						List[Any]							,				_A       :						Optional[Any]=None							,				_A       :						Optional[int]=None							,				_A       :						Dict=None							,				_A       :						Dict="<unk>"							,				_A       :						Dict="</s>"							,				_A       :						int="<pad>"							,				_A       :						Union[str, Any]=5_12							,				_A       :						Union[str, Any] = None							,				_A       :						Union[str, Any]=False							,				**_A       :						str							,				)  ->    Tuple:
								UpperCAmelCase_     :   Union[str, Any]       =   {} if sp_model_kwargs is None else sp_model_kwargs

								super().__init__(
								    # bos_token=bos_token,  unused. Start decoding with config.decoder_start_token_id
								    source_lang=lowercase__							,				target_lang=lowercase__							,				unk_token=lowercase__							,				eos_token=lowercase__							,				pad_token=lowercase__							,				model_max_length=lowercase__							,				sp_model_kwargs=self.sp_model_kwargs							,				target_vocab_file=lowercase__							,				separate_vocabs=lowercase__							,				**lowercase__							,				)
								assert Path(lowercase__     ).exists(), F"cannot find spm source {source_spm}"

								UpperCAmelCase_     :   Optional[Any]       =   separate_vocabs
								UpperCAmelCase_     :   int       =   load_json(lowercase__     )
								if self.unk_token not in self.encoder:
											raise KeyError('''<unk> token must be in vocab'''     )
								assert self.pad_token in self.encoder

								if separate_vocabs:
											UpperCAmelCase_     :   str       =   load_json(lowercase__     )
											UpperCAmelCase_     :   Optional[int]       =   {v: k for k, v in self.target_encoder.items()}
											UpperCAmelCase_     :   Any       =   []
								else:
											UpperCAmelCase_     :   List[str]       =   {v: k for k, v in self.encoder.items()}
											UpperCAmelCase_     :   list       =   [k for k in self.encoder if k.startswith('''>>'''     ) and k.endswith('''<<'''     )]

								UpperCAmelCase_     :   Union[str, Any]       =   source_lang
								UpperCAmelCase_     :   Tuple       =   target_lang
								UpperCAmelCase_     :   Optional[Any]       =   [source_spm, target_spm]

								# load SentencePiece model for pre-processing
								UpperCAmelCase_     :   Any       =   load_spm(lowercase__							,				self.sp_model_kwargs     )
								UpperCAmelCase_     :   Any       =   load_spm(lowercase__							,				self.sp_model_kwargs     )
								UpperCAmelCase_     :   str       =   self.spm_source
								UpperCAmelCase_     :   str       =   self.encoder

								# Multilingual target side: default to using first supported language code.

								self._setup_normalizer()




					def 						A     (       self       :						Dict     )  ->    int:






								try:
											from sacremoses import MosesPunctNormalizer

											UpperCAmelCase_     :   Tuple       =   MosesPunctNormalizer(self.source_lang     ).normalize
								except (ImportError, FileNotFoundError):
											warnings.warn('''Recommended: pip install sacremoses.'''     )
											UpperCAmelCase_     :   Optional[int]       =   lambda _A     : x




					def 						A     (       self       :						List[str]							,				_A       :						List[str]     )  ->    Dict:
								return self.punc_normalizer(lowercase__     ) if x else ""




					def 						A     (       self       :						int							,				_A       :						Union[str, Any]     )  ->    int:
								return self.current_encoder.get(lowercase__							,				self.current_encoder[self.unk_token]     )




					def 						A     (       self       :						int							,				_A       :						Dict     )  ->    Union[str, Any]:
								UpperCAmelCase_     :   Union[str, Any]       =   self.language_code_re.match(lowercase__     )
								UpperCAmelCase_     :   list       =   [match.group(0     )] if match else []
								return code, self.language_code_re.sub(''''''							,				lowercase__     )




					def 						A     (       self       :						List[Any]							,				_A       :						Tuple     )  ->    List[str]:
								UpperCAmelCase_     :   Tuple       =   self.remove_language_code(lowercase__     )
								UpperCAmelCase_     :   List[Any]       =   self.current_spm.encode(lowercase__							,				out_type=lowercase__     )
								return code + pieces




					def 						A     (       self       :						int							,				_A       :						str     )  ->    Optional[int]:
								return self.decoder.get(lowercase__							,				self.unk_token     )




					def 						A     (       self       :						List[Any]							,				_A       :						Union[str, Any]							,				**_A       :						Any     )  ->    str:
								return super().batch_decode(lowercase__							,				**lowercase__     )




					def 						A     (       self       :						Dict							,				_A       :						Optional[int]							,				**_A       :						str     )  ->    Dict:
								return super().decode(lowercase__							,				**lowercase__     )




					def 						A     (       self       :						Optional[int]							,				_A       :						str     )  ->    Any:
								UpperCAmelCase_     :   Tuple       =   self.spm_source if self._decode_use_source_tokenizer else self.spm_target
								UpperCAmelCase_     :   Tuple       =   []
								UpperCAmelCase_     :   Any       =   ""
								for token in tokens:
											# make sure that special tokens are not decoded using sentencepiece model
											if token in self.all_special_tokens:
														out_string += sp_model.decode_pieces(lowercase__     ) + token + " "
														UpperCAmelCase_     :   Optional[int]       =   []
											else:
														current_sub_tokens.append(lowercase__     )
								out_string += sp_model.decode_pieces(lowercase__     )
								return out_string.strip()




					def 						A     (       self       :						Optional[int]							,				_A       :						str							,				_A       :						int=None     )  ->    Any:






								if token_ids_a is None:
											return token_ids_a + [self.eos_token_id]
								# We don't expect to process pairs, but leave the pair logic for API consistency
								return token_ids_a + token_ids_a + [self.eos_token_id]




					def 						A     (       self       :						List[Any]     )  ->    Dict:
								UpperCAmelCase_     :   Optional[int]       =   self.spm_source
								UpperCAmelCase_     :   Optional[int]       =   self.encoder




					def 						A     (       self       :						Any     )  ->    Tuple:
								UpperCAmelCase_     :   Optional[int]       =   self.spm_target
								if self.separate_vocabs:
											UpperCAmelCase_     :   Dict       =   self.target_encoder




					@property
					def 						A     (       self       :						List[Any]     )  ->    Tuple:
								return len(self.encoder     )




					def 						A     (       self       :						int							,				_A       :						str							,				_A       :						List[Any] = None     )  ->    int:






								if not os.path.isdir(lowercase__     ):
											logger.error(F"Vocabulary path ({save_directory}) should be a directory"     )
											return
								UpperCAmelCase_     :   str       =   []

								if self.separate_vocabs:
											UpperCAmelCase_     :   Dict       =   os.path.join(
											    lowercase__							,				(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab''']							,				)
											UpperCAmelCase_     :   List[Any]       =   os.path.join(
											    lowercase__							,				(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''target_vocab_file''']							,				)
											save_json(self.encoder							,				lowercase__     )
											save_json(self.target_encoder							,				lowercase__     )
											saved_files.append(lowercase__     )
											saved_files.append(lowercase__     )
								else:
											UpperCAmelCase_     :   List[Any]       =   os.path.join(
											    lowercase__							,				(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab''']     )
											save_json(self.encoder							,				lowercase__     )
											saved_files.append(lowercase__     )

								for spm_save_filename, spm_orig_path, spm_model in zip(
								    [VOCAB_FILES_NAMES['''source_spm'''], VOCAB_FILES_NAMES['''target_spm''']]							,				self.spm_files							,				[self.spm_source, self.spm_target]							,				):
											UpperCAmelCase_     :   Any       =   os.path.join(
											    lowercase__							,				(filename_prefix + '''-''' if filename_prefix else '''''') + spm_save_filename     )
											if os.path.abspath(lowercase__     ) != os.path.abspath(lowercase__     ) and os.path.isfile(lowercase__     ):
														copyfile(lowercase__							,				lowercase__     )
														saved_files.append(lowercase__     )
											elif not os.path.isfile(lowercase__     ):
														with open(lowercase__							,				'''wb'''     ) as fi:
																	UpperCAmelCase_     :   Dict       =   spm_model.serialized_model_proto()
																	fi.write(lowercase__     )
														saved_files.append(lowercase__     )

								return tuple(lowercase__     )




					def 						A     (       self       :						Any     )  ->    Optional[Any]:
								return self.get_src_vocab()




					def 						A     (       self       :						int     )  ->    List[Any]:
								return dict(self.encoder							,				**self.added_tokens_encoder     )




					def 						A     (       self       :						Optional[int]     )  ->    Optional[int]:
								return dict(self.target_encoder							,				**self.added_tokens_decoder     )




					def __getstate__(       self       :						int     )  ->    int:
								UpperCAmelCase_     :   Any       =   self.__dict__.copy()
								state.update(
								    {k: None for k in ['''spm_source''', '''spm_target''', '''current_spm''', '''punc_normalizer''', '''target_vocab_file''']}     )
								return state




					def __setstate__(       self       :						List[Any]							,				_A       :						Optional[int]     )  ->    Optional[int]:
								UpperCAmelCase_     :   Tuple       =   d

								# for backward compatibility
								if not hasattr(self							,				'''sp_model_kwargs'''     ):
											UpperCAmelCase_     :   Union[str, Any]       =   {}

								UpperCAmelCase_     :   Optional[Any]       =   (load_spm(lowercase__							,				self.sp_model_kwargs     ) for f in self.spm_files)
								UpperCAmelCase_     :   Union[str, Any]       =   self.spm_source
								self._setup_normalizer()




					def 						A     (       self       :						Tuple							,				*_A       :						Optional[Any]							,				**_A       :						Any     )  ->    Union[str, Any]:
								return 1




					def 						A     (       self       :						Optional[Any]							,				_A       :						Tuple     )  ->    List[Any]:
								UpperCAmelCase_     :   str       =   set(self.all_special_ids     )  # call it once instead of inside list comp
								all_special_ids.remove(self.unk_token_id     )  # <unk> is only sometimes special
								return [1 if x in all_special_ids else 0 for x in seq]





					def 						A     (       self       :						Optional[int]							,				_A       :						Union[str, Any]							,				_A       :						Union[str, Any] = None							,				_A       :						str = False     )  ->    Optional[Any]:






								if already_has_special_tokens:
											return self._special_token_mask(lowercase__     )
								elif token_ids_a is None:
											return self._special_token_mask(lowercase__     ) + [1]
								else:
											return self._special_token_mask(token_ids_a + token_ids_a     ) + [1]






def __UpperCAmelCase (			A			:	str	,   A			:	Dict[str, Any]						)  -> sentencepiece.SentencePieceProcessor:
			UpperCAmelCase_     :   Optional[Any]       =   sentencepiece.SentencePieceProcessor(**SCREAMING_SNAKE_CASE_						)
			spm.Load(SCREAMING_SNAKE_CASE_						)
			return spm
def __UpperCAmelCase (			A			:	Any	,   A			:	str						)  -> None:

			with open(SCREAMING_SNAKE_CASE_	,   '''w'''						) as f:
						json.dump(SCREAMING_SNAKE_CASE_	,   SCREAMING_SNAKE_CASE_	,   indent=2						)







def __UpperCAmelCase (			A			:	str						)  -> Union[Dict, List]:

			with open(SCREAMING_SNAKE_CASE_	,   '''r'''						) as f:
						return json.load(SCREAMING_SNAKE_CASE_						)










'''simple docstring'''





def __UpperCAmelCase (			)  -> Optional[Any]:
			UpperCAmelCase_     :   Union[str, Any]       =   1

			while True:
						if (
						    sorted(str(A						)						)
						    == sorted(str(2 * i						)						)
						    == sorted(str(3 * i						)						)
						    == sorted(str(4 * i						)						)
						    == sorted(str(5 * i						)						)
						    == sorted(str(6 * i						)						)
						):
									return i

						i += 1


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


