

'''simple docstring'''
import os
import tempfile
import unittest

from transformers import NezhaConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import (
					    MODEL_FOR_PRETRAINING_MAPPING,
					    NezhaForMaskedLM,
					    NezhaForMultipleChoice,
					    NezhaForNextSentencePrediction,
					    NezhaForPreTraining,
					    NezhaForQuestionAnswering,
					    NezhaForSequenceClassification,
					    NezhaForTokenClassification,
					    NezhaModel,
					)
					from transformers.models.nezha.modeling_nezha import NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST







class 							A__   :





		def __init__(		self				:     Tuple							, _a				:     List[str]							, _a				:     Tuple=13							, _a				:     Union[str, Any]=7							, _a				:     Optional[int]=True							, _a				:     List[str]=True							, _a				:     Tuple=True							, _a				:     Dict=True							, _a				:     Union[str, Any]=99							, _a				:     Any=32							, _a				:     Optional[Any]=5							, _a				:     Any=4							, _a				:     int=37							, _a				:     Optional[Any]="gelu"							, _a				:     Optional[int]=0.1							, _a				:     Tuple=0.1							, _a				:     Dict=128							, _a				:     Any=32							, _a				:     List[Any]=16							, _a				:     List[str]=2							, _a				:     int=0.02							, _a				:     List[str]=3							, _a				:     Any=4							, _a				:     List[str]=None							, )     ->   int:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =parent
							_SCREAMING_SNAKE_CASE							   =batch_size
							_SCREAMING_SNAKE_CASE							   =seq_length
							_SCREAMING_SNAKE_CASE							   =is_training
							_SCREAMING_SNAKE_CASE							   =use_input_mask
							_SCREAMING_SNAKE_CASE							   =use_token_type_ids
							_SCREAMING_SNAKE_CASE							   =use_labels
							_SCREAMING_SNAKE_CASE							   =vocab_size
							_SCREAMING_SNAKE_CASE							   =hidden_size
							_SCREAMING_SNAKE_CASE							   =num_hidden_layers
							_SCREAMING_SNAKE_CASE							   =num_attention_heads
							_SCREAMING_SNAKE_CASE							   =intermediate_size
							_SCREAMING_SNAKE_CASE							   =hidden_act
							_SCREAMING_SNAKE_CASE							   =hidden_dropout_prob
							_SCREAMING_SNAKE_CASE							   =attention_probs_dropout_prob
							_SCREAMING_SNAKE_CASE							   =max_position_embeddings
							_SCREAMING_SNAKE_CASE							   =type_vocab_size
							_SCREAMING_SNAKE_CASE							   =type_sequence_label_size
							_SCREAMING_SNAKE_CASE							   =initializer_range
							_SCREAMING_SNAKE_CASE							   =num_labels
							_SCREAMING_SNAKE_CASE							   =num_choices
							_SCREAMING_SNAKE_CASE							   =scope





		def 						A  (		self				:     Dict			)     ->   str:





							'''simple docstring'''






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

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

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

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

							_SCREAMING_SNAKE_CASE							   =self.get_config()

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





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





							'''simple docstring'''






							return NezhaConfig(
							    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 						A  (		self				:     List[str]			)     ->   Any:





							'''simple docstring'''






							(
							    _SCREAMING_SNAKE_CASE 
							)							   =self.prepare_config_and_inputs()

							_SCREAMING_SNAKE_CASE							   =True
							_SCREAMING_SNAKE_CASE							   =floats_tensor([self.batch_size, self.seq_length, self.hidden_size]			)
							_SCREAMING_SNAKE_CASE							   =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 						A  (		self				:     Optional[int]							, _a				:     str							, _a				:     Tuple							, _a				:     Tuple							, _a				:     int							, _a				:     str							, _a				:     Dict							, _a				:     List[Any]			)     ->   Optional[Any]:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =NezhaModel(config=_a			)
							model.to(_a			)
							model.eval()
							_SCREAMING_SNAKE_CASE							   =model(_a							, attention_mask=_a							, token_type_ids=_a			)
							_SCREAMING_SNAKE_CASE							   =model(_a							, token_type_ids=_a			)
							_SCREAMING_SNAKE_CASE							   =model(_a			)
							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 						A  (		self				:     List[str]							, _a				:     int							, _a				:     str							, _a				:     List[Any]							, _a				:     List[str]							, _a				:     Optional[int]							, _a				:     Optional[Any]							, _a				:     Optional[int]							, _a				:     Dict							, _a				:     List[Any]							, )     ->   Optional[Any]:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =True
							_SCREAMING_SNAKE_CASE							   =NezhaModel(_a			)
							model.to(_a			)
							model.eval()
							_SCREAMING_SNAKE_CASE							   =model(
							    _a							, attention_mask=_a							, token_type_ids=_a							, encoder_hidden_states=_a							, encoder_attention_mask=_a							, )
							_SCREAMING_SNAKE_CASE							   =model(
							    _a							, attention_mask=_a							, token_type_ids=_a							, encoder_hidden_states=_a							, )
							_SCREAMING_SNAKE_CASE							   =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)			)
							self.parent.assertEqual(result.pooler_output.shape							, (self.batch_size, self.hidden_size)			)





		def 						A  (		self				:     str							, _a				:     List[Any]							, _a				:     int							, _a				:     Optional[int]							, _a				:     Optional[int]							, _a				:     Union[str, Any]							, _a				:     Optional[Any]							, _a				:     List[Any]			)     ->   List[str]:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =NezhaForMaskedLM(config=_a			)
							model.to(_a			)
							model.eval()
							_SCREAMING_SNAKE_CASE							   =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 						A  (		self				:     int							, _a				:     str							, _a				:     Dict							, _a				:     str							, _a				:     List[str]							, _a				:     Tuple							, _a				:     Any							, _a				:     Optional[Any]			)     ->   Tuple:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =NezhaForNextSentencePrediction(config=_a			)
							model.to(_a			)
							model.eval()
							_SCREAMING_SNAKE_CASE							   =model(
							    _a							, attention_mask=_a							, token_type_ids=_a							, labels=_a							, )
							self.parent.assertEqual(result.logits.shape							, (self.batch_size, 2)			)





		def 						A  (		self				:     Union[str, Any]							, _a				:     Optional[Any]							, _a				:     Optional[Any]							, _a				:     Tuple							, _a				:     Tuple							, _a				:     List[Any]							, _a				:     Any							, _a				:     int			)     ->   Optional[int]:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =NezhaForPreTraining(config=_a			)
							model.to(_a			)
							model.eval()
							_SCREAMING_SNAKE_CASE							   =model(
							    _a							, attention_mask=_a							, token_type_ids=_a							, labels=_a							, next_sentence_label=_a							, )
							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 						A  (		self				:     Optional[int]							, _a				:     Tuple							, _a				:     Union[str, Any]							, _a				:     Dict							, _a				:     List[Any]							, _a				:     Any							, _a				:     Any							, _a				:     Dict			)     ->   Optional[int]:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =NezhaForQuestionAnswering(config=_a			)
							model.to(_a			)
							model.eval()
							_SCREAMING_SNAKE_CASE							   =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 						A  (		self				:     int							, _a				:     int							, _a				:     Dict							, _a				:     str							, _a				:     List[str]							, _a				:     int							, _a				:     Any							, _a				:     Union[str, Any]			)     ->   str:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.num_labels
							_SCREAMING_SNAKE_CASE							   =NezhaForSequenceClassification(_a			)
							model.to(_a			)
							model.eval()
							_SCREAMING_SNAKE_CASE							   =model(_a							, attention_mask=_a							, token_type_ids=_a							, labels=_a			)
							self.parent.assertEqual(result.logits.shape							, (self.batch_size, self.num_labels)			)





		def 						A  (		self				:     int							, _a				:     str							, _a				:     List[Any]							, _a				:     int							, _a				:     str							, _a				:     int							, _a				:     Any							, _a				:     int			)     ->   Tuple:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.num_labels
							_SCREAMING_SNAKE_CASE							   =NezhaForTokenClassification(config=_a			)
							model.to(_a			)
							model.eval()
							_SCREAMING_SNAKE_CASE							   =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 						A  (		self				:     int							, _a				:     Optional[Any]							, _a				:     Optional[Any]							, _a				:     Dict							, _a				:     Dict							, _a				:     Dict							, _a				:     Optional[Any]							, _a				:     Dict			)     ->   List[str]:





							'''simple docstring'''






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





		def 						A  (		self				:     Optional[Any]			)     ->   List[str]:





							'''simple docstring'''






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







@require_torch
class 							A__   (	__lowercase					,       __lowercase					,       __lowercase					,       unittest.TestCase  ):
		A__					=    (
		    (
		        NezhaModel,
		        NezhaForMaskedLM,
		        NezhaForMultipleChoice,
		        NezhaForNextSentencePrediction,
		        NezhaForPreTraining,
		        NezhaForQuestionAnswering,
		        NezhaForSequenceClassification,
		        NezhaForTokenClassification,
		    )
		    if is_torch_available()
		    else ()
		)
		A__					=    (
		    {
		        "feature-extraction": NezhaModel,
		        "fill-mask": NezhaForMaskedLM,
		        "question-answering": NezhaForQuestionAnswering,
		        "text-classification": NezhaForSequenceClassification,
		        "token-classification": NezhaForTokenClassification,
		        "zero-shot": NezhaForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)
		A__					=    True





		def 						A  (		self				:     Optional[Any]							, _a				:     Optional[int]							, _a				:     Tuple							, _a				:     str=False			)     ->   List[Any]:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =super()._prepare_for_class(_a							, _a							, return_labels=_a			)

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





		def 						A  (		self				:     List[str]			)     ->   str:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =NezhaModelTester(self			)
							_SCREAMING_SNAKE_CASE							   =ConfigTester(self							, config_class=_a							, hidden_size=37			)





		def 						A  (		self				:     int			)     ->   Optional[Any]:





							'''simple docstring'''






							self.config_tester.run_common_tests()





		def 						A  (		self				:     int			)     ->   Any:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*_a			)





		def 						A  (		self				:     List[str]			)     ->   Any:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs_for_decoder()
							self.model_tester.create_and_check_model_as_decoder(*_a			)





		def 						A  (		self				:     List[str]			)     ->   Union[str, Any]:





							'''simple docstring'''






							(
							    _SCREAMING_SNAKE_CASE 
							)							   =self.model_tester.prepare_config_and_inputs_for_decoder()

							_SCREAMING_SNAKE_CASE							   =None

							self.model_tester.create_and_check_model_as_decoder(
							    _a							, _a							, _a							, _a							, _a							, _a							, _a							, _a							, _a							, )





		def 						A  (		self				:     Optional[int]			)     ->   Tuple:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*_a			)





		def 						A  (		self				:     Optional[int]			)     ->   List[str]:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_multiple_choice(*_a			)





		def 						A  (		self				:     int			)     ->   Union[str, Any]:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_next_sequence_prediction(*_a			)





		def 						A  (		self				:     Tuple			)     ->   Tuple:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_pretraining(*_a			)





		def 						A  (		self				:     str			)     ->   Union[str, Any]:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*_a			)





		def 						A  (		self				:     List[str]			)     ->   Dict:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*_a			)





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





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*_a			)





		@slow
		def 						A  (		self				:     Tuple			)     ->   Tuple:





							'''simple docstring'''






							for model_name in NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												_SCREAMING_SNAKE_CASE							   =NezhaModel.from_pretrained(_a			)
												self.assertIsNotNone(_a			)





		@slow
		@require_torch_gpu
		def 						A  (		self				:     Optional[Any]			)     ->   Optional[Any]:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs_for_common()
							for model_class in self.all_model_classes:
												# NezhaForMultipleChoice behaves incorrectly in JIT environments.
												if model_class == NezhaForMultipleChoice:
																	return

												_SCREAMING_SNAKE_CASE							   =True
												_SCREAMING_SNAKE_CASE							   =model_class(config=_a			)

												_SCREAMING_SNAKE_CASE							   =self._prepare_for_class(_a							, _a			)
												_SCREAMING_SNAKE_CASE							   =torch.jit.trace(
												    _a							, (inputs_dict['input_ids'].to('cpu'			), inputs_dict['attention_mask'].to('cpu'			))			)

												with tempfile.TemporaryDirectory() as tmp:
																	torch.jit.save(_a							, os.path.join(_a							, 'bert.pt'			)			)
																	_SCREAMING_SNAKE_CASE							   =torch.jit.load(os.path.join(_a							, 'bert.pt'			)							, map_location=_a			)
																	loaded(inputs_dict['input_ids'].to(_a			)							, inputs_dict['attention_mask'].to(_a			)			)







@require_torch
class 							A__   (	unittest.TestCase  ):





		@slow
		def 						A  (		self				:     Union[str, Any]			)     ->   str:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =NezhaModel.from_pretrained('sijunhe/nezha-cn-base'			)
							_SCREAMING_SNAKE_CASE							   =torch.tensor([[0, 1, 2, 3, 4, 5]]			)
							_SCREAMING_SNAKE_CASE							   =torch.tensor([[0, 1, 1, 1, 1, 1]]			)
							with torch.no_grad():
												_SCREAMING_SNAKE_CASE							   =model(_a							, attention_mask=_a			)[0]
							_SCREAMING_SNAKE_CASE							   =torch.Size((1, 6, 768)			)
							self.assertEqual(output.shape							, _a			)
							_SCREAMING_SNAKE_CASE							   =torch.tensor([[[0.06_85, 0.24_41, 0.11_02], [0.06_00, 0.19_06, 0.13_49], [0.02_21, 0.08_19, 0.05_86]]]			)

							self.assertTrue(torch.allclose(output[:, 1:4, 1:4]							, _a							, atol=1e-4			)			)





		@slow
		def 						A  (		self				:     Union[str, Any]			)     ->   Dict:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =NezhaForMaskedLM.from_pretrained('sijunhe/nezha-cn-base'			)
							_SCREAMING_SNAKE_CASE							   =torch.tensor([[0, 1, 2, 3, 4, 5]]			)
							_SCREAMING_SNAKE_CASE							   =torch.tensor([[1, 1, 1, 1, 1, 1]]			)
							with torch.no_grad():
												_SCREAMING_SNAKE_CASE							   =model(_a							, attention_mask=_a			)[0]
							_SCREAMING_SNAKE_CASE							   =torch.Size((1, 6, 2_1128)			)
							self.assertEqual(output.shape							, _a			)
							_SCREAMING_SNAKE_CASE							   =torch.tensor(
							    [[-2.79_39, -1.79_02, -2.21_89], [-2.85_85, -1.89_08, -2.37_23], [-2.64_99, -1.77_50, -2.25_58]]			)

							self.assertTrue(torch.allclose(output[:, 1:4, 1:4]							, _a							, atol=1e-4			)			)



'''simple docstring'''
from __future__ import annotations

from fractions import Fraction
from math import gcd, sqrt


def 	_lowerCAmelCase (						_UpperCamelCase						:					int    )				->      bool:
     """simple docstring"""




     _SCREAMING_SNAKE_CASE							   =int(number**0.5    )
     return number == sq * sq


def 	_lowerCAmelCase (						_UpperCamelCase						:					int							,			_UpperCamelCase						:					int							,			_UpperCamelCase						:					int							,			_UpperCamelCase						:					int							,			_UpperCamelCase						:					int							,			_UpperCamelCase						:					int    )				->      tuple[int, int]:
     """simple docstring"""




     _SCREAMING_SNAKE_CASE							   =x_num * y_den * z_den + y_num * x_den * z_den + z_num * x_den * y_den
     _SCREAMING_SNAKE_CASE							   =x_den * y_den * z_den
     _SCREAMING_SNAKE_CASE							   =gcd(_UpperCamelCase							,			_UpperCamelCase    )
     top //= hcf
     bottom //= hcf
     return top, bottom


def 	_lowerCAmelCase (						_UpperCamelCase						:					int = 35    )				->      int:
     """simple docstring"""




     _SCREAMING_SNAKE_CASE							   =set()
     _SCREAMING_SNAKE_CASE							   =42
     _SCREAMING_SNAKE_CASE							   =Fraction(0    )
     _SCREAMING_SNAKE_CASE							   =42

     for x_num in range(1							,			order + 1    ):
          for x_den in range(x_num + 1							,			order + 1    ):
               for y_num in range(1							,			order + 1    ):
                    for y_den in range(y_num + 1							,			order + 1    ):
                         # n=1
                         _SCREAMING_SNAKE_CASE							   =x_num * y_den + x_den * y_num
                         _SCREAMING_SNAKE_CASE							   =x_den * y_den
                         _SCREAMING_SNAKE_CASE							   =gcd(_UpperCamelCase							,			_UpperCamelCase    )
                         z_num //= hcf
                         z_den //= hcf
                         if 0 < z_num < z_den <= order:
                              _SCREAMING_SNAKE_CASE							   =add_three(
                                  _UpperCamelCase							,			_UpperCamelCase							,			_UpperCamelCase							,			_UpperCamelCase							,			_UpperCamelCase							,			_UpperCamelCase    )
                              unique_s.add(_UpperCamelCase    )

                         # n=2
                         _SCREAMING_SNAKE_CASE							   =(
                             x_num * x_num * y_den * y_den + x_den * x_den * y_num * y_num
                         )
                         _SCREAMING_SNAKE_CASE							   =x_den * x_den * y_den * y_den
                         if is_sq(_UpperCamelCase    ) and is_sq(_UpperCamelCase    ):
                              _SCREAMING_SNAKE_CASE							   =int(sqrt(_UpperCamelCase    )    )
                              _SCREAMING_SNAKE_CASE							   =int(sqrt(_UpperCamelCase    )    )
                              _SCREAMING_SNAKE_CASE							   =gcd(_UpperCamelCase							,			_UpperCamelCase    )
                              z_num //= hcf
                              z_den //= hcf
                              if 0 < z_num < z_den <= order:
                                   _SCREAMING_SNAKE_CASE							   =add_three(
                                       _UpperCamelCase							,			_UpperCamelCase							,			_UpperCamelCase							,			_UpperCamelCase							,			_UpperCamelCase							,			_UpperCamelCase    )
                                   unique_s.add(_UpperCamelCase    )

                    # n=-1
                         _SCREAMING_SNAKE_CASE							   =x_num * y_num
                         _SCREAMING_SNAKE_CASE							   =x_den * y_num + x_num * y_den
                         _SCREAMING_SNAKE_CASE							   =gcd(_UpperCamelCase							,			_UpperCamelCase    )
                         z_num //= hcf
                         z_den //= hcf
                         if 0 < z_num < z_den <= order:
                              _SCREAMING_SNAKE_CASE							   =add_three(
                                  _UpperCamelCase							,			_UpperCamelCase							,			_UpperCamelCase							,			_UpperCamelCase							,			_UpperCamelCase							,			_UpperCamelCase    )
                              unique_s.add(_UpperCamelCase    )

                         # n=2
                         _SCREAMING_SNAKE_CASE							   =x_num * x_num * y_num * y_num
                         _SCREAMING_SNAKE_CASE							   =(
                             x_den * x_den * y_num * y_num + x_num * x_num * y_den * y_den
                         )
                         if is_sq(_UpperCamelCase    ) and is_sq(_UpperCamelCase    ):
                              _SCREAMING_SNAKE_CASE							   =int(sqrt(_UpperCamelCase    )    )
                              _SCREAMING_SNAKE_CASE							   =int(sqrt(_UpperCamelCase    )    )
                              _SCREAMING_SNAKE_CASE							   =gcd(_UpperCamelCase							,			_UpperCamelCase    )
                              z_num //= hcf
                              z_den //= hcf
                              if 0 < z_num < z_den <= order:
                                   _SCREAMING_SNAKE_CASE							   =add_three(
                                       _UpperCamelCase							,			_UpperCamelCase							,			_UpperCamelCase							,			_UpperCamelCase							,			_UpperCamelCase							,			_UpperCamelCase    )
                                   unique_s.add(_UpperCamelCase    )

     for num, den in unique_s:
          total += Fraction(_UpperCamelCase							,			_UpperCamelCase    )

     return total.denominator + total.numerator


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