"""simple docstring"""





import gc
import random
import unittest

import numpy as np
import torch
from PIL import Image
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import AutoencoderKL, DDIMScheduler, DDPMScheduler, StableDiffusionUpscalePipeline, UNetaDConditionModel
from diffusers.utils import floats_tensor, load_image, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()
class  _snake_case     (					unittest.TestCase		):






						def       lowerCamelCase__     (       self      :			Union[str, Any]    ):
													# clean up the VRAM after each test
													super().tearDown()
													gc.collect()
													torch.cuda.empty_cache()






						@property
						def       lowerCamelCase__     (       self      :			Optional[int]    ):
													__lowerCamelCase					:		Optional[Any]		   =     1
													__lowerCamelCase					:		Optional[Any]		   =     3
													__lowerCamelCase					:		Optional[Any]		   =     (32, 32)

													__lowerCamelCase					:		Union[str, Any]		   =     floats_tensor((batch_size, num_channels) + sizes							,					rng=random.Random(0    )    ).to(UpperCAmelCase    )
													return image






						@property
						def       lowerCamelCase__     (       self      :			List[Any]    ):
													torch.manual_seed(0    )
													__lowerCamelCase					:		Union[str, Any]		   =     UNetaDConditionModel(
													    block_out_channels=(32, 32, 64)							,					layers_per_block=2							,					sample_size=32							,					in_channels=7							,					out_channels=4							,					down_block_types=("DownBlock2D", "CrossAttnDownBlock2D", "CrossAttnDownBlock2D")							,					up_block_types=("CrossAttnUpBlock2D", "CrossAttnUpBlock2D", "UpBlock2D")							,					cross_attention_dim=32							,					attention_head_dim=8							,					use_linear_projection=UpperCAmelCase							,					only_cross_attention=(True, True, False)							,					num_class_embeds=100							,					)
													return model






						@property
						def       lowerCamelCase__     (       self      :			Tuple    ):
													torch.manual_seed(0    )
													__lowerCamelCase					:		List[str]		   =     AutoencoderKL(
													    block_out_channels=[32, 32, 64]							,					in_channels=3							,					out_channels=3							,					down_block_types=["DownEncoderBlock2D", "DownEncoderBlock2D", "DownEncoderBlock2D"]							,					up_block_types=["UpDecoderBlock2D", "UpDecoderBlock2D", "UpDecoderBlock2D"]							,					latent_channels=4							,					)
													return model






						@property
						def       lowerCamelCase__     (       self      :			Dict    ):
													torch.manual_seed(0    )
													__lowerCamelCase					:		Optional[int]		   =     CLIPTextConfig(
													    bos_token_id=0							,					eos_token_id=2							,					hidden_size=32							,					intermediate_size=37							,					layer_norm_eps=1E-05							,					num_attention_heads=4							,					num_hidden_layers=5							,					pad_token_id=1							,					vocab_size=1000							,					hidden_act="gelu"							,					projection_dim=512							,					)
													return CLIPTextModel(UpperCAmelCase    )






						def       lowerCamelCase__     (       self      :			Any    ):
													__lowerCamelCase					:		Optional[Any]		   =     "cpu"  # ensure determinism for the device-dependent torch.Generator
													__lowerCamelCase					:		Any		   =     self.dummy_cond_unet_upscale
													__lowerCamelCase					:		Dict		   =     DDPMScheduler()
													__lowerCamelCase					:		Dict		   =     DDIMScheduler(prediction_type="v_prediction"    )
													__lowerCamelCase					:		str		   =     self.dummy_vae
													__lowerCamelCase					:		List[str]		   =     self.dummy_text_encoder
													__lowerCamelCase					:		Optional[int]		   =     CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"    )

													__lowerCamelCase					:		Any		   =     self.dummy_image.cpu().permute(0							,					2							,					3							,					1    )[0]
													__lowerCamelCase					:		List[Any]		   =     Image.fromarray(np.uinta(UpperCAmelCase    )    ).convert("RGB"    ).resize((64, 64)    )

													# make sure here that pndm scheduler skips prk
													__lowerCamelCase					:		Optional[Any]		   =     StableDiffusionUpscalePipeline(
													    unet=UpperCAmelCase							,					low_res_scheduler=UpperCAmelCase							,					scheduler=UpperCAmelCase							,					vae=UpperCAmelCase							,					text_encoder=UpperCAmelCase							,					tokenizer=UpperCAmelCase							,					max_noise_level=350							,					)
													__lowerCamelCase					:		Any		   =     sd_pipe.to(UpperCAmelCase    )
													sd_pipe.set_progress_bar_config(disable=UpperCAmelCase    )

													__lowerCamelCase					:		Tuple		   =     "A painting of a squirrel eating a burger"
													__lowerCamelCase					:		Dict		   =     torch.Generator(device=UpperCAmelCase    ).manual_seed(0    )
													__lowerCamelCase					:		List[str]		   =     sd_pipe(
													    [prompt]							,					image=UpperCAmelCase							,					generator=UpperCAmelCase							,					guidance_scale=6.0							,					noise_level=20							,					num_inference_steps=2							,					output_type="np"							,					)

													__lowerCamelCase					:		Union[str, Any]		   =     output.images

													__lowerCamelCase					:		Dict		   =     torch.Generator(device=UpperCAmelCase    ).manual_seed(0    )
													__lowerCamelCase					:		Any		   =     sd_pipe(
													    [prompt]							,					image=UpperCAmelCase							,					generator=UpperCAmelCase							,					guidance_scale=6.0							,					noise_level=20							,					num_inference_steps=2							,					output_type="np"							,					return_dict=UpperCAmelCase							,					)[0]

													__lowerCamelCase					:		Any		   =     image[0, -3:, -3:, -1]
													__lowerCamelCase					:		List[Any]		   =     image_from_tuple[0, -3:, -3:, -1]

													__lowerCamelCase					:		Union[str, Any]		   =     low_res_image.size[0] * 4
													assert image.shape == (1, expected_height_width, expected_height_width, 3)
													__lowerCamelCase					:		Any		   =     np.array([0.3_1_1_3, 0.3_9_1_0, 0.4_2_7_2, 0.4_8_5_9, 0.5_0_6_1, 0.4_6_5_2, 0.5_3_6_2, 0.5_7_1_5, 0.5_6_6_1]    )

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






						def       lowerCamelCase__     (       self      :			Any    ):
													__lowerCamelCase					:		Optional[int]		   =     "cpu"  # ensure determinism for the device-dependent torch.Generator
													__lowerCamelCase					:		List[Any]		   =     self.dummy_cond_unet_upscale
													__lowerCamelCase					:		List[str]		   =     DDPMScheduler()
													__lowerCamelCase					:		Optional[int]		   =     DDIMScheduler(prediction_type="v_prediction"    )
													__lowerCamelCase					:		Union[str, Any]		   =     self.dummy_vae
													__lowerCamelCase					:		str		   =     self.dummy_text_encoder
													__lowerCamelCase					:		Union[str, Any]		   =     CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"    )

													__lowerCamelCase					:		Optional[Any]		   =     self.dummy_image.cpu().permute(0							,					2							,					3							,					1    )[0]
													__lowerCamelCase					:		List[Any]		   =     Image.fromarray(np.uinta(UpperCAmelCase    )    ).convert("RGB"    ).resize((64, 64)    )

													# make sure here that pndm scheduler skips prk
													__lowerCamelCase					:		Optional[int]		   =     StableDiffusionUpscalePipeline(
													    unet=UpperCAmelCase							,					low_res_scheduler=UpperCAmelCase							,					scheduler=UpperCAmelCase							,					vae=UpperCAmelCase							,					text_encoder=UpperCAmelCase							,					tokenizer=UpperCAmelCase							,					max_noise_level=350							,					)
													__lowerCamelCase					:		Union[str, Any]		   =     sd_pipe.to(UpperCAmelCase    )
													sd_pipe.set_progress_bar_config(disable=UpperCAmelCase    )

													__lowerCamelCase					:		Any		   =     "A painting of a squirrel eating a burger"
													__lowerCamelCase					:		Optional[Any]		   =     sd_pipe(
													    2 * [prompt]							,					image=2 * [low_res_image]							,					guidance_scale=6.0							,					noise_level=20							,					num_inference_steps=2							,					output_type="np"							,					)
													__lowerCamelCase					:		List[str]		   =     output.images
													assert image.shape[0] == 2

													__lowerCamelCase					:		Union[str, Any]		   =     torch.Generator(device=UpperCAmelCase    ).manual_seed(0    )
													__lowerCamelCase					:		Any		   =     sd_pipe(
													    [prompt]							,					image=UpperCAmelCase							,					generator=UpperCAmelCase							,					num_images_per_prompt=2							,					guidance_scale=6.0							,					noise_level=20							,					num_inference_steps=2							,					output_type="np"							,					)
													__lowerCamelCase					:		Optional[Any]		   =     output.images
													assert image.shape[0] == 2







						@unittest.skipIf(torch_device != "cuda"							,					"This test requires a GPU"    )
						def       lowerCamelCase__     (       self      :			Tuple    ):
													__lowerCamelCase					:		List[Any]		   =     self.dummy_cond_unet_upscale
													__lowerCamelCase					:		str		   =     DDPMScheduler()
													__lowerCamelCase					:		Optional[Any]		   =     DDIMScheduler(prediction_type="v_prediction"    )
													__lowerCamelCase					:		Tuple		   =     self.dummy_vae
													__lowerCamelCase					:		List[str]		   =     self.dummy_text_encoder
													__lowerCamelCase					:		List[str]		   =     CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"    )

													__lowerCamelCase					:		List[Any]		   =     self.dummy_image.cpu().permute(0							,					2							,					3							,					1    )[0]
													__lowerCamelCase					:		int		   =     Image.fromarray(np.uinta(UpperCAmelCase    )    ).convert("RGB"    ).resize((64, 64)    )

													# put models in fp16, except vae as it overflows in fp16
													__lowerCamelCase					:		int		   =     unet.half()
													__lowerCamelCase					:		Any		   =     text_encoder.half()

													# make sure here that pndm scheduler skips prk
													__lowerCamelCase					:		Tuple		   =     StableDiffusionUpscalePipeline(
													    unet=UpperCAmelCase							,					low_res_scheduler=UpperCAmelCase							,					scheduler=UpperCAmelCase							,					vae=UpperCAmelCase							,					text_encoder=UpperCAmelCase							,					tokenizer=UpperCAmelCase							,					max_noise_level=350							,					)
													__lowerCamelCase					:		List[Any]		   =     sd_pipe.to(UpperCAmelCase    )
													sd_pipe.set_progress_bar_config(disable=UpperCAmelCase    )

													__lowerCamelCase					:		List[str]		   =     "A painting of a squirrel eating a burger"
													__lowerCamelCase					:		Any		   =     torch.manual_seed(0    )
													__lowerCamelCase					:		Tuple		   =     sd_pipe(
													    [prompt]							,					image=UpperCAmelCase							,					generator=UpperCAmelCase							,					num_inference_steps=2							,					output_type="np"							,					).images

													__lowerCamelCase					:		Union[str, Any]		   =     low_res_image.size[0] * 4
													assert image.shape == (1, expected_height_width, expected_height_width, 3)

@slow
@require_torch_gpu
class  _snake_case     (					unittest.TestCase		):






						def       lowerCamelCase__     (       self      :			Optional[int]    ):
													# clean up the VRAM after each test
													super().tearDown()
													gc.collect()
													torch.cuda.empty_cache()






						def       lowerCamelCase__     (       self      :			Union[str, Any]    ):
													__lowerCamelCase					:		List[Any]		   =     load_image(
													    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
													    "/sd2-upscale/low_res_cat.png"    )
													__lowerCamelCase					:		Optional[int]		   =     load_numpy(
													    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-upscale"
													    "/upsampled_cat.npy"    )

													__lowerCamelCase					:		Dict		   =     "stabilityai/stable-diffusion-x4-upscaler"
													__lowerCamelCase					:		Union[str, Any]		   =     StableDiffusionUpscalePipeline.from_pretrained(UpperCAmelCase    )
													pipe.to(UpperCAmelCase    )
													pipe.set_progress_bar_config(disable=UpperCAmelCase    )
													pipe.enable_attention_slicing()

													__lowerCamelCase					:		Optional[Any]		   =     "a cat sitting on a park bench"

													__lowerCamelCase					:		int		   =     torch.manual_seed(0    )
													__lowerCamelCase					:		Optional[int]		   =     pipe(
													    prompt=UpperCAmelCase							,					image=UpperCAmelCase							,					generator=UpperCAmelCase							,					output_type="np"							,					)
													__lowerCamelCase					:		List[str]		   =     output.images[0]

													assert image.shape == (512, 512, 3)
													assert np.abs(expected_image - image    ).max() < 1E-3






						def       lowerCamelCase__     (       self      :			Union[str, Any]    ):
													__lowerCamelCase					:		List[str]		   =     load_image(
													    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
													    "/sd2-upscale/low_res_cat.png"    )
													__lowerCamelCase					:		int		   =     load_numpy(
													    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-upscale"
													    "/upsampled_cat_fp16.npy"    )

													__lowerCamelCase					:		Any		   =     "stabilityai/stable-diffusion-x4-upscaler"
													__lowerCamelCase					:		List[str]		   =     StableDiffusionUpscalePipeline.from_pretrained(
													    UpperCAmelCase							,					torch_dtype=torch.floataa							,					)
													pipe.to(UpperCAmelCase    )
													pipe.set_progress_bar_config(disable=UpperCAmelCase    )
													pipe.enable_attention_slicing()

													__lowerCamelCase					:		int		   =     "a cat sitting on a park bench"

													__lowerCamelCase					:		List[Any]		   =     torch.manual_seed(0    )
													__lowerCamelCase					:		List[Any]		   =     pipe(
													    prompt=UpperCAmelCase							,					image=UpperCAmelCase							,					generator=UpperCAmelCase							,					output_type="np"							,					)
													__lowerCamelCase					:		Tuple		   =     output.images[0]

													assert image.shape == (512, 512, 3)
													assert np.abs(expected_image - image    ).max() < 5E-1







						def       lowerCamelCase__     (       self      :			Union[str, Any]    ):
													torch.cuda.empty_cache()
													torch.cuda.reset_max_memory_allocated()
													torch.cuda.reset_peak_memory_stats()

													__lowerCamelCase					:		Tuple		   =     load_image(
													    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
													    "/sd2-upscale/low_res_cat.png"    )

													__lowerCamelCase					:		List[Any]		   =     "stabilityai/stable-diffusion-x4-upscaler"
													__lowerCamelCase					:		Tuple		   =     StableDiffusionUpscalePipeline.from_pretrained(
													    UpperCAmelCase							,					torch_dtype=torch.floataa							,					)
													pipe.to(UpperCAmelCase    )
													pipe.set_progress_bar_config(disable=UpperCAmelCase    )
													pipe.enable_attention_slicing(1    )
													pipe.enable_sequential_cpu_offload()

													__lowerCamelCase					:		Optional[int]		   =     "a cat sitting on a park bench"

													__lowerCamelCase					:		Any		   =     torch.manual_seed(0    )
													__lowerCamelCase					:		List[Any]		   =     pipe(
													    prompt=UpperCAmelCase							,					image=UpperCAmelCase							,					generator=UpperCAmelCase							,					num_inference_steps=5							,					output_type="np"							,					)

													__lowerCamelCase					:		str		   =     torch.cuda.max_memory_allocated()
													# make sure that less than 2.9 GB is allocated
													assert mem_bytes < 2.9 * 10**9
"""simple docstring"""





from functools import lru_cache


def    lowercase_   (   _lowerCamelCase:	int      ) ->      set:



							'''simple docstring'''

							__lowerCamelCase					:		Optional[Any]		   =     2
							__lowerCamelCase					:		Tuple		   =     set()
							while i * i <= n:
														if n % i:
																					i += 1
														else:
																					n //= i
																					factors.add(_lowerCamelCase      )
							if n > 1:
														factors.add(_lowerCamelCase      )
							return factors


@lru_cache
def    lowercase_   (   _lowerCamelCase:	int      ) ->      int:



							'''simple docstring'''

							return len(unique_prime_factors(_lowerCamelCase      )      )


def    lowercase_   (   _lowerCamelCase:	list      ) ->      bool:



							'''simple docstring'''

							return len(set(_lowerCamelCase      )      ) in (0, 1)


def    lowercase_   (   _lowerCamelCase:	int      ) ->      list:



							'''simple docstring'''

							__lowerCamelCase					:		str		   =     2

							while True:
														# Increment each value of a generated range
														__lowerCamelCase					:		int		   =     [base + i for i in range(_lowerCamelCase      )]

														# Run elements through out unique_prime_factors function
														# Append our target number to the end.
														__lowerCamelCase					:		Dict		   =     [upf_len(_lowerCamelCase      ) for x in group]
														checker.append(_lowerCamelCase      )

														# If all numbers in the list are equal, return the group variable.
														if equality(_lowerCamelCase      ):
																					return group

														# Increment our base variable by 1
														base += 1


def    lowercase_   (   _lowerCamelCase:	int = 4      ) ->      int:



							'''simple docstring'''

							__lowerCamelCase					:		Any		   =     run(_lowerCamelCase      )
							return results[0] if len(_lowerCamelCase      ) else None


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