

"""simple docstring"""






from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


snake_case_        =       logging.get_logger(__name__)

snake_case_        =       {
    """Helsinki-NLP/opus-mt-en-de""": """https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/config.json""",
    # See all Marian models at https://huggingface.co/models?filter=marian
}







class       snake_case__  ( lowerCAmelCase_     ):
			SCREAMING_SNAKE_CASE__     				=						'''marian'''
			SCREAMING_SNAKE_CASE__     				=						['''past_key_values''']
			SCREAMING_SNAKE_CASE__     				=						{'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}







			def __init__(			self			: Optional[Any]			,  lowercase			: Any=5_81_01			,  lowercase			: Any=None			,  lowercase			: str=10_24			,  lowercase			: Tuple=12			,  lowercase			: Dict=40_96			,  lowercase			: str=16			,  lowercase			: List[Any]=12			,  lowercase			: List[str]=40_96			,  lowercase			: int=16			,  lowercase			: Any=0.0			,  lowercase			: Union[str, Any]=0.0			,  lowercase			: int=True			,  lowercase			: Optional[Any]=True			,  lowercase			: List[str]="gelu"			,  lowercase			: List[Any]=10_24			,  lowercase			: str=0.1			,  lowercase			: Dict=0.0			,  lowercase			: List[str]=0.0			,  lowercase			: Tuple=0.0_2			,  lowercase			: Optional[Any]=5_81_00			,  lowercase			: Dict=False			,  lowercase			: Optional[Any]=5_81_00			,  lowercase			: Union[str, Any]=0			,  lowercase			: List[Any]=0			,  lowercase			: Optional[Any]=True			,  **lowercase			: Dict			,  ):





								'''simple docstring'''



								UpperCAmelCase			:   List[str]      =				vocab_size
								UpperCAmelCase			:   List[Any]      =				decoder_vocab_size or vocab_size
								UpperCAmelCase			:   str      =				max_position_embeddings
								UpperCAmelCase			:   List[Any]      =				d_model
								UpperCAmelCase			:   Tuple      =				encoder_ffn_dim
								UpperCAmelCase			:   Tuple      =				encoder_layers
								UpperCAmelCase			:   Union[str, Any]      =				encoder_attention_heads
								UpperCAmelCase			:   str      =				decoder_ffn_dim
								UpperCAmelCase			:   List[Any]      =				decoder_layers
								UpperCAmelCase			:   Dict      =				decoder_attention_heads
								UpperCAmelCase			:   int      =				dropout
								UpperCAmelCase			:   Any      =				attention_dropout
								UpperCAmelCase			:   str      =				activation_dropout
								UpperCAmelCase			:   Optional[int]      =				activation_function
								UpperCAmelCase			:   List[str]      =				init_std
								UpperCAmelCase			:   int      =				encoder_layerdrop
								UpperCAmelCase			:   Any      =				decoder_layerdrop
								UpperCAmelCase			:   Any      =				use_cache
								UpperCAmelCase			:   List[str]      =				encoder_layers
								UpperCAmelCase			:   List[str]      =				scale_embedding  # scale factor will be sqrt(d_model) if True
								UpperCAmelCase			:   Union[str, Any]      =				share_encoder_decoder_embeddings
								super().__init__(
								    pad_token_id=lowercase			,  eos_token_id=lowercase			,  is_encoder_decoder=lowercase			,  decoder_start_token_id=lowercase			,  forced_eos_token_id=lowercase			,  **lowercase			,  )







class       snake_case__  ( lowerCAmelCase_     ):







			@property
			# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.inputs
			def 			__lowerCAmelCase				(			self			: Any  ):





								'''simple docstring'''



								if self.task in ["default", "seq2seq-lm"]:
													UpperCAmelCase			:   Union[str, Any]      =				OrderedDict(
													    [
													        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
													        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
													    ]  )

													if self.use_past:
																		UpperCAmelCase			:   Union[str, Any]      =				{0: "batch"}
																		UpperCAmelCase			:   List[Any]      =				{0: "batch", 1: "past_decoder_sequence + sequence"}
													else:
																		UpperCAmelCase			:   List[Any]      =				{0: "batch", 1: "decoder_sequence"}
																		UpperCAmelCase			:   List[Any]      =				{0: "batch", 1: "decoder_sequence"}

													if self.use_past:
																		self.fill_with_past_key_values_(lowercase			,  direction="inputs"  )
								elif self.task == "causal-lm":
													# TODO: figure this case out.
													UpperCAmelCase			:   str      =				OrderedDict(
													    [
													        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
													        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
													    ]  )
													if self.use_past:
																		UpperCAmelCase			:   Dict      =				self.num_layers
																		for i in range(lowercase  ):
																							UpperCAmelCase			:   List[Any]      =				{0: "batch", 2: "past_sequence + sequence"}
																							UpperCAmelCase			:   List[Any]      =				{0: "batch", 2: "past_sequence + sequence"}
								else:
													UpperCAmelCase			:   Tuple      =				OrderedDict(
													    [
													        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
													        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
													        ("decoder_input_ids", {0: "batch", 1: "decoder_sequence"}),
													        ("decoder_attention_mask", {0: "batch", 1: "decoder_sequence"}),
													    ]  )

								return common_inputs







			@property
			# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
			def 			__lowerCAmelCase				(			self			: Any  ):





								'''simple docstring'''



								if self.task in ["default", "seq2seq-lm"]:
													UpperCAmelCase			:   Optional[int]      =				super().outputs
								else:
													UpperCAmelCase			:   str      =				super(lowercase			,  self  ).outputs
													if self.use_past:
																		UpperCAmelCase			:   int      =				self.num_layers
																		for i in range(lowercase  ):
																							UpperCAmelCase			:   List[str]      =				{0: "batch", 2: "past_sequence + sequence"}
																							UpperCAmelCase			:   Dict      =				{0: "batch", 2: "past_sequence + sequence"}
								return common_outputs







			def 			__lowerCAmelCase				(			self			: Any			,  lowercase			: PreTrainedTokenizer			,  lowercase			: int = -1			,  lowercase			: int = -1			,  lowercase			: bool = False			,  lowercase			: Optional[TensorType] = None			,  ):





								'''simple docstring'''



								UpperCAmelCase			:   Optional[Any]      =				self._generate_dummy_inputs_for_encoder_and_decoder(
								    lowercase			,  lowercase			,  lowercase			,  lowercase			,  lowercase  )

								# Generate decoder inputs
								UpperCAmelCase			:   Dict      =				seq_length if not self.use_past else 1
								UpperCAmelCase			:   Any      =				self._generate_dummy_inputs_for_encoder_and_decoder(
								    lowercase			,  lowercase			,  lowercase			,  lowercase			,  lowercase  )
								UpperCAmelCase			:   List[str]      =				{f"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
								UpperCAmelCase			:   Optional[Any]      =				dict(**lowercase			,  **lowercase  )

								if self.use_past:
													if not is_torch_available():
																		raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."  )
													else:
																		import torch
													UpperCAmelCase			:   int      =				common_inputs["input_ids"].shape
													UpperCAmelCase			:   List[str]      =				common_inputs["decoder_input_ids"].shape[1]
													UpperCAmelCase			:   List[Any]      =				self.num_attention_heads
													UpperCAmelCase			:   int      =				(
													    batch,
													    num_encoder_attention_heads,
													    encoder_seq_length,
													    self._config.hidden_size // num_encoder_attention_heads,
													)
													UpperCAmelCase			:   Any      =				decoder_seq_length + 3
													UpperCAmelCase			:   Dict      =				(
													    batch,
													    num_decoder_attention_heads,
													    decoder_past_length,
													    self._config.hidden_size // num_decoder_attention_heads,
													)

													UpperCAmelCase			:   Tuple      =				torch.cat(
													    [common_inputs["decoder_attention_mask"], torch.ones(lowercase			,  lowercase  )]			,  dim=1  )

													UpperCAmelCase			:   str      =				[]
													# If the number of encoder and decoder layers are present in the model configuration, both are considered
													UpperCAmelCase			:   List[Any]      =				self.num_layers
													UpperCAmelCase			:   int      =				min(lowercase			,  lowercase  )
													UpperCAmelCase			:   Union[str, Any]      =				max(lowercase			,  lowercase  ) - min_num_layers
													UpperCAmelCase			:   str      =				"encoder" if num_encoder_layers > num_decoder_layers else "decoder"

													for _ in range(lowercase  ):
																		common_inputs["past_key_values"].append(
																		    (
																		        torch.zeros(lowercase  ),
																		        torch.zeros(lowercase  ),
																		        torch.zeros(lowercase  ),
																		        torch.zeros(lowercase  ),
																		    )  )
													# TODO: test this.
													UpperCAmelCase			:   Optional[int]      =				encoder_shape if remaining_side_name == "encoder" else decoder_shape
													for _ in range(lowercase			,  lowercase  ):
																		common_inputs["past_key_values"].append((torch.zeros(lowercase  ), torch.zeros(lowercase  ))  )
								return common_inputs







			def 			__lowerCAmelCase				(			self			: List[str]			,  lowercase			: PreTrainedTokenizer			,  lowercase			: int = -1			,  lowercase			: int = -1			,  lowercase			: bool = False			,  lowercase			: Optional[TensorType] = None			,  ):





								'''simple docstring'''



								UpperCAmelCase			:   int      =				self._generate_dummy_inputs_for_encoder_and_decoder(
								    lowercase			,  lowercase			,  lowercase			,  lowercase			,  lowercase  )

								if self.use_past:
													if not is_torch_available():
																		raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."  )
													else:
																		import torch
													UpperCAmelCase			:   List[str]      =				common_inputs["input_ids"].shape
													# Not using the same length for past_key_values
													UpperCAmelCase			:   str      =				seqlen + 2
													UpperCAmelCase			:   str      =				self.num_layers
													UpperCAmelCase			:   Optional[Any]      =				self.num_attention_heads
													UpperCAmelCase			:   List[str]      =				(
													    batch,
													    num_encoder_attention_heads,
													    past_key_values_length,
													    self._config.hidden_size // num_encoder_attention_heads,
													)

													UpperCAmelCase			:   List[Any]      =				common_inputs["attention_mask"].dtype
													UpperCAmelCase			:   Optional[int]      =				torch.cat(
													    [common_inputs["attention_mask"], torch.ones(lowercase			,  lowercase			,  dtype=lowercase  )]			,  dim=1  )
													UpperCAmelCase			:   List[str]      =				[
													    (torch.zeros(lowercase  ), torch.zeros(lowercase  )) for _ in range(lowercase  )
													]
								return common_inputs







			def 			__lowerCAmelCase				(			self			: List[Any]			,  lowercase			: PreTrainedTokenizer			,  lowercase			: int = -1			,  lowercase			: int = -1			,  lowercase			: bool = False			,  lowercase			: Optional[TensorType] = None			,  ):





								'''simple docstring'''



								UpperCAmelCase			:   Union[str, Any]      =				compute_effective_axis_dimension(
								    lowercase			,  fixed_dimension=OnnxConfig.default_fixed_batch			,  num_token_to_add=0  )

								# If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
								UpperCAmelCase			:   Tuple      =				tokenizer.num_special_tokens_to_add(lowercase  )
								UpperCAmelCase			:   Dict      =				compute_effective_axis_dimension(
								    lowercase			,  fixed_dimension=OnnxConfig.default_fixed_sequence			,  num_token_to_add=lowercase  )

								# Generate dummy inputs according to compute batch and sequence
								UpperCAmelCase			:   Optional[Any]      =				[" ".join([tokenizer.unk_token]  ) * seq_length] * batch_size
								UpperCAmelCase			:   int      =				dict(tokenizer(lowercase			,  return_tensors=lowercase  )  )
								return common_inputs







			def 			__lowerCAmelCase				(			self			: Any			,  lowercase			: PreTrainedTokenizer			,  lowercase			: int = -1			,  lowercase			: int = -1			,  lowercase			: bool = False			,  lowercase			: Optional[TensorType] = None			,  ):





								'''simple docstring'''



								if self.task in ["default", "seq2seq-lm"]:
													UpperCAmelCase			:   Optional[int]      =				self._generate_dummy_inputs_for_default_and_seqaseq_lm(
													    lowercase			,  batch_size=lowercase			,  seq_length=lowercase			,  is_pair=lowercase			,  framework=lowercase  )

								else:
													UpperCAmelCase			:   str      =				self._generate_dummy_inputs_for_causal_lm(
													    lowercase			,  batch_size=lowercase			,  seq_length=lowercase			,  is_pair=lowercase			,  framework=lowercase  )

								return common_inputs







			def 			__lowerCAmelCase				(			self			: Tuple			,  lowercase			: int			,  lowercase			: str			,  lowercase			: Union[str, Any]			,  lowercase			: str  ):





								'''simple docstring'''



								if self.task in ["default", "seq2seq-lm"]:
													UpperCAmelCase			:   Union[str, Any]      =				super()._flatten_past_key_values_(lowercase			,  lowercase			,  lowercase			,  lowercase  )
								else:
													UpperCAmelCase			:   Optional[int]      =				super(lowercase			,  self  )._flatten_past_key_values_(
													    lowercase			,  lowercase			,  lowercase			,  lowercase  )







			@property
			def 			__lowerCAmelCase				(			self			: Dict  ):





								'''simple docstring'''



								return 1E-4





"""simple docstring"""






from functools import reduce

snake_case_   :   List[Any]        =       (
    """73167176531330624919225119674426574742355349194934"""
    """96983520312774506326239578318016984801869478851843"""
    """85861560789112949495459501737958331952853208805511"""
    """12540698747158523863050715693290963295227443043557"""
    """66896648950445244523161731856403098711121722383113"""
    """62229893423380308135336276614282806444486645238749"""
    """30358907296290491560440772390713810515859307960866"""
    """70172427121883998797908792274921901699720888093776"""
    """65727333001053367881220235421809751254540594752243"""
    """52584907711670556013604839586446706324415722155397"""
    """53697817977846174064955149290862569321978468622482"""
    """83972241375657056057490261407972968652414535100474"""
    """82166370484403199890008895243450658541227588666881"""
    """16427171479924442928230863465674813919123162824586"""
    """17866458359124566529476545682848912883142607690042"""
    """24219022671055626321111109370544217506941658960408"""
    """07198403850962455444362981230987879927244284909188"""
    """84580156166097919133875499200524063689912560717606"""
    """05886116467109405077541002256983155200055935729725"""
    """71636269561882670428252483600823257530420752963450"""
)



def   lowercase_	(    _lowercase       :		str = N	):




					'''simple docstring'''






					return max(
					    # mypy cannot properly interpret reduce
					    int(reduce(lambda _lowercase							,      _lowercase	: str(int(_lowercase	) * int(_lowercase	)	)							,      n[i : i + 13]	)	)
					    for i in range(len(_lowercase	) - 12	)	)


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


