





import unittest

from transformers import MraConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_torch_available():
				import torch

				from transformers import (
				    MraForMaskedLM,
				    MraForMultipleChoice,
				    MraForQuestionAnswering,
				    MraForSequenceClassification,
				    MraForTokenClassification,
				    MraModel,
				)
				from transformers.models.mra.modeling_mra import MRA_PRETRAINED_MODEL_ARCHIVE_LIST

class 	A_       :
	def __init__(    self							,					_A							,					_A=2							,					_A=8							,					_A=True							,					_A=True							,					_A=True							,					_A=True							,					_A=9_9							,					_A=1_6							,					_A=5							,					_A=2							,					_A=3_6							,					_A="gelu"							,					_A=0.0							,					_A=0.0							,					_A=5_1_2							,					_A=1_6							,					_A=2							,					_A=0.02							,					_A=3							,					_A=4							,					_A=None							,					):






				'''simple docstring'''







				UpperCAmelCase   		=				parent
				UpperCAmelCase   		=				batch_size
				UpperCAmelCase   		=				seq_length
				UpperCAmelCase   		=				is_training
				UpperCAmelCase   		=				use_input_mask
				UpperCAmelCase   		=				use_token_type_ids
				UpperCAmelCase   		=				use_labels
				UpperCAmelCase   		=				vocab_size
				UpperCAmelCase   		=				hidden_size
				UpperCAmelCase   		=				num_hidden_layers
				UpperCAmelCase   		=				num_attention_heads
				UpperCAmelCase   		=				intermediate_size
				UpperCAmelCase   		=				hidden_act
				UpperCAmelCase   		=				hidden_dropout_prob
				UpperCAmelCase   		=				attention_probs_dropout_prob
				UpperCAmelCase   		=				max_position_embeddings
				UpperCAmelCase   		=				type_vocab_size
				UpperCAmelCase   		=				type_sequence_label_size
				UpperCAmelCase   		=				initializer_range
				UpperCAmelCase   		=				num_labels
				UpperCAmelCase   		=				num_choices
				UpperCAmelCase   		=				scope
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				ids_tensor([self.batch_size, self.seq_length]							,					self.vocab_size		)

				UpperCAmelCase   		=				None
				if self.use_input_mask:
							UpperCAmelCase   		=				random_attention_mask([self.batch_size, self.seq_length]		)

				UpperCAmelCase   		=				None
				if self.use_token_type_ids:
							UpperCAmelCase   		=				ids_tensor([self.batch_size, self.seq_length]							,					self.type_vocab_size		)

				UpperCAmelCase   		=				None
				UpperCAmelCase   		=				None
				UpperCAmelCase   		=				None
				if self.use_labels:
							UpperCAmelCase   		=				ids_tensor([self.batch_size]							,					self.type_sequence_label_size		)
							UpperCAmelCase   		=				ids_tensor([self.batch_size, self.seq_length]							,					self.num_labels		)
							UpperCAmelCase   		=				ids_tensor([self.batch_size]							,					self.num_choices		)

				UpperCAmelCase   		=				self.get_config()

				return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
	def      _lowercase				(    self		):






				'''simple docstring'''







				return MraConfig(
				    vocab_size=self.vocab_size							,					hidden_size=self.hidden_size							,					num_hidden_layers=self.num_hidden_layers							,					num_attention_heads=self.num_attention_heads							,					intermediate_size=self.intermediate_size							,					hidden_act=self.hidden_act							,					hidden_dropout_prob=self.hidden_dropout_prob							,					attention_probs_dropout_prob=self.attention_probs_dropout_prob							,					max_position_embeddings=self.max_position_embeddings							,					type_vocab_size=self.type_vocab_size							,					is_decoder=_A							,					initializer_range=self.initializer_range							,					)
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.get_config()
				UpperCAmelCase   		=				3_0_0
				return config
	def      _lowercase				(    self		):






				'''simple docstring'''







				(
				    (
				    UpperCAmelCase
				)		,			(
				    UpperCAmelCase
				)		,			(
				    UpperCAmelCase
				)		,			(
				    UpperCAmelCase
				)		,			(
				    UpperCAmelCase
				)		,			(
				    UpperCAmelCase
				)		,			(
				    UpperCAmelCase
				)		,			
				)   		=				self.prepare_config_and_inputs()

				UpperCAmelCase   		=				True
				UpperCAmelCase   		=				floats_tensor([self.batch_size, self.seq_length, self.hidden_size]		)
				UpperCAmelCase   		=				ids_tensor([self.batch_size, self.seq_length]							,					vocab_size=2		)

				return (
				    config,
				    input_ids,
				    token_type_ids,
				    input_mask,
				    sequence_labels,
				    token_labels,
				    choice_labels,
				    encoder_hidden_states,
				    encoder_attention_mask,
				)
	def      _lowercase				(    self							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A		):






				'''simple docstring'''







				UpperCAmelCase   		=				MraModel(config=_A		)
				model.to(_A		)
				model.eval()
				UpperCAmelCase   		=				model(_A							,					attention_mask=_A							,					token_type_ids=_A		)
				UpperCAmelCase   		=				model(_A							,					token_type_ids=_A		)
				UpperCAmelCase   		=				model(_A		)
				self.parent.assertEqual(result.last_hidden_state.shape							,					(self.batch_size, self.seq_length, self.hidden_size)		)
	def      _lowercase				(    self							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					):






				'''simple docstring'''







				UpperCAmelCase   		=				True
				UpperCAmelCase   		=				MraModel(_A		)
				model.to(_A		)
				model.eval()
				UpperCAmelCase   		=				model(
				    _A							,					attention_mask=_A							,					token_type_ids=_A							,					encoder_hidden_states=_A							,					encoder_attention_mask=_A							,					)
				UpperCAmelCase   		=				model(
				    _A							,					attention_mask=_A							,					token_type_ids=_A							,					encoder_hidden_states=_A							,					)
				UpperCAmelCase   		=				model(_A							,					attention_mask=_A							,					token_type_ids=_A		)
				self.parent.assertEqual(result.last_hidden_state.shape							,					(self.batch_size, self.seq_length, self.hidden_size)		)
	def      _lowercase				(    self							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A		):






				'''simple docstring'''







				UpperCAmelCase   		=				MraForMaskedLM(config=_A		)
				model.to(_A		)
				model.eval()
				UpperCAmelCase   		=				model(_A							,					attention_mask=_A							,					token_type_ids=_A							,					labels=_A		)
				self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.seq_length, self.vocab_size)		)
	def      _lowercase				(    self							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A		):






				'''simple docstring'''







				UpperCAmelCase   		=				MraForQuestionAnswering(config=_A		)
				model.to(_A		)
				model.eval()
				UpperCAmelCase   		=				model(
				    _A							,					attention_mask=_A							,					token_type_ids=_A							,					start_positions=_A							,					end_positions=_A							,					)
				self.parent.assertEqual(result.start_logits.shape							,					(self.batch_size, self.seq_length)		)
				self.parent.assertEqual(result.end_logits.shape							,					(self.batch_size, self.seq_length)		)
	def      _lowercase				(    self							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.num_labels
				UpperCAmelCase   		=				MraForSequenceClassification(_A		)
				model.to(_A		)
				model.eval()
				UpperCAmelCase   		=				model(_A							,					attention_mask=_A							,					token_type_ids=_A							,					labels=_A		)
				self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.num_labels)		)
	def      _lowercase				(    self							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.num_labels
				UpperCAmelCase   		=				MraForTokenClassification(config=_A		)
				model.to(_A		)
				model.eval()
				UpperCAmelCase   		=				model(_A							,					attention_mask=_A							,					token_type_ids=_A							,					labels=_A		)
				self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.seq_length, self.num_labels)		)
	def      _lowercase				(    self							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.num_choices
				UpperCAmelCase   		=				MraForMultipleChoice(config=_A		)
				model.to(_A		)
				model.eval()
				UpperCAmelCase   		=				input_ids.unsqueeze(1		).expand(-1							,					self.num_choices							,					-1		).contiguous()
				UpperCAmelCase   		=				token_type_ids.unsqueeze(1		).expand(-1							,					self.num_choices							,					-1		).contiguous()
				UpperCAmelCase   		=				input_mask.unsqueeze(1		).expand(-1							,					self.num_choices							,					-1		).contiguous()
				UpperCAmelCase   		=				model(
				    _A							,					attention_mask=_A							,					token_type_ids=_A							,					labels=_A							,					)
				self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.num_choices)		)







	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.prepare_config_and_inputs()
				(
				    (
				    UpperCAmelCase
				)		,			(
				    UpperCAmelCase
				)		,			(
				    UpperCAmelCase
				)		,			(
				    UpperCAmelCase
				)		,			(
				    UpperCAmelCase
				)		,			(
				    UpperCAmelCase
				)		,			(
				    UpperCAmelCase
				)		,			
				)   		=				config_and_inputs
				UpperCAmelCase   		=				{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
				return config, inputs_dict

@require_torch
class 	A_       (a_     ,							unittest.TestCase			):
	UpperCAmelCase__					=			(
	    (
	        MraModel,
	        MraForMaskedLM,
	        MraForMultipleChoice,
	        MraForQuestionAnswering,
	        MraForSequenceClassification,
	        MraForTokenClassification,
	    )
	    if is_torch_available()
	    else ()
	)
	UpperCAmelCase__					=			False
	UpperCAmelCase__					=			False
	UpperCAmelCase__					=			False
	UpperCAmelCase__					=			False

	UpperCAmelCase__					=			()
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				MraModelTester(self		)
				UpperCAmelCase   		=				ConfigTester(self							,					config_class=_A							,					hidden_size=3_7		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				self.config_tester.run_common_tests()
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*_A		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs()
				for type in ["absolute", "relative_key", "relative_key_query"]:
							UpperCAmelCase   		=				type
							self.model_tester.create_and_check_model(*_A		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_masked_lm(*_A		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_multiple_choice(*_A		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_question_answering(*_A		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_sequence_classification(*_A		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_token_classification(*_A		)
	@slow
	def      _lowercase				(    self		):






				'''simple docstring'''







				for model_name in MRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							UpperCAmelCase   		=				MraModel.from_pretrained(_A		)
							self.assertIsNotNone(_A		)







	@unittest.skip(reason='''MRA does not output attentions'''		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				return

@require_torch
class 	A_       (unittest.TestCase			):
	@slow
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				MraModel.from_pretrained('''uw-madison/mra-base-512-4'''		)
				UpperCAmelCase   		=				torch.arange(2_5_6		).unsqueeze(0		)

				with torch.no_grad():
							UpperCAmelCase   		=				model(_A		)[0]

				UpperCAmelCase   		=				torch.Size((1, 2_5_6, 7_6_8)		)
				self.assertEqual(output.shape							,					_A		)

				UpperCAmelCase   		=				torch.tensor(
				    [[[-0.01_40, 0.08_30, -0.03_81], [0.15_46, 0.14_02, 0.02_20], [0.11_62, 0.08_51, 0.01_65]]]		)

				self.assertTrue(torch.allclose(output[:, :3, :3]							,					_A							,					atol=1E-4		)		)
	@slow
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				MraForMaskedLM.from_pretrained('''uw-madison/mra-base-512-4'''		)
				UpperCAmelCase   		=				torch.arange(2_5_6		).unsqueeze(0		)

				with torch.no_grad():
							UpperCAmelCase   		=				model(_A		)[0]

				UpperCAmelCase   		=				5_0_2_6_5

				UpperCAmelCase   		=				torch.Size((1, 2_5_6, vocab_size)		)
				self.assertEqual(output.shape							,					_A		)

				UpperCAmelCase   		=				torch.tensor(
				    [[[9.25_95, -3.60_38, 11.88_19], [9.38_69, -3.26_93, 11.09_56], [11.85_24, -3.49_38, 13.12_10]]]		)

				self.assertTrue(torch.allclose(output[:, :3, :3]							,					_A							,					atol=1E-4		)		)







	@slow
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				MraForMaskedLM.from_pretrained('''uw-madison/mra-base-4096-8-d3'''		)
				UpperCAmelCase   		=				torch.arange(4_0_9_6		).unsqueeze(0		)

				with torch.no_grad():
							UpperCAmelCase   		=				model(_A		)[0]

				UpperCAmelCase   		=				5_0_2_6_5

				UpperCAmelCase   		=				torch.Size((1, 4_0_9_6, vocab_size)		)
				self.assertEqual(output.shape							,					_A		)

				UpperCAmelCase   		=				torch.tensor(
				    [[[5.47_89, -2.35_64, 7.50_64], [7.90_67, -1.33_69, 9.96_68], [9.07_12, -1.81_06, 7.03_80]]]		)

				self.assertTrue(torch.allclose(output[:, :3, :3]							,					_A							,					atol=1E-4		)		)







'''simple docstring'''

from __future__ import annotations

from fractions import Fraction





def __snake_case					(      UpperCAmelCase_						:						int					,				UpperCAmelCase_						:						int		):
 return (
     num != den and num % 10 == den // 10 and (num // 10) / (den % 10) == num / den
 )





def __snake_case					(      UpperCAmelCase_						:						int		):
 lowerCamelCase_      =  []
 lowerCamelCase_      =  11
 lowerCamelCase_      =  int("1" + "0" * digit_len		)
 for num in range(UpperCAmelCase_					,				UpperCAmelCase_		):
  while den <= 99:
   if (num != den) and (num % 10 == den // 10) and (den % 10 != 0):
    if is_digit_cancelling(UpperCAmelCase_					,				UpperCAmelCase_		):
     solutions.append(F'''{num}/{den}'''		)
   den += 1
  num += 1
  lowerCamelCase_      =  10
 return solutions





def __snake_case					(      UpperCAmelCase_						:						int = 2		):
 lowerCamelCase_      =  1.0
 for fraction in fraction_list(UpperCAmelCase_		):
  lowerCamelCase_      =  Fraction(UpperCAmelCase_		)
  result *= frac.denominator / frac.numerator
 return int(UpperCAmelCase_		)


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



