


from __future__ import annotations

from queue import Queue

def       _a	(					SCREAMING_SNAKE_CASE						:					int     ,			SCREAMING_SNAKE_CASE						:					int  ):







 """simple docstring"""



 a ^= b
 b ^= a
 a ^= b
 return a, b

def       _a	(					SCREAMING_SNAKE_CASE						:					int     ,			SCREAMING_SNAKE_CASE						:					list[list[int]]  ):







 """simple docstring"""



 UpperCamelCase__       :     str 							= 1
 while (1 << j) < max_node:
  for i in range(1     ,			max_node + 1  ):
   UpperCamelCase__       :     Dict 							= parent[j - 1][parent[j - 1][i]]
  j += 1
 return parent

def       _a	(					SCREAMING_SNAKE_CASE						:					int     ,			SCREAMING_SNAKE_CASE						:					int     ,			SCREAMING_SNAKE_CASE						:					list[int]     ,			SCREAMING_SNAKE_CASE						:					list[list[int]]  ):







 """simple docstring"""



 if level[u] < level[v]:
  UpperCamelCase__							,					UpperCamelCase__       :     List[Any] 							= swap(SCREAMING_SNAKE_CASE     ,			SCREAMING_SNAKE_CASE  )
 # making depth of u same as depth of v
 for i in range(18     ,			-1     ,			-1  ):
  if level[u] - (1 << i) >= level[v]:
   UpperCamelCase__       :     Dict 							= parent[i][u]
    # at the same depth if u==v that mean lca is found
 if u == v:
  return u
 # moving both nodes upwards till lca in found
 for i in range(18     ,			-1     ,			-1  ):
  if parent[i][u] not in [0, parent[i][v]]:
   UpperCamelCase__							,					UpperCamelCase__       :     Union[str, Any] 							= parent[i][u], parent[i][v]
    # returning longest common ancestor of u,v
 return parent[0][u]

def       _a	(					SCREAMING_SNAKE_CASE						:					list[int]     ,			SCREAMING_SNAKE_CASE						:					list[list[int]]     ,			SCREAMING_SNAKE_CASE						:					int     ,			SCREAMING_SNAKE_CASE						:					dict[int, list[int]]     ,			SCREAMING_SNAKE_CASE						:					int = 1     ,			):







 """simple docstring"""



 UpperCamelCase__       :     Any 							= 0
 UpperCamelCase__       :     Queue[int] 							= Queue(maxsize=SCREAMING_SNAKE_CASE  )
 q.put(SCREAMING_SNAKE_CASE  )
 while q.qsize() != 0:
  UpperCamelCase__       :     List[str] 							= q.get()
  for v in graph[u]:
   if level[v] == -1:
    UpperCamelCase__       :     Union[str, Any] 							= level[u] + 1
    q.put(SCREAMING_SNAKE_CASE  )
    UpperCamelCase__       :     Optional[Any] 							= u
 return level, parent

def       _a	(					):







 """simple docstring"""



 UpperCamelCase__       :     Union[str, Any] 							= 13
 # initializing with 0
 UpperCamelCase__       :     Optional[int] 							= [[0 for _ in range(max_node + 10  )] for _ in range(20  )]
 # initializing with -1 which means every node is unvisited
 UpperCamelCase__       :     Optional[Any] 							= [-1 for _ in range(max_node + 10  )]
 UpperCamelCase__       :     dict[int, list[int]] 							= {
     1: [2, 3, 4],
     2: [5],
     3: [6, 7],
     4: [8],
     5: [9, 10],
     6: [11],
     7: [],
     8: [12, 13],
     9: [],
     10: [],
     11: [],
     12: [],
     13: [],
 }
 UpperCamelCase__							,					UpperCamelCase__       :     Dict 							= breadth_first_search(SCREAMING_SNAKE_CASE     ,			SCREAMING_SNAKE_CASE     ,			SCREAMING_SNAKE_CASE     ,			SCREAMING_SNAKE_CASE     ,			1  )
 UpperCamelCase__       :     List[str] 							= create_sparse(SCREAMING_SNAKE_CASE     ,			SCREAMING_SNAKE_CASE  )
 print('''LCA of node 1 and 3 is: '''     ,			lowest_common_ancestor(1     ,			3     ,			SCREAMING_SNAKE_CASE     ,			SCREAMING_SNAKE_CASE  )  )
 print('''LCA of node 5 and 6 is: '''     ,			lowest_common_ancestor(5     ,			6     ,			SCREAMING_SNAKE_CASE     ,			SCREAMING_SNAKE_CASE  )  )
 print('''LCA of node 7 and 11 is: '''     ,			lowest_common_ancestor(7     ,			11     ,			SCREAMING_SNAKE_CASE     ,			SCREAMING_SNAKE_CASE  )  )
 print('''LCA of node 6 and 7 is: '''     ,			lowest_common_ancestor(6     ,			7     ,			SCREAMING_SNAKE_CASE     ,			SCREAMING_SNAKE_CASE  )  )
 print('''LCA of node 4 and 12 is: '''     ,			lowest_common_ancestor(4     ,			12     ,			SCREAMING_SNAKE_CASE     ,			SCREAMING_SNAKE_CASE  )  )
 print('''LCA of node 8 and 8 is: '''     ,			lowest_common_ancestor(8     ,			8     ,			SCREAMING_SNAKE_CASE     ,			SCREAMING_SNAKE_CASE  )  )


if __name__ == "__main__":
       main()






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

import PIL.Image
import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionImgaImgPipeline,
    StableDiffusionInpaintPipelineLegacy,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.configuration_utils import FrozenDict
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
from diffusers.utils import deprecate, logging


__UpperCamelCase							:							Any    							=					logging.get_logger(__name__)  # pylint: disable=invalid-name

class    __magic_name__						(  __lowerCAmelCase):
     A:		Dict								=   ["safety_checker", "feature_extractor"]


     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				,						)	->   Optional[Any]:





      '''simple docstring'''






      super().__init__()
      if hasattr(scheduler.config				,						'''steps_offset'''      ) and scheduler.config.steps_offset != 1:
       UpperCamelCase__       :     int 							= (
           F"The configuration file of this scheduler: {scheduler} is outdated. `steps_offset`"
           F" should be set to 1 instead of {scheduler.config.steps_offset}. Please make sure "
           '''to update the config accordingly as leaving `steps_offset` might led to incorrect results'''
           ''' in future versions. If you have downloaded this checkpoint from the Hugging Face Hub,'''
           ''' it would be very nice if you could open a Pull request for the `scheduler/scheduler_config.json`'''
           ''' file'''
       )
       deprecate('''steps_offset!=1'''				,						'''1.0.0'''				,						lowerCamelCase__				,						standard_warn=lowerCamelCase__      )
       UpperCamelCase__       :     int 							= dict(scheduler.config      )
       UpperCamelCase__       :     List[str] 							= 1
       UpperCamelCase__       :     List[str] 							= FrozenDict(lowerCamelCase__      )

      self.register_modules(
          vae=lowerCamelCase__				,						text_encoder=lowerCamelCase__				,						tokenizer=lowerCamelCase__				,						unet=lowerCamelCase__				,						scheduler=lowerCamelCase__				,						safety_checker=lowerCamelCase__				,						feature_extractor=lowerCamelCase__				,						)
      self.register_to_config(requires_safety_checker=lowerCamelCase__      )


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





      '''simple docstring'''






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


     def   UpperCAmelCase__						(   self				:  str				,						lowerCamelCase__				:  Optional[Union[str, int]] = "auto"      )	->   str:





      '''simple docstring'''






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


     def   UpperCAmelCase__						(   self				:  int      )	->   Tuple:





      '''simple docstring'''






      self.enable_attention_slicing(lowerCamelCase__      )


     @torch.no_grad()
     def   UpperCAmelCase__						(   self				:  Optional[Any]				,						lowerCamelCase__				:  Union[str, List[str]]				,						lowerCamelCase__				:  Union[torch.FloatTensor, PIL.Image.Image]				,						lowerCamelCase__				:  Union[torch.FloatTensor, PIL.Image.Image]				,						lowerCamelCase__				:  float = 0.8				,						lowerCamelCase__				:  Optional[int] = 50				,						lowerCamelCase__				:  Optional[float] = 7.5				,						lowerCamelCase__				:  Optional[Union[str, List[str]]] = None				,						lowerCamelCase__				:  Optional[int] = 1				,						lowerCamelCase__				:  Optional[float] = 0.0				,						lowerCamelCase__				:  Optional[torch.Generator] = None				,						lowerCamelCase__				:  Optional[str] = "pil"				,						lowerCamelCase__				:  bool = True				,						lowerCamelCase__				:  Optional[Callable[[int, int, torch.FloatTensor], None]] = None				,						lowerCamelCase__				:  int = 1				,						)	->   Optional[Any]:





      '''simple docstring'''






      return StableDiffusionInpaintPipelineLegacy(**self.components      )(
          prompt=lowerCamelCase__				,						image=lowerCamelCase__				,						mask_image=lowerCamelCase__				,						strength=lowerCamelCase__				,						num_inference_steps=lowerCamelCase__				,						guidance_scale=lowerCamelCase__				,						negative_prompt=lowerCamelCase__				,						num_images_per_prompt=lowerCamelCase__				,						eta=lowerCamelCase__				,						generator=lowerCamelCase__				,						output_type=lowerCamelCase__				,						return_dict=lowerCamelCase__				,						callback=lowerCamelCase__				,						)


     @torch.no_grad()
     def   UpperCAmelCase__						(   self				:  Any				,						lowerCamelCase__				:  Union[str, List[str]]				,						lowerCamelCase__				:  Union[torch.FloatTensor, PIL.Image.Image]				,						lowerCamelCase__				:  float = 0.8				,						lowerCamelCase__				:  Optional[int] = 50				,						lowerCamelCase__				:  Optional[float] = 7.5				,						lowerCamelCase__				:  Optional[Union[str, List[str]]] = None				,						lowerCamelCase__				:  Optional[int] = 1				,						lowerCamelCase__				:  Optional[float] = 0.0				,						lowerCamelCase__				:  Optional[torch.Generator] = None				,						lowerCamelCase__				:  Optional[str] = "pil"				,						lowerCamelCase__				:  bool = True				,						lowerCamelCase__				:  Optional[Callable[[int, int, torch.FloatTensor], None]] = None				,						lowerCamelCase__				:  int = 1				,						**lowerCamelCase__				:  str				,						)	->   str:





      '''simple docstring'''






      return StableDiffusionImgaImgPipeline(**self.components      )(
          prompt=lowerCamelCase__				,						image=lowerCamelCase__				,						strength=lowerCamelCase__				,						num_inference_steps=lowerCamelCase__				,						guidance_scale=lowerCamelCase__				,						negative_prompt=lowerCamelCase__				,						num_images_per_prompt=lowerCamelCase__				,						eta=lowerCamelCase__				,						generator=lowerCamelCase__				,						output_type=lowerCamelCase__				,						return_dict=lowerCamelCase__				,						callback=lowerCamelCase__				,						callback_steps=lowerCamelCase__				,						)


     @torch.no_grad()
     def   UpperCAmelCase__						(   self				:  Optional[int]				,						lowerCamelCase__				:  Union[str, List[str]]				,						lowerCamelCase__				:  int = 512				,						lowerCamelCase__				:  int = 512				,						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				,						)	->   Optional[Any]:





      '''simple docstring'''






      return StableDiffusionPipeline(**self.components      )(
          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__				,						)


