



from __future__ import annotations

from sys import maxsize
from typing import Generic, TypeVar

a_    :  int						  =		TypeVar('T')

def      __lowercase(						UpperCAmelCase__			):


      """simple docstring"""



      return (position - 1) // 2

def      __lowercase(						UpperCAmelCase__			):


      """simple docstring"""



      return (2 * position) + 1

def      __lowercase(						UpperCAmelCase__			):


      """simple docstring"""



      return (2 * position) + 2





class  lowerCamelCase__	(    Generic[T]):
     """simple docstring"""



     def __init__(self     ):






           '''simple docstring'''



           lowerCamelCase             =		[]
           lowerCamelCase             =		{}
           lowerCamelCase             =		0







     def __len__(self     ):






           '''simple docstring'''



           return self.elements







     def __repr__(self     ):






           '''simple docstring'''



           return str(self.heap     )







     def     _a   (self     ):






           '''simple docstring'''



           return self.elements == 0







     def     _a   (self					,      __a					,      __a     ):






           '''simple docstring'''



           self.heap.append((elem, weight)     )
           lowerCamelCase             =		self.elements
           self.elements += 1
           self._bubble_up(_snake_case     )







     def     _a   (self     ):






           '''simple docstring'''



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







     def     _a   (self					,      __a					,      __a     ):






           '''simple docstring'''



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







     def     _a   (self					,      __a     ):






           '''simple docstring'''



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







     def     _a   (self					,      __a     ):






           '''simple docstring'''



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







     def     _a   (self					,      __a					,      __a     ):






           '''simple docstring'''



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





class  lowerCamelCase__	(    Generic[T]):
     """simple docstring"""



     def __init__(self     ):






           '''simple docstring'''



           lowerCamelCase             =		{}
           lowerCamelCase             =		0







     def __repr__(self     ):






           '''simple docstring'''



           return str(self.connections     )







     def __len__(self     ):






           '''simple docstring'''



           return self.nodes







     def     _a   (self					,      __a     ):






           '''simple docstring'''



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







     def     _a   (self					,      __a					,      __a					,      __a     ):






           '''simple docstring'''



           self.add_node(_snake_case     )
           self.add_node(_snake_case     )
           lowerCamelCase             =		weight
           lowerCamelCase             =		weight



def      __lowercase(						UpperCAmelCase__ , ):


      """simple docstring"""



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

      lowerCamelCase             =		MinPriorityQueue()
      for node, weight in dist.items():
            priority_queue.push(_UpperCAmelCase , _UpperCAmelCase			)

      if priority_queue.is_empty():
            return dist, parent

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

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






"""simple docstring"""
from __future__ import annotations

import requests

def 		_SCREAMING_SNAKE_CASE			(_UpperCAmelCase					:    str			):
 lowerCAmelCase    				= F'https://hacker-news.firebaseio.com/v0/item/{story_id}.json?print=pretty'
 return requests.get(_UpperCAmelCase			).json()

def 		_SCREAMING_SNAKE_CASE			(_UpperCAmelCase					:    int = 10			):
 lowerCAmelCase    				= 'https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty'
 lowerCAmelCase    				= requests.get(_UpperCAmelCase			).json()[:max_stories]
 return [get_hackernews_story(_UpperCAmelCase			) for story_id in story_ids]

def 		_SCREAMING_SNAKE_CASE			(_UpperCAmelCase					:    int = 10			):
 lowerCAmelCase    				= hackernews_top_stories(_UpperCAmelCase			)
 return "\n".join('* [{title}]({url})'.format(**_UpperCAmelCase			) for story in stories			)


if __name__ == "__main__":
       print(hackernews_top_stories_as_markdown())





