


'''simple docstring'''






def 		_A			(lowerCAmelCase__					:int						)				->					None:




     '''simple docstring'''



     _a      =							generate_pascal_triangle(lowerCAmelCase__						)
     for row_idx in range(lowerCAmelCase__						):
          # Print left spaces
          for _ in range(num_rows - row_idx - 1						):
               print(end=' '						)
          # Print row values
          for col_idx in range(row_idx + 1						):
               if col_idx != row_idx:
                    print(triangle[row_idx][col_idx]			,  end=' '						)
               else:
                    print(triangle[row_idx][col_idx]			,  end=''						)
          print()






def 		_A			(lowerCAmelCase__					:int						)				->					list[list[int]]:




     '''simple docstring'''



     if not isinstance(lowerCAmelCase__			,  lowerCAmelCase__						):
          raise TypeError('The input value of \'num_rows\' should be \'int\''						)

     if num_rows == 0:
          return []
     elif num_rows < 0:
          raise ValueError(
              'The input value of \'num_rows\' should be greater than or equal to 0'						)

     _a      =							[]
     for current_row_idx in range(lowerCAmelCase__						):
          _a      =							populate_current_row(lowerCAmelCase__			,  lowerCAmelCase__						)
          triangle.append(lowerCAmelCase__						)
     return triangle






def 		_A			(lowerCAmelCase__					:list[list[int]]			,  lowerCAmelCase__					:int						)				->					list[int]:




     '''simple docstring'''



     _a      =							[-1] * (current_row_idx + 1)
     # first and last elements of current row are equal to 1
     _a ,				_a      =							1, 1
     for current_col_idx in range(1			,  lowerCAmelCase__						):
          calculate_current_element(
              lowerCAmelCase__			,  lowerCAmelCase__			,  lowerCAmelCase__			,  lowerCAmelCase__						)
     return current_row






def 		_A			(lowerCAmelCase__					:list[list[int]]			,  lowerCAmelCase__					:list[int]			,  lowerCAmelCase__					:int			,  lowerCAmelCase__					:int			,  )				->					None:




     '''simple docstring'''



     _a      =							triangle[current_row_idx - 1][current_col_idx - 1]
     _a      =							triangle[current_row_idx - 1][current_col_idx]
     _a      =							above_to_left_elt + above_to_right_elt






def 		_A			(lowerCAmelCase__					:int						)				->					list[list[int]]:




     '''simple docstring'''



     if not isinstance(lowerCAmelCase__			,  lowerCAmelCase__						):
          raise TypeError('The input value of \'num_rows\' should be \'int\''						)

     if num_rows == 0:
          return []
     elif num_rows < 0:
          raise ValueError(
              'The input value of \'num_rows\' should be greater than or equal to 0'						)

     _a      =							[[1]]

     for row_index in range(1			,  lowerCAmelCase__						):
          _a      =							[0] + result[-1] + [0]
          _a      =							row_index + 1
          # Calculate the number of distinct elements in a row
          _a      =							sum(divmod(lowerCAmelCase__			,  2						)						)
          _a      =							[
              temp_row[i - 1] + temp_row[i] for i in range(1			,  distinct_elements + 1						)
          ]
          _a      =							row_first_half[: (row_index + 1) // 2]
          row_second_half.reverse()
          _a      =							row_first_half + row_second_half
          result.append(lowerCAmelCase__						)

     return result






def 		_A			()				->					None:




     '''simple docstring'''



     from collections.abc import Callable
     from timeit import timeit

     def benchmark_a_function(lowerCAmelCase__					:Callable			,  lowerCAmelCase__					:int						) -> None:
          _a      =							f'{func.__name__}({value})'
          _a      =							timeit(f'__main__.{call}'			,  setup='import __main__'						)
          # print(f"{call:38} = {func(value)} -- {timing:.4f} seconds")
          print(f'{call:38} -- {timing:.4f} seconds'						)

     for value in range(15						):  # (1, 7, 14):
          for func in (generate_pascal_triangle, generate_pascal_triangle_optimized):
               benchmark_a_function(lowerCAmelCase__			,  lowerCAmelCase__						)
          print()


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  benchmark()





'''simple docstring'''






from __future__ import annotations

from sys import maxsize
from typing import Generic, TypeVar

a_   :      Optional[Any]				    =      TypeVar("T")






def 		_A			(lowerCAmelCase__					:int						)				->					int:




     '''simple docstring'''



     return (position - 1) // 2






def 		_A			(lowerCAmelCase__					:int						)				->					int:




     '''simple docstring'''



     return (2 * position) + 1






def 		_A			(lowerCAmelCase__					:int						)				->					int:




     '''simple docstring'''



     return (2 * position) + 2




class 	a       (       Generic[T]    ):
 def __init__(	self  )   ->							None:
      _a      =							[]
      _a      =							{}
      _a      =							0
 def __len__(	self  )   ->							int:
      return self.elements
 def __repr__(	self  )   ->							str:
      return str(self.heap  )
 def 							__UpperCAmelCase						(	self  )   ->							bool:
      # Check if the priority queue is empty
      return self.elements == 0
 def 							__UpperCAmelCase						(	self ,			__magic_name__ ,			__magic_name__  )   ->							None:
      # Add an element with given priority to the queue
      self.heap.append((elem, weight)  )
      _a      =							self.elements
      self.elements += 1
      self._bubble_up(__magic_name__  )
 def 							__UpperCAmelCase						(	self  )   ->							T:
      # Remove and return the element with lowest weight (highest priority)
      if self.elements > 1:
           self._swap_nodes(0 ,			self.elements - 1  )
      _a ,				_a      =							self.heap.pop()
      del self.position_map[elem]
      self.elements -= 1
      if self.elements > 0:
           _a ,				_a      =							self.heap[0]
           self._bubble_down(__magic_name__  )
      return elem
 def 							__UpperCAmelCase						(	self ,			__magic_name__ ,			__magic_name__  )   ->							None:
      # Update the weight of the given key
      _a      =							self.position_map[elem]
      _a      =							(elem, weight)
      if position > 0:
           _a      =							get_parent_position(__magic_name__  )
           _a ,				_a      =							self.heap[parent_position]
           if parent_weight > weight:
                self._bubble_up(__magic_name__  )
           else:
                self._bubble_down(__magic_name__  )
      else:
           self._bubble_down(__magic_name__  )
 def 							__UpperCAmelCase						(	self ,			__magic_name__  )   ->							None:
      # Place a node at the proper position (upward movement) [to be used internally
      # only]
      _a      =							self.position_map[elem]
      if curr_pos == 0:
           return None
      _a      =							get_parent_position(__magic_name__  )
      _a ,				_a      =							self.heap[curr_pos]
      _a ,				_a      =							self.heap[parent_position]
      if parent_weight > weight:
           self._swap_nodes(__magic_name__ ,			__magic_name__  )
           return self._bubble_up(__magic_name__  )
      return None
 def 							__UpperCAmelCase						(	self ,			__magic_name__  )   ->							None:
      # Place a node at the proper position (downward movement) [to be used
      # internally only]
      _a      =							self.position_map[elem]
      _a ,				_a      =							self.heap[curr_pos]
      _a      =							get_child_left_position(__magic_name__  )
      _a      =							get_child_right_position(__magic_name__  )
      if child_left_position < self.elements and child_right_position < self.elements:
           _a ,				_a      =							self.heap[child_left_position]
           _a ,				_a      =							self.heap[child_right_position]
           if child_right_weight < child_left_weight and child_right_weight < weight:
                self._swap_nodes(__magic_name__ ,			__magic_name__  )
                return self._bubble_down(__magic_name__  )
      if child_left_position < self.elements:
           _a ,				_a      =							self.heap[child_left_position]
           if child_left_weight < weight:
                self._swap_nodes(__magic_name__ ,			__magic_name__  )
                return self._bubble_down(__magic_name__  )
      else:
           return None
      if child_right_position < self.elements:
           _a ,				_a      =							self.heap[child_right_position]
           if child_right_weight < weight:
                self._swap_nodes(__magic_name__ ,			__magic_name__  )
                return self._bubble_down(__magic_name__  )
      return None




 def 							__UpperCAmelCase						(	self ,			__magic_name__ ,			__magic_name__  )   ->							None:
      # Swap the nodes at the given positions
      _a      =							self.heap[nodea_pos][0]
      _a      =							self.heap[nodea_pos][0]
      _a ,				_a      =							(
          self.heap[nodea_pos],
          self.heap[nodea_pos],
      )
      _a      =							nodea_pos
      _a      =							nodea_pos





class 	a       (       Generic[T]    ):
 def __init__(	self  )   ->							None:
      _a      =							{}
      _a      =							0
 def __repr__(	self  )   ->							str:
      return str(self.connections  )
 def __len__(	self  )   ->							int:
      return self.nodes
 def 							__UpperCAmelCase						(	self ,			__magic_name__  )   ->							None:
      # Add a node in the graph if it is not in the graph
      if node not in self.connections:
           _a      =							{}
           self.nodes += 1




 def 							__UpperCAmelCase						(	self ,			__magic_name__ ,			__magic_name__ ,			__magic_name__  )   ->							None:
      # Add an edge between 2 nodes in the graph
      self.add_node(__magic_name__  )
      self.add_node(__magic_name__  )
      _a      =							weight
      _a      =							weight






def 		_A			(lowerCAmelCase__					:GraphUndirectedWeighted[T]			,  )				->					tuple[dict[T, int], dict[T, T | None]]:




     '''simple docstring'''



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

     _a      =							MinPriorityQueue()
     for node, weight in dist.items():
          priority_queue.push(lowerCAmelCase__			,  lowerCAmelCase__						)

     if priority_queue.is_empty():
          return dist, parent

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

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

