





from typing import Any, Callable, Dict, List, Optional, Union

import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker


A   : Optional[int]			=				'''CompVis/stable-diffusion-v1-1'''
A   : Optional[int]			=				'''CompVis/stable-diffusion-v1-2'''
A   : str			=				'''CompVis/stable-diffusion-v1-3'''
A   : Optional[int]			=				'''CompVis/stable-diffusion-v1-4'''


class   A      (SCREAMING_SNAKE_CASE   ):
			'''simple docstring'''




			def __init__(      self       :   List[str]							,     __lowerCAmelCase       :   AutoencoderKL							,     __lowerCAmelCase       :   CLIPTextModel							,     __lowerCAmelCase       :   CLIPTokenizer							,     __lowerCAmelCase       :   UNetaDConditionModel							,     __lowerCAmelCase       :   Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]							,     __lowerCAmelCase       :   StableDiffusionSafetyChecker							,     __lowerCAmelCase       :   CLIPImageProcessor							,     __lowerCAmelCase       :   bool = True							,     )     ->     Tuple:







					"""simple docstring"""






					super()._init_()

					A__  				=       StableDiffusionPipeline.from_pretrained(__lowerCAmelCase       )
					A__  				=       StableDiffusionPipeline.from_pretrained(__lowerCAmelCase       )
					A__  				=       StableDiffusionPipeline.from_pretrained(__lowerCAmelCase       )
					A__  				=       StableDiffusionPipeline(
					    vae=__lowerCAmelCase							,     text_encoder=__lowerCAmelCase							,     tokenizer=__lowerCAmelCase							,     unet=__lowerCAmelCase							,     scheduler=__lowerCAmelCase							,     safety_checker=__lowerCAmelCase							,     feature_extractor=__lowerCAmelCase							,     requires_safety_checker=__lowerCAmelCase							,     )

					self.register_modules(pipelinea=self.pipea							,     pipelinea=self.pipea							,     pipelinea=self.pipea							,     pipelinea=self.pipea       )






			@property
			def        a_	(      self       :   Optional[Any]       )     ->     Dict[str, Any]:







					"""simple docstring"""






					return {k: getattr(self							,     __lowerCAmelCase       ) for k in self.config.keys() if not k.startswith("""_"""       )}






			def        a_	(      self       :   Any							,     __lowerCAmelCase       :   Optional[Union[str, int]] = "auto"       )     ->     List[Any]:







					"""simple docstring"""






					if slice_size == "auto":
							# half the attention head size is usually a good trade-off between
							# speed and memory
							A__  				=       self.unet.config.attention_head_dim // 2
					self.unet.set_attention_slice(__lowerCAmelCase       )






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







					"""simple docstring"""






					self.enable_attention_slicing(__lowerCAmelCase       )






			@torch.no_grad()
			def        a_	(      self       :   Union[str, Any]							,     __lowerCAmelCase       :   Union[str, List[str]]							,     __lowerCAmelCase       :   int = 5_12							,     __lowerCAmelCase       :   int = 5_12							,     __lowerCAmelCase       :   int = 50							,     __lowerCAmelCase       :   float = 7.5							,     __lowerCAmelCase       :   Optional[Union[str, List[str]]] = None							,     __lowerCAmelCase       :   Optional[int] = 1							,     __lowerCAmelCase       :   float = 0.0							,     __lowerCAmelCase       :   Optional[torch.Generator] = None							,     __lowerCAmelCase       :   Optional[torch.FloatTensor] = None							,     __lowerCAmelCase       :   Optional[str] = "pil"							,     __lowerCAmelCase       :   bool = True							,     __lowerCAmelCase       :   Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,     __lowerCAmelCase       :   int = 1							,     **__lowerCAmelCase       :   Dict							,     )     ->     Any:







					"""simple docstring"""






					return self.pipea(
					    prompt=__lowerCAmelCase							,     height=__lowerCAmelCase							,     width=__lowerCAmelCase							,     num_inference_steps=__lowerCAmelCase							,     guidance_scale=__lowerCAmelCase							,     negative_prompt=__lowerCAmelCase							,     num_images_per_prompt=__lowerCAmelCase							,     eta=__lowerCAmelCase							,     generator=__lowerCAmelCase							,     latents=__lowerCAmelCase							,     output_type=__lowerCAmelCase							,     return_dict=__lowerCAmelCase							,     callback=__lowerCAmelCase							,     callback_steps=__lowerCAmelCase							,     **__lowerCAmelCase							,     )






			@torch.no_grad()
			def        a_	(      self       :   Tuple							,     __lowerCAmelCase       :   Union[str, List[str]]							,     __lowerCAmelCase       :   int = 5_12							,     __lowerCAmelCase       :   int = 5_12							,     __lowerCAmelCase       :   int = 50							,     __lowerCAmelCase       :   float = 7.5							,     __lowerCAmelCase       :   Optional[Union[str, List[str]]] = None							,     __lowerCAmelCase       :   Optional[int] = 1							,     __lowerCAmelCase       :   float = 0.0							,     __lowerCAmelCase       :   Optional[torch.Generator] = None							,     __lowerCAmelCase       :   Optional[torch.FloatTensor] = None							,     __lowerCAmelCase       :   Optional[str] = "pil"							,     __lowerCAmelCase       :   bool = True							,     __lowerCAmelCase       :   Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,     __lowerCAmelCase       :   int = 1							,     **__lowerCAmelCase       :   int							,     )     ->     Tuple:







					"""simple docstring"""






					return self.pipea(
					    prompt=__lowerCAmelCase							,     height=__lowerCAmelCase							,     width=__lowerCAmelCase							,     num_inference_steps=__lowerCAmelCase							,     guidance_scale=__lowerCAmelCase							,     negative_prompt=__lowerCAmelCase							,     num_images_per_prompt=__lowerCAmelCase							,     eta=__lowerCAmelCase							,     generator=__lowerCAmelCase							,     latents=__lowerCAmelCase							,     output_type=__lowerCAmelCase							,     return_dict=__lowerCAmelCase							,     callback=__lowerCAmelCase							,     callback_steps=__lowerCAmelCase							,     **__lowerCAmelCase							,     )






			@torch.no_grad()
			def        a_	(      self       :   Union[str, Any]							,     __lowerCAmelCase       :   Union[str, List[str]]							,     __lowerCAmelCase       :   int = 5_12							,     __lowerCAmelCase       :   int = 5_12							,     __lowerCAmelCase       :   int = 50							,     __lowerCAmelCase       :   float = 7.5							,     __lowerCAmelCase       :   Optional[Union[str, List[str]]] = None							,     __lowerCAmelCase       :   Optional[int] = 1							,     __lowerCAmelCase       :   float = 0.0							,     __lowerCAmelCase       :   Optional[torch.Generator] = None							,     __lowerCAmelCase       :   Optional[torch.FloatTensor] = None							,     __lowerCAmelCase       :   Optional[str] = "pil"							,     __lowerCAmelCase       :   bool = True							,     __lowerCAmelCase       :   Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,     __lowerCAmelCase       :   int = 1							,     **__lowerCAmelCase       :   Optional[Any]							,     )     ->     Optional[Any]:







					"""simple docstring"""






					return self.pipea(
					    prompt=__lowerCAmelCase							,     height=__lowerCAmelCase							,     width=__lowerCAmelCase							,     num_inference_steps=__lowerCAmelCase							,     guidance_scale=__lowerCAmelCase							,     negative_prompt=__lowerCAmelCase							,     num_images_per_prompt=__lowerCAmelCase							,     eta=__lowerCAmelCase							,     generator=__lowerCAmelCase							,     latents=__lowerCAmelCase							,     output_type=__lowerCAmelCase							,     return_dict=__lowerCAmelCase							,     callback=__lowerCAmelCase							,     callback_steps=__lowerCAmelCase							,     **__lowerCAmelCase							,     )






			@torch.no_grad()
			def        a_	(      self       :   List[str]							,     __lowerCAmelCase       :   Union[str, List[str]]							,     __lowerCAmelCase       :   int = 5_12							,     __lowerCAmelCase       :   int = 5_12							,     __lowerCAmelCase       :   int = 50							,     __lowerCAmelCase       :   float = 7.5							,     __lowerCAmelCase       :   Optional[Union[str, List[str]]] = None							,     __lowerCAmelCase       :   Optional[int] = 1							,     __lowerCAmelCase       :   float = 0.0							,     __lowerCAmelCase       :   Optional[torch.Generator] = None							,     __lowerCAmelCase       :   Optional[torch.FloatTensor] = None							,     __lowerCAmelCase       :   Optional[str] = "pil"							,     __lowerCAmelCase       :   bool = True							,     __lowerCAmelCase       :   Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,     __lowerCAmelCase       :   int = 1							,     **__lowerCAmelCase       :   Tuple							,     )     ->     List[str]:







					"""simple docstring"""






					return self.pipea(
					    prompt=__lowerCAmelCase							,     height=__lowerCAmelCase							,     width=__lowerCAmelCase							,     num_inference_steps=__lowerCAmelCase							,     guidance_scale=__lowerCAmelCase							,     negative_prompt=__lowerCAmelCase							,     num_images_per_prompt=__lowerCAmelCase							,     eta=__lowerCAmelCase							,     generator=__lowerCAmelCase							,     latents=__lowerCAmelCase							,     output_type=__lowerCAmelCase							,     return_dict=__lowerCAmelCase							,     callback=__lowerCAmelCase							,     callback_steps=__lowerCAmelCase							,     **__lowerCAmelCase							,     )







			@torch.no_grad()
			def        a_	(      self       :   int							,     __lowerCAmelCase       :   Union[str, List[str]]							,     __lowerCAmelCase       :   int = 5_12							,     __lowerCAmelCase       :   int = 5_12							,     __lowerCAmelCase       :   int = 50							,     __lowerCAmelCase       :   float = 7.5							,     __lowerCAmelCase       :   Optional[Union[str, List[str]]] = None							,     __lowerCAmelCase       :   Optional[int] = 1							,     __lowerCAmelCase       :   float = 0.0							,     __lowerCAmelCase       :   Optional[torch.Generator] = None							,     __lowerCAmelCase       :   Optional[torch.FloatTensor] = None							,     __lowerCAmelCase       :   Optional[str] = "pil"							,     __lowerCAmelCase       :   bool = True							,     __lowerCAmelCase       :   Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,     __lowerCAmelCase       :   int = 1							,     **__lowerCAmelCase       :   Optional[int]							,     )     ->     Optional[int]:







					"""simple docstring"""






					A__  				=       """cuda""" if torch.cuda.is_available() else """cpu"""
					self.to(__lowerCAmelCase       )

					# Checks if the height and width are divisible by 8 or not
					if height % 8 != 0 or width % 8 != 0:
							raise ValueError(f'`height` and `width` must be divisible by 8 but are {height} and {width}.'       )

					# Get first result from Stable Diffusion Checkpoint v1.1
					A__  				=       self.textaimg_sda_a(
					    prompt=__lowerCAmelCase							,     height=__lowerCAmelCase							,     width=__lowerCAmelCase							,     num_inference_steps=__lowerCAmelCase							,     guidance_scale=__lowerCAmelCase							,     negative_prompt=__lowerCAmelCase							,     num_images_per_prompt=__lowerCAmelCase							,     eta=__lowerCAmelCase							,     generator=__lowerCAmelCase							,     latents=__lowerCAmelCase							,     output_type=__lowerCAmelCase							,     return_dict=__lowerCAmelCase							,     callback=__lowerCAmelCase							,     callback_steps=__lowerCAmelCase							,     **__lowerCAmelCase							,     )

					# Get first result from Stable Diffusion Checkpoint v1.2
					A__  				=       self.textaimg_sda_a(
					    prompt=__lowerCAmelCase							,     height=__lowerCAmelCase							,     width=__lowerCAmelCase							,     num_inference_steps=__lowerCAmelCase							,     guidance_scale=__lowerCAmelCase							,     negative_prompt=__lowerCAmelCase							,     num_images_per_prompt=__lowerCAmelCase							,     eta=__lowerCAmelCase							,     generator=__lowerCAmelCase							,     latents=__lowerCAmelCase							,     output_type=__lowerCAmelCase							,     return_dict=__lowerCAmelCase							,     callback=__lowerCAmelCase							,     callback_steps=__lowerCAmelCase							,     **__lowerCAmelCase							,     )

					# Get first result from Stable Diffusion Checkpoint v1.3
					A__  				=       self.textaimg_sda_a(
					    prompt=__lowerCAmelCase							,     height=__lowerCAmelCase							,     width=__lowerCAmelCase							,     num_inference_steps=__lowerCAmelCase							,     guidance_scale=__lowerCAmelCase							,     negative_prompt=__lowerCAmelCase							,     num_images_per_prompt=__lowerCAmelCase							,     eta=__lowerCAmelCase							,     generator=__lowerCAmelCase							,     latents=__lowerCAmelCase							,     output_type=__lowerCAmelCase							,     return_dict=__lowerCAmelCase							,     callback=__lowerCAmelCase							,     callback_steps=__lowerCAmelCase							,     **__lowerCAmelCase							,     )

					# Get first result from Stable Diffusion Checkpoint v1.4
					A__  				=       self.textaimg_sda_a(
					    prompt=__lowerCAmelCase							,     height=__lowerCAmelCase							,     width=__lowerCAmelCase							,     num_inference_steps=__lowerCAmelCase							,     guidance_scale=__lowerCAmelCase							,     negative_prompt=__lowerCAmelCase							,     num_images_per_prompt=__lowerCAmelCase							,     eta=__lowerCAmelCase							,     generator=__lowerCAmelCase							,     latents=__lowerCAmelCase							,     output_type=__lowerCAmelCase							,     return_dict=__lowerCAmelCase							,     callback=__lowerCAmelCase							,     callback_steps=__lowerCAmelCase							,     **__lowerCAmelCase							,     )

					# Get all result images into a single list and pass it via StableDiffusionPipelineOutput for final result
					return StableDiffusionPipelineOutput([resa[0], resa[0], resa[0], resa[0]]       )










import math







def        __lowerCamelCase (							__a       :int   )		->    bool:






		"""simple docstring"""

		A__  				=       math.loga(math.sqrt(4 * positive_integer + 1   ) / 2 + 1 / 2   )

		return exponent == int(__a   )







def        __lowerCamelCase (							__a       :float = 1 / 1_2_3_4_5   )		->    int:






		"""simple docstring"""

		A__  				=       0
		A__  				=       0

		A__  				=       3
		while True:
				A__  				=       (integer**2 - 1) / 4
				# if candidate is an integer, then there is a partition for k
				if partition_candidate == int(__a   ):
						A__  				=       int(__a   )
						total_partitions += 1
						if check_partition_perfect(__a   ):
								perfect_partitions += 1
				if perfect_partitions > 0:
						if perfect_partitions / total_partitions < max_proportion:
								return int(__a   )
				integer += 1


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



