






'''simple docstring'''

from __future__ import annotations

import os
from collections.abc import Mapping

SCREAMING_SNAKE_CASE__											=     tuple[int, int]






class        a_		:

  def __init__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   Any:



        """simple docstring"""






        UpperCamelCase       						=      vertices
        UpperCamelCase       						=      {
            (min(_SCREAMING_SNAKE_CASE   ), max(_SCREAMING_SNAKE_CASE   )): weight for edge, weight in edges.items()
        }

  def 						A__		(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   List[str]:



        """simple docstring"""






        self.vertices.add(edge[0]   )
        self.vertices.add(edge[1]   )
        UpperCamelCase       						=      weight


  def 						A__		(   self   )						->   List[Any]:



        """simple docstring"""






        UpperCamelCase       						=      Graph({min(self.vertices   )}    ,	{}   )
        UpperCamelCase       						=      42
        UpperCamelCase       						=      42
        UpperCamelCase       						=      42
        UpperCamelCase       						=      42

        while len(subgraph.vertices   ) < len(self.vertices   ):
              UpperCamelCase       						=      max(self.edges.values()   ) + 1
              for edge, weight in self.edges.items():
                    if (edge[0] in subgraph.vertices) ^ (edge[1] in subgraph.vertices):
                          if weight < min_weight:
                                UpperCamelCase       						=      edge
                                UpperCamelCase       						=      weight

              subgraph.add_edge(_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )

        return subgraph







def 					lowercase__				(   __UpperCamelCase = "p107_network.txt"					)->				int:
      UpperCamelCase       						=      os.path.abspath(os.path.dirname(__UpperCamelCase					)					)
      UpperCamelCase       						=      os.path.join(__UpperCamelCase	,		__UpperCamelCase					)
      UpperCamelCase       						=      {}
      UpperCamelCase       						=      42
      UpperCamelCase       						=      42
      UpperCamelCase       						=      42

      with open(__UpperCamelCase					) as f:
            UpperCamelCase       						=      f.read().strip().split("""\n"""					)

      UpperCamelCase       						=      [line.split(""","""					) for line in data]

      for edgea in range(1	,		len(__UpperCamelCase					)					):
            for edgea in range(__UpperCamelCase					):
                  if adjaceny_matrix[edgea][edgea] != "-":
                        UpperCamelCase       						=      int(adjaceny_matrix[edgea][edgea]					)

      UpperCamelCase       						=      Graph(set(range(len(__UpperCamelCase					)					)					)	,		__UpperCamelCase					)

      UpperCamelCase       						=      graph.prims_algorithm()

      UpperCamelCase       						=      sum(graph.edges.values()					)
      UpperCamelCase       						=      sum(subgraph.edges.values()					)

      return initial_total - optimal_total


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








'''simple docstring'''

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


SCREAMING_SNAKE_CASE__											=     'CompVis/stable-diffusion-v1-1'
SCREAMING_SNAKE_CASE__											=     'CompVis/stable-diffusion-v1-2'
SCREAMING_SNAKE_CASE__											=     'CompVis/stable-diffusion-v1-3'
SCREAMING_SNAKE_CASE__											=     'CompVis/stable-diffusion-v1-4'






class        a_		(    lowerCamelCase       ):

  def __init__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE = True    ,	)						->   Any:



        """simple docstring"""






        super()._init_()

        UpperCamelCase       						=      StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE   )
        UpperCamelCase       						=      StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE   )
        UpperCamelCase       						=      StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE   )
        UpperCamelCase       						=      StableDiffusionPipeline(
            vae=_SCREAMING_SNAKE_CASE    ,	text_encoder=_SCREAMING_SNAKE_CASE    ,	tokenizer=_SCREAMING_SNAKE_CASE    ,	unet=_SCREAMING_SNAKE_CASE    ,	scheduler=_SCREAMING_SNAKE_CASE    ,	safety_checker=_SCREAMING_SNAKE_CASE    ,	feature_extractor=_SCREAMING_SNAKE_CASE    ,	requires_safety_checker=_SCREAMING_SNAKE_CASE    ,	)

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

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



        """simple docstring"""






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

  def 						A__		(   self    ,	_SCREAMING_SNAKE_CASE = "auto"   )						->   Optional[Any]:



        """simple docstring"""






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

  def 						A__		(   self   )						->   Tuple:



        """simple docstring"""






        self.enable_attention_slicing(_SCREAMING_SNAKE_CASE   )

  @torch.no_grad()
  def 						A__		(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE = 512    ,	_SCREAMING_SNAKE_CASE = 512    ,	_SCREAMING_SNAKE_CASE = 50    ,	_SCREAMING_SNAKE_CASE = 7.5    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = 1    ,	_SCREAMING_SNAKE_CASE = 0.0    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = "pil"    ,	_SCREAMING_SNAKE_CASE = True    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = 1    ,	**_SCREAMING_SNAKE_CASE    ,	)						->   List[Any]:



        """simple docstring"""






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

  @torch.no_grad()
  def 						A__		(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE = 512    ,	_SCREAMING_SNAKE_CASE = 512    ,	_SCREAMING_SNAKE_CASE = 50    ,	_SCREAMING_SNAKE_CASE = 7.5    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = 1    ,	_SCREAMING_SNAKE_CASE = 0.0    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = "pil"    ,	_SCREAMING_SNAKE_CASE = True    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = 1    ,	**_SCREAMING_SNAKE_CASE    ,	)						->   List[Any]:



        """simple docstring"""






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

  @torch.no_grad()
  def 						A__		(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE = 512    ,	_SCREAMING_SNAKE_CASE = 512    ,	_SCREAMING_SNAKE_CASE = 50    ,	_SCREAMING_SNAKE_CASE = 7.5    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = 1    ,	_SCREAMING_SNAKE_CASE = 0.0    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = "pil"    ,	_SCREAMING_SNAKE_CASE = True    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = 1    ,	**_SCREAMING_SNAKE_CASE    ,	)						->   Dict:



        """simple docstring"""






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

  @torch.no_grad()
  def 						A__		(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE = 512    ,	_SCREAMING_SNAKE_CASE = 512    ,	_SCREAMING_SNAKE_CASE = 50    ,	_SCREAMING_SNAKE_CASE = 7.5    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = 1    ,	_SCREAMING_SNAKE_CASE = 0.0    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = "pil"    ,	_SCREAMING_SNAKE_CASE = True    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = 1    ,	**_SCREAMING_SNAKE_CASE    ,	)						->   str:



        """simple docstring"""






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


  @torch.no_grad()
  def 						A__		(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE = 512    ,	_SCREAMING_SNAKE_CASE = 512    ,	_SCREAMING_SNAKE_CASE = 50    ,	_SCREAMING_SNAKE_CASE = 7.5    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = 1    ,	_SCREAMING_SNAKE_CASE = 0.0    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = "pil"    ,	_SCREAMING_SNAKE_CASE = True    ,	_SCREAMING_SNAKE_CASE = None    ,	_SCREAMING_SNAKE_CASE = 1    ,	**_SCREAMING_SNAKE_CASE    ,	)						->   List[str]:



        """simple docstring"""






        UpperCamelCase       						=      """cuda""" if torch.cuda.is_available() else """cpu"""
        self.to(_SCREAMING_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
        UpperCamelCase       						=      self.textaimg_sda_a(
            prompt=_SCREAMING_SNAKE_CASE    ,	height=_SCREAMING_SNAKE_CASE    ,	width=_SCREAMING_SNAKE_CASE    ,	num_inference_steps=_SCREAMING_SNAKE_CASE    ,	guidance_scale=_SCREAMING_SNAKE_CASE    ,	negative_prompt=_SCREAMING_SNAKE_CASE    ,	num_images_per_prompt=_SCREAMING_SNAKE_CASE    ,	eta=_SCREAMING_SNAKE_CASE    ,	generator=_SCREAMING_SNAKE_CASE    ,	latents=_SCREAMING_SNAKE_CASE    ,	output_type=_SCREAMING_SNAKE_CASE    ,	return_dict=_SCREAMING_SNAKE_CASE    ,	callback=_SCREAMING_SNAKE_CASE    ,	callback_steps=_SCREAMING_SNAKE_CASE    ,	**_SCREAMING_SNAKE_CASE    ,	)

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

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

        # Get first result from Stable Diffusion Checkpoint v1.4
        UpperCamelCase       						=      self.textaimg_sda_a(
            prompt=_SCREAMING_SNAKE_CASE    ,	height=_SCREAMING_SNAKE_CASE    ,	width=_SCREAMING_SNAKE_CASE    ,	num_inference_steps=_SCREAMING_SNAKE_CASE    ,	guidance_scale=_SCREAMING_SNAKE_CASE    ,	negative_prompt=_SCREAMING_SNAKE_CASE    ,	num_images_per_prompt=_SCREAMING_SNAKE_CASE    ,	eta=_SCREAMING_SNAKE_CASE    ,	generator=_SCREAMING_SNAKE_CASE    ,	latents=_SCREAMING_SNAKE_CASE    ,	output_type=_SCREAMING_SNAKE_CASE    ,	return_dict=_SCREAMING_SNAKE_CASE    ,	callback=_SCREAMING_SNAKE_CASE    ,	callback_steps=_SCREAMING_SNAKE_CASE    ,	**_SCREAMING_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]]   )
