





import math
import os
import unittest

from transformers import MegatronBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import (
							    MODEL_FOR_PRETRAINING_MAPPING,
							    MegatronBertForCausalLM,
							    MegatronBertForMaskedLM,
							    MegatronBertForMultipleChoice,
							    MegatronBertForNextSentencePrediction,
							    MegatronBertForPreTraining,
							    MegatronBertForQuestionAnswering,
							    MegatronBertForSequenceClassification,
							    MegatronBertForTokenClassification,
							    MegatronBertModel,
							)

class       __A     :


				def __init__(		self   , UpperCAmelCase_   , UpperCAmelCase_=13   , UpperCAmelCase_=7   , UpperCAmelCase_=True   , UpperCAmelCase_=True   , UpperCAmelCase_=True   , UpperCAmelCase_=True   , UpperCAmelCase_=99   , UpperCAmelCase_=64   , UpperCAmelCase_=32   , UpperCAmelCase_=5   , UpperCAmelCase_=4   , UpperCAmelCase_=37   , UpperCAmelCase_="gelu"   , UpperCAmelCase_=0.1   , UpperCAmelCase_=0.1   , UpperCAmelCase_=512   , UpperCAmelCase_=16   , UpperCAmelCase_=2   , UpperCAmelCase_=0.0_2   , UpperCAmelCase_=3   , UpperCAmelCase_=4   , UpperCAmelCase_=None   , ):
								lowerCamelCase	 =parent
								lowerCamelCase	 =batch_size
								lowerCamelCase	 =seq_length
								lowerCamelCase	 =is_training
								lowerCamelCase	 =use_input_mask
								lowerCamelCase	 =use_token_type_ids
								lowerCamelCase	 =use_labels
								lowerCamelCase	 =vocab_size
								lowerCamelCase	 =hidden_size
								lowerCamelCase	 =embedding_size
								lowerCamelCase	 =num_hidden_layers
								lowerCamelCase	 =num_attention_heads
								lowerCamelCase	 =intermediate_size
								lowerCamelCase	 =hidden_act
								lowerCamelCase	 =hidden_dropout_prob
								lowerCamelCase	 =attention_probs_dropout_prob
								lowerCamelCase	 =max_position_embeddings
								lowerCamelCase	 =type_vocab_size
								lowerCamelCase	 =type_sequence_label_size
								lowerCamelCase	 =initializer_range
								lowerCamelCase	 =num_labels
								lowerCamelCase	 =num_choices
								lowerCamelCase	 =scope


				def _snake_case       (		self							):
								lowerCamelCase	 =ids_tensor([self.batch_size, self.seq_length]   , self.vocab_size							)

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

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

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

								lowerCamelCase	 =self.get_config()

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


				def _snake_case       (		self							):
								return MegatronBertConfig(
								    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   , embedding_size=self.embedding_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=UpperCAmelCase_   , initializer_range=self.initializer_range   , )


				def _snake_case       (		self   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_							):
								lowerCamelCase	 =MegatronBertModel(config=UpperCAmelCase_							)
								model.to(UpperCAmelCase_							)
								model.eval()
								lowerCamelCase	 =model(UpperCAmelCase_   , attention_mask=UpperCAmelCase_   , token_type_ids=UpperCAmelCase_							)
								lowerCamelCase	 =model(UpperCAmelCase_   , token_type_ids=UpperCAmelCase_							)
								lowerCamelCase	 =model(UpperCAmelCase_							)

								self.parent.assertEqual(result.last_hidden_state.shape   , (self.batch_size, self.seq_length, self.hidden_size)							)
								self.parent.assertEqual(result.pooler_output.shape   , (self.batch_size, self.hidden_size)							)


				def _snake_case       (		self   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_							):
								lowerCamelCase	 =MegatronBertForMaskedLM(config=UpperCAmelCase_							)
								model.to(UpperCAmelCase_							)
								model.eval()
								lowerCamelCase	 =model(UpperCAmelCase_   , attention_mask=UpperCAmelCase_   , token_type_ids=UpperCAmelCase_   , labels=UpperCAmelCase_							)
								self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.seq_length, self.vocab_size)							)


				def _snake_case       (		self   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_							):
								lowerCamelCase	 =MegatronBertForCausalLM(config=UpperCAmelCase_							)
								model.to(UpperCAmelCase_							)
								model.eval()
								lowerCamelCase	 =model(UpperCAmelCase_   , attention_mask=UpperCAmelCase_   , token_type_ids=UpperCAmelCase_   , labels=UpperCAmelCase_							)
								self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.seq_length, self.vocab_size)							)


				def _snake_case       (		self   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_							):
								lowerCamelCase	 =MegatronBertForNextSentencePrediction(config=UpperCAmelCase_							)
								model.to(UpperCAmelCase_							)
								model.eval()
								lowerCamelCase	 =model(
								    UpperCAmelCase_   , attention_mask=UpperCAmelCase_   , token_type_ids=UpperCAmelCase_   , labels=UpperCAmelCase_   , )
								self.parent.assertEqual(result.logits.shape   , (self.batch_size, 2)							)


				def _snake_case       (		self   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_							):
								lowerCamelCase	 =MegatronBertForPreTraining(config=UpperCAmelCase_							)
								model.to(UpperCAmelCase_							)
								model.eval()
								lowerCamelCase	 =model(
								    UpperCAmelCase_   , attention_mask=UpperCAmelCase_   , token_type_ids=UpperCAmelCase_   , labels=UpperCAmelCase_   , next_sentence_label=UpperCAmelCase_   , )
								self.parent.assertEqual(result.prediction_logits.shape   , (self.batch_size, self.seq_length, self.vocab_size)							)
								self.parent.assertEqual(result.seq_relationship_logits.shape   , (self.batch_size, 2)							)


				def _snake_case       (		self   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_							):
								lowerCamelCase	 =MegatronBertForQuestionAnswering(config=UpperCAmelCase_							)
								model.to(UpperCAmelCase_							)
								model.eval()
								lowerCamelCase	 =model(
								    UpperCAmelCase_   , attention_mask=UpperCAmelCase_   , token_type_ids=UpperCAmelCase_   , start_positions=UpperCAmelCase_   , end_positions=UpperCAmelCase_   , )
								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   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_							):
								lowerCamelCase	 =self.num_labels
								lowerCamelCase	 =MegatronBertForSequenceClassification(UpperCAmelCase_							)
								model.to(UpperCAmelCase_							)
								model.eval()
								lowerCamelCase	 =model(UpperCAmelCase_   , attention_mask=UpperCAmelCase_   , token_type_ids=UpperCAmelCase_   , labels=UpperCAmelCase_							)
								self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.num_labels)							)


				def _snake_case       (		self   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_							):
								lowerCamelCase	 =self.num_labels
								lowerCamelCase	 =MegatronBertForTokenClassification(config=UpperCAmelCase_							)
								model.to(UpperCAmelCase_							)
								model.eval()
								lowerCamelCase	 =model(UpperCAmelCase_   , attention_mask=UpperCAmelCase_   , token_type_ids=UpperCAmelCase_   , labels=UpperCAmelCase_							)
								self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.seq_length, self.num_labels)							)


				def _snake_case       (		self   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_							):
								lowerCamelCase	 =self.num_choices
								lowerCamelCase	 =MegatronBertForMultipleChoice(config=UpperCAmelCase_							)
								model.to(UpperCAmelCase_							)
								model.eval()
								lowerCamelCase	 =input_ids.unsqueeze(1							).expand(-1   , self.num_choices   , -1							).contiguous()
								lowerCamelCase	 =token_type_ids.unsqueeze(1							).expand(-1   , self.num_choices   , -1							).contiguous()
								lowerCamelCase	 =input_mask.unsqueeze(1							).expand(-1   , self.num_choices   , -1							).contiguous()
								lowerCamelCase	 =model(
								    UpperCAmelCase_   , attention_mask=UpperCAmelCase_   , token_type_ids=UpperCAmelCase_   , labels=UpperCAmelCase_   , )
								self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.num_choices)							)


				def _snake_case       (		self							):
								lowerCamelCase	 =self.prepare_config_and_inputs()
								(
								    (
								    lowerCamelCase
								) ,  (
								    lowerCamelCase
								) ,  (
								    lowerCamelCase
								) ,  (
								    lowerCamelCase
								) ,  (
								    lowerCamelCase
								) ,  (
								    lowerCamelCase
								) ,  (
								    lowerCamelCase
								) ,  
								)	 =config_and_inputs
								lowerCamelCase	 ={"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
								return config, inputs_dict




@require_torch
class       __A     (						a    ,					a    ,					unittest.TestCase    ):
				__A      =				(
				    (
				        MegatronBertModel,
				        MegatronBertForMaskedLM,
				        MegatronBertForCausalLM,
				        MegatronBertForMultipleChoice,
				        MegatronBertForNextSentencePrediction,
				        MegatronBertForPreTraining,
				        MegatronBertForQuestionAnswering,
				        MegatronBertForSequenceClassification,
				        MegatronBertForTokenClassification,
				    )
				    if is_torch_available()
				    else ()
				)
				__A      =				(
				    {
				        """feature-extraction""": MegatronBertModel,
				        """fill-mask""": MegatronBertForMaskedLM,
				        """question-answering""": MegatronBertForQuestionAnswering,
				        """text-classification""": MegatronBertForSequenceClassification,
				        """text-generation""": MegatronBertForCausalLM,
				        """token-classification""": MegatronBertForTokenClassification,
				        """zero-shot""": MegatronBertForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)
				__A      =				True
				# test_resize_embeddings = False
				__A      =				False


				def _snake_case       (		self   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_=False							):
								lowerCamelCase	 =super()._prepare_for_class(UpperCAmelCase_   , UpperCAmelCase_   , return_labels=UpperCAmelCase_							)

								if return_labels:
												if model_class in get_values(UpperCAmelCase_							):
																lowerCamelCase	 =torch.zeros(
																    (self.model_tester.batch_size, self.model_tester.seq_length)   , dtype=torch.long   , device=UpperCAmelCase_							)
																lowerCamelCase	 =torch.zeros(
																    self.model_tester.batch_size   , dtype=torch.long   , device=UpperCAmelCase_							)
								return inputs_dict


				def _snake_case       (		self							):
								lowerCamelCase	 =MegatronBertModelTester(self							)
								lowerCamelCase	 =ConfigTester(self   , config_class=UpperCAmelCase_   , hidden_size=37							)


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


				def _snake_case       (		self							):
								lowerCamelCase	 =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_megatron_bert_model(*UpperCAmelCase_							)


				def _snake_case       (		self							):
								lowerCamelCase	 =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_megatron_bert_for_masked_lm(*UpperCAmelCase_							)


				def _snake_case       (		self							):
								lowerCamelCase	 =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_megatron_bert_for_multiple_choice(*UpperCAmelCase_							)


				def _snake_case       (		self							):
								lowerCamelCase	 =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_megatron_bert_for_next_sequence_prediction(*UpperCAmelCase_							)


				def _snake_case       (		self							):
								lowerCamelCase	 =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_megatron_bert_for_pretraining(*UpperCAmelCase_							)


				def _snake_case       (		self							):
								lowerCamelCase	 =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_megatron_bert_for_question_answering(*UpperCAmelCase_							)


				def _snake_case       (		self							):
								lowerCamelCase	 =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_megatron_bert_for_sequence_classification(*UpperCAmelCase_							)


				def _snake_case       (		self							):
								lowerCamelCase	 =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_megatron_bert_for_token_classification(*UpperCAmelCase_							)





def      _lowercase					(						_UpperCAmelCase				)						->  int:
				return torch.tensor(
				    _UpperCAmelCase			,      dtype=torch.long			,      device=_UpperCAmelCase			,      )


UpperCAmelCase__						:			str									=1E-4




@require_torch
@require_sentencepiece
@require_tokenizers
class       __A     (						unittest.TestCase    ):


				@slow
				@unittest.skip("""Model is not available."""							)
				def _snake_case       (		self							):
								lowerCamelCase	 ="""nvidia/megatron-bert-uncased-345m"""
								if "MYDIR" in os.environ:
												lowerCamelCase	 =os.path.join(os.environ["""MYDIR"""]   , UpperCAmelCase_							)
								lowerCamelCase	 =MegatronBertModel.from_pretrained(UpperCAmelCase_							)
								model.to(UpperCAmelCase_							)
								model.half()
								lowerCamelCase	 =_long_tensor([[101, 7110, 1005, 1056, 2023, 11333, 17413, 1029, 102]]							)
								with torch.no_grad():
												lowerCamelCase	 =model(UpperCAmelCase_							)[0]
								lowerCamelCase	 =torch.Size((1, 9, 1024)							)
								self.assertEqual(output.shape   , UpperCAmelCase_							)

								lowerCamelCase	 =[-0.6_0_4_0, -0.2_5_1_7, -0.1_0_2_5, 0.3_4_2_0, -0.6_7_5_8, -0.0_0_1_7, -0.1_0_8_9, -0.1_9_9_0, 0.5_7_2_8]
								for ii in range(3							):
												for jj in range(3							):
																lowerCamelCase	 =output[0, ii, jj]
																lowerCamelCase	 =expected[3 * ii + jj]
																lowerCamelCase	 ="""ii={} jj={} a={} b={}""".format(UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_							)
																self.assertTrue(math.isclose(UpperCAmelCase_   , UpperCAmelCase_   , rel_tol=UpperCAmelCase_   , abs_tol=UpperCAmelCase_							)   , msg=UpperCAmelCase_							)












from math import sqrt





def      _lowercase					(						_UpperCAmelCase				)						->  int:
				lowerCamelCase	 =0
				for i in range(1			,      int(sqrt(_UpperCAmelCase				) + 1				)				):
								if n % i == 0 and i != sqrt(_UpperCAmelCase				):
												total += i + n // i
								elif i == sqrt(_UpperCAmelCase				):
												total += i
				return total - n





def      _lowercase					(						_UpperCAmelCase = 1_00_00				)						->  int:
				lowerCamelCase	 =sum(
				    i
				    for i in range(1			,      _UpperCAmelCase				)
				    if sum_of_divisors(sum_of_divisors(_UpperCAmelCase				)				) == i and sum_of_divisors(_UpperCAmelCase				) != i				)
				return total


if __name__ == "__main__":
							print(solution(int(str(input()).strip())))





