





import colorsys

from PIL import Image  # type: ignore




def     a__ (					lowercase__  ,    lowercase__  ,    lowercase__  ):






   '''simple docstring'''






   UpperCAmelCase_     :   List[Any]											=x
   UpperCAmelCase_     :   List[Any]											=y
   for step in range(lowercase__  ):  # noqa: B007
      UpperCAmelCase_     :   Union[str, Any]											=a * a - b * b + x
      UpperCAmelCase_     :   str											=2 * a * b + y
      UpperCAmelCase_     :   List[Any]											=a_new

      # divergence happens for all complex number with an absolute value
      # greater than 4
      if a * a + b * b > 4:
         break
   return step / (max_step - 1)




def     a__ (					lowercase__  ):






   '''simple docstring'''






   if distance == 1:
      return (0, 0, 0)
   else:
      return (2_5_5, 2_5_5, 2_5_5)




def     a__ (					lowercase__  ):






   '''simple docstring'''






   if distance == 1:
      return (0, 0, 0)
   else:
      return tuple(round(i * 2_5_5  ) for i in colorsys.hsv_to_rgb(lowercase__  ,    1  ,    1  )  )




def     a__ (					lowercase__ = 8_0_0  ,    lowercase__ = 6_0_0  ,    lowercase__ = -0.6  ,    lowercase__ = 0  ,    lowercase__ = 3.2  ,    lowercase__ = 5_0  ,    lowercase__ = True  ,    ):






   '''simple docstring'''






   UpperCAmelCase_     :   Any											=Image.new("RGB"  ,    (image_width, image_height)  )
   UpperCAmelCase_     :   Tuple											=img.load()

   # loop through the image-coordinates
   for image_x in range(lowercase__  ):
      for image_y in range(lowercase__  ):
         # determine the figure-coordinates based on the image-coordinates
         UpperCAmelCase_     :   int											=figure_width / image_width * image_height
         UpperCAmelCase_     :   str											=figure_center_x + (image_x / image_width - 0.5) * figure_width
         UpperCAmelCase_     :   Optional[Any]											=figure_center_y + (image_y / image_height - 0.5) * figure_height

         UpperCAmelCase_     :   str											=get_distance(lowercase__  ,    lowercase__  ,    lowercase__  )

         # color the corresponding pixel based on the selected coloring-function
         if use_distance_color_coding:
            UpperCAmelCase_     :   Union[str, Any]											=get_color_coded_rgb(lowercase__  )
         else:
            UpperCAmelCase_     :   int											=get_black_and_white_rgb(lowercase__  )

   return img


if __name__ == "__main__":
     import doctest

     doctest.testmod()

     # colored version, full figure
     __lowercase  :   Tuple						      =get_image()

     # uncomment for colored version, different section, zoomed in
     # img = get_image(figure_center_x = -0.6, figure_center_y = -0.4,
     # figure_width = 0.8)

     # uncomment for black and white version, full figure
     # img = get_image(use_distance_color_coding = False)

     # uncomment to save the image
     # img.save("mandelbrot.png")

     img.show()











from __future__ import annotations

from sys import maxsize
from typing import Generic, TypeVar

__lowercase  :   Optional[int]						      =TypeVar("""T""")




def     a__ (					lowercase__  ):






   '''simple docstring'''






   return (position - 1) // 2




def     a__ (					lowercase__  ):






   '''simple docstring'''






   return (2 * position) + 1




def     a__ (					lowercase__  ):






   '''simple docstring'''






   return (2 * position) + 2

class      A       (	Generic[T]						):



      def __init__(	self:						List[str]       )						->    None:
         '''simple docstring'''

         UpperCAmelCase_											=[]
         UpperCAmelCase_											={}
         UpperCAmelCase_											=0



      def __len__(	self:						Union[str, Any]       )						->    int:
         '''simple docstring'''

         return self.elements



      def __repr__(	self:						Dict       )						->    str:
         '''simple docstring'''

         return str(self.heap       )



      def 	lowerCAmelCase__    (	self:						Any       )						->    bool:
         '''simple docstring'''

         return self.elements == 0



      def 	lowerCAmelCase__    (	self:						Optional[int]		,  _lowerCAmelCase:						T		,  _lowerCAmelCase:						int       )						->    None:
         '''simple docstring'''

         self.heap.append((elem, weight)       )
         UpperCAmelCase_											=self.elements
         self.elements += 1
         self._bubble_up(_lowerCAmelCase       )



      def 	lowerCAmelCase__    (	self:						Tuple       )						->    T:
         '''simple docstring'''

         if self.elements > 1:
            self._swap_nodes(0		,  self.elements - 1       )
         UpperCAmelCase_						,       UpperCAmelCase_											=self.heap.pop()
         del self.position_map[elem]
         self.elements -= 1
         if self.elements > 0:
            UpperCAmelCase_						,       UpperCAmelCase_											=self.heap[0]
            self._bubble_down(_lowerCAmelCase       )
         return elem



      def 	lowerCAmelCase__    (	self:						Optional[Any]		,  _lowerCAmelCase:						T		,  _lowerCAmelCase:						int       )						->    None:
         '''simple docstring'''

         UpperCAmelCase_											=self.position_map[elem]
         UpperCAmelCase_											=(elem, weight)
         if position > 0:
            UpperCAmelCase_											=get_parent_position(_lowerCAmelCase       )
            UpperCAmelCase_						,       UpperCAmelCase_											=self.heap[parent_position]
            if parent_weight > weight:
               self._bubble_up(_lowerCAmelCase       )
            else:
               self._bubble_down(_lowerCAmelCase       )
         else:
            self._bubble_down(_lowerCAmelCase       )



      def 	lowerCAmelCase__    (	self:						Any		,  _lowerCAmelCase:						T       )						->    None:
         '''simple docstring'''

         UpperCAmelCase_											=self.position_map[elem]
         if curr_pos == 0:
            return None
         UpperCAmelCase_											=get_parent_position(_lowerCAmelCase       )
         UpperCAmelCase_						,       UpperCAmelCase_											=self.heap[curr_pos]
         UpperCAmelCase_						,       UpperCAmelCase_											=self.heap[parent_position]
         if parent_weight > weight:
            self._swap_nodes(_lowerCAmelCase		,  _lowerCAmelCase       )
            return self._bubble_up(_lowerCAmelCase       )
         return None



      def 	lowerCAmelCase__    (	self:						Optional[Any]		,  _lowerCAmelCase:						T       )						->    None:
         '''simple docstring'''

         UpperCAmelCase_											=self.position_map[elem]
         UpperCAmelCase_						,       UpperCAmelCase_											=self.heap[curr_pos]
         UpperCAmelCase_											=get_child_left_position(_lowerCAmelCase       )
         UpperCAmelCase_											=get_child_right_position(_lowerCAmelCase       )
         if child_left_position < self.elements and child_right_position < self.elements:
            UpperCAmelCase_						,       UpperCAmelCase_											=self.heap[child_left_position]
            UpperCAmelCase_						,       UpperCAmelCase_											=self.heap[child_right_position]
            if child_right_weight < child_left_weight and child_right_weight < weight:
               self._swap_nodes(_lowerCAmelCase		,  _lowerCAmelCase       )
               return self._bubble_down(_lowerCAmelCase       )
         if child_left_position < self.elements:
            UpperCAmelCase_						,       UpperCAmelCase_											=self.heap[child_left_position]
            if child_left_weight < weight:
               self._swap_nodes(_lowerCAmelCase		,  _lowerCAmelCase       )
               return self._bubble_down(_lowerCAmelCase       )
         else:
            return None
         if child_right_position < self.elements:
            UpperCAmelCase_						,       UpperCAmelCase_											=self.heap[child_right_position]
            if child_right_weight < weight:
               self._swap_nodes(_lowerCAmelCase		,  _lowerCAmelCase       )
               return self._bubble_down(_lowerCAmelCase       )
         return None






      def 	lowerCAmelCase__    (	self:						Optional[Any]		,  _lowerCAmelCase:						int		,  _lowerCAmelCase:						int       )						->    None:
         '''simple docstring'''

         UpperCAmelCase_											=self.heap[nodea_pos][0]
         UpperCAmelCase_											=self.heap[nodea_pos][0]
         UpperCAmelCase_						,       UpperCAmelCase_											=(
             self.heap[nodea_pos],
             self.heap[nodea_pos],
         )
         UpperCAmelCase_											=nodea_pos
         UpperCAmelCase_											=nodea_pos

class      A       (	Generic[T]						):



      def __init__(	self:						Tuple       )						->    None:
         '''simple docstring'''

         UpperCAmelCase_											={}
         UpperCAmelCase_											=0



      def __repr__(	self:						List[str]       )						->    str:
         '''simple docstring'''

         return str(self.connections       )



      def __len__(	self:						Optional[Any]       )						->    int:
         '''simple docstring'''

         return self.nodes



      def 	lowerCAmelCase__    (	self:						Union[str, Any]		,  _lowerCAmelCase:						T       )						->    None:
         '''simple docstring'''

         if node not in self.connections:
            UpperCAmelCase_											={}
            self.nodes += 1






      def 	lowerCAmelCase__    (	self:						Optional[Any]		,  _lowerCAmelCase:						T		,  _lowerCAmelCase:						T		,  _lowerCAmelCase:						int       )						->    None:
         '''simple docstring'''

         self.add_node(_lowerCAmelCase       )
         self.add_node(_lowerCAmelCase       )
         UpperCAmelCase_											=weight
         UpperCAmelCase_											=weight




def     a__ (					lowercase__  ,    ):






   '''simple docstring'''






   UpperCAmelCase_											={node: maxsize for node in graph.connections}
   UpperCAmelCase_											={node: None for node in graph.connections}

   UpperCAmelCase_											=MinPriorityQueue()
   for node, weight in dist.items():
      priority_queue.push(lowercase__  ,    lowercase__  )

   if priority_queue.is_empty():
      return dist, parent

   # initialization
   UpperCAmelCase_											=priority_queue.extract_min()
   UpperCAmelCase_											=0
   for neighbour in graph.connections[node]:
      if dist[neighbour] > dist[node] + graph.connections[node][neighbour]:
         UpperCAmelCase_											=dist[node] + graph.connections[node][neighbour]
         priority_queue.update_key(lowercase__  ,    dist[neighbour]  )
         UpperCAmelCase_											=node

    # running prim's algorithm
   while not priority_queue.is_empty():
      UpperCAmelCase_											=priority_queue.extract_min()
      for neighbour in graph.connections[node]:
         if dist[neighbour] > dist[node] + graph.connections[node][neighbour]:
            UpperCAmelCase_											=dist[node] + graph.connections[node][neighbour]
            priority_queue.update_key(lowercase__  ,    dist[neighbour]  )
            UpperCAmelCase_											=node
   return dist, parent




