import gc
import unittest

import numpy as np
import torch

from diffusers import StableDiffusionKDiffusionPipeline
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()
@slow
@require_torch_gpu
class      __lowercase					(    unittest.TestCase    ):

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


									'''simple docstring'''

									super().tearDown()
									gc.collect()
									torch.cuda.empty_cache()

						def        __a		(	self				:      Any   )							->		Tuple:


									'''simple docstring'''

									lowercase							=		StableDiffusionKDiffusionPipeline.from_pretrained('''CompVis/stable-diffusion-v1-4'''   )
									lowercase							=		sd_pipe.to(__A   )
									sd_pipe.set_progress_bar_config(disable=__A   )

									sd_pipe.set_scheduler('''sample_euler'''   )

									lowercase							=		'''A painting of a squirrel eating a burger'''
									lowercase							=		torch.manual_seed(0   )
									lowercase							=		sd_pipe([prompt]							,							generator=__A							,							guidance_scale=9.0							,							num_inference_steps=20							,							output_type='''np'''   )

									lowercase							=		output.images

									lowercase							=		image[0, -3:, -3:, -1]

									assert image.shape == (1, 5_12, 5_12, 3)
									lowercase							=		np.array([0.0447, 0.0492, 0.0468, 0.0408, 0.0383, 0.0408, 0.0354, 0.0380, 0.0339]   )

									assert np.abs(image_slice.flatten() - expected_slice   ).max() < 1E-2

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


									'''simple docstring'''

									lowercase							=		StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''   )
									lowercase							=		sd_pipe.to(__A   )
									sd_pipe.set_progress_bar_config(disable=__A   )

									sd_pipe.set_scheduler('''sample_euler'''   )

									lowercase							=		'''A painting of a squirrel eating a burger'''
									lowercase							=		torch.manual_seed(0   )
									lowercase							=		sd_pipe([prompt]							,							generator=__A							,							guidance_scale=9.0							,							num_inference_steps=20							,							output_type='''np'''   )

									lowercase							=		output.images

									lowercase							=		image[0, -3:, -3:, -1]

									assert image.shape == (1, 5_12, 5_12, 3)
									lowercase							=		np.array([0.1237, 0.1320, 0.1438, 0.1359, 0.1390, 0.1132, 0.1277, 0.1175, 0.1112]   )

									assert np.abs(image_slice.flatten() - expected_slice   ).max() < 5E-1



						def        __a		(	self				:      Tuple   )							->		int:


									'''simple docstring'''

									lowercase							=		StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''   )
									lowercase							=		sd_pipe.to(__A   )
									sd_pipe.set_progress_bar_config(disable=__A   )

									sd_pipe.set_scheduler('''sample_dpmpp_2m'''   )

									lowercase							=		'''A painting of a squirrel eating a burger'''
									lowercase							=		torch.manual_seed(0   )
									lowercase							=		sd_pipe(
									    [prompt]							,							generator=__A							,							guidance_scale=7.5							,							num_inference_steps=15							,							output_type='''np'''							,							use_karras_sigmas=__A							,							)

									lowercase							=		output.images

									lowercase							=		image[0, -3:, -3:, -1]

									assert image.shape == (1, 5_12, 5_12, 3)
									lowercase							=		np.array(
									    [0.1138_1689, 0.1211_2921, 0.138_9457, 0.1254_9606, 0.124_4964, 0.1083_1517, 0.1156_2866, 0.1086_7816, 0.1049_9048]   )

									assert np.abs(image_slice.flatten() - expected_slice   ).max() < 1E-2






from __future__ import annotations

from fractions import Fraction
from math import gcd, sqrt






def        __UpperCAmelCase    (       UpperCAmelCase       )->       bool:



			"""simple docstring"""







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






def        __UpperCAmelCase    (       UpperCAmelCase,		UpperCAmelCase,		UpperCAmelCase,		UpperCAmelCase,		UpperCAmelCase,		UpperCAmelCase       )->       tuple[int, int]:



			"""simple docstring"""







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






def        __UpperCAmelCase    (       UpperCAmelCase = 35       )->       int:



			"""simple docstring"""







			lowercase							=		set()
			lowercase							=		42
			lowercase							=		Fraction(0       )
			lowercase							=		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
															lowercase							=		x_num * y_den + x_den * y_num
															lowercase							=		x_den * y_den
															lowercase							=		gcd(UpperCAmelCase,		UpperCAmelCase       )
															z_num //= hcf
															z_den //= hcf
															if 0 < z_num < z_den <= order:
																		lowercase							=		add_three(
																		    UpperCAmelCase,		UpperCAmelCase,		UpperCAmelCase,		UpperCAmelCase,		UpperCAmelCase,		UpperCAmelCase       )
																		unique_s.add(UpperCAmelCase       )

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

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

															# n=2
															lowercase							=		x_num * x_num * y_num * y_num
															lowercase							=		(
															    x_den * x_den * y_num * y_num + x_num * x_num * y_den * y_den
															)
															if is_sq(UpperCAmelCase       ) and is_sq(UpperCAmelCase       ):
																		lowercase							=		int(sqrt(UpperCAmelCase       )       )
																		lowercase							=		int(sqrt(UpperCAmelCase       )       )
																		lowercase							=		gcd(UpperCAmelCase,		UpperCAmelCase       )
																		z_num //= hcf
																		z_den //= hcf
																		if 0 < z_num < z_den <= order:
																					lowercase							=		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() = }")





