




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


UpperCamelCase__ :   str						=							'''CompVis/stable-diffusion-v1-1'''
UpperCamelCase__ :   Optional[Any]						=							'''CompVis/stable-diffusion-v1-2'''
UpperCamelCase__ :   Optional[int]						=							'''CompVis/stable-diffusion-v1-3'''
UpperCamelCase__ :   Union[str, Any]						=							'''CompVis/stable-diffusion-v1-4'''







class 				lowerCAmelCase_       (					lowerCamelCase_							):






				def __init__(			self      ,snake_case__      ,snake_case__      ,snake_case__      ,snake_case__      ,snake_case__      ,snake_case__      ,snake_case__      ,snake_case__ = True      ,):
							super()._init_()

							SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      StableDiffusionPipeline.from_pretrained(snake_case__ )
							SCREAMING_SNAKE_CASE_   : str					  =      StableDiffusionPipeline.from_pretrained(snake_case__ )
							SCREAMING_SNAKE_CASE_   : Dict					  =      StableDiffusionPipeline.from_pretrained(snake_case__ )
							SCREAMING_SNAKE_CASE_   : Tuple					  =      StableDiffusionPipeline(
							    vae=snake_case__      ,text_encoder=snake_case__      ,tokenizer=snake_case__      ,unet=snake_case__      ,scheduler=snake_case__      ,safety_checker=snake_case__      ,feature_extractor=snake_case__      ,requires_safety_checker=snake_case__      ,)

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






				@property
				def 		snake_case	(			self ):
							return {k: getattr(self      ,snake_case__ ) for k in self.config.keys() if not k.startswith('_' )}






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






				def 		snake_case	(			self ):
							self.enable_attention_slicing(snake_case__ )






				@torch.no_grad()
				def 		snake_case	(			self      ,snake_case__      ,snake_case__ = 512      ,snake_case__ = 512      ,snake_case__ = 50      ,snake_case__ = 7.5      ,snake_case__ = None      ,snake_case__ = 1      ,snake_case__ = 0.0      ,snake_case__ = None      ,snake_case__ = None      ,snake_case__ = "pil"      ,snake_case__ = True      ,snake_case__ = None      ,snake_case__ = 1      ,**snake_case__      ,):
							return self.pipea(
							    prompt=snake_case__      ,height=snake_case__      ,width=snake_case__      ,num_inference_steps=snake_case__      ,guidance_scale=snake_case__      ,negative_prompt=snake_case__      ,num_images_per_prompt=snake_case__      ,eta=snake_case__      ,generator=snake_case__      ,latents=snake_case__      ,output_type=snake_case__      ,return_dict=snake_case__      ,callback=snake_case__      ,callback_steps=snake_case__      ,**snake_case__      ,)






				@torch.no_grad()
				def 		snake_case	(			self      ,snake_case__      ,snake_case__ = 512      ,snake_case__ = 512      ,snake_case__ = 50      ,snake_case__ = 7.5      ,snake_case__ = None      ,snake_case__ = 1      ,snake_case__ = 0.0      ,snake_case__ = None      ,snake_case__ = None      ,snake_case__ = "pil"      ,snake_case__ = True      ,snake_case__ = None      ,snake_case__ = 1      ,**snake_case__      ,):
							return self.pipea(
							    prompt=snake_case__      ,height=snake_case__      ,width=snake_case__      ,num_inference_steps=snake_case__      ,guidance_scale=snake_case__      ,negative_prompt=snake_case__      ,num_images_per_prompt=snake_case__      ,eta=snake_case__      ,generator=snake_case__      ,latents=snake_case__      ,output_type=snake_case__      ,return_dict=snake_case__      ,callback=snake_case__      ,callback_steps=snake_case__      ,**snake_case__      ,)






				@torch.no_grad()
				def 		snake_case	(			self      ,snake_case__      ,snake_case__ = 512      ,snake_case__ = 512      ,snake_case__ = 50      ,snake_case__ = 7.5      ,snake_case__ = None      ,snake_case__ = 1      ,snake_case__ = 0.0      ,snake_case__ = None      ,snake_case__ = None      ,snake_case__ = "pil"      ,snake_case__ = True      ,snake_case__ = None      ,snake_case__ = 1      ,**snake_case__      ,):
							return self.pipea(
							    prompt=snake_case__      ,height=snake_case__      ,width=snake_case__      ,num_inference_steps=snake_case__      ,guidance_scale=snake_case__      ,negative_prompt=snake_case__      ,num_images_per_prompt=snake_case__      ,eta=snake_case__      ,generator=snake_case__      ,latents=snake_case__      ,output_type=snake_case__      ,return_dict=snake_case__      ,callback=snake_case__      ,callback_steps=snake_case__      ,**snake_case__      ,)






				@torch.no_grad()
				def 		snake_case	(			self      ,snake_case__      ,snake_case__ = 512      ,snake_case__ = 512      ,snake_case__ = 50      ,snake_case__ = 7.5      ,snake_case__ = None      ,snake_case__ = 1      ,snake_case__ = 0.0      ,snake_case__ = None      ,snake_case__ = None      ,snake_case__ = "pil"      ,snake_case__ = True      ,snake_case__ = None      ,snake_case__ = 1      ,**snake_case__      ,):
							return self.pipea(
							    prompt=snake_case__      ,height=snake_case__      ,width=snake_case__      ,num_inference_steps=snake_case__      ,guidance_scale=snake_case__      ,negative_prompt=snake_case__      ,num_images_per_prompt=snake_case__      ,eta=snake_case__      ,generator=snake_case__      ,latents=snake_case__      ,output_type=snake_case__      ,return_dict=snake_case__      ,callback=snake_case__      ,callback_steps=snake_case__      ,**snake_case__      ,)






				@torch.no_grad()
				def 		snake_case	(			self      ,snake_case__      ,snake_case__ = 512      ,snake_case__ = 512      ,snake_case__ = 50      ,snake_case__ = 7.5      ,snake_case__ = None      ,snake_case__ = 1      ,snake_case__ = 0.0      ,snake_case__ = None      ,snake_case__ = None      ,snake_case__ = "pil"      ,snake_case__ = True      ,snake_case__ = None      ,snake_case__ = 1      ,**snake_case__      ,):
							SCREAMING_SNAKE_CASE_   : Optional[int]					  =      'cuda' if torch.cuda.is_available() else 'cpu'
							self.to(snake_case__ )

							# 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
							SCREAMING_SNAKE_CASE_   : Any					  =      self.textaimg_sda_a(
							    prompt=snake_case__      ,height=snake_case__      ,width=snake_case__      ,num_inference_steps=snake_case__      ,guidance_scale=snake_case__      ,negative_prompt=snake_case__      ,num_images_per_prompt=snake_case__      ,eta=snake_case__      ,generator=snake_case__      ,latents=snake_case__      ,output_type=snake_case__      ,return_dict=snake_case__      ,callback=snake_case__      ,callback_steps=snake_case__      ,**snake_case__      ,)

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

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

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

							# 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]] )








'''simple docstring'''





import functools

def 			a_	(				_lowerCAmelCase			,_lowerCAmelCase			) -> int:

  # Validation
  if not isinstance(_lowerCAmelCase			,_lowerCAmelCase			) or not all(isinstance(_lowerCAmelCase			,_lowerCAmelCase			) for day in days			):
    raise ValueError('The parameter days should be a list of integers'			)

  if len(_lowerCAmelCase			) != 3 or not all(isinstance(_lowerCAmelCase			,_lowerCAmelCase			) for cost in costs			):
    raise ValueError('The parameter costs should be a list of three integers'			)

  if len(_lowerCAmelCase			) == 0:
    return 0

  if min(_lowerCAmelCase			) <= 0:
    raise ValueError('All days elements should be greater than 0'			)

  if max(_lowerCAmelCase			) >= 366:
    raise ValueError('All days elements should be less than 366'			)

  __lowerCamelCase			:			int       			=					set(_lowerCAmelCase			)

  @functools.cache
  def dynamic_programming(_lowerCAmelCase			) -> int:
    if index > 365:
      return 0

    if index not in days_set:
      return dynamic_programming(index + 1			)

    return min(
        costs[0] + dynamic_programming(index + 1			)			,costs[1] + dynamic_programming(index + 7			)			,costs[2] + dynamic_programming(index + 30			)			,)

  return dynamic_programming(1			)


if __name__ == "__main__":
   import doctest

   doctest.testmod()






