



'''simple docstring'''






def 					snake_case_	(   _lowerCAmelCase    :		int    ) ->  str:
							UpperCAmelCase					:			List[str]									=						0
							while num > 0:
														digit_sum += num % 10
														num //= 10
							return digit_sum


def 					snake_case_	(   _lowerCAmelCase    :		int = 100    ) ->  Any:
							UpperCAmelCase					:			Dict									=						1
							UpperCAmelCase					:			Any									=						2

							for i in range(2  , max_n + 1    ):
														UpperCAmelCase					:			List[Any]									=						pre_numerator
														UpperCAmelCase					:			Optional[int]									=						2 * i // 3 if i % 3 == 0 else 1
														UpperCAmelCase					:			List[str]									=						cur_numerator
														UpperCAmelCase					:			Tuple									=						e_cont * pre_numerator + temp

							return sum_digits(lowerCAmelCase__    )


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










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,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_=2,   SCREAMING_SNAKE_CASE_=8,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=99,   SCREAMING_SNAKE_CASE_=16,   SCREAMING_SNAKE_CASE_=5,   SCREAMING_SNAKE_CASE_=2,   SCREAMING_SNAKE_CASE_=36,   SCREAMING_SNAKE_CASE_="gelu",   SCREAMING_SNAKE_CASE_=0.0,   SCREAMING_SNAKE_CASE_=0.0,   SCREAMING_SNAKE_CASE_=512,   SCREAMING_SNAKE_CASE_=16,   SCREAMING_SNAKE_CASE_=2,   SCREAMING_SNAKE_CASE_=0.0_2,   SCREAMING_SNAKE_CASE_=3,   SCREAMING_SNAKE_CASE_=4,   SCREAMING_SNAKE_CASE_=None,   )       ->   str:
						UpperCAmelCase_:		int							      =     parent
						UpperCAmelCase_:		Dict							      =     batch_size
						UpperCAmelCase_:		Optional[int]							      =     seq_length
						UpperCAmelCase_:		int							      =     is_training
						UpperCAmelCase_:		List[Any]							      =     use_input_mask
						UpperCAmelCase_:		int							      =     use_token_type_ids
						UpperCAmelCase_:		Tuple							      =     use_labels
						UpperCAmelCase_:		Tuple							      =     vocab_size
						UpperCAmelCase_:		int							      =     hidden_size
						UpperCAmelCase_:		List[str]							      =     num_hidden_layers
						UpperCAmelCase_:		List[str]							      =     num_attention_heads
						UpperCAmelCase_:		Any							      =     intermediate_size
						UpperCAmelCase_:		str							      =     hidden_act
						UpperCAmelCase_:		Optional[int]							      =     hidden_dropout_prob
						UpperCAmelCase_:		Optional[Any]							      =     attention_probs_dropout_prob
						UpperCAmelCase_:		List[str]							      =     max_position_embeddings
						UpperCAmelCase_:		Optional[int]							      =     type_vocab_size
						UpperCAmelCase_:		Tuple							      =     type_sequence_label_size
						UpperCAmelCase_:		Tuple							      =     initializer_range
						UpperCAmelCase_:		str							      =     num_labels
						UpperCAmelCase_:		str							      =     num_choices
						UpperCAmelCase_:		Optional[int]							      =     scope

			def      __snake_case       (self					)       ->   Optional[Any]:
						UpperCAmelCase_:		Tuple							      =     ids_tensor([self.batch_size, self.seq_length],   self.vocab_size					)

						UpperCAmelCase_:		List[str]							      =     None
						if self.use_input_mask:
									UpperCAmelCase_:		Union[str, Any]							      =     random_attention_mask([self.batch_size, self.seq_length]					)

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

						UpperCAmelCase_:		str							      =     None
						UpperCAmelCase_:		List[Any]							      =     None
						UpperCAmelCase_:		Tuple							      =     None
						if self.use_labels:
									UpperCAmelCase_:		Tuple							      =     ids_tensor([self.batch_size],   self.type_sequence_label_size					)
									UpperCAmelCase_:		str							      =     ids_tensor([self.batch_size, self.seq_length],   self.num_labels					)
									UpperCAmelCase_:		Tuple							      =     ids_tensor([self.batch_size],   self.num_choices					)

						UpperCAmelCase_:		List[Any]							      =     self.get_config()

						return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

			def      __snake_case       (self					)       ->   List[Any]:
						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=SCREAMING_SNAKE_CASE_,   initializer_range=self.initializer_range,   )

			def      __snake_case       (self					)       ->   Optional[int]:
						UpperCAmelCase_:		Optional[Any]							      =     self.get_config()
						UpperCAmelCase_:		Dict							      =     300
						return config

			def      __snake_case       (self					)       ->   List[Any]:
						(
						    (
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							
						):		Any							      =     self.prepare_config_and_inputs()

						UpperCAmelCase_:		List[str]							      =     True
						UpperCAmelCase_:		Any							      =     floats_tensor([self.batch_size, self.seq_length, self.hidden_size]					)
						UpperCAmelCase_:		List[str]							      =     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      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)       ->   Optional[Any]:
						UpperCAmelCase_:		Optional[int]							      =     MraModel(config=SCREAMING_SNAKE_CASE_					)
						model.to(SCREAMING_SNAKE_CASE_					)
						model.eval()
						UpperCAmelCase_:		Optional[Any]							      =     model(SCREAMING_SNAKE_CASE_,   attention_mask=SCREAMING_SNAKE_CASE_,   token_type_ids=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Tuple							      =     model(SCREAMING_SNAKE_CASE_,   token_type_ids=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Tuple							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, self.seq_length, self.hidden_size)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   Union[str, Any]:
						UpperCAmelCase_:		Any							      =     True
						UpperCAmelCase_:		Union[str, Any]							      =     MraModel(SCREAMING_SNAKE_CASE_					)
						model.to(SCREAMING_SNAKE_CASE_					)
						model.eval()
						UpperCAmelCase_:		Optional[Any]							      =     model(
						    SCREAMING_SNAKE_CASE_,   attention_mask=SCREAMING_SNAKE_CASE_,   token_type_ids=SCREAMING_SNAKE_CASE_,   encoder_hidden_states=SCREAMING_SNAKE_CASE_,   encoder_attention_mask=SCREAMING_SNAKE_CASE_,   )
						UpperCAmelCase_:		List[Any]							      =     model(
						    SCREAMING_SNAKE_CASE_,   attention_mask=SCREAMING_SNAKE_CASE_,   token_type_ids=SCREAMING_SNAKE_CASE_,   encoder_hidden_states=SCREAMING_SNAKE_CASE_,   )
						UpperCAmelCase_:		Tuple							      =     model(SCREAMING_SNAKE_CASE_,   attention_mask=SCREAMING_SNAKE_CASE_,   token_type_ids=SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, self.seq_length, self.hidden_size)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)       ->   List[Any]:
						UpperCAmelCase_:		int							      =     MraForMaskedLM(config=SCREAMING_SNAKE_CASE_					)
						model.to(SCREAMING_SNAKE_CASE_					)
						model.eval()
						UpperCAmelCase_:		int							      =     model(SCREAMING_SNAKE_CASE_,   attention_mask=SCREAMING_SNAKE_CASE_,   token_type_ids=SCREAMING_SNAKE_CASE_,   labels=SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.seq_length, self.vocab_size)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)       ->   List[str]:
						UpperCAmelCase_:		Any							      =     MraForQuestionAnswering(config=SCREAMING_SNAKE_CASE_					)
						model.to(SCREAMING_SNAKE_CASE_					)
						model.eval()
						UpperCAmelCase_:		str							      =     model(
						    SCREAMING_SNAKE_CASE_,   attention_mask=SCREAMING_SNAKE_CASE_,   token_type_ids=SCREAMING_SNAKE_CASE_,   start_positions=SCREAMING_SNAKE_CASE_,   end_positions=SCREAMING_SNAKE_CASE_,   )
						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      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)       ->   Optional[int]:
						UpperCAmelCase_:		List[str]							      =     self.num_labels
						UpperCAmelCase_:		Any							      =     MraForSequenceClassification(SCREAMING_SNAKE_CASE_					)
						model.to(SCREAMING_SNAKE_CASE_					)
						model.eval()
						UpperCAmelCase_:		List[str]							      =     model(SCREAMING_SNAKE_CASE_,   attention_mask=SCREAMING_SNAKE_CASE_,   token_type_ids=SCREAMING_SNAKE_CASE_,   labels=SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.num_labels)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)       ->   List[Any]:
						UpperCAmelCase_:		Tuple							      =     self.num_labels
						UpperCAmelCase_:		Any							      =     MraForTokenClassification(config=SCREAMING_SNAKE_CASE_					)
						model.to(SCREAMING_SNAKE_CASE_					)
						model.eval()
						UpperCAmelCase_:		List[str]							      =     model(SCREAMING_SNAKE_CASE_,   attention_mask=SCREAMING_SNAKE_CASE_,   token_type_ids=SCREAMING_SNAKE_CASE_,   labels=SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.seq_length, self.num_labels)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)       ->   List[Any]:
						UpperCAmelCase_:		Optional[Any]							      =     self.num_choices
						UpperCAmelCase_:		int							      =     MraForMultipleChoice(config=SCREAMING_SNAKE_CASE_					)
						model.to(SCREAMING_SNAKE_CASE_					)
						model.eval()
						UpperCAmelCase_:		Dict							      =     input_ids.unsqueeze(1					).expand(-1,   self.num_choices,   -1					).contiguous()
						UpperCAmelCase_:		List[str]							      =     token_type_ids.unsqueeze(1					).expand(-1,   self.num_choices,   -1					).contiguous()
						UpperCAmelCase_:		List[Any]							      =     input_mask.unsqueeze(1					).expand(-1,   self.num_choices,   -1					).contiguous()
						UpperCAmelCase_:		List[Any]							      =     model(
						    SCREAMING_SNAKE_CASE_,   attention_mask=SCREAMING_SNAKE_CASE_,   token_type_ids=SCREAMING_SNAKE_CASE_,   labels=SCREAMING_SNAKE_CASE_,   )
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.num_choices)					)

			def      __snake_case       (self					)       ->   Union[str, Any]:
						UpperCAmelCase_:		int							      =     self.prepare_config_and_inputs()
						(
						    (
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							
						):		Any							      =     config_and_inputs
						UpperCAmelCase_:		Dict							      =     {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
						return config, inputs_dict







@require_torch
class 				_a				(   _lowerCAmelCase ,		unittest.TestCase					):
			A      		=	(
			    (
			        MraModel,
			        MraForMaskedLM,
			        MraForMultipleChoice,
			        MraForQuestionAnswering,
			        MraForSequenceClassification,
			        MraForTokenClassification,
			    )
			    if is_torch_available()
			    else ()
			)
			A      		=	False
			A      		=	False
			A      		=	False
			A      		=	False

			A      		=	()

			def      __snake_case       (self					)       ->   Tuple:
						UpperCAmelCase_:		Dict							      =     MraModelTester(self					)
						UpperCAmelCase_:		List[Any]							      =     ConfigTester(self,   config_class=SCREAMING_SNAKE_CASE_,   hidden_size=37					)

			def      __snake_case       (self					)       ->   Tuple:
						self.config_tester.run_common_tests()

			def      __snake_case       (self					)       ->   str:
						UpperCAmelCase_:		int							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Optional[int]:
						UpperCAmelCase_:		List[str]							      =     self.model_tester.prepare_config_and_inputs()
						for type in ["absolute", "relative_key", "relative_key_query"]:
									UpperCAmelCase_:		str							      =     type
									self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Union[str, Any]:
						UpperCAmelCase_:		str							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   List[str]:
						UpperCAmelCase_:		Optional[Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_multiple_choice(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Dict:
						UpperCAmelCase_:		Union[str, Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Tuple:
						UpperCAmelCase_:		Union[str, Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Any:
						UpperCAmelCase_:		str							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE_					)

			@slow
			def      __snake_case       (self					)       ->   Any:
						for model_name in MRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									UpperCAmelCase_:		List[str]							      =     MraModel.from_pretrained(SCREAMING_SNAKE_CASE_					)
									self.assertIsNotNone(SCREAMING_SNAKE_CASE_					)

			@unittest.skip(reason="""MRA does not output attentions"""					)
			def      __snake_case       (self					)       ->   List[str]:
						return







@require_torch
class 				_a				(   unittest.TestCase					):

			@slow
			def      __snake_case       (self					)       ->   Tuple:
						UpperCAmelCase_:		Union[str, Any]							      =     MraModel.from_pretrained("""uw-madison/mra-base-512-4"""					)
						UpperCAmelCase_:		Optional[Any]							      =     torch.arange(256					).unsqueeze(0					)

						with torch.no_grad():
									UpperCAmelCase_:		Optional[Any]							      =     model(SCREAMING_SNAKE_CASE_					)[0]

						UpperCAmelCase_:		Optional[int]							      =     torch.Size((1, 256, 768)					)
						self.assertEqual(output.shape,   SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		int							      =     torch.tensor(
						    [[[-0.0_1_4_0, 0.0_8_3_0, -0.0_3_8_1], [0.1_5_4_6, 0.1_4_0_2, 0.0_2_2_0], [0.1_1_6_2, 0.0_8_5_1, 0.0_1_6_5]]]					)

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

			@slow
			def      __snake_case       (self					)       ->   Any:
						UpperCAmelCase_:		List[str]							      =     MraForMaskedLM.from_pretrained("""uw-madison/mra-base-512-4"""					)
						UpperCAmelCase_:		Dict							      =     torch.arange(256					).unsqueeze(0					)

						with torch.no_grad():
									UpperCAmelCase_:		List[str]							      =     model(SCREAMING_SNAKE_CASE_					)[0]

						UpperCAmelCase_:		Any							      =     50265

						UpperCAmelCase_:		Any							      =     torch.Size((1, 256, vocab_size)					)
						self.assertEqual(output.shape,   SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		Dict							      =     torch.tensor(
						    [[[9.2_5_9_5, -3.6_0_3_8, 1_1.8_8_1_9], [9.3_8_6_9, -3.2_6_9_3, 1_1.0_9_5_6], [1_1.8_5_2_4, -3.4_9_3_8, 1_3.1_2_1_0]]]					)

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

			@slow
			def      __snake_case       (self					)       ->   Optional[int]:
						UpperCAmelCase_:		Optional[int]							      =     MraForMaskedLM.from_pretrained("""uw-madison/mra-base-4096-8-d3"""					)
						UpperCAmelCase_:		List[Any]							      =     torch.arange(4096					).unsqueeze(0					)

						with torch.no_grad():
									UpperCAmelCase_:		List[Any]							      =     model(SCREAMING_SNAKE_CASE_					)[0]

						UpperCAmelCase_:		Dict							      =     50265

						UpperCAmelCase_:		int							      =     torch.Size((1, 4096, vocab_size)					)
						self.assertEqual(output.shape,   SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		List[Any]							      =     torch.tensor(
						    [[[5.4_7_8_9, -2.3_5_6_4, 7.5_0_6_4], [7.9_0_6_7, -1.3_3_6_9, 9.9_6_6_8], [9.0_7_1_2, -1.8_1_0_6, 7.0_3_8_0]]]					)

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






